1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Srmklive\PayPal\Traits\PayPalAPI; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This trait provides methods for the Reference Transactions API, |
7
|
|
|
* which is available on a limited-use basis. |
8
|
|
|
* |
9
|
|
|
* See: https://developer.paypal.com/limited-release/reference-transactions/ |
10
|
|
|
* and https://developer.paypal.com/api/limited-release/reference-transactions/v1/ |
11
|
|
|
* for more details. |
12
|
|
|
*/ |
13
|
|
|
trait BillingAgreements |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Create a new billing agreement. |
17
|
|
|
* |
18
|
|
|
* @param array $data |
19
|
|
|
* |
20
|
|
|
* @throws \Throwable |
21
|
|
|
* |
22
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
23
|
|
|
* |
24
|
|
|
* @see https://developer.paypal.com/api/limited-release/reference-transactions/v1/#agreement-tokens_post |
25
|
|
|
*/ |
26
|
|
|
public function createBillingAgreementToken(array $data) |
27
|
|
|
{ |
28
|
|
|
$this->apiEndPoint = 'v1/billing-agreements/agreement-tokens'; |
29
|
|
|
|
30
|
|
|
$this->options['json'] = $data; |
31
|
|
|
|
32
|
|
|
$this->verb = 'post'; |
33
|
|
|
|
34
|
|
|
return $this->doPayPalRequest(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Get details of a billing agreement token. |
39
|
|
|
* |
40
|
|
|
* @param string $token_id |
41
|
|
|
* |
42
|
|
|
* @throws \Throwable |
43
|
|
|
* |
44
|
|
|
* @return array|string|\Psr\Http\Message\StreamInterface |
45
|
|
|
* |
46
|
|
|
* @see https://developer.paypal.com/api/limited-release/reference-transactions/v1/#agreement-tokens_get |
47
|
|
|
*/ |
48
|
|
|
public function getBillingAgreementTokenDetails(string $token_id) |
49
|
|
|
{ |
50
|
|
|
$this->apiEndPoint = "v1/billing-agreements/agreement-tokens/{$token_id}"; |
51
|
|
|
|
52
|
|
|
$this->verb = 'get'; |
53
|
|
|
|
54
|
|
|
return $this->doPayPalRequest(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Create a billing agreement. |
59
|
|
|
* |
60
|
|
|
* @param string $token_id |
61
|
|
|
* |
62
|
|
|
* @throws \Throwable |
63
|
|
|
* |
64
|
|
|
* @return array|string|\Psr\Http\Message\StreamInterface |
65
|
|
|
* |
66
|
|
|
* @see https://developer.paypal.com/api/limited-release/reference-transactions/v1/#agreements_create |
67
|
|
|
*/ |
68
|
|
|
public function createBillingAgreement(string $token_id) |
69
|
|
|
{ |
70
|
|
|
$this->apiEndPoint = 'v1/billing-agreements/agreements'; |
71
|
|
|
|
72
|
|
|
$this->options['json'] = [ |
73
|
|
|
'token_id' => $token_id, |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
$this->verb = 'post'; |
77
|
|
|
|
78
|
|
|
return $this->doPayPalRequest(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Update an existing billing agreement. |
83
|
|
|
* |
84
|
|
|
* @param string $agreement_id |
85
|
|
|
* @param array $data |
86
|
|
|
* |
87
|
|
|
* @throws \Throwable |
88
|
|
|
* |
89
|
|
|
* @return array|string|\Psr\Http\Message\StreamInterface |
90
|
|
|
* |
91
|
|
|
* @see https://developer.paypal.com/api/limited-release/reference-transactions/v1/#agreements_patch |
92
|
|
|
*/ |
93
|
|
|
public function updateBillingAgreement(string $agreement_id, array $data) |
94
|
|
|
{ |
95
|
|
|
$this->apiEndPoint = "v1/billing-agreements/agreements/{$agreement_id}"; |
96
|
|
|
|
97
|
|
|
$this->options['json'] = $data; |
98
|
|
|
|
99
|
|
|
$this->verb = 'patch'; |
100
|
|
|
|
101
|
|
|
return $this->doPayPalRequest(false); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Show details for an existing billing agreement. |
106
|
|
|
* |
107
|
|
|
* @param string $agreement_id |
108
|
|
|
* |
109
|
|
|
* @throws \Throwable |
110
|
|
|
* |
111
|
|
|
* @return array|string|\Psr\Http\Message\StreamInterface |
112
|
|
|
* |
113
|
|
|
* @see https://developer.paypal.com/api/limited-release/reference-transactions/v1/#agreements_get |
114
|
|
|
*/ |
115
|
|
|
public function showBillingAgreementDetails(string $agreement_id) |
116
|
|
|
{ |
117
|
|
|
$this->apiEndPoint = "v1/billing-agreements/agreements/{$agreement_id}"; |
118
|
|
|
|
119
|
|
|
$this->verb = 'get'; |
120
|
|
|
|
121
|
|
|
return $this->doPayPalRequest(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Cancel an existing billing agreement. |
126
|
|
|
* |
127
|
|
|
* @param string $agreement_id |
128
|
|
|
* |
129
|
|
|
* @throws \Throwable |
130
|
|
|
* |
131
|
|
|
* @return array|string|\Psr\Http\Message\StreamInterface |
132
|
|
|
* |
133
|
|
|
* @see https://developer.paypal.com/api/limited-release/reference-transactions/v1/#agreements_cancel |
134
|
|
|
*/ |
135
|
|
|
public function cancelBillingAgreement(string $agreement_id) |
136
|
|
|
{ |
137
|
|
|
$this->apiEndPoint = "v1/billing-agreements/agreements/{$agreement_id}/cancel"; |
138
|
|
|
|
139
|
|
|
$this->verb = 'post'; |
140
|
|
|
|
141
|
|
|
return $this->doPayPalRequest(false); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|