} if (defined('PAYMENT_NOTIFICATION')) { if ($mode == 'process') { $payment_id = $_REQUEST['payment_id']; // Get Instamojo details from backend instamojo_error_logger("Callback called with Payment ID: " . $payment_id); $processor_details = fn_get_processor_data_by_name('instamojo.php'); $pdata = db_get_row("SELECT * FROM ?:payments WHERE processor_id = ?i", $processor_details['processor_id']); instamojo_error_logger("Instamojo processor details from DB: " . print_r($pdata, true)); $processor_details['processor_params'] = unserialize($pdata['processor_params']); instamojo_error_logger("Instamojo's settings from DB: " . print_r($processor_details['processor_params'], true)); $api_key = $processor_details['processor_params']['instamojo_api_key']; $auth_token = $processor_details['processor_params']['instamojo_auth_token']; $custom_field = $processor_details['processor_params']['instamojo_custom_field']; # Callback Instamojo $response = check_instamojo_payment_status($api_key, $auth_token, $payment_id); instamojo_error_logger("{$api_key} | {$auth_token} | {$custom_field}"); instamojo_error_logger("Response from Instamojo is: " . print_r($response, true)); instamojo_error_logger(print_r($response, true)); $pp_response = array(); if ($response['payment']['status'] == 'Credit') { instamojo_error_logger("Payment credited for Payment ID: " . $payment_id); $order_id = $response['payment']['custom_fields'][$custom_field]['value']; instamojo_error_logger("And the Order ID is: " . $order_id); $order_info = fn_get_order_info($order_id); $pp_response['order_status'] = 'P'; $pp_response['transaction_id'] = $payment_id; if (fn_check_payment_script('instamojo.php', $order_id)) { fn_finish_payment($order_id, $pp_response, false); } } else {
/** * Check for valid Instamojo server callback **/ function check_instamojo_response() { global $woocommerce; $msg = array(); if (isset($_REQUEST['status']) && isset($_REQUEST['payment_id'])) { $payment_id = $_REQUEST['payment_id']; $data = check_instamojo_payment_status($this->api_key, $this->auth_token, $payment_id); if (!empty($data)) { try { try { if ($data['payment']['status'] == "Credit" || $data['payment']['status'] == "Failed" || $data['payment']['status'] == "Initiated") { $order_id = $data['payment']['custom_fields'][$this->custom_field]['value']; $order = new WC_Order($order_id); if ($data['payment']['status'] == "Credit") { $order->add_order_note('Payment was successfull.<br />Instamojo Payment ID: ' . $payment_id); $order->payment_complete(); if (empty($this->thank_you_msg)) { $msg['msg'] = "Payment received, your item(s) are now being processed."; } else { $msg['msg'] = $this->thank_you_msg; } $msg['class'] = 'woocommerce-message'; if (empty($this->redirect_url)) { $this->redirect_url = site_url() . "/checkout/order-received/"; $redirect_url = $this->redirect_url . $order_id . '/?key=' . $order->order_key; wp_redirect($redirect_url); exit; } } else { if ($data['payment']['status'] == "Failed") { $order->update_status('failed'); $order->add_order_note('Payment failed. <br />Instamojo Payment ID: ' . $payment_id); $msg['class'] = 'woocommerce-error'; $msg['msg'] = "Payment failed."; } else { if ($data['payment']['status'] == "Initiated") { $order->update_status('failed'); $order->add_order_note('Payment was initiated but never completed for Instamojo Payment ID: ' . $payment_id); $msg['class'] = 'woocommerce-error'; $msg['msg'] = "Payment failed."; } } } $woocommerce->cart->empty_cart(); } else { throw new Exception($data['payment']['status']); } } catch (Exception $e) { $msg['class'] = 'woocommerce-error'; $msg['msg'] = "Failed to get the payment details: " . $e->getMessage(); } } catch (Exception $e) { $msg['class'] = 'woocommerce-error'; $msg['msg'] = "Oops! something went wrong while processing the request."; } } else { $msg['class'] = 'woocommerce-error'; $msg['msg'] = "Invalid order."; } } else { $msg['class'] = 'woocommerce-error'; $msg['msg'] = "Invalid or missing parameters."; } if (empty($this->redirect_url)) { $this->redirect_url = site_url(); } if (substr($this->redirect_url, -1) != '/') { $this->redirect_url .= '/'; } $redirect_url = add_query_arg(array('msg' => urlencode($msg['msg']), 'class' => urlencode($msg['class'])), $this->redirect_url); wp_redirect($redirect_url); exit; }