ameliabooking
/
src
/
Application
/
Commands
/
Notification
/
SendAmeliaSmsApiRequestCommandHandler.php
GetNotificationsCommand.php
7 years ago
GetNotificationsCommandHandler.php
2 years ago
GetSMSNotificationsHistoryCommand.php
7 years ago
GetSMSNotificationsHistoryCommandHandler.php
2 years ago
SendAmeliaSmsApiRequestCommand.php
7 years ago
SendAmeliaSmsApiRequestCommandHandler.php
2 years ago
SendTestEmailCommand.php
7 years ago
SendTestEmailCommandHandler.php
2 years ago
SendUndeliveredNotificationsCommand.php
4 years ago
SendUndeliveredNotificationsCommandHandler.php
2 years ago
UpdateNotificationCommand.php
7 years ago
UpdateNotificationCommandHandler.php
2 years ago
UpdateNotificationStatusCommand.php
7 years ago
UpdateNotificationStatusCommandHandler.php
2 years ago
UpdateSMSNotificationHistoryCommand.php
7 years ago
UpdateSMSNotificationHistoryCommandHandler.php
1 year ago
SendAmeliaSmsApiRequestCommandHandler.php
59 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Application\Commands\Notification; |
| 4 | |
| 5 | use AmeliaBooking\Application\Commands\CommandHandler; |
| 6 | use AmeliaBooking\Application\Commands\CommandResult; |
| 7 | use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException; |
| 8 | use AmeliaBooking\Application\Services\Notification\SMSAPIService; |
| 9 | use AmeliaBooking\Domain\Entity\Entities; |
| 10 | use Interop\Container\Exception\ContainerException; |
| 11 | |
| 12 | /** |
| 13 | * Class SendAmeliaSmsApiRequestCommandHandler |
| 14 | * |
| 15 | * @package AmeliaBooking\Application\Commands\Notification |
| 16 | */ |
| 17 | class SendAmeliaSmsApiRequestCommandHandler extends CommandHandler |
| 18 | { |
| 19 | /** |
| 20 | * @param SendAmeliaSmsApiRequestCommand $command |
| 21 | * |
| 22 | * @return CommandResult |
| 23 | * |
| 24 | * @throws ContainerException |
| 25 | * @throws AccessDeniedException |
| 26 | */ |
| 27 | public function handle(SendAmeliaSmsApiRequestCommand $command) |
| 28 | { |
| 29 | if (!$this->getContainer()->getPermissionsService()->currentUserCanWrite(Entities::NOTIFICATIONS)) { |
| 30 | throw new AccessDeniedException('You are not allowed to send test email'); |
| 31 | } |
| 32 | |
| 33 | $result = new CommandResult(); |
| 34 | |
| 35 | /** @var SMSAPIService $smsApiService */ |
| 36 | $smsApiService = $this->getContainer()->get('application.smsApi.service'); |
| 37 | |
| 38 | |
| 39 | $action = $command->getField('process'); |
| 40 | |
| 41 | $data = $command->getField('data'); |
| 42 | |
| 43 | $data = apply_filters('amelia_before_send_sms_request_filter', $data, $action); |
| 44 | |
| 45 | do_action('amelia_before_send_sms_request', $data, $action); |
| 46 | |
| 47 | // Call method dynamically and pass data to the function. Method name is the request field. |
| 48 | $apiResponse = $smsApiService->{$action}($data); |
| 49 | |
| 50 | do_action('amelia_after_send_sms_request', $data, $action); |
| 51 | |
| 52 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 53 | $result->setMessage('Amelia SMS API request successful'); |
| 54 | $result->setData($apiResponse); |
| 55 | |
| 56 | return $result; |
| 57 | } |
| 58 | } |
| 59 |