|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Srmklive\PayPal\Traits\PayPalAPI; |
|
4
|
|
|
|
|
5
|
|
|
trait Orders |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* Creates an order. |
|
9
|
|
|
* |
|
10
|
|
|
* @param array $data |
|
11
|
|
|
* |
|
12
|
|
|
* @throws \Throwable |
|
13
|
|
|
* |
|
14
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
|
15
|
|
|
* |
|
16
|
|
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_create |
|
17
|
|
|
*/ |
|
18
|
|
|
public function createOrder(array $data) |
|
19
|
|
|
{ |
|
20
|
|
|
$this->apiEndPoint = "v2/checkout/orders"; |
|
21
|
|
|
$this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/'); |
|
22
|
|
|
|
|
23
|
|
|
$this->options['json'] = (object) $data; |
|
24
|
|
|
|
|
25
|
|
|
$this->verb = 'post'; |
|
26
|
|
|
|
|
27
|
|
|
return $this->doPayPalRequest(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Updates an order with the `CREATED` or `APPROVED` status. |
|
32
|
|
|
* |
|
33
|
|
|
* @param string $order_id |
|
34
|
|
|
* @param array $data |
|
35
|
|
|
* |
|
36
|
|
|
* @throws \Throwable |
|
37
|
|
|
* |
|
38
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
|
39
|
|
|
* |
|
40
|
|
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_patch |
|
41
|
|
|
*/ |
|
42
|
|
|
public function updateOrder($order_id, array $data) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->apiEndPoint = "v2/checkout/orders/{$order_id}"; |
|
45
|
|
|
$this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/'); |
|
46
|
|
|
|
|
47
|
|
|
$this->options['json'] = (object) $data; |
|
48
|
|
|
|
|
49
|
|
|
$this->verb = 'patch'; |
|
50
|
|
|
|
|
51
|
|
|
return $this->doPayPalRequest(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Shows details for an order. |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $order_id |
|
58
|
|
|
* |
|
59
|
|
|
* @throws \Throwable |
|
60
|
|
|
* |
|
61
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
|
62
|
|
|
* |
|
63
|
|
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_get |
|
64
|
|
|
*/ |
|
65
|
|
|
public function showOrderDetails($order_id) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->apiEndPoint = "v2/checkout/orders/{$order_id}"; |
|
68
|
|
|
$this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/'); |
|
69
|
|
|
|
|
70
|
|
|
$this->verb = 'get'; |
|
71
|
|
|
|
|
72
|
|
|
return $this->doPayPalRequest(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Authorizes payment for an order. |
|
77
|
|
|
* |
|
78
|
|
|
* @param string $order_id |
|
79
|
|
|
* @param array $data |
|
80
|
|
|
* |
|
81
|
|
|
* @throws \Throwable |
|
82
|
|
|
* |
|
83
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
|
84
|
|
|
* |
|
85
|
|
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_authorize |
|
86
|
|
|
*/ |
|
87
|
|
|
public function authorizePaymentOrder($order_id, array $data = []) |
|
88
|
|
|
{ |
|
89
|
|
|
$this->apiEndPoint = "v2/checkout/orders/{$order_id}/authorize"; |
|
90
|
|
|
$this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/'); |
|
91
|
|
|
|
|
92
|
|
|
$this->options['json'] = (object) $data; |
|
93
|
|
|
|
|
94
|
|
|
$this->verb = 'post'; |
|
95
|
|
|
|
|
96
|
|
|
return $this->doPayPalRequest(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Captures payment for an order. |
|
101
|
|
|
* |
|
102
|
|
|
* @param string $order_id |
|
103
|
|
|
* @param array $data |
|
104
|
|
|
* |
|
105
|
|
|
* @throws \Throwable |
|
106
|
|
|
* |
|
107
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
|
108
|
|
|
* |
|
109
|
|
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture |
|
110
|
|
|
*/ |
|
111
|
|
|
public function capturePaymentOrder($order_id, array $data = []) |
|
112
|
|
|
{ |
|
113
|
|
|
$this->apiEndPoint = "v2/checkout/orders/{$order_id}/capture"; |
|
114
|
|
|
$this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/'); |
|
115
|
|
|
|
|
116
|
|
|
$this->options['json'] = (object) $data; |
|
117
|
|
|
|
|
118
|
|
|
$this->verb = 'post'; |
|
119
|
|
|
|
|
120
|
|
|
return $this->doPayPalRequest(); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|