dealhub/app/Actions/PasswordReset/SendOTPToUserAction.php

36 lines
894 B
PHP

<?php
namespace App\Actions\PasswordReset;
use App\Actions\SendPasswordResetMailAction;
use App\Services\TwilioService;
use Twilio\Exceptions\TwilioException;
final readonly class SendOTPToUserAction
{
public function __construct(
private SendPasswordResetMailAction $mailAction,
private TwilioService $twilioService
) {}
/**
* @param array<string, mixed> $data
*
* @throws \Throwable
*/
public function execute(array $data): void
{
['user' => $user,'otp' => $otp] = $data;
$this->mailAction->execute($user->email, $otp);
if ($user?->type->phone !== null) {
try {
$this->twilioService->sendSms($user->type->phone, "Your OTP is $otp");
} catch (TwilioException $e) {
\Log::error('SMS send failed', [$e->getMessage()]);
}
}
}
}