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
|
|
|
public function updateOrder(string $order_id, array $data)
|
31
|
|
|
{
|
32
|
|
|
$this->apiEndPoint = "v2/checkout/orders/{$order_id}";
|
33
|
|
|
$this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
|
34
|
|
|
|
35
|
|
|
$this->options['json'] = (object) $data;
|
36
|
|
|
|
37
|
|
|
$this->verb = 'patch';
|
38
|
|
|
|
39
|
|
|
return $this->doPayPalRequest();
|
40
|
|
|
}
|
41
|
|
|
|
42
|
|
|
/**
|
43
|
|
|
* Shows details for an order.
|
44
|
|
|
*
|
45
|
|
|
* @param string $order_id
|
46
|
|
|
*
|
47
|
|
|
* @throws \Throwable
|
48
|
|
|
*
|
49
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string
|
50
|
|
|
*
|
51
|
|
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_get
|
52
|
|
|
*/
|
53
|
|
|
public function showOrderDetails($order_id)
|
54
|
|
|
{
|
55
|
|
|
$this->apiEndPoint = "v2/checkout/orders/{$order_id}";
|
56
|
|
|
$this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
|
57
|
|
|
|
58
|
|
|
$this->verb = 'get';
|
59
|
|
|
|
60
|
|
|
return $this->doPayPalRequest();
|
61
|
|
|
}
|
62
|
|
|
|
63
|
|
|
/**
|
64
|
|
|
* Authorizes payment for an order.
|
65
|
|
|
*
|
66
|
|
|
* @param string $order_id
|
67
|
|
|
* @param array $data
|
68
|
|
|
*
|
69
|
|
|
* @throws \Throwable
|
70
|
|
|
*
|
71
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string
|
72
|
|
|
*
|
73
|
|
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_authorize
|
74
|
|
|
*/
|
75
|
|
|
public function authorizePaymentOrder($order_id, array $data = [])
|
76
|
|
|
{
|
77
|
|
|
$this->apiEndPoint = "v2/checkout/orders/{$order_id}/authorize";
|
78
|
|
|
$this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
|
79
|
|
|
|
80
|
|
|
$this->options['json'] = (object) $data;
|
81
|
|
|
|
82
|
|
|
$this->verb = 'post';
|
83
|
|
|
|
84
|
|
|
return $this->doPayPalRequest();
|
85
|
|
|
}
|
86
|
|
|
|
87
|
|
|
/**
|
88
|
|
|
* Captures payment for an order.
|
89
|
|
|
*
|
90
|
|
|
* @param string $order_id
|
91
|
|
|
* @param array $data
|
92
|
|
|
*
|
93
|
|
|
* @throws \Throwable
|
94
|
|
|
*
|
95
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string
|
96
|
|
|
*
|
97
|
|
|
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
|
98
|
|
|
*/
|
99
|
|
|
public function capturePaymentOrder($order_id, array $data = [])
|
100
|
|
|
{
|
101
|
|
|
$this->apiEndPoint = "v2/checkout/orders/{$order_id}/capture";
|
102
|
|
|
$this->apiUrl = collect([$this->config['api_url'], $this->apiEndPoint])->implode('/');
|
103
|
|
|
|
104
|
|
|
$this->options['json'] = (object) $data;
|
105
|
|
|
|
106
|
|
|
$this->verb = 'post';
|
107
|
|
|
|
108
|
|
|
return $this->doPayPalRequest();
|
109
|
|
|
}
|
110
|
|
|
} |