Files
eko54r 05fd3230b8
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 5m14s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 17s
Build, Push and Deploy / deploy-staging (push) Successful in 41s
Build, Push and Deploy / deploy-production (push) Has been skipped
update marketing
2026-05-14 11:55:22 +07:00

47 lines
1.2 KiB
PHP

<?php
namespace Modules\MarketingAddon\App\Services;
use Exception;
use Modules\MarketingAddon\App\Models\Smsgateway;
class SmsService
{
public function send(string $phone, $template, array $data)
{
$gateways = Smsgateway::where('status', 1)->where('channel', 'sms')->where('business_id', $template->business_id)->get();
if (empty($gateways)) {
throw new \Exception('No active SMS gateway found for this business.');
}
$response = [
'status' => false,
'message' => 'Something went wrong, Please try again.'
];
$contents = $this->buildContent($template, $data);
foreach ($gateways as $gateway) {
$response = $gateway->namespace::send_message($gateway, $phone, $contents);
if (($response['status'] ?? false) === true) {
return;
}
}
throw new Exception('All SMS gateways failed');
}
protected function buildContent($template, array $data)
{
$message = $template->message;
foreach ($data as $key => $value) {
$message = str_replace('[' . $key . ']', $value, $message);
}
return $message;
}
}