feat: update SMS templates and logic to ensure required tokens are present for Kavenegar integration
This commit is contained in:
@@ -43,6 +43,17 @@ class KavehNegarProvider implements SmsProviderInterface
|
||||
}
|
||||
}
|
||||
|
||||
// token/token2/token3 مقدارِ دارای فاصله را رد میکنند؛ فاصله را با نیمفاصله (ZWNJ) جایگزین میکنیم.
|
||||
private const NO_SPACE_SLOTS = ['token', 'token2', 'token3'];
|
||||
|
||||
private function forSlot(string $slot, string $value): string
|
||||
{
|
||||
if (!in_array($slot, self::NO_SPACE_SLOTS, true)) {
|
||||
return $value;
|
||||
}
|
||||
return preg_replace('/\s+/u', "\u{200C}", $value) ?? $value;
|
||||
}
|
||||
|
||||
public function sendTemplate(string $mobile, string $templateCode, array $vars): bool
|
||||
{
|
||||
try {
|
||||
@@ -54,11 +65,12 @@ class KavehNegarProvider implements SmsProviderInterface
|
||||
if ($vars !== [] && array_keys($vars) !== range(0, count($vars) - 1)
|
||||
&& array_diff(array_keys($vars), $slots) === []) {
|
||||
foreach ($vars as $slot => $v) {
|
||||
$params[$slot] = $v;
|
||||
$params[$slot] = $this->forSlot($slot, (string) $v);
|
||||
}
|
||||
} else {
|
||||
foreach (array_values($vars) as $i => $v) {
|
||||
$params['token' . ($i > 0 ? $i + 1 : '')] = $v;
|
||||
$slot = 'token' . ($i > 0 ? $i + 1 : '');
|
||||
$params[$slot] = $this->forSlot($slot, (string) $v);
|
||||
}
|
||||
}
|
||||
$resp = $this->httpClient->request('POST',
|
||||
|
||||
Reference in New Issue
Block a user