1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Srmklive\PayPal\Services; |
4
|
|
|
|
5
|
|
|
use Srmklive\PayPal\Traits\PayPalRequest as PayPalAPIRequest; |
6
|
|
|
|
7
|
|
|
class ExpressCheckout |
8
|
|
|
{ |
9
|
|
|
// Integrate PayPal Request trait |
10
|
|
|
use PayPalAPIRequest; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* PayPal Processor Constructor. |
14
|
|
|
*/ |
15
|
|
|
public function __construct() |
16
|
|
|
{ |
17
|
|
|
// Setting PayPal API Credentials |
18
|
|
|
$this->setConfig(); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Function to perform SetExpressCheckout PayPal API operation. |
23
|
|
|
* |
24
|
|
|
* @param array $data |
25
|
|
|
* @param bool $subscription |
26
|
|
|
* |
27
|
|
|
* @return array |
28
|
|
|
*/ |
29
|
|
|
public function setExpressCheckout($data, $subscription = false) |
30
|
|
|
{ |
31
|
|
View Code Duplication |
$this->post = collect($data['items'])->map(function($item, $num) { |
|
|
|
|
32
|
|
|
return [ |
33
|
|
|
'L_PAYMENTREQUEST_0_NAME'.$num => $item['name'], |
34
|
|
|
'L_PAYMENTREQUEST_0_AMT'.$num => $item['price'], |
35
|
|
|
'L_PAYMENTREQUEST_0_QTY'.$num => $item['qty'], |
36
|
|
|
]; |
37
|
|
|
})->flatMap(function($value) { |
38
|
|
|
return $value; |
39
|
|
|
})->merge([ |
40
|
|
|
'PAYMENTREQUEST_0_ITEMAMT' => $data['total'], |
41
|
|
|
'PAYMENTREQUEST_0_AMT' => $data['total'], |
42
|
|
|
'PAYMENTREQUEST_0_PAYMENTACTION' => $this->paymentAction, |
43
|
|
|
'PAYMENTREQUEST_0_CURRENCYCODE' => $this->currency, |
44
|
|
|
'PAYMENTREQUEST_0_DESC' => $data['invoice_description'], |
45
|
|
|
'PAYMENTREQUEST_0_INVNUM' => $data['invoice_id'], |
46
|
|
|
'NOSHIPPING' => 1, |
47
|
|
|
'RETURNURL' => $data['return_url'], |
48
|
|
|
'CANCELURL' => $data['cancel_url'], |
49
|
|
|
'LOCALE' => $this->locale, |
50
|
|
|
]); |
51
|
|
|
|
52
|
|
|
if ($subscription) { |
53
|
|
|
$this->post->merge([ |
54
|
|
|
'L_BILLINGTYPE0' => 'RecurringPayment', |
55
|
|
|
'L_BILLINGAGREEMENTDESCRIPTION0' => !empty($data['subscription_desc']) ? |
56
|
|
|
$data['subscription_desc'] : $data['invoice_description'], |
57
|
|
|
]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$response = $this->doPayPalRequest('SetExpressCheckout'); |
61
|
|
|
|
62
|
|
|
if (!empty($response['TOKEN'])) { |
63
|
|
|
$response['paypal_link'] = $this->config['gateway_url']. |
64
|
|
|
'/webscr?cmd=_express-checkout&token='.$response['TOKEN']; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $response; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Function to perform GetExpressCheckoutDetails PayPal API operation. |
72
|
|
|
* |
73
|
|
|
* @param string $token |
74
|
|
|
* |
75
|
|
|
* @return array |
76
|
|
|
*/ |
77
|
|
|
public function getExpressCheckoutDetails($token) |
78
|
|
|
{ |
79
|
|
|
$this->post = collect([ |
|
|
|
|
80
|
|
|
'TOKEN' => $token, |
81
|
|
|
]); |
82
|
|
|
|
83
|
|
|
return $this->doPayPalRequest('GetExpressCheckoutDetails'); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Function to perform DoExpressCheckoutPayment PayPal API operation. |
88
|
|
|
* |
89
|
|
|
* @param array $data |
90
|
|
|
* @param string $token |
91
|
|
|
* @param string $payerid |
92
|
|
|
* |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
|
|
public function doExpressCheckoutPayment($data, $token, $payerid) |
96
|
|
|
{ |
97
|
|
View Code Duplication |
$this->post = collect($data['items'])->map(function($item, $num) { |
|
|
|
|
98
|
|
|
return [ |
99
|
|
|
'L_PAYMENTREQUEST_0_NAME'.$num => $item['name'], |
100
|
|
|
'L_PAYMENTREQUEST_0_AMT'.$num => $item['price'], |
101
|
|
|
'L_PAYMENTREQUEST_0_QTY'.$num => $item['qty'], |
102
|
|
|
]; |
103
|
|
|
})->flatMap(function($value) { |
104
|
|
|
return $value; |
105
|
|
|
})->merge([ |
106
|
|
|
'TOKEN' => $token, |
107
|
|
|
'PAYERID' => $payerid, |
108
|
|
|
'PAYMENTREQUEST_0_ITEMAMT' => $data['total'], |
109
|
|
|
'PAYMENTREQUEST_0_AMT' => $data['total'], |
110
|
|
|
'PAYMENTREQUEST_0_PAYMENTACTION' => !empty($this->config['payment_action']) ? $this->config['payment_action'] : 'Sale', |
111
|
|
|
'PAYMENTREQUEST_0_CURRENCYCODE' => $this->currency, |
112
|
|
|
'PAYMENTREQUEST_0_DESC' => $data['invoice_description'], |
113
|
|
|
'PAYMENTREQUEST_0_INVNUM' => $data['invoice_id'], |
114
|
|
|
'PAYMENTREQUEST_0_NOTIFYURL' => config('paypal.notify_url'), |
115
|
|
|
]); |
116
|
|
|
|
117
|
|
|
return $this->doPayPalRequest('DoExpressCheckoutPayment'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Function to perform DoCapture PayPal API operation. |
122
|
|
|
* |
123
|
|
|
* @param string $authorization_id Transaction ID |
124
|
|
|
* @param float $amount Amount to capture |
125
|
|
|
* @param string $complete Indicates whether or not this is the last capture. |
126
|
|
|
* @param array $data Optional request fields |
127
|
|
|
* |
128
|
|
|
* @return array |
129
|
|
|
*/ |
130
|
|
|
public function doCapture($authorization_id, $amount, $complete = 'Complete', $data = []) |
131
|
|
|
{ |
132
|
|
|
$this->post = collect($data)->merge([ |
|
|
|
|
133
|
|
|
'AUTHORIZATIONID' => $authorization_id, |
134
|
|
|
'AMT' => $amount, |
135
|
|
|
'COMPLETETYPE' => $complete, |
136
|
|
|
'CURRENCYCODE' => $this->currency, |
137
|
|
|
]); |
138
|
|
|
|
139
|
|
|
return $this->doPayPalRequest('DoCapture'); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Function to perform DoAuthorization PayPal API operation. |
144
|
|
|
* |
145
|
|
|
* @param string $authorization_id Transaction ID |
146
|
|
|
* @param float $amount Amount to capture |
147
|
|
|
* @param array $data Optional request fields |
148
|
|
|
* |
149
|
|
|
* @return array |
150
|
|
|
*/ |
151
|
|
View Code Duplication |
public function doAuthorization($authorization_id, $amount, $data = []) |
|
|
|
|
152
|
|
|
{ |
153
|
|
|
$this->post = collect($data)->merge([ |
|
|
|
|
154
|
|
|
'AUTHORIZATIONID' => $authorization_id, |
155
|
|
|
'AMT' => $amount, |
156
|
|
|
]); |
157
|
|
|
|
158
|
|
|
return $this->doPayPalRequest('DoAuthorization'); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Function to perform DoVoid PayPal API operation. |
163
|
|
|
* |
164
|
|
|
* @param string $authorization_id Transaction ID |
165
|
|
|
* @param array $data Optional request fields |
166
|
|
|
* |
167
|
|
|
* @return array |
168
|
|
|
*/ |
169
|
|
View Code Duplication |
public function doVoid($authorization_id, $data = []) |
|
|
|
|
170
|
|
|
{ |
171
|
|
|
$this->post = collect($data)->merge([ |
|
|
|
|
172
|
|
|
'AUTHORIZATIONID' => $authorization_id, |
173
|
|
|
]); |
174
|
|
|
|
175
|
|
|
return $this->doPayPalRequest('DoVoid'); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Function to perform CreateBillingAgreement PayPal API operation. |
180
|
|
|
* |
181
|
|
|
* @param string $token |
182
|
|
|
* |
183
|
|
|
* @return array |
184
|
|
|
*/ |
185
|
|
|
public function createBillingAgreement($token) |
186
|
|
|
{ |
187
|
|
|
$this->post = [ |
188
|
|
|
'TOKEN' => $token, |
189
|
|
|
]; |
190
|
|
|
|
191
|
|
|
return $this->doPayPalRequest('CreateBillingAgreement'); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Function to perform CreateRecurringPaymentsProfile PayPal API operation. |
196
|
|
|
* |
197
|
|
|
* @param array $data |
198
|
|
|
* @param string $token |
199
|
|
|
* |
200
|
|
|
* @return array |
201
|
|
|
*/ |
202
|
|
|
public function createRecurringPaymentsProfile($data, $token) |
203
|
|
|
{ |
204
|
|
|
$this->post = collect([ |
|
|
|
|
205
|
|
|
'token' => $token, |
206
|
|
|
])->merge($data); |
207
|
|
|
|
208
|
|
|
return $this->doPayPalRequest('CreateRecurringPaymentsProfile'); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Function to perform GetRecurringPaymentsProfileDetails PayPal API operation. |
213
|
|
|
* |
214
|
|
|
* @param string $id |
215
|
|
|
* |
216
|
|
|
* @return array |
217
|
|
|
*/ |
218
|
|
|
public function getRecurringPaymentsProfileDetails($id) |
219
|
|
|
{ |
220
|
|
|
$this->post = collect([ |
|
|
|
|
221
|
|
|
'PROFILEID' => $id, |
222
|
|
|
]); |
223
|
|
|
|
224
|
|
|
return $this->doPayPalRequest('GetRecurringPaymentsProfileDetails'); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Function to perform UpdateRecurringPaymentsProfile PayPal API operation. |
229
|
|
|
* |
230
|
|
|
* @param array $data |
231
|
|
|
* @param string $id |
232
|
|
|
* |
233
|
|
|
* @return array |
234
|
|
|
*/ |
235
|
|
|
public function updateRecurringPaymentsProfile($data, $id) |
236
|
|
|
{ |
237
|
|
|
$this->post = collect([ |
|
|
|
|
238
|
|
|
'PROFILEID' => $id, |
239
|
|
|
])->merge($data); |
240
|
|
|
|
241
|
|
|
return $this->doPayPalRequest('UpdateRecurringPaymentsProfile'); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* Function to cancel RecurringPaymentsProfile on PayPal. |
246
|
|
|
* |
247
|
|
|
* @param string $id |
248
|
|
|
* |
249
|
|
|
* @return array |
250
|
|
|
*/ |
251
|
|
View Code Duplication |
public function cancelRecurringPaymentsProfile($id) |
|
|
|
|
252
|
|
|
{ |
253
|
|
|
$this->post = collect([ |
|
|
|
|
254
|
|
|
'PROFILEID' => $id, |
255
|
|
|
'ACTION' => 'Cancel', |
256
|
|
|
]); |
257
|
|
|
|
258
|
|
|
return $this->doPayPalRequest('ManageRecurringPaymentsProfileStatus'); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* Function to suspend an active RecurringPaymentsProfile on PayPal. |
263
|
|
|
* |
264
|
|
|
* @param string $id |
265
|
|
|
* |
266
|
|
|
* @return array |
267
|
|
|
*/ |
268
|
|
View Code Duplication |
public function suspendRecurringPaymentsProfile($id) |
|
|
|
|
269
|
|
|
{ |
270
|
|
|
$this->post = collect([ |
|
|
|
|
271
|
|
|
'PROFILEID' => $id, |
272
|
|
|
'ACTION' => 'Suspend', |
273
|
|
|
]); |
274
|
|
|
|
275
|
|
|
return $this->doPayPalRequest('ManageRecurringPaymentsProfileStatus'); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Function to reactivate a suspended RecurringPaymentsProfile on PayPal. |
280
|
|
|
* |
281
|
|
|
* @param string $id |
282
|
|
|
* |
283
|
|
|
* @return array |
284
|
|
|
*/ |
285
|
|
View Code Duplication |
public function reactivateRecurringPaymentsProfile($id) |
|
|
|
|
286
|
|
|
{ |
287
|
|
|
$this->post = collect([ |
|
|
|
|
288
|
|
|
'PROFILEID' => $id, |
289
|
|
|
'ACTION' => 'Reactivate', |
290
|
|
|
]); |
291
|
|
|
|
292
|
|
|
return $this->doPayPalRequest('ManageRecurringPaymentsProfileStatus'); |
293
|
|
|
} |
294
|
|
|
} |
295
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..