@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event function |
428 | 428 | * for getting attendees and how many registrations they each have for an event) |
429 | 429 | * |
430 | - * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
430 | + * @return EE_Base_Class[] EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
431 | 431 | * @throws \EE_Error |
432 | 432 | */ |
433 | 433 | public function attendees() { |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | |
465 | 465 | /** |
466 | 466 | * Gets all payments which have not been approved |
467 | - * @return \EEI_Payment[] |
|
467 | + * @return EE_Base_Class[] |
|
468 | 468 | * @throws EE_Error if a model is misconfigured somehow |
469 | 469 | */ |
470 | 470 | public function pending_payments() |
@@ -709,7 +709,7 @@ discard block |
||
709 | 709 | * Gets all the extra meta info on this payment |
710 | 710 | * |
711 | 711 | * @param array $query_params like EEM_Base::get_all |
712 | - * @return EE_Extra_Meta |
|
712 | + * @return EE_Base_Class[] |
|
713 | 713 | * @throws \EE_Error |
714 | 714 | */ |
715 | 715 | public function extra_meta( $query_params = array() ) { |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | * Sets PMD_ID |
887 | 887 | * |
888 | 888 | * @param int $PMD_ID |
889 | - * @return boolean |
|
889 | + * @return boolean|null |
|
890 | 890 | * @throws \EE_Error |
891 | 891 | */ |
892 | 892 | public function set_payment_method_ID($PMD_ID) { |
@@ -462,29 +462,29 @@ |
||
462 | 462 | |
463 | 463 | |
464 | 464 | |
465 | - /** |
|
466 | - * Gets all payments which have not been approved |
|
467 | - * @return \EEI_Payment[] |
|
468 | - * @throws EE_Error if a model is misconfigured somehow |
|
469 | - */ |
|
465 | + /** |
|
466 | + * Gets all payments which have not been approved |
|
467 | + * @return \EEI_Payment[] |
|
468 | + * @throws EE_Error if a model is misconfigured somehow |
|
469 | + */ |
|
470 | 470 | public function pending_payments() |
471 | - { |
|
472 | - return $this->get_many_related( |
|
473 | - 'Payment', |
|
474 | - array( |
|
475 | - array( |
|
476 | - 'STS_ID' => EEM_Payment::status_id_pending |
|
477 | - ), |
|
478 | - 'order_by' => array( |
|
479 | - 'PAY_timestamp' => 'DESC' |
|
480 | - ) |
|
481 | - ) |
|
482 | - ); |
|
483 | - } |
|
484 | - |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
471 | + { |
|
472 | + return $this->get_many_related( |
|
473 | + 'Payment', |
|
474 | + array( |
|
475 | + array( |
|
476 | + 'STS_ID' => EEM_Payment::status_id_pending |
|
477 | + ), |
|
478 | + 'order_by' => array( |
|
479 | + 'PAY_timestamp' => 'DESC' |
|
480 | + ) |
|
481 | + ) |
|
482 | + ); |
|
483 | + } |
|
484 | + |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | 488 | * echoes $this->pretty_status() |
489 | 489 | * |
490 | 490 | * @param bool $show_icons |
@@ -45,23 +45,23 @@ |
||
45 | 45 | |
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * If the transaction has pending mijireh payments, we check with mijireh to see if they've been completed. |
|
50 | - * @param EE_Transaction $transaction |
|
51 | - * @throws EE_Error if a model is misconfigured |
|
52 | - */ |
|
48 | + /** |
|
49 | + * If the transaction has pending mijireh payments, we check with mijireh to see if they've been completed. |
|
50 | + * @param EE_Transaction $transaction |
|
51 | + * @throws EE_Error if a model is misconfigured |
|
52 | + */ |
|
53 | 53 | public static function check_for_payment_update_on_transaction( $transaction ) { |
54 | 54 | if( $transaction instanceof EE_Transaction ) { |
55 | 55 | //are there pending Mijireh payments on this transaction? |
56 | - $a_mijireh_payment = EEM_Payment::instance()->get_one( |
|
57 | - array( |
|
58 | - array( |
|
59 | - 'TXN_ID' => $transaction->ID(), |
|
60 | - 'STS_ID' => EEM_Payment::status_id_pending, |
|
61 | - 'Payment_Method.PMD_type' => 'Mijireh', |
|
62 | - ) |
|
63 | - ) |
|
64 | - ); |
|
56 | + $a_mijireh_payment = EEM_Payment::instance()->get_one( |
|
57 | + array( |
|
58 | + array( |
|
59 | + 'TXN_ID' => $transaction->ID(), |
|
60 | + 'STS_ID' => EEM_Payment::status_id_pending, |
|
61 | + 'Payment_Method.PMD_type' => 'Mijireh', |
|
62 | + ) |
|
63 | + ) |
|
64 | + ); |
|
65 | 65 | if($a_mijireh_payment instanceof EE_Payment) { |
66 | 66 | add_action( |
67 | 67 | 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * @author Mike Nelson |
20 | 20 | * |
21 | 21 | */ |
22 | -class EED_Mijireh_Payment_Checker extends EED_Module{ |
|
22 | +class EED_Mijireh_Payment_Checker extends EED_Module { |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * set_hooks - for hooking into EE Core, other modules, etc |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @return void |
41 | 41 | */ |
42 | 42 | public static function set_hooks_admin() { |
43 | - add_action( 'AHEE__Transactions_Admin_Page__transaction_details__start', array( 'EED_Mijireh_Payment_Checker', 'check_for_payment_update_on_transaction' ), 10, 1 ); |
|
43 | + add_action('AHEE__Transactions_Admin_Page__transaction_details__start', array('EED_Mijireh_Payment_Checker', 'check_for_payment_update_on_transaction'), 10, 1); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | * @param EE_Transaction $transaction |
51 | 51 | * @throws EE_Error if a model is misconfigured |
52 | 52 | */ |
53 | - public static function check_for_payment_update_on_transaction( $transaction ) { |
|
54 | - if( $transaction instanceof EE_Transaction ) { |
|
53 | + public static function check_for_payment_update_on_transaction($transaction) { |
|
54 | + if ($transaction instanceof EE_Transaction) { |
|
55 | 55 | //are there pending Mijireh payments on this transaction? |
56 | 56 | $a_mijireh_payment = EEM_Payment::instance()->get_one( |
57 | 57 | array( |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | ) |
63 | 63 | ) |
64 | 64 | ); |
65 | - if($a_mijireh_payment instanceof EE_Payment) { |
|
65 | + if ($a_mijireh_payment instanceof EE_Payment) { |
|
66 | 66 | add_action( |
67 | 67 | 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
68 | - array( 'EED_Mijireh_Payment_Checker', 'send_notifications_after_mijireh_ipn' ), |
|
68 | + array('EED_Mijireh_Payment_Checker', 'send_notifications_after_mijireh_ipn'), |
|
69 | 69 | 5, 2 |
70 | 70 | ); |
71 | - EE_Payment_Processor::instance()->process_ipn( array(), $transaction, $a_mijireh_payment->payment_method() ); |
|
71 | + EE_Payment_Processor::instance()->process_ipn(array(), $transaction, $a_mijireh_payment->payment_method()); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | } |
@@ -84,10 +84,10 @@ discard block |
||
84 | 84 | * @param EE_Registration $registration |
85 | 85 | * @param array $additional_details |
86 | 86 | */ |
87 | - public static function send_notifications_after_mijireh_ipn( $registration, $additional_details ) { |
|
88 | - $last_payment = isset( $additional_details[ 'last_payment' ] ) ? $additional_details[ 'last_payment' ] : null; |
|
89 | - if ( ! $last_payment instanceof EE_Payment || $last_payment->status() != EEM_Payment::status_id_approved ) { |
|
90 | - add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15 ); |
|
87 | + public static function send_notifications_after_mijireh_ipn($registration, $additional_details) { |
|
88 | + $last_payment = isset($additional_details['last_payment']) ? $additional_details['last_payment'] : null; |
|
89 | + if ( ! $last_payment instanceof EE_Payment || $last_payment->status() != EEM_Payment::status_id_approved) { |
|
90 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15); |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @access public |
100 | 100 | * @param WP_Query $WP_Query |
101 | 101 | */ |
102 | - public function run( $WP_Query = null ) { |
|
102 | + public function run($WP_Query = null) { |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 |
@@ -111,45 +111,45 @@ discard block |
||
111 | 111 | 'body'=> wp_json_encode($order) |
112 | 112 | ); |
113 | 113 | $response = wp_remote_post( $this->_mijireh_api_orders_url, $args ); |
114 | - $problems_string = false; |
|
114 | + $problems_string = false; |
|
115 | 115 | $this->log(array('get checkout url request_args' => $args, 'response' => $response ), $payment); |
116 | 116 | if( ! $response instanceof WP_Error ){ |
117 | 117 | $response_body = json_decode($response['body']); |
118 | 118 | if($response_body && isset($response_body->checkout_url)){ |
119 | - $payment->set_redirect_url($response_body->checkout_url); |
|
120 | - $payment->set_txn_id_chq_nmbr($response_body->order_number); |
|
121 | - $payment->set_details($response['body']); |
|
119 | + $payment->set_redirect_url($response_body->checkout_url); |
|
120 | + $payment->set_txn_id_chq_nmbr($response_body->order_number); |
|
121 | + $payment->set_details($response['body']); |
|
122 | 122 | } else { |
123 | - if( is_array( $response_body ) || is_object( $response_body)){ |
|
124 | - $response_body_as_array = (array)$response_body; |
|
125 | - foreach($response_body_as_array as $problem_parameter => $problems){ |
|
126 | - $problems_string.= sprintf(__('\nProblems with %s: %s','event_espresso'),$problem_parameter,implode(", ",$problems)); |
|
127 | - } |
|
128 | - }else{ |
|
129 | - $problems_string = $response['body']; |
|
130 | - } |
|
131 | - if( ! $problems_string ) { |
|
132 | - //no message to show? wack |
|
133 | - if( isset( $response[ 'headers' ][ 'status' ] ) ){ |
|
134 | - $problems_string = $response[ 'headers' ][ 'status' ]; |
|
135 | - }else{ |
|
136 | - $problems_string = __( 'No response from Mijireh', 'event_espresso' ); |
|
137 | - } |
|
138 | - } |
|
139 | - } |
|
123 | + if( is_array( $response_body ) || is_object( $response_body)){ |
|
124 | + $response_body_as_array = (array)$response_body; |
|
125 | + foreach($response_body_as_array as $problem_parameter => $problems){ |
|
126 | + $problems_string.= sprintf(__('\nProblems with %s: %s','event_espresso'),$problem_parameter,implode(", ",$problems)); |
|
127 | + } |
|
128 | + }else{ |
|
129 | + $problems_string = $response['body']; |
|
130 | + } |
|
131 | + if( ! $problems_string ) { |
|
132 | + //no message to show? wack |
|
133 | + if( isset( $response[ 'headers' ][ 'status' ] ) ){ |
|
134 | + $problems_string = $response[ 'headers' ][ 'status' ]; |
|
135 | + }else{ |
|
136 | + $problems_string = __( 'No response from Mijireh', 'event_espresso' ); |
|
137 | + } |
|
138 | + } |
|
139 | + } |
|
140 | 140 | }else{ |
141 | - $problems_string = implode( ",", $response->get_error_messages() ); |
|
141 | + $problems_string = implode( ",", $response->get_error_messages() ); |
|
142 | 142 | } |
143 | 143 | |
144 | - if( $problems_string ) { |
|
145 | - $payment->set_gateway_response( sprintf( __( 'Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string ) ); |
|
146 | - $payment->set_details( $response ); |
|
147 | - $payment->set_redirect_url( null ); |
|
148 | - //even though the payment's status is failed at this point anyways, |
|
149 | - //let's be explicit about it. The fact that the redirect url is null |
|
150 | - //should be enough to client code that they can't redirect the user |
|
151 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
152 | - } |
|
144 | + if( $problems_string ) { |
|
145 | + $payment->set_gateway_response( sprintf( __( 'Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string ) ); |
|
146 | + $payment->set_details( $response ); |
|
147 | + $payment->set_redirect_url( null ); |
|
148 | + //even though the payment's status is failed at this point anyways, |
|
149 | + //let's be explicit about it. The fact that the redirect url is null |
|
150 | + //should be enough to client code that they can't redirect the user |
|
151 | + $payment->set_status( $this->_pay_model->failed_status() ); |
|
152 | + } |
|
153 | 153 | return $payment; |
154 | 154 | } |
155 | 155 | |
@@ -186,70 +186,70 @@ discard block |
||
186 | 186 | * @param array $update_info unused. We just use the $transaction |
187 | 187 | * @param EEI_Transaction $transaction |
188 | 188 | * @return \EEI_Payment |
189 | - * @throws EE_Error |
|
189 | + * @throws EE_Error |
|
190 | 190 | */ |
191 | 191 | public function handle_payment_update($update_info, $transaction) { |
192 | - foreach( $transaction->pending_payments() as $payment){ |
|
193 | - $payment = $this->check_payment_in_mijireh($payment); |
|
194 | - if( $payment->status() === $this->_pay_model->approved_status()){ |
|
195 | - return $payment; |
|
196 | - } |
|
197 | - } |
|
198 | - $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL; |
|
192 | + foreach( $transaction->pending_payments() as $payment){ |
|
193 | + $payment = $this->check_payment_in_mijireh($payment); |
|
194 | + if( $payment->status() === $this->_pay_model->approved_status()){ |
|
195 | + return $payment; |
|
196 | + } |
|
197 | + } |
|
198 | + $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL; |
|
199 | 199 | |
200 | - if ( ! $payment instanceof EEI_Payment ){ |
|
201 | - throw new EE_Error( sprintf( __( "Could not find Mijireh payment for transaction %s", 'event_espresso' ), $transaction->ID() ) ); |
|
202 | - } |
|
203 | - return $payment; |
|
200 | + if ( ! $payment instanceof EEI_Payment ){ |
|
201 | + throw new EE_Error( sprintf( __( "Could not find Mijireh payment for transaction %s", 'event_espresso' ), $transaction->ID() ) ); |
|
202 | + } |
|
203 | + return $payment; |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | |
207 | 207 | |
208 | - /** |
|
209 | - * Checks the payment's status in Mijireh for this specific payment |
|
210 | - * @param \EEI_Payment $payment |
|
211 | - * @return \EEI_Payment |
|
212 | - */ |
|
208 | + /** |
|
209 | + * Checks the payment's status in Mijireh for this specific payment |
|
210 | + * @param \EEI_Payment $payment |
|
211 | + * @return \EEI_Payment |
|
212 | + */ |
|
213 | 213 | public function check_payment_in_mijireh( EEI_Payment $payment ){ |
214 | - $request_args = array( |
|
215 | - 'headers' => array( |
|
216 | - 'Authorization' => 'Basic ' . base64_encode( $this->_access_key . ':' ), |
|
217 | - 'Accept'=>'application/json' |
|
218 | - ) |
|
219 | - ); |
|
214 | + $request_args = array( |
|
215 | + 'headers' => array( |
|
216 | + 'Authorization' => 'Basic ' . base64_encode( $this->_access_key . ':' ), |
|
217 | + 'Accept'=>'application/json' |
|
218 | + ) |
|
219 | + ); |
|
220 | 220 | |
221 | - $response = wp_remote_get( |
|
222 | - $this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(), |
|
223 | - $request_args |
|
224 | - ); |
|
221 | + $response = wp_remote_get( |
|
222 | + $this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(), |
|
223 | + $request_args |
|
224 | + ); |
|
225 | 225 | |
226 | - $this->log( |
|
227 | - array( 'get payment status request_args' => $request_args, 'response' => $response ), |
|
228 | - $payment |
|
229 | - ); |
|
230 | - // validate response |
|
231 | - $response_body = isset( $response[ 'body' ] ) ? json_decode( $response[ 'body' ] ) : ''; |
|
232 | - if( $response && $response_body ){ |
|
233 | - switch( $response_body->status ){ |
|
234 | - case 'paid': |
|
235 | - $payment->set_status($this->_pay_model->approved_status()); |
|
236 | - break; |
|
237 | - case 'pending': |
|
238 | - $payment->set_status($this->_pay_model->pending_status()); |
|
239 | - break; |
|
240 | - default: |
|
241 | - $payment->set_status($this->_pay_model->declined_status()); |
|
242 | - } |
|
226 | + $this->log( |
|
227 | + array( 'get payment status request_args' => $request_args, 'response' => $response ), |
|
228 | + $payment |
|
229 | + ); |
|
230 | + // validate response |
|
231 | + $response_body = isset( $response[ 'body' ] ) ? json_decode( $response[ 'body' ] ) : ''; |
|
232 | + if( $response && $response_body ){ |
|
233 | + switch( $response_body->status ){ |
|
234 | + case 'paid': |
|
235 | + $payment->set_status($this->_pay_model->approved_status()); |
|
236 | + break; |
|
237 | + case 'pending': |
|
238 | + $payment->set_status($this->_pay_model->pending_status()); |
|
239 | + break; |
|
240 | + default: |
|
241 | + $payment->set_status($this->_pay_model->declined_status()); |
|
242 | + } |
|
243 | 243 | |
244 | - } else { |
|
245 | - $payment->set_gateway_response( __( 'Response from Mijireh could not be understood.', 'event_espresso' ) ); |
|
246 | - $payment->set_details( $response ); |
|
247 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
248 | - } |
|
249 | - // the following is ONLY for testing the Mijireh IPN and should NEVER be uncommented for real usage |
|
244 | + } else { |
|
245 | + $payment->set_gateway_response( __( 'Response from Mijireh could not be understood.', 'event_espresso' ) ); |
|
246 | + $payment->set_details( $response ); |
|
247 | + $payment->set_status( $this->_pay_model->failed_status() ); |
|
248 | + } |
|
249 | + // the following is ONLY for testing the Mijireh IPN and should NEVER be uncommented for real usage |
|
250 | 250 | // $payment->set_status( $this->_pay_model->pending_status() ); |
251 | - return $payment; |
|
252 | - } |
|
251 | + return $payment; |
|
252 | + } |
|
253 | 253 | |
254 | 254 | } |
255 | 255 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @author Mike Nelson |
9 | 9 | * |
10 | 10 | */ |
11 | -class EEG_Mijireh extends EE_Offsite_Gateway{ |
|
11 | +class EEG_Mijireh extends EE_Offsite_Gateway { |
|
12 | 12 | |
13 | 13 | protected $_access_key; |
14 | 14 | |
@@ -37,14 +37,14 @@ discard block |
||
37 | 37 | $primary_attendee = $primary_registrant->attendee(); |
38 | 38 | $items = array(); |
39 | 39 | //if we're are charging for the full amount, show the normal line items |
40 | - if( $this->_can_easily_itemize_transaction_for( $payment )){ |
|
40 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
41 | 41 | $total_line_item = $transaction->total_line_item(); |
42 | 42 | $tax_total = $total_line_item->get_total_tax(); |
43 | - foreach($total_line_item->get_items() as $line_item){ |
|
43 | + foreach ($total_line_item->get_items() as $line_item) { |
|
44 | 44 | $items[] = array( |
45 | 45 | 'name'=>apply_filters( |
46 | 46 | 'FHEE__EEG_Mijireh__set_redirection_info__full_amount_line_item_name', |
47 | - $this->_format_line_item_name( $line_item, $payment ), |
|
47 | + $this->_format_line_item_name($line_item, $payment), |
|
48 | 48 | $line_item, |
49 | 49 | $payment, |
50 | 50 | $primary_registrant |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | 'quantity'=>$line_item->quantity() |
55 | 55 | ); |
56 | 56 | } |
57 | - }else{//its a partial payment |
|
57 | + } else {//its a partial payment |
|
58 | 58 | $tax_total = 0; |
59 | 59 | //partial payment, so just add 1 item |
60 | 60 | $items[] = array( |
61 | 61 | 'name'=> apply_filters( |
62 | 62 | 'FHEE__EEG_Mijireh__set_redirection_info__partial_amount_line_item_name', |
63 | - $this->_format_partial_payment_line_item_name( $payment ), |
|
63 | + $this->_format_partial_payment_line_item_name($payment), |
|
64 | 64 | $payment, |
65 | 65 | $primary_registrant |
66 | 66 | ), |
@@ -72,18 +72,18 @@ discard block |
||
72 | 72 | $order = array( |
73 | 73 | 'total'=>$this->format_currency($payment->amount()), |
74 | 74 | 'return_url'=>$return_url, |
75 | - 'items'=>$this->_prepare_for_mijireh( $items ), |
|
75 | + 'items'=>$this->_prepare_for_mijireh($items), |
|
76 | 76 | 'email'=>$primary_attendee->email(), |
77 | 77 | 'first_name'=>$primary_attendee->fname(), |
78 | 78 | 'last_name'=>$primary_attendee->lname(), |
79 | 79 | 'tax'=>$this->format_currency($tax_total), |
80 | 80 | 'partner_id'=>'ee'); |
81 | 81 | //setup address? |
82 | - if( $primary_attendee->address() && |
|
83 | - $primary_attendee->city() && |
|
84 | - $primary_attendee->state_ID() && |
|
85 | - $primary_attendee->country_ID() && |
|
86 | - $primary_attendee->zip() ){ |
|
82 | + if ($primary_attendee->address() && |
|
83 | + $primary_attendee->city() && |
|
84 | + $primary_attendee->state_ID() && |
|
85 | + $primary_attendee->country_ID() && |
|
86 | + $primary_attendee->zip()) { |
|
87 | 87 | $shipping_address = array( |
88 | 88 | 'first_name'=>$primary_attendee->fname(), |
89 | 89 | 'last_name'=>$primary_attendee->lname(), |
@@ -93,62 +93,62 @@ discard block |
||
93 | 93 | 'zip_code' => $primary_attendee->zip(), |
94 | 94 | 'country' => $primary_attendee->country_ID() |
95 | 95 | ); |
96 | - if( $primary_attendee->address2() ){ |
|
97 | - $shipping_address[ 'apt_suite' ] = $primary_attendee->address2(); |
|
96 | + if ($primary_attendee->address2()) { |
|
97 | + $shipping_address['apt_suite'] = $primary_attendee->address2(); |
|
98 | 98 | } |
99 | - if( $primary_attendee->phone() ){ |
|
100 | - $shipping_address[ 'phone' ] = $primary_attendee->phone(); |
|
99 | + if ($primary_attendee->phone()) { |
|
100 | + $shipping_address['phone'] = $primary_attendee->phone(); |
|
101 | 101 | } |
102 | - $order[ 'shipping_address' ] = $shipping_address; |
|
102 | + $order['shipping_address'] = $shipping_address; |
|
103 | 103 | } |
104 | - $order = apply_filters( 'FHEE__EEG_Mijireh__set_redirection_info__order_arguments', $order, $payment, $primary_registrant ); |
|
105 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, serialize(get_object_vars($this)) ); |
|
104 | + $order = apply_filters('FHEE__EEG_Mijireh__set_redirection_info__order_arguments', $order, $payment, $primary_registrant); |
|
105 | + do_action('AHEE_log', __FILE__, __FUNCTION__, serialize(get_object_vars($this))); |
|
106 | 106 | $args = array( |
107 | 107 | 'headers' => array( |
108 | - 'Authorization' => 'Basic ' . base64_encode( $this->_access_key . ':' ), |
|
108 | + 'Authorization' => 'Basic '.base64_encode($this->_access_key.':'), |
|
109 | 109 | 'Accept'=>'application/json' |
110 | 110 | ), |
111 | 111 | 'body'=> wp_json_encode($order) |
112 | 112 | ); |
113 | - $response = wp_remote_post( $this->_mijireh_api_orders_url, $args ); |
|
113 | + $response = wp_remote_post($this->_mijireh_api_orders_url, $args); |
|
114 | 114 | $problems_string = false; |
115 | - $this->log(array('get checkout url request_args' => $args, 'response' => $response ), $payment); |
|
116 | - if( ! $response instanceof WP_Error ){ |
|
115 | + $this->log(array('get checkout url request_args' => $args, 'response' => $response), $payment); |
|
116 | + if ( ! $response instanceof WP_Error) { |
|
117 | 117 | $response_body = json_decode($response['body']); |
118 | - if($response_body && isset($response_body->checkout_url)){ |
|
118 | + if ($response_body && isset($response_body->checkout_url)) { |
|
119 | 119 | $payment->set_redirect_url($response_body->checkout_url); |
120 | 120 | $payment->set_txn_id_chq_nmbr($response_body->order_number); |
121 | 121 | $payment->set_details($response['body']); |
122 | 122 | } else { |
123 | - if( is_array( $response_body ) || is_object( $response_body)){ |
|
124 | - $response_body_as_array = (array)$response_body; |
|
125 | - foreach($response_body_as_array as $problem_parameter => $problems){ |
|
126 | - $problems_string.= sprintf(__('\nProblems with %s: %s','event_espresso'),$problem_parameter,implode(", ",$problems)); |
|
123 | + if (is_array($response_body) || is_object($response_body)) { |
|
124 | + $response_body_as_array = (array) $response_body; |
|
125 | + foreach ($response_body_as_array as $problem_parameter => $problems) { |
|
126 | + $problems_string .= sprintf(__('\nProblems with %s: %s', 'event_espresso'), $problem_parameter, implode(", ", $problems)); |
|
127 | 127 | } |
128 | - }else{ |
|
128 | + } else { |
|
129 | 129 | $problems_string = $response['body']; |
130 | 130 | } |
131 | - if( ! $problems_string ) { |
|
131 | + if ( ! $problems_string) { |
|
132 | 132 | //no message to show? wack |
133 | - if( isset( $response[ 'headers' ][ 'status' ] ) ){ |
|
134 | - $problems_string = $response[ 'headers' ][ 'status' ]; |
|
135 | - }else{ |
|
136 | - $problems_string = __( 'No response from Mijireh', 'event_espresso' ); |
|
133 | + if (isset($response['headers']['status'])) { |
|
134 | + $problems_string = $response['headers']['status']; |
|
135 | + } else { |
|
136 | + $problems_string = __('No response from Mijireh', 'event_espresso'); |
|
137 | 137 | } |
138 | 138 | } |
139 | 139 | } |
140 | - }else{ |
|
141 | - $problems_string = implode( ",", $response->get_error_messages() ); |
|
140 | + } else { |
|
141 | + $problems_string = implode(",", $response->get_error_messages()); |
|
142 | 142 | } |
143 | 143 | |
144 | - if( $problems_string ) { |
|
145 | - $payment->set_gateway_response( sprintf( __( 'Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string ) ); |
|
146 | - $payment->set_details( $response ); |
|
147 | - $payment->set_redirect_url( null ); |
|
144 | + if ($problems_string) { |
|
145 | + $payment->set_gateway_response(sprintf(__('Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), $problems_string)); |
|
146 | + $payment->set_details($response); |
|
147 | + $payment->set_redirect_url(null); |
|
148 | 148 | //even though the payment's status is failed at this point anyways, |
149 | 149 | //let's be explicit about it. The fact that the redirect url is null |
150 | 150 | //should be enough to client code that they can't redirect the user |
151 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
151 | + $payment->set_status($this->_pay_model->failed_status()); |
|
152 | 152 | } |
153 | 153 | return $payment; |
154 | 154 | } |
@@ -161,16 +161,16 @@ discard block |
||
161 | 161 | * @param mixed $data |
162 | 162 | * @return mixed same type as $data |
163 | 163 | */ |
164 | - private function _prepare_for_mijireh( $data ){ |
|
165 | - if( is_array( $data ) ){ |
|
164 | + private function _prepare_for_mijireh($data) { |
|
165 | + if (is_array($data)) { |
|
166 | 166 | $prepared_data = array(); |
167 | - foreach($data as $key => $datum ){ |
|
168 | - $prepared_data[ $key ] = $this->_prepare_for_mijireh( $datum ); |
|
167 | + foreach ($data as $key => $datum) { |
|
168 | + $prepared_data[$key] = $this->_prepare_for_mijireh($datum); |
|
169 | 169 | } |
170 | 170 | return $prepared_data; |
171 | - }elseif(is_string( $data ) ){ |
|
172 | - return str_replace( '%', 'percent', $data ); |
|
173 | - }else{ |
|
171 | + }elseif (is_string($data)) { |
|
172 | + return str_replace('%', 'percent', $data); |
|
173 | + } else { |
|
174 | 174 | return $data; |
175 | 175 | } |
176 | 176 | } |
@@ -189,16 +189,16 @@ discard block |
||
189 | 189 | * @throws EE_Error |
190 | 190 | */ |
191 | 191 | public function handle_payment_update($update_info, $transaction) { |
192 | - foreach( $transaction->pending_payments() as $payment){ |
|
192 | + foreach ($transaction->pending_payments() as $payment) { |
|
193 | 193 | $payment = $this->check_payment_in_mijireh($payment); |
194 | - if( $payment->status() === $this->_pay_model->approved_status()){ |
|
194 | + if ($payment->status() === $this->_pay_model->approved_status()) { |
|
195 | 195 | return $payment; |
196 | 196 | } |
197 | 197 | } |
198 | 198 | $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL; |
199 | 199 | |
200 | - if ( ! $payment instanceof EEI_Payment ){ |
|
201 | - throw new EE_Error( sprintf( __( "Could not find Mijireh payment for transaction %s", 'event_espresso' ), $transaction->ID() ) ); |
|
200 | + if ( ! $payment instanceof EEI_Payment) { |
|
201 | + throw new EE_Error(sprintf(__("Could not find Mijireh payment for transaction %s", 'event_espresso'), $transaction->ID())); |
|
202 | 202 | } |
203 | 203 | return $payment; |
204 | 204 | } |
@@ -210,27 +210,27 @@ discard block |
||
210 | 210 | * @param \EEI_Payment $payment |
211 | 211 | * @return \EEI_Payment |
212 | 212 | */ |
213 | - public function check_payment_in_mijireh( EEI_Payment $payment ){ |
|
213 | + public function check_payment_in_mijireh(EEI_Payment $payment) { |
|
214 | 214 | $request_args = array( |
215 | 215 | 'headers' => array( |
216 | - 'Authorization' => 'Basic ' . base64_encode( $this->_access_key . ':' ), |
|
216 | + 'Authorization' => 'Basic '.base64_encode($this->_access_key.':'), |
|
217 | 217 | 'Accept'=>'application/json' |
218 | 218 | ) |
219 | 219 | ); |
220 | 220 | |
221 | 221 | $response = wp_remote_get( |
222 | - $this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(), |
|
222 | + $this->_mijireh_api_orders_url.'/'.$payment->txn_id_chq_nmbr(), |
|
223 | 223 | $request_args |
224 | 224 | ); |
225 | 225 | |
226 | 226 | $this->log( |
227 | - array( 'get payment status request_args' => $request_args, 'response' => $response ), |
|
227 | + array('get payment status request_args' => $request_args, 'response' => $response), |
|
228 | 228 | $payment |
229 | 229 | ); |
230 | 230 | // validate response |
231 | - $response_body = isset( $response[ 'body' ] ) ? json_decode( $response[ 'body' ] ) : ''; |
|
232 | - if( $response && $response_body ){ |
|
233 | - switch( $response_body->status ){ |
|
231 | + $response_body = isset($response['body']) ? json_decode($response['body']) : ''; |
|
232 | + if ($response && $response_body) { |
|
233 | + switch ($response_body->status) { |
|
234 | 234 | case 'paid': |
235 | 235 | $payment->set_status($this->_pay_model->approved_status()); |
236 | 236 | break; |
@@ -242,9 +242,9 @@ discard block |
||
242 | 242 | } |
243 | 243 | |
244 | 244 | } else { |
245 | - $payment->set_gateway_response( __( 'Response from Mijireh could not be understood.', 'event_espresso' ) ); |
|
246 | - $payment->set_details( $response ); |
|
247 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
245 | + $payment->set_gateway_response(__('Response from Mijireh could not be understood.', 'event_espresso')); |
|
246 | + $payment->set_details($response); |
|
247 | + $payment->set_status($this->_pay_model->failed_status()); |
|
248 | 248 | } |
249 | 249 | // the following is ONLY for testing the Mijireh IPN and should NEVER be uncommented for real usage |
250 | 250 | // $payment->set_status( $this->_pay_model->pending_status() ); |