2022-11-02 08:31:46 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2022-11-02 08:31:46 +01:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Jobs\User;
|
|
|
|
|
|
|
|
use App\Libraries\MultiDB;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
2023-02-16 02:36:09 +01:00
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
2022-11-02 08:31:46 +01:00
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
|
|
|
class VerifyPhone implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, MakesHash;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @param User $user
|
|
|
|
*/
|
2023-02-16 02:36:09 +01:00
|
|
|
public function __construct(private User $user)
|
|
|
|
{
|
|
|
|
}
|
2022-11-02 08:31:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
2023-08-07 07:30:34 +02:00
|
|
|
* @return void
|
2022-11-02 08:31:46 +01:00
|
|
|
*/
|
|
|
|
public function handle() : void
|
|
|
|
{
|
2023-02-16 02:36:09 +01:00
|
|
|
MultiDB::checkUserEmailExists($this->user->email);
|
2022-11-02 08:31:46 +01:00
|
|
|
|
2023-02-16 02:36:09 +01:00
|
|
|
$sid = config('ninja.twilio_account_sid');
|
|
|
|
$token = config('ninja.twilio_auth_token');
|
2022-11-02 08:31:46 +01:00
|
|
|
|
2023-02-16 02:36:09 +01:00
|
|
|
if (!$sid) {
|
|
|
|
return;
|
|
|
|
} // no twilio api credentials provided, bail.
|
2022-11-02 08:31:46 +01:00
|
|
|
|
2023-02-16 02:36:09 +01:00
|
|
|
$twilio = new \Twilio\Rest\Client($sid, $token);
|
2022-11-02 08:31:46 +01:00
|
|
|
|
2023-02-16 02:36:09 +01:00
|
|
|
$country = $this->user->account?->companies()?->first()?->country();
|
2022-11-02 08:31:46 +01:00
|
|
|
|
2023-02-16 02:36:09 +01:00
|
|
|
if (!$country || strlen($this->user->phone) < 2) {
|
|
|
|
return;
|
|
|
|
}
|
2022-11-02 08:31:46 +01:00
|
|
|
|
2023-02-16 02:36:09 +01:00
|
|
|
$countryCode = $country->iso_3166_2;
|
2022-11-02 08:31:46 +01:00
|
|
|
|
2023-02-16 02:36:09 +01:00
|
|
|
try {
|
|
|
|
$phone_number = $twilio->lookups->v1->phoneNumbers($this->user->phone)
|
|
|
|
->fetch(["countryCode" => $countryCode]);
|
|
|
|
} catch(\Exception $e) {
|
|
|
|
$this->user->verified_phone_number = false;
|
|
|
|
$this->user->save();
|
|
|
|
return;
|
|
|
|
}
|
2022-11-02 08:31:46 +01:00
|
|
|
|
2023-02-16 02:36:09 +01:00
|
|
|
if ($phone_number && strlen($phone_number->phoneNumber) > 1) {
|
|
|
|
$this->user->phone = $phone_number->phoneNumber;
|
|
|
|
$this->user->verified_phone_number = true;
|
|
|
|
$this->user->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|