|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace tbclla\RevolutMerchant\Resources; |
|
4
|
|
|
|
|
5
|
|
|
class Order extends Resource |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* The Revolut merchant payment orders endpoint |
|
9
|
|
|
* |
|
10
|
|
|
* @var string |
|
11
|
|
|
*/ |
|
12
|
|
|
const ENDPOINT = '/orders'; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Create a new payment order |
|
16
|
|
|
* |
|
17
|
|
|
* @param array $json |
|
18
|
|
|
* @return array The response body |
|
19
|
|
|
* @throws \tbclla\RevolutMerchant\Exceptions\MerchantException |
|
20
|
|
|
*/ |
|
21
|
|
|
public function create(array $json) |
|
22
|
|
|
{ |
|
23
|
|
|
return $this->client->post(self::ENDPOINT, ['json' => $json]); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Retrieve a payment order by its ID |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $id The payment order ID |
|
30
|
|
|
* @return array The response body |
|
31
|
|
|
* @throws \tbclla\RevolutMerchant\Exceptions\MerchantException |
|
32
|
|
|
*/ |
|
33
|
|
|
public function get(string $id) |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->client->get(self::ENDPOINT . '/' . $id); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Capture a authorised payment |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $id The payment order ID |
|
42
|
|
|
* @return array The response body |
|
43
|
|
|
* @throws \tbclla\RevolutMerchant\Exceptions\MerchantException |
|
44
|
|
|
*/ |
|
45
|
|
|
public function capture(string $id) |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->client->post(self::ENDPOINT . '/' . $id . '/capture'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Cancel a payment which has not been captured yet |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $id The payment order ID |
|
54
|
|
|
* @return array The response body |
|
55
|
|
|
* @throws \tbclla\RevolutMerchant\Exceptions\MerchantException |
|
56
|
|
|
*/ |
|
57
|
|
|
public function cancel(string $id) |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->client->post(self::ENDPOINT . '/' . $id . '/cancel'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Create a full or partial refund |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $id The payment order ID |
|
66
|
|
|
* @param array $json The request body |
|
67
|
|
|
* @return array The respone body |
|
68
|
|
|
* @throws \tbclla\RevolutMerchant\Exceptions\MerchantException |
|
69
|
|
|
*/ |
|
70
|
|
|
public function refund(string $id, array $json) |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->client->post(self::ENDPOINT . '/' . $id . '/refund', [ |
|
73
|
|
|
'json' => $json, |
|
74
|
|
|
]); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|