'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; } }