-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmsTransactionApi.php
More file actions
55 lines (46 loc) · 1.89 KB
/
Copy pathSmsTransactionApi.php
File metadata and controls
55 lines (46 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
declare(strict_types=1);
namespace Simpay;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use Simpay\Exception\ExceptionFactory;
use Simpay\Model\Request\ServiceId;
use Simpay\Model\Request\SmsTransactionId;
use Simpay\Model\Response\Pagination;
use Simpay\Model\Response\SmsTransaction;
use Simpay\Model\Response\SmsTransactionCollection;
class SmsTransactionApi implements SmsTransactionInterface
{
private ClientInterface $client;
public function __construct(HttpClientFactoryInterface $factory)
{
$this->client = $factory->create();
}
public function smsTransactionsList(ServiceId $serviceId): SmsTransactionCollection
{
try {
$response = $this->client->request('GET', \sprintf('sms/%s/transactions', $serviceId),);
$data = \json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR,);
$transactions = [];
foreach ($data['data'] as $transaction) {
$transactions[] = SmsTransaction::createFromResponse($transaction);
}
return new SmsTransactionCollection($transactions, Pagination::createFromResponse($data['pagination']), );
} catch (RequestException $exception) {
throw ExceptionFactory::create($exception);
}
}
public function smsTransactionsShow(ServiceId $serviceId, SmsTransactionId $transactionId): SmsTransaction
{
try {
$response = $this->client->request(
'GET',
\sprintf('sms/%s/transactions/%s', $serviceId, $transactionId),
);
$data = \json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR,);
return SmsTransaction::createFromResponse($data['data']);
} catch (RequestException $exception) {
throw ExceptionFactory::create($exception);
}
}
}