/** * Check the PayZippy Charging API response, validate it, update DB */ function check_payzippy_response() { //require('lib/Constants.php'); global $woocommerce; // Instantiate the ChargingResponse class. $pz_response = new ChargingResponse(array_merge($_POST, $_GET), $this->settings); if ($pz_response->get_merchant_transaction_id() != '') { $transaction_id = $pz_response->get_merchant_transaction_id(); $order = new WC_Order($transaction_id); $transaction_key = $order->order_key; if ($pz_response->validate()) { if ($pz_response->get_transaction_response_code() == PZ_Constants::RESPONSE_SUCCESS) { // Payment Successful $message = PZ_Constants::PAYMENT_SUCCESS; $class = 'message'; $order->payment_complete(); $woocommerce->cart->empty_cart(); } else { if ($pz_response->get_transaction_response_code() == PZ_Constants::RESPONSE_PENDING) { // Payment Response Pending. $order->update_status('on-hold'); $message = PZ_Constants::PAYMENT_ONHOLD; $class = 'message'; $woocommerce->cart->empty_cart(); } else { if ($pz_response->get_transaction_response_code() == PZ_Constants::RESPONSE_INITIATED) { // Payment Response Initiated. $order->update_status('pending'); $message = PZ_Constants::PAYMENT_INITIATED; $class = 'message'; $woocommerce->cart->empty_cart(); } else { // Payment Failed. $order->update_status('failed'); $class = 'error'; $message = PZ_Constants::PAYMENT_FAILED; } } } } else { // Hash Validation Failed. $message = PZ_Constants::PAYMENT_ILLEGAL; $order->update_status('failed'); $order->add_order_note($message); $class = 'error'; } $order->add_order_note($message); $this->update_order_info($order, $pz_response); } else { $class = 'error'; $message = 'Error: 747. Contact us with this error code and transaction details.'; } $callback_url = $this->redirect_page_id == "" || $this->redirect_page_id == 0 ? get_site_url() . "/" : get_permalink($this->redirect_page_id); if (version_compare(WOOCOMMERCE_VERSION, '2.1.0', '>=')) { $callback_url = add_query_arg(array('view-order' => $transaction_id, 'key' => $transaction_key, 'msg' => urlencode($message), 'type' => $class), $callback_url); } else { $callback_url = add_query_arg(array('order' => $transaction_id, 'key' => $transaction_key, 'msg' => urlencode($message), 'type' => $class), $callback_url); } wp_redirect($callback_url); exit; }
$transaction_success = $pz_charging_response->is_transaction_successful(); $transaction_status = $pz_charging_response->get_transaction_status(); $transaction_response_message = $pz_charging_response->get_transaction_response_message(); $transaction_response_code = $pz_charging_response->get_transaction_response_code(); if ($transaction_success) { echo "<p class='text-success'><b>"; } else { echo "<p class='text-error'><b>"; } echo "Transaction Status : {$transaction_status}<br/>"; echo "Transaction Response Code : {$transaction_response_code}<br/>"; echo "Transaction Response Message : {$transaction_response_message}<br/>"; echo "</b></p>"; // To check the validity of the response, call the validate function on // the ChargingResponse object. It verifies the hash returned in the response. $hash_match = $pz_charging_response->validate(); if ($hash_match) { echo "<p class='text-success'><b>Hash matches. The response is valid.</b></p>"; } else { echo "<p class='text-error'><b>Hash mismatch. Response is invalid</b></p>"; } echo "<h4>Charging Response</h4>"; echo "Merchant ID: {$pz_charging_response->get_merchant_id()}<br/>"; echo "Merchant Key ID: {$pz_charging_response->get_merchant_key_id()}<br/>"; echo "Merchant Transaction ID: {$pz_charging_response->get_merchant_transaction_id()}<br/>"; echo "PayZippy Transaction ID: {$pz_charging_response->get_payzippy_transaction_id()}<br/>"; echo "Transaction Status: {$pz_charging_response->get_transaction_status()}<br/>"; echo "Transaction Response Code: {$pz_charging_response->get_transaction_response_code()}<br/>"; echo "Transaction Response Message: {$pz_charging_response->get_transaction_response_message()}<br/>"; echo "Payment Method: {$pz_charging_response->get_payment_method()}<br/>"; echo "Bank Name: {$pz_charging_response->get_bank_name()}<br/>";