1
|
|
|
<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' )) { exit('NO direct script access allowed'); } |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ---------------------------------------------- |
5
|
|
|
* |
6
|
|
|
* Class EEG_Paypal_Express |
7
|
|
|
* |
8
|
|
|
* @package Event Espresso |
9
|
|
|
* @subpackage eea-paypal-express |
10
|
|
|
* @author Event Espresso |
11
|
|
|
* @version $VID:$ |
12
|
|
|
* |
13
|
|
|
* ---------------------------------------------- |
14
|
|
|
*/ |
15
|
|
|
class EEG_Paypal_Express extends EE_Offsite_Gateway { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Merchant API Username. |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $_api_username; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Merchant API Password. |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $_api_password; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* API Signature. |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $_api_signature; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Request Shipping address on PP checkout page. |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $_request_shipping_addr; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Business/personal logo. |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $_image_url; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* gateway URL variable |
49
|
|
|
* |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
protected $_base_gateway_url = ''; |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* EEG_Paypal_Express constructor. |
58
|
|
|
*/ |
59
|
|
|
public function __construct() |
60
|
|
|
{ |
61
|
|
|
$this->_currencies_supported = array( |
62
|
|
|
'USD', |
63
|
|
|
'AUD', |
64
|
|
|
'BRL', |
65
|
|
|
'CAD', |
66
|
|
|
'CZK', |
67
|
|
|
'DKK', |
68
|
|
|
'EUR', |
69
|
|
|
'HKD', |
70
|
|
|
'HUF', |
71
|
|
|
'ILS', |
72
|
|
|
'JPY', |
73
|
|
|
'MYR', |
74
|
|
|
'MXN', |
75
|
|
|
'NOK', |
76
|
|
|
'NZD', |
77
|
|
|
'PHP', |
78
|
|
|
'PLN', |
79
|
|
|
'GBP', |
80
|
|
|
'RUB', |
81
|
|
|
'SGD', |
82
|
|
|
'SEK', |
83
|
|
|
'CHF', |
84
|
|
|
'TWD', |
85
|
|
|
'THB', |
86
|
|
|
'TRY' |
87
|
|
|
); |
88
|
|
|
parent::__construct(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Sets the gateway URL variable based on whether debug mode is enabled or not. |
95
|
|
|
|
96
|
|
|
* |
97
|
|
|
*@param array $settings_array |
98
|
|
|
*/ |
99
|
|
|
public function set_settings( $settings_array ) { |
100
|
|
|
parent::set_settings($settings_array); |
101
|
|
|
// Redirect URL. |
102
|
|
|
$this->_base_gateway_url = $this->_debug_mode |
103
|
|
|
? 'https://api-3t.sandbox.paypal.com/nvp' |
104
|
|
|
: 'https://api-3t.paypal.com/nvp'; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param EEI_Payment $payment |
111
|
|
|
* @param array $billing_info |
112
|
|
|
* @param string $return_url |
113
|
|
|
* @param string $notify_url |
114
|
|
|
* @param string $cancel_url |
115
|
|
|
* @return \EE_Payment|\EEI_Payment |
116
|
|
|
* @throws \EE_Error |
117
|
|
|
*/ |
118
|
|
|
public function set_redirection_info( $payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL ) { |
119
|
|
View Code Duplication |
if ( ! $payment instanceof EEI_Payment ) { |
120
|
|
|
$payment->set_gateway_response( __( 'Error. No associated payment was found.', 'event_espresso' ) ); |
121
|
|
|
$payment->set_status( $this->_pay_model->failed_status() ); |
122
|
|
|
return $payment; |
123
|
|
|
} |
124
|
|
|
$transaction = $payment->transaction(); |
125
|
|
View Code Duplication |
if ( ! $transaction instanceof EEI_Transaction ) { |
126
|
|
|
$payment->set_gateway_response( __( 'Could not process this payment because it has no associated transaction.', 'event_espresso' ) ); |
127
|
|
|
$payment->set_status( $this->_pay_model->failed_status() ); |
128
|
|
|
return $payment; |
129
|
|
|
} |
130
|
|
|
$order_description = substr( $this->_format_order_description($payment), 0, 127 ); |
131
|
|
|
$primary_registration = $transaction->primary_registration(); |
132
|
|
|
$primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : false; |
133
|
|
|
$locale = explode('-', get_bloginfo('language')); |
134
|
|
|
|
135
|
|
|
// Gather request parameters. |
136
|
|
|
$token_request_dtls = array( |
137
|
|
|
'METHOD' => 'SetExpressCheckout', |
138
|
|
|
'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
139
|
|
|
'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
140
|
|
|
'PAYMENTREQUEST_0_DESC' => $order_description, |
141
|
|
|
'RETURNURL' => $return_url, |
142
|
|
|
'CANCELURL' => $cancel_url, |
143
|
|
|
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
144
|
|
|
'SOLUTIONTYPE' => 'Sole', // Buyer does not need to create a PayPal account to check out. This is referred to as PayPal Account Optional. |
145
|
|
|
'BUTTONSOURCE' => 'EventEspresso_SP',//EE will blow up if you change this |
146
|
|
|
'LOCALECODE' => $locale[1] // Locale of the pages displayed by PayPal during Express Checkout. |
147
|
|
|
); |
148
|
|
|
|
149
|
|
|
// Show itemized list. |
150
|
|
|
if ( $this->_money->compare_floats( $payment->amount(), $transaction->total(), '==' ) ) { |
151
|
|
|
$item_num = 0; |
152
|
|
|
$itemized_sum = 0; |
153
|
|
|
$total_line_items = $transaction->total_line_item(); |
154
|
|
|
// Go through each item in the list. |
155
|
|
|
foreach ( $total_line_items->get_items() as $line_item ) { |
156
|
|
|
if ( $line_item instanceof EE_Line_Item ) { |
157
|
|
|
// PayPal doesn't like line items with 0.00 amount, so we may skip those. |
158
|
|
|
if ( EEH_Money::compare_floats( $line_item->total(), '0.00', '==' ) ) { |
159
|
|
|
continue; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
$unit_price = $line_item->unit_price(); |
163
|
|
|
$line_item_quantity = $line_item->quantity(); |
164
|
|
|
// This is a discount. |
165
|
|
|
if ( $line_item->is_percent() ) { |
166
|
|
|
$unit_price = $line_item->total(); |
167
|
|
|
$line_item_quantity = 1; |
168
|
|
|
} |
169
|
|
|
// Item Name. |
170
|
|
|
$token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr($this->_format_line_item_name( $line_item, $payment), 0, 127); |
171
|
|
|
// Item description. |
172
|
|
|
$token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr($this->_format_line_item_desc( $line_item, $payment), 0, 127); |
173
|
|
|
// Cost of individual item. |
174
|
|
|
$token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( $unit_price ); |
175
|
|
|
// Item Number. |
176
|
|
|
$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
177
|
|
|
// Item quantity. |
178
|
|
|
$token_request_dtls['L_PAYMENTREQUEST_0_QTY'.$item_num] = $line_item_quantity; |
179
|
|
|
// Digital item is sold. |
180
|
|
|
$token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
181
|
|
|
$itemized_sum += $line_item->total(); |
182
|
|
|
++$item_num; |
183
|
|
|
} |
184
|
|
|
} |
185
|
|
|
// Item's sales S/H and tax amount. |
186
|
|
|
$token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
187
|
|
|
$token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
188
|
|
|
$token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
189
|
|
|
$token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
190
|
|
|
|
191
|
|
|
$itemized_sum_diff_from_txn_total = round( $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), 2 ); |
192
|
|
|
// If we were not able to recognize some item like promotion, surcharge or cancellation, |
193
|
|
|
// add the difference as an extra line item. |
194
|
|
|
if ( $this->_money->compare_floats( $itemized_sum_diff_from_txn_total, 0, '!=' ) ) { |
195
|
|
|
// Item Name. |
196
|
|
|
$token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr( __( 'Other (promotion/surcharge/cancellation)', 'event_espresso' ), 0, 127 ); |
197
|
|
|
// Item description. |
198
|
|
|
$token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = ''; |
199
|
|
|
// Cost of individual item. |
200
|
|
|
$token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( $itemized_sum_diff_from_txn_total ); |
201
|
|
|
// Item Number. |
202
|
|
|
$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
203
|
|
|
// Item quantity. |
204
|
|
|
$token_request_dtls['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1; |
205
|
|
|
// Digital item is sold. |
206
|
|
|
$token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
207
|
|
|
$item_num++; |
208
|
|
|
} |
209
|
|
|
} else { |
210
|
|
|
// Just one Item. |
211
|
|
|
// Item Name. |
212
|
|
|
$token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr( $this->_format_partial_payment_line_item_name($payment), 0, 127 ); |
213
|
|
|
// Item description. |
214
|
|
|
$token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr( $this->_format_partial_payment_line_item_desc($payment), 0, 127 ); |
215
|
|
|
// Cost of individual item. |
216
|
|
|
$token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency( $payment->amount() ); |
217
|
|
|
// Item Number. |
218
|
|
|
$token_request_dtls['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
219
|
|
|
// Item quantity. |
220
|
|
|
$token_request_dtls['L_PAYMENTREQUEST_0_QTY0'] = 1; |
221
|
|
|
// Digital item is sold. |
222
|
|
|
$token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
223
|
|
|
// Item's sales S/H and tax amount. |
224
|
|
|
$token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency( $payment->amount() ); |
225
|
|
|
$token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
226
|
|
|
$token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
227
|
|
|
$token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
228
|
|
|
} |
229
|
|
|
// Automatically filling out shipping and contact information. |
230
|
|
|
if ( $this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee ) { |
231
|
|
|
$token_request_dtls['NOSHIPPING'] = '2'; // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
232
|
|
|
$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
233
|
|
|
$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
234
|
|
|
$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
235
|
|
|
$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
236
|
|
|
$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
237
|
|
|
$token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
238
|
|
|
$token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
239
|
|
|
$token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
240
|
|
|
} elseif ( ! $this->_request_shipping_addr ) { |
241
|
|
|
// Do not request shipping details on the PP Checkout page. |
242
|
|
|
$token_request_dtls['NOSHIPPING'] = '1'; |
243
|
|
|
$token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
244
|
|
|
|
245
|
|
|
} |
246
|
|
|
// Used a business/personal logo on the PayPal page. |
247
|
|
|
if ( ! empty($this->_image_url) ) { |
248
|
|
|
$token_request_dtls['LOGOIMG'] = $this->_image_url; |
249
|
|
|
} |
250
|
|
|
// Request PayPal token. |
251
|
|
|
$token_request_response = $this->_ppExpress_request( $token_request_dtls, 'Payment Token', $payment ); |
252
|
|
|
$token_rstatus = $this->_ppExpress_check_response( $token_request_response ); |
253
|
|
|
$response_args = ( isset($token_rstatus['args']) && is_array($token_rstatus['args']) ) ? $token_rstatus['args'] : array(); |
254
|
|
|
if ( $token_rstatus['status'] ) { |
255
|
|
|
// We got the Token so we may continue with the payment and redirect the client. |
256
|
|
|
$payment->set_details( $response_args ); |
257
|
|
|
|
258
|
|
|
$gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
259
|
|
|
$payment->set_redirect_url( $gateway_url . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' . $response_args['TOKEN'] ); |
260
|
|
View Code Duplication |
} else { |
261
|
|
|
if ( isset($response_args['L_ERRORCODE']) ) { |
262
|
|
|
$payment->set_gateway_response( $response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE'] ); |
263
|
|
|
} else { |
264
|
|
|
$payment->set_gateway_response( __( 'Error occurred while trying to setup the Express Checkout.', 'event_espresso' ) ); |
265
|
|
|
} |
266
|
|
|
$payment->set_details( $response_args ); |
267
|
|
|
$payment->set_status( $this->_pay_model->failed_status() ); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
return $payment; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
|
276
|
|
|
* @param array $update_info { |
277
|
|
|
* @type string $gateway_txn_id |
278
|
|
|
* @type string status an EEMI_Payment status |
279
|
|
|
* } |
280
|
|
|
* @param EEI_Transaction $transaction |
281
|
|
|
* @return EEI_Payment |
282
|
|
|
*/ |
283
|
|
|
public function handle_payment_update( $update_info, $transaction ) { |
284
|
|
|
$payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
285
|
|
|
|
286
|
|
|
if ( $payment instanceof EEI_Payment ) { |
287
|
|
|
$this->log( array( 'Return from Authorization' => $update_info ), $payment ); |
288
|
|
|
$transaction = $payment->transaction(); |
289
|
|
View Code Duplication |
if ( ! $transaction instanceof EEI_Transaction ) { |
290
|
|
|
$payment->set_gateway_response( __( 'Could not process this payment because it has no associated transaction.', 'event_espresso' ) ); |
291
|
|
|
$payment->set_status( $this->_pay_model->failed_status() ); |
292
|
|
|
return $payment; |
293
|
|
|
} |
294
|
|
|
$primary_registrant = $transaction->primary_registration(); |
295
|
|
|
$payment_details = $payment->details(); |
296
|
|
|
// Check if we still have the token. |
297
|
|
|
if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN']) ) { |
298
|
|
|
$payment->set_status( $this->_pay_model->failed_status() ); |
299
|
|
|
return $payment; |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
$cdetails_request_dtls = array( |
303
|
|
|
'METHOD' => 'GetExpressCheckoutDetails', |
304
|
|
|
'TOKEN' => $payment_details['TOKEN'] |
305
|
|
|
); |
306
|
|
|
// Request Customer Details. |
307
|
|
|
$cdetails_request_response = $this->_ppExpress_request( $cdetails_request_dtls, 'Customer Details', $payment ); |
308
|
|
|
$cdetails_rstatus = $this->_ppExpress_check_response( $cdetails_request_response ); |
309
|
|
|
$cdata_response_args = ( isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']) ) ? $cdetails_rstatus['args'] : array(); |
310
|
|
|
if ( $cdetails_rstatus['status'] ) { |
311
|
|
|
// We got the PayerID so now we can Complete the transaction. |
312
|
|
|
$docheckout_request_dtls = array( |
313
|
|
|
'METHOD' => 'DoExpressCheckoutPayment', |
314
|
|
|
'PAYERID' => $cdata_response_args['PAYERID'], |
315
|
|
|
'TOKEN' => $payment_details['TOKEN'], |
316
|
|
|
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
317
|
|
|
'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
318
|
|
|
'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code() |
319
|
|
|
); |
320
|
|
|
// Payment Checkout/Capture. |
321
|
|
|
$docheckout_request_response = $this->_ppExpress_request( $docheckout_request_dtls, 'Do Payment', $payment ); |
322
|
|
|
$docheckout_rstatus = $this->_ppExpress_check_response( $docheckout_request_response ); |
323
|
|
|
$docheckout_response_args = ( isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']) ) ? $docheckout_rstatus['args'] : array(); |
324
|
|
|
if ( $docheckout_rstatus['status'] ) { |
325
|
|
|
// All is well, payment approved. |
326
|
|
|
$primary_registration_code = $primary_registrant instanceof EE_Registration ? $primary_registrant->reg_code() : ''; |
327
|
|
|
$payment->set_extra_accntng( $primary_registration_code ); |
328
|
|
|
$payment->set_amount( isset($docheckout_response_args['PAYMENTINFO_0_AMT']) ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] : 0 ); |
329
|
|
|
$payment->set_txn_id_chq_nmbr( isset( $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] ) ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] : null ); |
330
|
|
|
$payment->set_details( $cdata_response_args ); |
331
|
|
|
$payment->set_gateway_response( isset( $docheckout_response_args['PAYMENTINFO_0_ACK'] ) ? $docheckout_response_args['PAYMENTINFO_0_ACK'] : '' ); |
332
|
|
|
$payment->set_status( $this->_pay_model->approved_status() ); |
333
|
|
View Code Duplication |
} else { |
334
|
|
|
if ( isset($docheckout_response_args['L_ERRORCODE']) ) { |
335
|
|
|
$payment->set_gateway_response( $docheckout_response_args['L_ERRORCODE'] . '; ' . $docheckout_response_args['L_SHORTMESSAGE'] ); |
336
|
|
|
} else { |
337
|
|
|
$payment->set_gateway_response( __( 'Error occurred while trying to Capture the funds.', 'event_espresso' ) ); |
338
|
|
|
} |
339
|
|
|
$payment->set_details( $docheckout_response_args ); |
340
|
|
|
$payment->set_status( $this->_pay_model->declined_status() ); |
341
|
|
|
} |
342
|
|
View Code Duplication |
} else { |
343
|
|
|
if ( isset($cdata_response_args['L_ERRORCODE']) ) { |
344
|
|
|
$payment->set_gateway_response( $cdata_response_args['L_ERRORCODE'] . '; ' . $cdata_response_args['L_SHORTMESSAGE'] ); |
345
|
|
|
} else { |
346
|
|
|
$payment->set_gateway_response( __( 'Error occurred while trying to get payment Details from PayPal.', 'event_espresso' ) ); |
347
|
|
|
} |
348
|
|
|
$payment->set_details( $cdata_response_args ); |
349
|
|
|
$payment->set_status( $this->_pay_model->failed_status() ); |
350
|
|
|
} |
351
|
|
|
} else { |
352
|
|
|
$payment->set_gateway_response( __( 'Error occurred while trying to process the payment.', 'event_espresso' ) ); |
|
|
|
|
353
|
|
|
$payment->set_status( $this->_pay_model->failed_status() ); |
|
|
|
|
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
return $payment; |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* Make the Express checkout request. |
362
|
|
|
* |
363
|
|
|
* @param array $request_params |
364
|
|
|
* @param string $request_text |
365
|
|
|
* @param EEI_Payment $payment |
366
|
|
|
* @return mixed |
367
|
|
|
*/ |
368
|
|
|
public function _ppExpress_request( $request_params, $request_text, $payment ) { |
369
|
|
|
$request_dtls = array( |
370
|
|
|
'VERSION' => '204.0', |
371
|
|
|
'USER' => urlencode( $this->_api_username ), |
372
|
|
|
'PWD' => urlencode( $this->_api_password ), |
373
|
|
|
'SIGNATURE' => urlencode( $this->_api_signature ) |
374
|
|
|
); |
375
|
|
|
$dtls = array_merge( $request_dtls, $request_params ); |
376
|
|
|
|
377
|
|
|
$this->_log_clean_request( $dtls, $payment, $request_text . ' Request' ); |
378
|
|
|
// Request Customer Details. |
379
|
|
|
$request_response = wp_remote_post( |
380
|
|
|
$this->_base_gateway_url, |
381
|
|
|
array( |
382
|
|
|
'method' => 'POST', |
383
|
|
|
'timeout' => 45, |
384
|
|
|
'httpversion' => '1.1', |
385
|
|
|
'cookies' => array(), |
386
|
|
|
'headers' => array(), |
387
|
|
|
'body' => http_build_query( $dtls ) |
388
|
|
|
) |
389
|
|
|
); |
390
|
|
|
// Log the response. |
391
|
|
|
$this->log( array( $request_text . ' Response' => $request_response), $payment ); |
392
|
|
|
|
393
|
|
|
return $request_response; |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
|
397
|
|
|
/** |
398
|
|
|
* Check the response status. |
399
|
|
|
* |
400
|
|
|
* @param mixed $request_response |
401
|
|
|
* @return array |
402
|
|
|
*/ |
403
|
|
|
public function _ppExpress_check_response( $request_response ) { |
404
|
|
|
if (empty($request_response['body']) || is_wp_error( $request_response ) ) { |
405
|
|
|
// If we got here then there was an error in this request. |
406
|
|
|
return array('status' => false, 'args' => $request_response); |
407
|
|
|
} |
408
|
|
|
$response_args = array(); |
409
|
|
|
parse_str( urldecode($request_response['body']), $response_args ); |
410
|
|
|
if ( ! isset($response_args['ACK'])) { |
411
|
|
|
return array('status' => false, 'args' => $request_response); |
412
|
|
|
} |
413
|
|
|
if ( |
414
|
|
|
$response_args['ACK'] === 'Success' |
415
|
|
|
&& ( |
416
|
|
|
isset($response_args['PAYERID']) |
417
|
|
|
|| isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
418
|
|
|
|| (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
419
|
|
|
|| isset($response_args['TOKEN']) |
420
|
|
|
) |
421
|
|
|
) { |
422
|
|
|
// Response status OK, return response parameters for further processing. |
423
|
|
|
return array('status' => true, 'args' => $response_args); |
424
|
|
|
} else { |
425
|
|
|
$errors = $this->_get_errors($response_args); |
426
|
|
|
return array('status' => false, 'args' => $errors); |
427
|
|
|
} |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* Log a "Cleared" request. |
433
|
|
|
* |
434
|
|
|
* @param array $request |
435
|
|
|
* @param EEI_Payment $payment |
436
|
|
|
* @param string $info |
437
|
|
|
* @return void |
438
|
|
|
*/ |
439
|
|
|
private function _log_clean_request($request, $payment, $info ) { |
440
|
|
|
$cleaned_request_data = $request; |
441
|
|
|
unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
442
|
|
|
$this->log( array($info => $cleaned_request_data), $payment ); |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* Get error from the response data. |
448
|
|
|
* |
449
|
|
|
* @param array $data_array |
450
|
|
|
* @return array |
451
|
|
|
*/ |
452
|
|
|
private function _get_errors( $data_array ) { |
453
|
|
|
$errors = array(); |
454
|
|
|
$n = 0; |
455
|
|
|
while ( isset($data_array["L_ERRORCODE{$n}"]) ) { |
456
|
|
|
$l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
457
|
|
|
? $data_array["L_ERRORCODE{$n}"] |
458
|
|
|
: ''; |
459
|
|
|
$l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"]) |
460
|
|
|
? $data_array["L_SEVERITYCODE{$n}"] |
461
|
|
|
: ''; |
462
|
|
|
$l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"]) |
463
|
|
|
? $data_array["L_SHORTMESSAGE{$n}"] |
464
|
|
|
: ''; |
465
|
|
|
$l_long_message = isset($data_array["L_LONGMESSAGE{$n}"]) |
466
|
|
|
? $data_array["L_LONGMESSAGE{$n}"] |
467
|
|
|
: ''; |
468
|
|
|
|
469
|
|
|
if ( $n === 0 ) { |
470
|
|
|
$errors = array( |
471
|
|
|
'L_ERRORCODE' => $l_error_code, |
472
|
|
|
'L_SHORTMESSAGE' => $l_short_message, |
473
|
|
|
'L_LONGMESSAGE' => $l_long_message, |
474
|
|
|
'L_SEVERITYCODE' => $l_severity_code |
475
|
|
|
); |
476
|
|
|
} else { |
477
|
|
|
$errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
478
|
|
|
$errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
479
|
|
|
$errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
480
|
|
|
$errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
$n++; |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
return $errors; |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
} |
490
|
|
|
// End of file EEG_Paypal_Express.gateway.php |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.