Skip to content

Instantly share code, notes, and snippets.

@cygeorgel

cygeorgel/ovhClick2Call

Last active Mar 1, 2021
Embed
What would you like to do?
OVH Click 2 Call
<?php
namespace App\Http\Controllers;
use App\ConfigOvh;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
use Ovh\Api;
class OvhClick2CallController extends Controller
{
public function test()
{
return view('admin.ovhClick2Call.test');
}
/**
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Validation\ValidationException
* @throws \Ovh\Exceptions\InvalidParameterException
*/
public function click2Call(Request $request)
{
$this->validate(request(), [
'calledNumber' => 'required',
]);
$calledNumber = phoneNumberFormat($request->calledNumber);
if (ConfigOvh::where('active', true)->where('click2Call', true)->count()) {
if (! empty(Auth::user()->ovhBillingAccount)
&& ! empty(Auth::user()->ovhCallingNumber)) {
$configOvh = ConfigOvh::where('active', true)->where('click2Call', true)->first();
$api = new Api($configOvh->app_key, $configOvh->app_secret, $configOvh->app_endpoint, $configOvh->app_conskey);
$api->post('/telephony/'.Auth::user()->ovhBillingAccount.'/line/'.Auth::user()->ovhCallingNumber.'/click2Call', [
'calledNumber' => $calledNumber,
'intercom' => true,
]);
flash(__('app.ovhClick2CallUp', ['calledNumber' => $calledNumber]))->success();
return back();
} else {
flash(__('app.ovhClick2CallNotConfigured'))->error();
return back();
}
} else {
flash(__('app.ovhClick2CallNotConfigured'))->error();
return back();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment