/** * Handles the payment update (note: mijireh doesn't send an IPN in the usual sense, * instead they just redirect the user back to our website and then we need to query them * for the payment's status). Also note that the $update_info should be an array with the key * 'payment' containing the EEI_Payment to update * @param array $update_info unused. We just use the $transaction * @param EEI_Transaction $transaction * @throws EE_Error */ public function handle_payment_update($update_info, $transaction) { $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL; if ($payment && $payment instanceof EEI_Payment) { $url = 'https://secure.mijireh.com/api/1/orders/' . $payment->txn_id_chq_nmbr(); $request_args = array('headers' => array('Authorization' => 'Basic ' . base64_encode($this->_access_key . ':'), 'Accept' => 'application/json')); $response = wp_remote_get($url, $request_args); $this->log(array('get payment status request_args' => $request_args, 'response' => $response), $payment); if ($response && isset($response['body']) && ($response_body = json_decode($response['body']))) { switch ($response_body->status) { case 'paid': $payment->set_status($this->_pay_model->approved_status()); break; case 'pending': $payment->set_status($this->_pay_model->pending_status()); break; default: $payment->set_status($this->_pay_model->declined_status()); } } else { $payment->set_gateway_response(__('Response from Mijireh could not be understood.', 'event_espresso')); $payment->set_details($response); $payment->set_status($this->_pay_model->failed_status()); } return $payment; } else { throw new EE_Error(sprintf(__("Could not find Mijireh payment for transaction %s", 'event_espresso'), $transaction->ID())); } }
/** * Handles the payment update (note: mijireh doesn't send an IPN in the usual sense, * instead they just redirect the user back to our website and then we need to query them * for the payment's status). Also note that the $update_info should be an array with the key * 'payment' containing the EEI_Payment to update * * @param array $update_info unused. We just use the $transaction * @param EEI_Transaction $transaction * @return \EEI_Payment|null */ public function handle_payment_update($update_info, $transaction) { $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL; if (!$payment instanceof EEI_Payment) { throw new EE_Error(sprintf(__("Could not find Mijireh payment for transaction %s", 'event_espresso'), $transaction->ID())); } $request_args = array('headers' => array('Authorization' => 'Basic ' . base64_encode($this->_access_key . ':'), 'Accept' => 'application/json')); $response = wp_remote_get($this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(), $request_args); $this->log(array('get payment status request_args' => $request_args, 'response' => $response), $payment); // validate response $response_body = isset($response['body']) ? json_decode($response['body']) : ''; if ($response && $response_body) { switch ($response_body->status) { case 'paid': $payment->set_status($this->_pay_model->approved_status()); break; case 'pending': $payment->set_status($this->_pay_model->pending_status()); break; default: $payment->set_status($this->_pay_model->declined_status()); } } else { $payment->set_gateway_response(__('Response from Mijireh could not be understood.', 'event_espresso')); $payment->set_details($response); $payment->set_status($this->_pay_model->failed_status()); } // the following is ONLY for testing the Mijireh IPN and should NEVER be uncommented for real usage // $payment->set_status( $this->_pay_model->pending_status() ); return $payment; }