1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2021 SURFnet B.V. |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
|
|
|
|
18
|
|
|
|
19
|
|
|
namespace Surfnet\StepupGateway\ApiBundle\Sms; |
20
|
|
|
|
21
|
|
|
use Psr\Log\LoggerInterface; |
22
|
|
|
use Surfnet\MessageBirdApiClient\Messaging\Message; |
23
|
|
|
use Surfnet\MessageBirdApiClientBundle\Service\MessagingService; |
24
|
|
|
use Surfnet\StepupGateway\ApiBundle\Dto\SmsMessage; |
25
|
|
|
|
26
|
|
|
class MessageBirdService implements SmsAdapterInterface |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
/** |
|
|
|
|
29
|
|
|
* @var MessagingService |
30
|
|
|
*/ |
31
|
|
|
private $messagingService; |
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
|
|
|
|
34
|
|
|
* @var LoggerInterface |
35
|
|
|
*/ |
36
|
|
|
private $logger; |
|
|
|
|
37
|
|
|
|
38
|
|
|
public function __construct(MessagingService $messagingService, LoggerInterface $logger) |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$this->messagingService = $messagingService; |
41
|
|
|
$this->logger = $logger; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function send(SmsMessage $message): SmsMessageResultInterface |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$this->logger->notice('Using MessageBird to send an SMS'); |
47
|
|
|
|
48
|
|
|
$message = new Message($message->originator, $message->recipient, $message->body); |
49
|
|
|
$result = $this->messagingService->send($message); |
50
|
|
|
|
51
|
|
|
if (!$result->isSuccess()) { |
52
|
|
|
$this->logger->warning('Sending OTP per SMS failed.'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return new MessageBirdMessageResult($result); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|