/** * Check for iPay88 Payment Response. * Process Payment based on the Response. **/ function check_status_response_ipay88() { $posted = stripslashes_deep($_POST); $is_backend_notification = WC_iPay88::get_get('iPay88_response') == 'backend'; $received_ok = 'ID' == $this->gateway ? 'RECEIVEOK' : 'OK'; //Debug log if ('yes' == $this->debug) { // Backend notification will get the OK response if ($is_backend_notification) { WC_iPay88::add_debug_log('Backend response.'); } WC_iPay88::add_debug_log('Payment response received. Response is: ' . print_r($_POST, true)); } if ($this->validate_response()) { $refno = WC_iPay88::get_post('RefNo'); $transid = WC_iPay88::get_post('TransId'); $estatus = WC_iPay88::get_post('Status'); $errdesc = WC_iPay88::get_post('ErrDesc'); $order_id = $this->get_order_id($refno); $order = new WC_Order((int) $order_id); $redirect_url = $this->get_return_url($order); // Check if the order was already processed if ('completed' == $order->status || 'processing' == $order->status) { // Debug log if ('yes' == $this->debug) { WC_iPay88::add_debug_log('Payment already processed. Aborting.'); } // Backend notification will get the OK response if ($is_backend_notification) { echo $received_ok; } else { // Normal Payment notification need to be redirected to the "Thank You" page. wp_safe_redirect($redirect_url); } exit; } switch ($estatus) { case 1: // Successful payment // Update order $order->add_order_note(sprintf(__('iPay88 Payment Completed.' . ' Transaction Reference Number: %s.', 'wc_ipay88'), $transid)); // Debug log if ('yes' == $this->debug) { WC_iPay88::add_debug_log('Payment completed.'); } WC_Compat_iPay88::empty_cart(); $order->payment_complete(); break; case 2: // Failed payment // Failed payment default: // Debug log if ('yes' == $this->debug) { WC_iPay88::add_debug_log('Payment failed.'); } // Update order $order->add_order_note(sprintf(__('iPay88 Payment Failed. Error Description: %s Transaction Reference Number: %s.', 'wc_ipay88'), $errdesc, $transid)); $order->update_status('failed'); // Add error to show the customer and the cancel URL WC_Compat_iPay88::wc_add_notice(__('Your Payment Failed. Please try again or use another payment option.', 'wc_ipay88'), 'error'); break; } // Backend notification will get the OK response if ($is_backend_notification) { echo $received_ok; } else { // Normal Payment notification needs to be redirected to the "Thank You" page. wp_safe_redirect($redirect_url); } exit; } }