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
|
|
|
/** @var bool */ |
27
|
|
|
private $allowMultiCurrency; |
28
|
|
|
|
29
|
|
|
public function initialise(string $apiKey, string $type, bool $sandbox = true, bool $allowMultiCurrency = false): void |
30
|
|
|
{ |
31
|
|
|
$this->type = $type; |
32
|
|
|
$this->allowMultiCurrency = $allowMultiCurrency; |
33
|
|
|
|
34
|
|
|
$this->client = new Client(); |
35
|
|
|
$this->client->setApiKey($apiKey); |
36
|
|
|
$this->client->setApiUrl( |
37
|
|
|
$sandbox ? self::API_URL_TEST : self::API_URL_LIVE |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function createPayment(array $data): Orders |
42
|
|
|
{ |
43
|
|
|
$this->client->orders->post($data); |
44
|
|
|
|
45
|
|
|
return $this->client->orders; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getOrderById(string $id): \stdClass |
49
|
|
|
{ |
50
|
|
|
return $this->client->orders->get('orders', $id); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getType(): string |
54
|
|
|
{ |
55
|
|
|
return $this->type; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getAllowMultiCurrency(): bool |
59
|
|
|
{ |
60
|
|
|
return $this->allowMultiCurrency; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function refund(string $orderId, int $amount, string $currencyCode): void |
64
|
|
|
{ |
65
|
|
|
$endpoint = sprintf('orders/%s/refunds', $orderId); |
66
|
|
|
|
67
|
|
|
$this->client->orders->post([ |
68
|
|
|
'type' => 'refund', |
69
|
|
|
'amount' => $amount, |
70
|
|
|
'currency' => $currencyCode, |
71
|
|
|
], $endpoint); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function isPaymentActive(string $status): bool |
75
|
|
|
{ |
76
|
|
|
return in_array($status, [self::STATUS_INITIALIZED, self::STATUS_COMPLETED, self::STATUS_UNCLEARED, self::STATUS_RESERVED], true); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|