Order   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 69
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A refund() 0 4 1
A create() 0 3 1
A get() 0 3 1
A cancel() 0 3 1
A capture() 0 3 1
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