@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | */ |
14 | 14 | class EE_Payment_Processor extends EE_Processor_Base { |
15 | 15 | /** |
16 | - * @var EE_Payment_Processor $_instance |
|
16 | + * @var EE_Payment_Processor $_instance |
|
17 | 17 | * @access private |
18 | - */ |
|
18 | + */ |
|
19 | 19 | private static $_instance; |
20 | 20 | |
21 | 21 | |
@@ -51,7 +51,6 @@ discard block |
||
51 | 51 | /** |
52 | 52 | * Using the selected gateway, processes the payment for that transaction, and updates the transaction appropriately. |
53 | 53 | * Saves the payment that is generated |
54 | - |
|
55 | 54 | * |
56 | 55 | *@param EE_Payment_Method $payment_method |
57 | 56 | * @param EE_Transaction $transaction |
@@ -131,7 +130,6 @@ discard block |
||
131 | 130 | |
132 | 131 | |
133 | 132 | /** |
134 | - |
|
135 | 133 | * @param EE_Transaction|int $transaction |
136 | 134 | * @param EE_Payment_Method $payment_method |
137 | 135 | * @throws EE_Error |
@@ -694,12 +692,12 @@ discard block |
||
694 | 692 | } |
695 | 693 | |
696 | 694 | /** |
697 | - * Force posts to PayPal to use TLS v1.2. See: |
|
698 | - * https://core.trac.wordpress.org/ticket/36320 |
|
699 | - * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
700 | - * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
695 | + * Force posts to PayPal to use TLS v1.2. See: |
|
696 | + * https://core.trac.wordpress.org/ticket/36320 |
|
697 | + * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
698 | + * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
701 | 699 | * This will affect paypal standard, pro, express, and payflow. |
702 | - */ |
|
700 | + */ |
|
703 | 701 | public static function _curl_requests_to_paypal_use_tls( $handle, $r, $url ) { |
704 | 702 | if ( strstr( $url, 'https://' ) && strstr( $url, '.paypal.com' ) ) { |
705 | 703 | //Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
2 | -EE_Registry::instance()->load_class( 'Processor_Base' ); |
|
2 | +EE_Registry::instance()->load_class('Processor_Base'); |
|
3 | 3 | /** |
4 | 4 | * |
5 | 5 | * EE_Payment_Processor |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public static function instance() { |
29 | 29 | // check if class object is instantiated |
30 | - if ( ! self::$_instance instanceof EE_Payment_Processor ) { |
|
30 | + if ( ! self::$_instance instanceof EE_Payment_Processor) { |
|
31 | 31 | self::$_instance = new self(); |
32 | 32 | } |
33 | 33 | return self::$_instance; |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | *@return EE_Payment_Processor |
43 | 43 | */ |
44 | 44 | private function __construct() { |
45 | - do_action( 'AHEE__EE_Payment_Processor__construct' ); |
|
46 | - add_action( 'http_api_curl', array( $this, '_curl_requests_to_paypal_use_tls' ), 10, 3 ); |
|
45 | + do_action('AHEE__EE_Payment_Processor__construct'); |
|
46 | + add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $update_txn = true, |
83 | 83 | $cancel_url = '' |
84 | 84 | ) { |
85 | - if( (float)$amount < 0 ) { |
|
85 | + if ((float) $amount < 0) { |
|
86 | 86 | throw new EE_Error( |
87 | 87 | sprintf( |
88 | 88 | __( |
@@ -95,33 +95,33 @@ discard block |
||
95 | 95 | ); |
96 | 96 | } |
97 | 97 | // verify payment method |
98 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj( $payment_method, TRUE ); |
|
98 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, TRUE); |
|
99 | 99 | // verify transaction |
100 | - EEM_Transaction::instance()->ensure_is_obj( $transaction ); |
|
101 | - $transaction->set_payment_method_ID( $payment_method->ID() ); |
|
100 | + EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
101 | + $transaction->set_payment_method_ID($payment_method->ID()); |
|
102 | 102 | // verify payment method type |
103 | - if ( $payment_method->type_obj() instanceof EE_PMT_Base ) { |
|
103 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
104 | 104 | $payment = $payment_method->type_obj()->process_payment( |
105 | 105 | $transaction, |
106 | - min( $amount, $transaction->remaining() ),//make sure we don't overcharge |
|
106 | + min($amount, $transaction->remaining()), //make sure we don't overcharge |
|
107 | 107 | $billing_form, |
108 | 108 | $return_url, |
109 | - add_query_arg( array( 'ee_cancel_payment' => true ), $cancel_url ), |
|
109 | + add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
110 | 110 | $method, |
111 | 111 | $by_admin |
112 | 112 | ); |
113 | 113 | // check if payment method uses an off-site gateway |
114 | - if ( $payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite ) { |
|
114 | + if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
115 | 115 | // don't process payments for off-site gateways yet because no payment has occurred yet |
116 | - $this->update_txn_based_on_payment( $transaction, $payment, $update_txn ); |
|
116 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
117 | 117 | } |
118 | 118 | return $payment; |
119 | 119 | } else { |
120 | 120 | EE_Error::add_error( |
121 | 121 | sprintf( |
122 | - __( 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso' ), |
|
122 | + __('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'), |
|
123 | 123 | '<br/>', |
124 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
124 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
125 | 125 | ), __FILE__, __FUNCTION__, __LINE__ |
126 | 126 | ); |
127 | 127 | return NULL; |
@@ -137,11 +137,11 @@ discard block |
||
137 | 137 | * @throws EE_Error |
138 | 138 | * @return string |
139 | 139 | */ |
140 | - public function get_ipn_url_for_payment_method( $transaction, $payment_method ){ |
|
140 | + public function get_ipn_url_for_payment_method($transaction, $payment_method) { |
|
141 | 141 | /** @type \EE_Transaction $transaction */ |
142 | - $transaction = EEM_Transaction::instance()->ensure_is_obj( $transaction ); |
|
142 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
143 | 143 | $primary_reg = $transaction->primary_registration(); |
144 | - if( ! $primary_reg instanceof EE_Registration ){ |
|
144 | + if ( ! $primary_reg instanceof EE_Registration) { |
|
145 | 145 | throw new EE_Error( |
146 | 146 | sprintf( |
147 | 147 | __( |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | ) |
153 | 153 | ); |
154 | 154 | } |
155 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method,true); |
|
155 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
156 | 156 | $url = add_query_arg( |
157 | 157 | array( |
158 | 158 | 'e_reg_url_link'=>$primary_reg->reg_url_link(), |
@@ -189,92 +189,92 @@ discard block |
||
189 | 189 | $update_txn = true, |
190 | 190 | $separate_IPN_request = true |
191 | 191 | ) { |
192 | - EE_Registry::instance()->load_model( 'Change_Log' ); |
|
193 | - $_req_data = $this->_remove_unusable_characters_from_array( (array)$_req_data ); |
|
194 | - EE_Processor_Base::set_IPN( $separate_IPN_request ); |
|
192 | + EE_Registry::instance()->load_model('Change_Log'); |
|
193 | + $_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data); |
|
194 | + EE_Processor_Base::set_IPN($separate_IPN_request); |
|
195 | 195 | $obj_for_log = null; |
196 | - if( $transaction instanceof EE_Transaction ){ |
|
196 | + if ($transaction instanceof EE_Transaction) { |
|
197 | 197 | $obj_for_log = $transaction; |
198 | - if( $payment_method instanceof EE_Payment_Method ) { |
|
198 | + if ($payment_method instanceof EE_Payment_Method) { |
|
199 | 199 | $obj_for_log = EEM_Payment::instance()->get_one( |
200 | 200 | array( |
201 | - array( 'TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID() ), |
|
202 | - 'order_by' => array( 'PAY_timestamp' => 'desc' ) |
|
201 | + array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
202 | + 'order_by' => array('PAY_timestamp' => 'desc') |
|
203 | 203 | ) |
204 | 204 | ); |
205 | 205 | } |
206 | - } else if( $payment_method instanceof EE_Payment ) { |
|
206 | + } else if ($payment_method instanceof EE_Payment) { |
|
207 | 207 | $obj_for_log = $payment_method; |
208 | 208 | } |
209 | 209 | $log = EEM_Change_Log::instance()->log( |
210 | 210 | EEM_Change_Log::type_gateway, |
211 | - array( 'IPN data received' => $_req_data ), |
|
211 | + array('IPN data received' => $_req_data), |
|
212 | 212 | $obj_for_log |
213 | 213 | ); |
214 | - try{ |
|
214 | + try { |
|
215 | 215 | /** |
216 | 216 | * @var EE_Payment $payment |
217 | 217 | */ |
218 | 218 | $payment = NULL; |
219 | - if($transaction && $payment_method){ |
|
219 | + if ($transaction && $payment_method) { |
|
220 | 220 | /** @type EE_Transaction $transaction */ |
221 | 221 | $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
222 | 222 | /** @type EE_Payment_Method $payment_method */ |
223 | 223 | $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
224 | - if ( $payment_method->type_obj() instanceof EE_PMT_Base ) { |
|
225 | - $payment = $payment_method->type_obj()->handle_ipn( $_req_data, $transaction ); |
|
224 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
225 | + $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
226 | 226 | $log->set_object($payment); |
227 | 227 | } else { |
228 | 228 | // not a payment |
229 | 229 | EE_Error::add_error( |
230 | 230 | sprintf( |
231 | - __( 'A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso' ), |
|
231 | + __('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'), |
|
232 | 232 | '<br/>', |
233 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
233 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
234 | 234 | ), |
235 | 235 | __FILE__, __FUNCTION__, __LINE__ |
236 | 236 | ); |
237 | 237 | } |
238 | - }else{ |
|
238 | + } else { |
|
239 | 239 | //that's actually pretty ok. The IPN just wasn't able |
240 | 240 | //to identify which transaction or payment method this was for |
241 | 241 | // give all active payment methods a chance to claim it |
242 | 242 | $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
243 | - foreach( $active_payment_methods as $active_payment_method ){ |
|
244 | - try{ |
|
245 | - $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn( $_req_data ); |
|
243 | + foreach ($active_payment_methods as $active_payment_method) { |
|
244 | + try { |
|
245 | + $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
246 | 246 | $payment_method = $active_payment_method; |
247 | 247 | EEM_Change_Log::instance()->log( |
248 | 248 | EEM_Change_Log::type_gateway, array('IPN data'=>$_req_data), $payment |
249 | 249 | ); |
250 | 250 | break; |
251 | - } catch( EE_Error $e ) { |
|
251 | + } catch (EE_Error $e) { |
|
252 | 252 | //that's fine- it apparently couldn't handle the IPN |
253 | 253 | } |
254 | 254 | } |
255 | 255 | |
256 | 256 | } |
257 | 257 | // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
258 | - if( $payment instanceof EE_Payment){ |
|
258 | + if ($payment instanceof EE_Payment) { |
|
259 | 259 | $payment->save(); |
260 | 260 | // update the TXN |
261 | - $this->update_txn_based_on_payment( $transaction, $payment, $update_txn, $separate_IPN_request ); |
|
262 | - }else{ |
|
261 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request); |
|
262 | + } else { |
|
263 | 263 | //we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
264 | - if($payment_method){ |
|
264 | + if ($payment_method) { |
|
265 | 265 | EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data'=>$_req_data), $payment_method); |
266 | - }elseif($transaction){ |
|
266 | + }elseif ($transaction) { |
|
267 | 267 | EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data'=>$_req_data), $transaction); |
268 | 268 | } |
269 | 269 | } |
270 | 270 | return $payment; |
271 | 271 | |
272 | - } catch( EE_Error $e ) { |
|
272 | + } catch (EE_Error $e) { |
|
273 | 273 | do_action( |
274 | 274 | 'AHEE__log', __FILE__, __FUNCTION__, sprintf( |
275 | - __( 'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso' ), |
|
276 | - print_r( $transaction, TRUE ), |
|
277 | - print_r( $_req_data, TRUE ), |
|
275 | + __('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'), |
|
276 | + print_r($transaction, TRUE), |
|
277 | + print_r($_req_data, TRUE), |
|
278 | 278 | $e->getMessage() |
279 | 279 | ) |
280 | 280 | ); |
@@ -289,10 +289,10 @@ discard block |
||
289 | 289 | * @param array $request_data |
290 | 290 | * @return array |
291 | 291 | */ |
292 | - protected function _remove_unusable_characters_from_array( array $request_data ) { |
|
292 | + protected function _remove_unusable_characters_from_array(array $request_data) { |
|
293 | 293 | $return_data = array(); |
294 | - foreach( $request_data as $key => $value ) { |
|
295 | - $return_data[ $this->_remove_unusable_characters( $key ) ] = $this->_remove_unusable_characters( $value ); |
|
294 | + foreach ($request_data as $key => $value) { |
|
295 | + $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value); |
|
296 | 296 | } |
297 | 297 | return $return_data; |
298 | 298 | } |
@@ -304,8 +304,8 @@ discard block |
||
304 | 304 | * @param string $request_data |
305 | 305 | * @return string |
306 | 306 | */ |
307 | - protected function _remove_unusable_characters( $request_data ) { |
|
308 | - return preg_replace( '/[^[:print:]]/', '', $request_data ); |
|
307 | + protected function _remove_unusable_characters($request_data) { |
|
308 | + return preg_replace('/[^[:print:]]/', '', $request_data); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | |
@@ -327,13 +327,13 @@ discard block |
||
327 | 327 | * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
328 | 328 | * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
329 | 329 | */ |
330 | - public function finalize_payment_for( $transaction, $update_txn = TRUE ){ |
|
330 | + public function finalize_payment_for($transaction, $update_txn = TRUE) { |
|
331 | 331 | /** @var $transaction EE_Transaction */ |
332 | - $transaction = EEM_Transaction::instance()->ensure_is_obj( $transaction ); |
|
332 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
333 | 333 | $last_payment_method = $transaction->payment_method(); |
334 | - if ( $last_payment_method instanceof EE_Payment_Method ) { |
|
335 | - $payment = $last_payment_method->type_obj()->finalize_payment_for( $transaction ); |
|
336 | - $this->update_txn_based_on_payment( $transaction, $payment, $update_txn ); |
|
334 | + if ($last_payment_method instanceof EE_Payment_Method) { |
|
335 | + $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
336 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
337 | 337 | return $payment; |
338 | 338 | } else { |
339 | 339 | return NULL; |
@@ -356,9 +356,9 @@ discard block |
||
356 | 356 | EE_Payment $payment_to_refund, |
357 | 357 | $refund_info = array() |
358 | 358 | ) { |
359 | - if ( $payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds() ) { |
|
360 | - $payment_method->type_obj()->process_refund( $payment_to_refund, $refund_info ); |
|
361 | - $this->update_txn_based_on_payment( $payment_to_refund->transaction(), $payment_to_refund ); |
|
359 | + if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
360 | + $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
361 | + $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
362 | 362 | } |
363 | 363 | return $payment_to_refund; |
364 | 364 | } |
@@ -399,12 +399,12 @@ discard block |
||
399 | 399 | * TXN is locked before updating |
400 | 400 | * @throws \EE_Error |
401 | 401 | */ |
402 | - public function update_txn_based_on_payment( $transaction, $payment, $update_txn = true, $IPN = false ){ |
|
402 | + public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) { |
|
403 | 403 | $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
404 | 404 | /** @type EE_Transaction $transaction */ |
405 | - $transaction = EEM_Transaction::instance()->ensure_is_obj( $transaction ); |
|
405 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
406 | 406 | // can we freely update the TXN at this moment? |
407 | - if ( $IPN && $transaction->is_locked() ) { |
|
407 | + if ($IPN && $transaction->is_locked()) { |
|
408 | 408 | // don't update the transaction at this exact moment |
409 | 409 | // because the TXN is active in another request |
410 | 410 | EE_Cron_Tasks::schedule_update_transaction_with_payment( |
@@ -414,45 +414,45 @@ discard block |
||
414 | 414 | ); |
415 | 415 | } else { |
416 | 416 | // verify payment and that it has been saved |
417 | - if ( $payment instanceof EE_Payment && $payment->ID() ) { |
|
418 | - if( |
|
417 | + if ($payment instanceof EE_Payment && $payment->ID()) { |
|
418 | + if ( |
|
419 | 419 | $payment->payment_method() instanceof EE_Payment_Method |
420 | 420 | && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
421 | - ){ |
|
422 | - $payment->payment_method()->type_obj()->update_txn_based_on_payment( $payment ); |
|
421 | + ) { |
|
422 | + $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
423 | 423 | // update TXN registrations with payment info |
424 | - $this->process_registration_payments( $transaction, $payment ); |
|
424 | + $this->process_registration_payments($transaction, $payment); |
|
425 | 425 | } |
426 | 426 | $do_action = $payment->just_approved() |
427 | 427 | ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
428 | 428 | : $do_action; |
429 | 429 | } else { |
430 | 430 | // send out notifications |
431 | - add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true' ); |
|
431 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
432 | 432 | $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
433 | 433 | } |
434 | 434 | // if this is an IPN, then we want to know the initial TXN status prior to updating the TXN |
435 | 435 | // so that we know whether the status has changed and notifications should be triggered |
436 | - if ( $IPN ) { |
|
436 | + if ($IPN) { |
|
437 | 437 | /** @type EE_Transaction_Processor $transaction_processor */ |
438 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
439 | - $transaction_processor->set_old_txn_status( $transaction->status_ID() ); |
|
438 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
439 | + $transaction_processor->set_old_txn_status($transaction->status_ID()); |
|
440 | 440 | } |
441 | - if ( $payment->status() !== EEM_Payment::status_id_failed ) { |
|
441 | + if ($payment->status() !== EEM_Payment::status_id_failed) { |
|
442 | 442 | /** @type EE_Transaction_Payments $transaction_payments */ |
443 | - $transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' ); |
|
443 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
444 | 444 | // set new value for total paid |
445 | - $transaction_payments->calculate_total_payments_and_update_status( $transaction ); |
|
445 | + $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
446 | 446 | // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
447 | - if ( $update_txn ) { |
|
448 | - $this->_post_payment_processing( $transaction, $payment, $IPN ); |
|
447 | + if ($update_txn) { |
|
448 | + $this->_post_payment_processing($transaction, $payment, $IPN); |
|
449 | 449 | } |
450 | 450 | } |
451 | 451 | // granular hook for others to use. |
452 | - do_action( $do_action, $transaction, $payment ); |
|
453 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action' ); |
|
452 | + do_action($do_action, $transaction, $payment); |
|
453 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
454 | 454 | //global hook for others to use. |
455 | - do_action( 'AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment ); |
|
455 | + do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
456 | 456 | } |
457 | 457 | } |
458 | 458 | |
@@ -472,25 +472,25 @@ discard block |
||
472 | 472 | $registrations = array() |
473 | 473 | ) { |
474 | 474 | // only process if payment was successful |
475 | - if ( $payment->status() !== EEM_Payment::status_id_approved ) { |
|
475 | + if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
476 | 476 | return; |
477 | 477 | } |
478 | 478 | //EEM_Registration::instance()->show_next_x_db_queries(); |
479 | - if ( empty( $registrations )) { |
|
479 | + if (empty($registrations)) { |
|
480 | 480 | // find registrations with monies owing that can receive a payment |
481 | 481 | $registrations = $transaction->registrations( |
482 | 482 | array( |
483 | 483 | array( |
484 | 484 | // only these reg statuses can receive payments |
485 | - 'STS_ID' => array( 'IN', EEM_Registration::reg_statuses_that_allow_payment() ), |
|
486 | - 'REG_final_price' => array( '!=', 0 ), |
|
487 | - 'REG_final_price*' => array( '!=', 'REG_paid', true ), |
|
485 | + 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
486 | + 'REG_final_price' => array('!=', 0), |
|
487 | + 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
488 | 488 | ) |
489 | 489 | ) |
490 | 490 | ); |
491 | 491 | } |
492 | 492 | // still nothing ??!?? |
493 | - if ( empty( $registrations )) { |
|
493 | + if (empty($registrations)) { |
|
494 | 494 | return; |
495 | 495 | } |
496 | 496 | // todo: break out the following logic into a separate strategy class |
@@ -502,28 +502,28 @@ discard block |
||
502 | 502 | |
503 | 503 | $refund = $payment->is_a_refund(); |
504 | 504 | // how much is available to apply to registrations? |
505 | - $available_payment_amount = abs( $payment->amount() ); |
|
506 | - foreach ( $registrations as $registration ) { |
|
507 | - if ( $registration instanceof EE_Registration ) { |
|
505 | + $available_payment_amount = abs($payment->amount()); |
|
506 | + foreach ($registrations as $registration) { |
|
507 | + if ($registration instanceof EE_Registration) { |
|
508 | 508 | // nothing left? |
509 | - if ( $available_payment_amount <= 0 ) { |
|
509 | + if ($available_payment_amount <= 0) { |
|
510 | 510 | break; |
511 | 511 | } |
512 | - if ( $refund ) { |
|
513 | - $available_payment_amount = $this->process_registration_refund( $registration, $payment, $available_payment_amount ); |
|
512 | + if ($refund) { |
|
513 | + $available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount); |
|
514 | 514 | } else { |
515 | - $available_payment_amount = $this->process_registration_payment( $registration, $payment, $available_payment_amount ); |
|
515 | + $available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount); |
|
516 | 516 | } |
517 | 517 | } |
518 | 518 | } |
519 | - if ( $available_payment_amount > 0 && apply_filters( 'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false ) ) { |
|
519 | + if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) { |
|
520 | 520 | EE_Error::add_attention( |
521 | 521 | sprintf( |
522 | - __( 'A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', 'event_espresso' ), |
|
523 | - EEH_Template::format_currency( $available_payment_amount ), |
|
524 | - implode( ', ', array_keys( $registrations ) ), |
|
522 | + __('A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', 'event_espresso'), |
|
523 | + EEH_Template::format_currency($available_payment_amount), |
|
524 | + implode(', ', array_keys($registrations)), |
|
525 | 525 | '<br/>', |
526 | - EEH_Template::format_currency( $payment->amount() ) |
|
526 | + EEH_Template::format_currency($payment->amount()) |
|
527 | 527 | ), |
528 | 528 | __FILE__, __FUNCTION__, __LINE__ |
529 | 529 | ); |
@@ -541,17 +541,17 @@ discard block |
||
541 | 541 | * @return float |
542 | 542 | * @throws \EE_Error |
543 | 543 | */ |
544 | - public function process_registration_payment( EE_Registration $registration, EE_Payment $payment, $available_payment_amount = 0.00 ) { |
|
544 | + public function process_registration_payment(EE_Registration $registration, EE_Payment $payment, $available_payment_amount = 0.00) { |
|
545 | 545 | $owing = $registration->final_price() - $registration->paid(); |
546 | - if ( $owing > 0 ) { |
|
546 | + if ($owing > 0) { |
|
547 | 547 | // don't allow payment amount to exceed the available payment amount, OR the amount owing |
548 | - $payment_amount = min( $available_payment_amount, $owing ); |
|
548 | + $payment_amount = min($available_payment_amount, $owing); |
|
549 | 549 | // update $available_payment_amount |
550 | 550 | $available_payment_amount -= $payment_amount; |
551 | 551 | //calculate and set new REG_paid |
552 | - $registration->set_paid( $registration->paid() + $payment_amount ); |
|
552 | + $registration->set_paid($registration->paid() + $payment_amount); |
|
553 | 553 | // now save it |
554 | - $this->_apply_registration_payment( $registration, $payment, $payment_amount ); |
|
554 | + $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
555 | 555 | } |
556 | 556 | return $available_payment_amount; |
557 | 557 | } |
@@ -567,19 +567,19 @@ discard block |
||
567 | 567 | * @return float |
568 | 568 | * @throws \EE_Error |
569 | 569 | */ |
570 | - protected function _apply_registration_payment( EE_Registration $registration, EE_Payment $payment, $payment_amount = 0.00 ) { |
|
570 | + protected function _apply_registration_payment(EE_Registration $registration, EE_Payment $payment, $payment_amount = 0.00) { |
|
571 | 571 | // find any existing reg payment records for this registration and payment |
572 | 572 | $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
573 | - array( array( 'REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID() ) ) |
|
573 | + array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
574 | 574 | ); |
575 | 575 | // if existing registration payment exists |
576 | - if ( $existing_reg_payment instanceof EE_Registration_Payment ) { |
|
576 | + if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
577 | 577 | // then update that record |
578 | - $existing_reg_payment->set_amount( $payment_amount ); |
|
578 | + $existing_reg_payment->set_amount($payment_amount); |
|
579 | 579 | $existing_reg_payment->save(); |
580 | 580 | } else { |
581 | 581 | // or add new relation between registration and payment and set amount |
582 | - $registration->_add_relation_to( $payment, 'Payment', array( 'RPY_amount' => $payment_amount ) ); |
|
582 | + $registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount)); |
|
583 | 583 | // make it stick |
584 | 584 | $registration->save(); |
585 | 585 | } |
@@ -596,21 +596,21 @@ discard block |
||
596 | 596 | * @return float |
597 | 597 | * @throws \EE_Error |
598 | 598 | */ |
599 | - public function process_registration_refund( EE_Registration $registration, EE_Payment $payment, $available_refund_amount = 0.00 ) { |
|
599 | + public function process_registration_refund(EE_Registration $registration, EE_Payment $payment, $available_refund_amount = 0.00) { |
|
600 | 600 | //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
601 | - if ( $registration->paid() > 0 ) { |
|
601 | + if ($registration->paid() > 0) { |
|
602 | 602 | // ensure $available_refund_amount is NOT negative |
603 | - $available_refund_amount = (float)abs( $available_refund_amount ); |
|
603 | + $available_refund_amount = (float) abs($available_refund_amount); |
|
604 | 604 | // don't allow refund amount to exceed the available payment amount, OR the amount paid |
605 | - $refund_amount = min( $available_refund_amount, (float)$registration->paid() ); |
|
605 | + $refund_amount = min($available_refund_amount, (float) $registration->paid()); |
|
606 | 606 | // update $available_payment_amount |
607 | 607 | $available_refund_amount -= $refund_amount; |
608 | 608 | //calculate and set new REG_paid |
609 | - $registration->set_paid( $registration->paid() - $refund_amount ); |
|
609 | + $registration->set_paid($registration->paid() - $refund_amount); |
|
610 | 610 | // convert payment amount back to a negative value for storage in the db |
611 | - $refund_amount = (float)abs( $refund_amount ) * -1; |
|
611 | + $refund_amount = (float) abs($refund_amount) * -1; |
|
612 | 612 | // now save it |
613 | - $this->_apply_registration_payment( $registration, $payment, $refund_amount ); |
|
613 | + $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
614 | 614 | } |
615 | 615 | return $available_refund_amount; |
616 | 616 | } |
@@ -629,21 +629,21 @@ discard block |
||
629 | 629 | * @param bool $IPN |
630 | 630 | * @throws \EE_Error |
631 | 631 | */ |
632 | - protected function _post_payment_processing( EE_Transaction $transaction, EE_Payment $payment, $IPN = false ) { |
|
632 | + protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) { |
|
633 | 633 | |
634 | 634 | /** @type EE_Transaction_Processor $transaction_processor */ |
635 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
635 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
636 | 636 | // is the Payment Options Reg Step completed ? |
637 | - $payment_options_step_completed = $transaction_processor->reg_step_completed( $transaction, 'payment_options' ); |
|
637 | + $payment_options_step_completed = $transaction_processor->reg_step_completed($transaction, 'payment_options'); |
|
638 | 638 | // if the Payment Options Reg Step is completed... |
639 | 639 | $revisit = $payment_options_step_completed === true ? true : false; |
640 | 640 | // then this is kinda sorta a revisit with regards to payments at least |
641 | - $transaction_processor->set_revisit( $revisit ); |
|
641 | + $transaction_processor->set_revisit($revisit); |
|
642 | 642 | // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
643 | 643 | if ( |
644 | 644 | $IPN && |
645 | 645 | $payment_options_step_completed !== true && |
646 | - ( $payment->is_approved() || $payment->is_pending() ) |
|
646 | + ($payment->is_approved() || $payment->is_pending()) |
|
647 | 647 | ) { |
648 | 648 | $payment_options_step_completed = $transaction_processor->set_reg_step_completed( |
649 | 649 | $transaction, |
@@ -651,34 +651,34 @@ discard block |
||
651 | 651 | ); |
652 | 652 | } |
653 | 653 | /** @type EE_Transaction_Payments $transaction_payments */ |
654 | - $transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' ); |
|
654 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
655 | 655 | // maybe update status, but don't save transaction just yet |
656 | - $transaction_payments->update_transaction_status_based_on_total_paid( $transaction, false ); |
|
656 | + $transaction_payments->update_transaction_status_based_on_total_paid($transaction, false); |
|
657 | 657 | // check if 'finalize_registration' step has been completed... |
658 | - $finalized = $transaction_processor->reg_step_completed( $transaction, 'finalize_registration' ); |
|
658 | + $finalized = $transaction_processor->reg_step_completed($transaction, 'finalize_registration'); |
|
659 | 659 | // if this is an IPN and the final step has not been initiated |
660 | - if ( $IPN && $payment_options_step_completed && $finalized === false ) { |
|
660 | + if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
661 | 661 | // and if it hasn't already been set as being started... |
662 | - $finalized = $transaction_processor->set_reg_step_initiated( $transaction, 'finalize_registration' ); |
|
662 | + $finalized = $transaction_processor->set_reg_step_initiated($transaction, 'finalize_registration'); |
|
663 | 663 | } |
664 | 664 | $transaction->save(); |
665 | 665 | // because the above will return false if the final step was not fully completed, we need to check again... |
666 | - if ( $IPN && $finalized !== false ) { |
|
666 | + if ($IPN && $finalized !== false) { |
|
667 | 667 | // and if we are all good to go, then send out notifications |
668 | - add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true' ); |
|
668 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
669 | 669 | //ok, now process the transaction according to the payment |
670 | - $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( $transaction, $payment ); |
|
670 | + $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment); |
|
671 | 671 | } |
672 | 672 | // DEBUG LOG |
673 | 673 | $payment_method = $payment->payment_method(); |
674 | - if ( $payment_method instanceof EE_Payment_Method ) { |
|
674 | + if ($payment_method instanceof EE_Payment_Method) { |
|
675 | 675 | $payment_method_type_obj = $payment_method->type_obj(); |
676 | - if ( $payment_method_type_obj instanceof EE_PMT_Base ) { |
|
676 | + if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
677 | 677 | $gateway = $payment_method_type_obj->get_gateway(); |
678 | - if ( $gateway instanceof EE_Gateway ){ |
|
678 | + if ($gateway instanceof EE_Gateway) { |
|
679 | 679 | $gateway->log( |
680 | 680 | array( |
681 | - 'message' => __( 'Post Payment Transaction Details', 'event_espresso' ), |
|
681 | + 'message' => __('Post Payment Transaction Details', 'event_espresso'), |
|
682 | 682 | 'transaction' => $transaction->model_field_array(), |
683 | 683 | 'finalized' => $finalized, |
684 | 684 | 'IPN' => $IPN, |
@@ -700,11 +700,11 @@ discard block |
||
700 | 700 | * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
701 | 701 | * This will affect paypal standard, pro, express, and payflow. |
702 | 702 | */ |
703 | - public static function _curl_requests_to_paypal_use_tls( $handle, $r, $url ) { |
|
704 | - if ( strstr( $url, 'https://' ) && strstr( $url, '.paypal.com' ) ) { |
|
703 | + public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) { |
|
704 | + if (strstr($url, 'https://') && strstr($url, '.paypal.com')) { |
|
705 | 705 | //Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
706 | 706 | //instead of the constant because it might not be defined |
707 | - curl_setopt( $handle, CURLOPT_SSLVERSION, 1 ); |
|
707 | + curl_setopt($handle, CURLOPT_SSLVERSION, 1); |
|
708 | 708 | } |
709 | 709 | } |
710 | 710 | } |