feat: implement SMS notification service and integrate with existing services

This commit is contained in:
2026-09-21 02:47:12 +03:30
parent 51b13631a3
commit 1e599b917b
9 changed files with 153 additions and 48 deletions
+39
View File
@@ -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;
}
}