1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Srmklive\PayPal\Traits\PayPalAPI; |
4
|
|
|
|
5
|
|
|
trait BillingPlans |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Create a new billing plan. |
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/subscriptions/v1/#plans_create |
17
|
|
|
*/ |
18
|
|
|
public function createPlan(array $data) |
19
|
|
|
{ |
20
|
|
|
$this->apiEndPoint = 'v1/billing/plans'; |
|
|
|
|
21
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
22
|
|
|
|
23
|
|
|
$this->options['json'] = $data; |
|
|
|
|
24
|
|
|
|
25
|
|
|
$this->verb = 'post'; |
|
|
|
|
26
|
|
|
|
27
|
|
|
return $this->doPayPalRequest(); |
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* List all billing plans. |
32
|
|
|
* |
33
|
|
|
* @param int $page |
34
|
|
|
* @param int $size |
35
|
|
|
* @param bool $totals |
36
|
|
|
* @param array $fields |
37
|
|
|
* |
38
|
|
|
* @throws \Throwable |
39
|
|
|
* |
40
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
41
|
|
|
* |
42
|
|
|
* @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_list |
43
|
|
|
*/ |
44
|
|
|
public function listPlans($page = 1, $size = 20, $totals = true, array $fields = []) |
45
|
|
|
{ |
46
|
|
|
$fields_list = collect($fields); |
47
|
|
|
|
48
|
|
|
$fields = ''; |
49
|
|
|
if ($fields_list->count() > 0) { |
50
|
|
|
$fields = "&fields={$fields_list->implode(',')}"; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$this->apiEndPoint = "v1/billing/plans?page={$page}&page_size={$size}&total_required={$totals}{$fields}"; |
|
|
|
|
54
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
55
|
|
|
|
56
|
|
|
$this->verb = 'get'; |
|
|
|
|
57
|
|
|
|
58
|
|
|
return $this->doPayPalRequest(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Update an existing billing plan. |
63
|
|
|
* |
64
|
|
|
* @param string $plan_id |
65
|
|
|
* @param array $data |
66
|
|
|
* |
67
|
|
|
* @throws \Throwable |
68
|
|
|
* |
69
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
70
|
|
|
* |
71
|
|
|
* @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_update |
72
|
|
|
*/ |
73
|
|
|
public function updatePlan($plan_id, array $data) |
74
|
|
|
{ |
75
|
|
|
$this->apiEndPoint = "v1/billing/plans/{$plan_id}"; |
|
|
|
|
76
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
77
|
|
|
|
78
|
|
|
$this->options['json'] = $data; |
|
|
|
|
79
|
|
|
|
80
|
|
|
$this->verb = 'patch'; |
|
|
|
|
81
|
|
|
|
82
|
|
|
return $this->doPayPalRequest(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Show details for an existing billing plan. |
87
|
|
|
* |
88
|
|
|
* @param string $plan_id |
89
|
|
|
* |
90
|
|
|
* @throws \Throwable |
91
|
|
|
* |
92
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
93
|
|
|
* |
94
|
|
|
* @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_get |
95
|
|
|
*/ |
96
|
|
|
public function showPlanDetails($plan_id) |
97
|
|
|
{ |
98
|
|
|
$this->apiEndPoint = "v1/billing/plans/{$plan_id}"; |
|
|
|
|
99
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
100
|
|
|
|
101
|
|
|
$this->verb = 'get'; |
|
|
|
|
102
|
|
|
|
103
|
|
|
return $this->doPayPalRequest(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Activate an existing billing plan. |
108
|
|
|
* |
109
|
|
|
* @param string $plan_id |
110
|
|
|
* |
111
|
|
|
* @throws \Throwable |
112
|
|
|
* |
113
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
114
|
|
|
* |
115
|
|
|
* @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_activate |
116
|
|
|
*/ |
117
|
|
|
public function activatePlan($plan_id) |
118
|
|
|
{ |
119
|
|
|
$this->apiEndPoint = "v1/billing/plans/{$plan_id}/activate"; |
|
|
|
|
120
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
121
|
|
|
|
122
|
|
|
$this->verb = 'post'; |
|
|
|
|
123
|
|
|
|
124
|
|
|
return $this->doPayPalRequest(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Deactivate an existing billing plan. |
129
|
|
|
* |
130
|
|
|
* @param string $plan_id |
131
|
|
|
* |
132
|
|
|
* @throws \Throwable |
133
|
|
|
* |
134
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
135
|
|
|
* |
136
|
|
|
* @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_deactivate |
137
|
|
|
*/ |
138
|
|
|
public function deactivatePlan($plan_id) |
139
|
|
|
{ |
140
|
|
|
$this->apiEndPoint = "v1/billing/plans/{$plan_id}/deactivate"; |
|
|
|
|
141
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
142
|
|
|
|
143
|
|
|
$this->verb = 'post'; |
|
|
|
|
144
|
|
|
|
145
|
|
|
return $this->doPayPalRequest(); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Update pricing for an existing billing plan. |
150
|
|
|
* |
151
|
|
|
* @param string $plan_id |
152
|
|
|
* @param array $pricing |
153
|
|
|
* |
154
|
|
|
* @throws \Throwable |
155
|
|
|
* |
156
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
157
|
|
|
* |
158
|
|
|
* @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_update-pricing-schemes |
159
|
|
|
*/ |
160
|
|
|
public function updatePlanPricing($plan_id, array $pricing) |
161
|
|
|
{ |
162
|
|
|
$this->apiEndPoint = "v1/billing/plans/{$plan_id}/update-pricing-schemes"; |
|
|
|
|
163
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
164
|
|
|
|
165
|
|
|
$this->options['json'] = [ |
|
|
|
|
166
|
|
|
"pricing_schemes" => $pricing |
167
|
|
|
]; |
168
|
|
|
|
169
|
|
|
$this->verb = 'post'; |
|
|
|
|
170
|
|
|
|
171
|
|
|
return $this->doPayPalRequest(); |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|