feat: implement SMS notification service and integrate with existing services
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Sms;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use RuntimeException;
|
||||
|
||||
class IranPayamakService
|
||||
{
|
||||
public function sendPattern(string $phone, string $patternKey, array $attributes): array
|
||||
{
|
||||
$response = Http::withHeaders([
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
'Api-Key' => config('services.iranpayamak.api_key'),
|
||||
])->post(config('services.iranpayamak.api_url'), [
|
||||
'code' => config("services.iranpayamak.patterns.{$patternKey}"),
|
||||
'attributes' => $attributes,
|
||||
'recipient' => $this->formatRecipient($phone),
|
||||
'line_number' => config('services.iranpayamak.line_number'),
|
||||
'number_format' => 'english',
|
||||
]);
|
||||
|
||||
if (!$response->successful()) {
|
||||
throw new RuntimeException('SMS sending failed: ' . $response->status() . ' ' . $response->body());
|
||||
}
|
||||
|
||||
return $response->json() ?? [];
|
||||
}
|
||||
|
||||
protected function formatRecipient(string $phone): string
|
||||
{
|
||||
if (str_starts_with($phone, '+98')) {
|
||||
return '0' . substr($phone, 3);
|
||||
}
|
||||
|
||||
return $phone;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user