1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file has been created by developers from BitBag. |
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
6
|
|
|
* another great project. |
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
8
|
|
|
* an email on [email protected]. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace BitBag\SyliusMultiSafepayPlugin\ApiClient; |
14
|
|
|
|
15
|
|
|
use MultiSafepayAPI\Client; |
16
|
|
|
use MultiSafepayAPI\Object\Orders; |
17
|
|
|
|
18
|
|
|
class MultiSafepayApiClient implements MultiSafepayApiClientInterface |
19
|
|
|
{ |
20
|
|
|
/** @var Client */ |
21
|
|
|
private $client; |
22
|
|
|
|
23
|
|
|
/** @var string */ |
24
|
|
|
private $type; |
25
|
|
|
|
26
|
|
|
public function initialise(string $apiKey, string $type, bool $sandbox = true): void |
27
|
|
|
{ |
28
|
|
|
$this->type = $type; |
29
|
|
|
|
30
|
|
|
$this->client = new Client(); |
31
|
|
|
|
32
|
|
|
$this->client->setApiKey($apiKey); |
33
|
|
|
$this->client->setApiUrl( |
34
|
|
|
$sandbox ? self::API_URL_TEST : self::API_URL_LIVE |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function createPayment(array $data): Orders |
39
|
|
|
{ |
40
|
|
|
$this->client->orders->post($data); |
41
|
|
|
|
42
|
|
|
return $this->client->orders; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getOrderById(string $id): \stdClass |
46
|
|
|
{ |
47
|
|
|
return $this->client->orders->get('orders', $id); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getType(): string |
51
|
|
|
{ |
52
|
|
|
return $this->type; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function refund(string $orderId, int $amount, string $currencyCode): void |
56
|
|
|
{ |
57
|
|
|
$endpoint = sprintf('orders/%s/refunds', $orderId); |
58
|
|
|
|
59
|
|
|
$this->client->orders->post([ |
60
|
|
|
'type' => 'refund', |
61
|
|
|
'amount' => $amount, |
62
|
|
|
'currency' => $currencyCode, |
63
|
|
|
], $endpoint); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function isPaymentActive(string $status): bool |
67
|
|
|
{ |
68
|
|
|
return in_array($status, [self::STATUS_INITIALIZED, self::STATUS_COMPLETED, self::STATUS_UNCLEARED, self::STATUS_RESERVED]); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|