| @@ 14-65 (lines=52) @@ | ||
| 11 | use LBHurtado\EngageSpark\Classes\ServiceMode; |
|
| 12 | use LBHurtado\EngageSpark\Classes\SendHttpApiParams; |
|
| 13 | ||
| 14 | class SendMessage implements ShouldQueue |
|
| 15 | { |
|
| 16 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
|
| 17 | ||
| 18 | /** @var string */ |
|
| 19 | public $mobile; |
|
| 20 | ||
| 21 | /** @var string */ |
|
| 22 | public $message; |
|
| 23 | ||
| 24 | /** @var string */ |
|
| 25 | public $senderId; |
|
| 26 | ||
| 27 | /** @var EngageSpark */ |
|
| 28 | public $service; |
|
| 29 | ||
| 30 | /** |
|
| 31 | * SendMessage constructor. |
|
| 32 | * @param string $mobile |
|
| 33 | * @param string $message |
|
| 34 | * @param string $senderId |
|
| 35 | */ |
|
| 36 | public function __construct(string $mobile, string $message, string $senderId = null) |
|
| 37 | { |
|
| 38 | $this->mobile = $mobile; |
|
| 39 | $this->message = $message; |
|
| 40 | $this->senderId = $senderId; |
|
| 41 | } |
|
| 42 | ||
| 43 | /** |
|
| 44 | * @param EngageSpark $service |
|
| 45 | * @throws \GuzzleHttp\Exception\GuzzleException |
|
| 46 | */ |
|
| 47 | public function handle(EngageSpark $service) |
|
| 48 | { |
|
| 49 | $this->setService($service)->send(); |
|
| 50 | } |
|
| 51 | ||
| 52 | protected function send() |
|
| 53 | { |
|
| 54 | tap(new SendHttpApiParams($this->service, $this->mobile, $this->message, $this->senderId), function ($params) { |
|
| 55 | $this->service->send($params->toArray(), ServiceMode::SMS); |
|
| 56 | }); |
|
| 57 | } |
|
| 58 | ||
| 59 | protected function setService(EngageSpark $service) |
|
| 60 | { |
|
| 61 | $this->service = $service; |
|
| 62 | ||
| 63 | return $this; |
|
| 64 | } |
|
| 65 | } |
|
| 66 | ||
| @@ 14-64 (lines=51) @@ | ||
| 11 | use LBHurtado\EngageSpark\Classes\ServiceMode; |
|
| 12 | use LBHurtado\EngageSpark\Classes\TopupHttpApiParams; |
|
| 13 | ||
| 14 | class TransferAirtime implements ShouldQueue |
|
| 15 | { |
|
| 16 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
|
| 17 | ||
| 18 | const MODE = 'topup'; |
|
| 19 | ||
| 20 | /** @var string */ |
|
| 21 | public $mobile; |
|
| 22 | ||
| 23 | /** @var int */ |
|
| 24 | public $amount; |
|
| 25 | ||
| 26 | /** @var string */ |
|
| 27 | public $reference; |
|
| 28 | ||
| 29 | /** |
|
| 30 | * TopupAmount constructor. |
|
| 31 | * @param string $mobile |
|
| 32 | * @param int $amount |
|
| 33 | * @param string $reference |
|
| 34 | */ |
|
| 35 | public function __construct(string $mobile, int $amount, string $reference) |
|
| 36 | { |
|
| 37 | $this->mobile = $mobile; |
|
| 38 | $this->amount = $amount; |
|
| 39 | $this->reference = $reference; |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * @param EngageSpark $service |
|
| 44 | * @throws \GuzzleHttp\Exception\GuzzleException |
|
| 45 | */ |
|
| 46 | public function handle(EngageSpark $service) |
|
| 47 | { |
|
| 48 | $this->setService($service)->topup(); |
|
| 49 | } |
|
| 50 | ||
| 51 | protected function topup() |
|
| 52 | { |
|
| 53 | tap(new TopupHttpApiParams($this->service, $this->mobile, $this->amount, $this->reference), function ($params) { |
|
| 54 | $this->service->send($params->toArray(), ServiceMode::TOPUP); |
|
| 55 | }); |
|
| 56 | } |
|
| 57 | ||
| 58 | protected function setService(EngageSpark $service) |
|
| 59 | { |
|
| 60 | $this->service = $service; |
|
| 61 | ||
| 62 | return $this; |
|
| 63 | } |
|
| 64 | } |
|
| 65 | ||