Skip to content

Commit

Permalink
feat: make sender parameter required for faraz sms
Browse files Browse the repository at this point in the history
  • Loading branch information
phrshteh committed Jul 9, 2024
1 parent ad8ea00 commit 6d964be
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
'faraz_sms' => [
'driver_class' => \Omalizadeh\Sms\Drivers\FarazSms\FarazSms::class,
'api_key' => '',
'default_sender' => env('FARAZ_DEFAULT_SENDER', '+983000505')
'default_sender' => env('FARAZ_DEFAULT_SENDER')
],
];
10 changes: 8 additions & 2 deletions src/Drivers/FarazSms/FarazSms.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,14 @@ public function getBulkSmsUrl(): string

protected function mergeSmsOptions(array $data, array $options): array
{
$sender = $options['sender'] ?? $this->getConfig('default_sender');

if (is_null($sender)) {
throw new InvalidParameterException('sender parameter is required for Faraz sms driver.');
}

return array_merge($data, [
'sender' => $options['sender'] ?? $this->getConfig('default_sender'),
'sender' => $sender,
'time' => $options['time'] ?? now()->addSecond(),
]);
}
Expand All @@ -117,7 +123,7 @@ protected function mergeTemplateOptions(array $data, array $options): array
protected function callApi(string $url, array $data)
{
if (empty($apiKey = $this->getConfig('api_key'))) {
throw new InvalidConfigurationException('invalid api_key sms provider config');
throw new InvalidConfigurationException('invalid api_key faraz sms provider config');
}

$response = Http::asJson()->acceptJson()->withHeaders([
Expand Down
8 changes: 8 additions & 0 deletions tests/FarazSmsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,12 @@ public function test_invalid_response_structure_exception()

$this->farazSms->send('09123456789', 'Test message', ['sender' => '1000']);
}

public function test_missing_sender_option_leads_to_exception()
{
$this->expectException(\Omalizadeh\Sms\Exceptions\InvalidParameterException::class);
$this->expectExceptionMessage('sender parameter is required for Faraz sms driver.');

$this->farazSms->send('09123456789', 'Test message');
}
}

0 comments on commit 6d964be

Please sign in to comment.