/** * Get the return url (thank you page) * * @param WC_Order $order * @return string */ public function get_return_url($order = null) { if ($order) { $return_url = $order->get_checkout_order_received_url(); } else { $return_url = wc_get_endpoint_url('order-received', '', wc_get_page_permalink('checkout')); } if (is_ssl() || get_option('woocommerce_force_ssl_checkout') == 'yes') { $return_url = str_replace('http:', 'https:', $return_url); } return apply_filters('woocommerce_get_return_url', $return_url); }
public function confirm_url_callback() { $transaction_id = $_GET['transactionId']; $results = get_posts(array('post_type' => 'shop_order', 'meta_query' => array(array('key' => '_hpd_linepay_transactionId', 'value' => $transaction_id)))); if (!$results) { http_response_code(404); exit; } $order_data = $results[0]; $order_id = $order_data->ID; $order = new WC_Order($order_id); $response_data = $this->client->confirm($transaction_id, $order->get_total(), get_woocommerce_currency()); if ($response_data->returnCode != '0000') { $order->update_status('failed', sprintf(__('Error return code: %1$s, message: %2$s', 'wc-payment-gateway-line-pay'), $response_data->returnCode, $response_data->returnMessage)); } else { $order->payment_complete(); } wp_redirect($order->get_checkout_order_received_url()); exit; }
/** * Generates a URL for the thanks page (order received) * * @since 2.0 * @param WC_Order $order * @return string url to thanks page */ public static function get_checkout_order_received_url($order) { if (self::is_wc_version_gte_2_1()) { return $order->get_checkout_order_received_url(); } else { return get_permalink(woocommerce_get_page_id('thanks')); } }
public function generate_atos_form($order_id) { global $woocommerce; $atos_settings = get_option('woocommerce_atos_settings'); $order = new WC_Order((int) $order_id); if ($atos_settings['exec_mode'] != 'off') { $sep = " "; } else { $sep = "&"; } $parm = "merchant_id=" . $atos_settings['merchantid']; // 011223344551112 (3D) 014213245611111 (no3D) $parm .= $sep . "merchant_country=" . $atos_settings['merchant_country']; $amount = number_format($order->order_total, 2, '.', '') * 100; $parm .= $sep . "amount=" . str_pad($amount, 3, "0", STR_PAD_LEFT); $parm .= $sep . "currency_code=" . $atos_settings['currency_code']; $parm .= $sep . "pathfile=" . $atos_settings['pathfile']; if (version_compare(WOOCOMMERCE_VERSION, '2.0.20', '>')) { /* WC 2.1 */ $normal_cancel_url = $order->get_checkout_order_received_url(); if ($atos_settings['exec_mode'] == 'off') { $normal_cancel_url = urlencode($normal_cancel_url); } $parm .= $sep . "normal_return_url=" . $normal_cancel_url; $parm .= $sep . "cancel_return_url=" . $normal_cancel_url; } else { $normal_cancel_url = add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(get_option('woocommerce_thanks_page_id')))); if ($atos_settings['exec_mode'] == 'off') { $normal_cancel_url = urlencode($normal_cancel_url); } $parm .= $sep . "normal_return_url=" . $normal_cancel_url; $parm .= $sep . "cancel_return_url=" . $normal_cancel_url; } $automatic_url = trailingslashit(str_replace('https', 'http', get_bloginfo('wpurl'))) . "?wc-api=WC_Gateway_Atos"; if ($atos_settings['exec_mode'] == 'off') { $automatic_url = urlencode($automatic_url); } $parm .= $sep . "automatic_response_url=" . $automatic_url; $parm .= $sep . "language=" . $atos_settings['language']; $parm .= $sep . "payment_means=" . $atos_settings['payment_means']; $parm .= $sep . "header_flag=no"; $parm .= $sep . "order_id=" . $order_id; $parm .= $sep . "logo_id2=" . $atos_settings['logo_id2']; $parm .= $sep . "advert=" . $atos_settings['advert']; $parm .= $sep . "customer_email=" . $order->billing_email; $parm .= $sep . "customer_ip_address=" . substr($_SERVER['REMOTE_ADDR'], 0, 19); $parm .= $sep . "capture_day=" . $atos_settings['capture_day']; $parm .= $sep . "capture_mode=" . $atos_settings['capture_mode']; $path_bin = $atos_settings['path_bin_request']; if ($atos_settings['exec_mode'] != 'off') { $parm = escapeshellcmd($parm); $result = exec("{$path_bin} {$parm}"); } else { $result = file_get_contents("http://" . $_SERVER['SERVER_NAME'] . "/cgi-bin/atos_request.pl?" . $parm . "&bindir=" . $path_bin); } $tableau = explode("!", "{$result}"); $code = $tableau[1]; $error = $tableau[2]; $message = $tableau[3]; if ($code == "" && $error == "") { print "<BR><CENTER>" . __('erreur appel request', 'atos') . "</CENTER><BR>"; print __("executable request non trouvé", "atos") . " {$path_bin}"; } else { if ($code != 0) { print "<center><b><h2>" . __("Erreur appel API de paiement.", "atos") . "</h2></b></center>"; print "<br><br><br>"; print " " . __("message d'erreur", "atos") . " : {$error}<br>"; } else { print "<br><br>"; if ($atos_settings['debug'] == 'yes') { print " {$error} <br>"; } print " {$message} <br>"; } } }
/** * @param WC_Order $order * @param string $checkout_url * @param int $redirect_id * @param WP_User $user * * @return array */ public static function get_checkout($order, $checkout_url, $redirect_id, $user) { $serializer = array('toc' => true, 'merchant' => array('confirmation_url' => add_query_arg('action', 'confirm', get_permalink($redirect_id)), 'cancel_url' => html_entity_decode($order->get_cancel_order_url()), 'checkout_url' => html_entity_decode($checkout_url), 'success_url' => html_entity_decode($order->get_checkout_order_received_url())), 'customer' => $user->ID ? self::get_user($user) : self::get_customer($order->billing_email), 'order' => self::get_order($order), 'billing' => self::get_address($order, 'billing'), 'meta' => static::get_meta()); $shipping_method = $order->get_shipping_method(); if (!empty($shipping_method)) { $serializer['shipping'] = self::get_shipping_info($order); } return $serializer; }
/** * Check for valid Authorize.net server callback to validate the transaction response. **/ function check_authorize_response() { global $woocommerce; $temp_order = new WC_Order(); if (count($_POST)) { $redirect_url = ''; $this->msg['class'] = 'error'; $this->msg['message'] = $this->failed_message; $order = new WC_Order($_POST['x_invoice_num']); $hash_key = $this->hash_key != '' ? $this->hash_key : ''; if ($_POST['x_response_code'] != '' && $_POST['x_MD5_Hash'] == strtoupper(md5($hash_key . $this->login . $_POST['x_trans_id'] . $_POST['x_amount']))) { try { $amount = $_POST['x_amount']; $hash = $_POST['x_MD5_Hash']; $transauthorised = false; if ($order->status != 'completed') { if ($_POST['x_response_code'] == 1) { $transauthorised = true; $this->msg['message'] = $this->success_message; $this->msg['class'] = 'success'; if ($order->status == 'processing') { } else { $order->payment_complete($_REQUEST['x_trans_id']); $order->add_order_note('Autorize.net payment successful<br/>Ref Number/Transaction ID: ' . $_REQUEST['x_trans_id']); $order->add_order_note($this->msg['message']); $woocommerce->cart->empty_cart(); } } else { $this->msg['class'] = 'error'; $this->msg['message'] = $this->failed_message; $order->add_order_note($this->msg['message']); $order->update_status('failed'); //extra code can be added here such as sending an email to customer on transaction fail } } if ($transauthorised == false) { $order->update_status('failed'); $order->add_order_note($this->msg['message']); } } catch (Exception $e) { // $errorOccurred = true; $msg = "Error"; } } else { $order->add_order_note('MD5 hash did not matched for this transaction. Please check documentation to set MD5 String. <a href="http://www.indatos.com/developer-documentation/md5-hash-security-feature-authorize-net/?ref=auth-sim">MD5 String Doc.</a>. Or <a href="http://www.indatos.com/wordpress-support/">contact plugin support</a> for help.'); } $redirect_url = $order->get_checkout_order_received_url(); $this->web_redirect($redirect_url); exit; } else { $redirect_url = $temp_order->get_checkout_order_received_url(); $this->web_redirect($redirect_url . '?msg=Unknown_error_occured'); exit; } }
function process_payment($order_id) { global $woocommerce; $order = new WC_Order($order_id); $order_number = $order->get_order_number(); $receiveCurrency = strtoupper(trim($this->get_option('receive_currency'))); $currency = $order->get_order_currency(); $amount = $order->get_total(); if ($currency != $receiveCurrency) { $receiveAmount = $this->unitConversion($amount, $currency, $receiveCurrency); } else { $receiveAmount = $amount; } if (!$receiveAmount || $receiveAmount < 0) { echo 'Spectrocoin is not fully configured. Please select different payment'; exit; } $scMerchantClient = new SCMerchantClient(SC_API_URL, $this->get_option('merchant_id'), $this->get_option('project_id'), $this->get_option('private_key')); set_query_var('invoice_id', $order_number); $callbackUrl = add_query_arg(array('wc-api' => 'WC_Gateway_Spectrocoin', 'invoice_id' => $order_number), home_url('/')); $createOrderRequest = new CreateOrderRequest(null, 0, $receiveAmount, '', 'en', $callbackUrl, $order->get_checkout_order_received_url(), $woocommerce->cart->get_checkout_url()); $createOrderResponse = $scMerchantClient->createOrder($createOrderRequest); if ($createOrderResponse instanceof ApiError) { $this->log('Error occurred: '); $this->log($createOrderResponse->getCode()); $this->log($createOrderResponse->getMessage()); } else { if ($createOrderResponse instanceof CreateOrderResponse) { return array('result' => 'success', 'redirect' => $createOrderResponse->getRedirectUrl()); } } return; }
function be_themes_exclude_woo_from_ajax() { global $woocommerce; global $order_id; echo '<script> var no_ajax_pages = []; </script>'; if ($woocommerce) { $order = new WC_Order($order_id); echo '<script> no_ajax_pages.push("' . $woocommerce->cart->get_cart_url() . '"); no_ajax_pages.push("' . $woocommerce->cart->get_checkout_url() . '"); no_ajax_pages.push("' . get_permalink(woocommerce_get_page_id('shop')) . '");'; if (version_compare(WOOCOMMERCE_VERSION, "2.1") >= 0) { echo 'no_ajax_pages.push("' . $order->get_checkout_payment_url() . '"); no_ajax_pages.push("' . $order->get_checkout_order_received_url() . '");'; } else { echo 'no_ajax_pages.push("' . get_permalink(woocommerce_get_page_id('pay')) . '");'; } $args = array('post_type' => 'product', 'posts_per_page' => -1); $loop = new WP_Query($args); if ($loop->have_posts()) { while ($loop->have_posts()) { $loop->the_post(); echo 'no_ajax_pages.push("' . get_permalink(get_the_ID()) . '");'; } } echo '</script>'; } }
/** * Process the pay form. */ public function pay_action() { global $wp; if (isset($_POST['woocommerce_pay']) && isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-pay')) { ob_start(); // Pay for existing order $order_key = $_GET['key']; $order_id = absint($wp->query_vars['order-pay']); $order = new WC_Order($order_id); if ($order->id == $order_id && $order->order_key == $order_key && in_array($order->status, array('pending', 'failed'))) { // Set customer location to order location if ($order->billing_country) { WC()->customer->set_country($order->billing_country); } if ($order->billing_state) { WC()->customer->set_state($order->billing_state); } if ($order->billing_postcode) { WC()->customer->set_postcode($order->billing_postcode); } if ($order->billing_city) { WC()->customer->set_city($order->billing_city); } // Update payment method if ($order->needs_payment()) { $payment_method = wc_clean($_POST['payment_method']); $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); // Update meta update_post_meta($order_id, '_payment_method', $payment_method); if (isset($available_gateways[$payment_method])) { $payment_method_title = $available_gateways[$payment_method]->get_title(); } update_post_meta($order_id, '_payment_method_title', $payment_method_title); // Validate $available_gateways[$payment_method]->validate_fields(); // Process if (wc_notice_count('error') == 0) { $result = $available_gateways[$payment_method]->process_payment($order_id); // Redirect to success/confirmation/payment page if ('success' == $result['result']) { wp_redirect($result['redirect']); exit; } } } else { // No payment was required for order $order->payment_complete(); wp_safe_redirect($order->get_checkout_order_received_url()); exit; } } } }
/** * Generate payu button link **/ function generate_payupaisa_form($order_id) { global $woocommerce; $order = new WC_Order($order_id); $txnid = $order_id . '_' . date("ymds"); if ($this->redirect_page_id == "" || $this->redirect_page_id == 0) { $redirect_url = $order->get_checkout_order_received_url(); } else { $redirect_url = get_permalink($this->redirect_page_id); } //For wooCoomerce 2.0 if (version_compare(WOOCOMMERCE_VERSION, '2.0.0', '>=')) { $redirect_url = add_query_arg('wc-api', get_class($this), $redirect_url); } $productinfo = "Order {$order_id}"; $str = "{$this->merchant_id}|{$txnid}|{$order->order_total}|{$productinfo}|{$order->billing_first_name}|{$order->billing_email}|{$order_id}||||||||||{$this->salt}"; $hash = strtolower(hash('sha512', $str)); $payupaisa_args = array('key' => $this->merchant_id, 'hash' => $hash, 'txnid' => $txnid, 'amount' => $order->order_total, 'firstname' => $order->billing_first_name, 'email' => $order->billing_email, 'phone' => $order->billing_phone, 'productinfo' => $productinfo, 'surl' => $redirect_url, 'furl' => $redirect_url, 'lastname' => $order->billing_last_name, 'address1' => $order->billing_address_1, 'address2' => $order->billing_address_2, 'city' => $order->billing_city, 'state' => $order->billing_state, 'country' => $order->billing_country, 'zipcode' => $order->billing_postcode, 'curl' => $redirect_url, 'pg' => 'NB', 'udf1' => $order_id, 'service_provider' => 'payu_paisa'); $payupaisa_args_array = array(); foreach ($payupaisa_args as $key => $value) { $payupaisa_args_array[] = "<input type='hidden' name='{$key}' value='{$value}'/>"; } return ' <form action="' . $this->liveurl . '" method="post" id="payupaisa_payment_form"> ' . implode('', $payupaisa_args_array) . ' <input type="submit" class="button-alt" id="submit_payupaisa_payment_form" value="' . __('Pay via PayU Money', 'kdc') . '" /> <a class="button cancel" href="' . $order->get_cancel_order_url() . '">' . __('Cancel order & restore cart', 'kdc') . '</a> <script type="text/javascript"> jQuery(function(){ jQuery("body").block({ message: "' . __('Thank you for your order. We are now redirecting you to Payment Gateway to make payment.', 'kdc') . '", overlayCSS: { background : "#fff", opacity : 0.6 }, css: { padding : 20, textAlign : "center", color : "#555", border : "3px solid #aaa", backgroundColor : "#fff", cursor : "wait", lineHeight : "32px" } }); jQuery("#submit_payupaisa_payment_form").click();}); </script> </form>'; }
public function process_payment($order_id) { $order = new WC_Order($order_id); return array('result' => 'success', 'redirect' => add_query_arg('order', $order->id, add_query_arg('key', $order->order_key, $order->get_checkout_order_received_url()))); }
public function gourlcallback($user_id, $order_id, $payment_details, $box_status) { if (!in_array($box_status, array("cryptobox_newrecord", "cryptobox_updated"))) { return false; } if (strpos($order_id, "order") === 0) { $order_id = substr($order_id, 5); } else { return false; } if (!$user_id || $payment_details["status"] != "payment_received") { return false; } $order = new WC_Order($order_id); if ($order === false) { return false; } $coinName = ucfirst($payment_details["coinname"]); $amount = $payment_details["amount"] . " " . $payment_details["coinlabel"] . "  ( \$" . $payment_details["amountusd"] . " )"; $payID = $payment_details["paymentID"]; $status = $payment_details["is_confirmed"] ? $this->ostatus2 : $this->ostatus; $confirmed = $payment_details["is_confirmed"] ? __('Yes', GOURLWC) : __('No', GOURLWC); // New Payment Received if ($box_status == "cryptobox_newrecord") { $order->add_order_note(sprintf(__("%s Payment Received<br>%s<br>Payment id <a href='%s'>%s</a> / <a href='%s'>order page</a> <br>Awaiting network confirmation...", GOURLWC), __($coinName, GOURLWC), $amount, GOURL_ADMIN . GOURL . "payments&s=payment_" . $payID, $payID, $order->get_checkout_order_received_url() . "&gourlcryptocoin=" . $payment_details["coinname"]) . '<br>'); update_post_meta($order->id, 'coinname', $coinName); update_post_meta($order->id, 'amount', $payment_details["amount"] . " " . $payment_details["coinlabel"]); update_post_meta($order->id, 'userid', $payment_details["userID"]); update_post_meta($order->id, 'country', get_country_name($payment_details["usercountry"])); update_post_meta($order->id, 'tx', $payment_details["tx"]); update_post_meta($order->id, 'confirmed', $confirmed); update_post_meta($order->id, 'details', $payment_details["paymentLink"]); } // Update Status $order->update_status($status); // Existing Payment confirmed (6+ confirmations) if ($payment_details["is_confirmed"]) { update_post_meta($order->id, 'confirmed', $confirmed); $order->add_order_note(sprintf(__("%s Payment id <a href='%s'>%s</a> Confirmed", GOURLWC), __($coinName, GOURLWC), GOURL_ADMIN . GOURL . "payments&s=payment_" . $payID, $payID) . '<br>'); } // Completed if ($status == "completed") { $order->payment_complete(); } return true; }
/** * handles return data and does redirects */ public function return_handler() { // Clean @ob_clean(); // Header header('HTTP/1.1 200 OK'); $result = isset($_POST['RESULT']) ? absint($_POST['RESULT']) : null; $order_id = isset($_POST['INVOICE']) ? absint(ltrim($_POST['INVOICE'], '#')) : 0; if (is_null($result) || empty($order_id)) { echo "Invalid request."; exit; } // Get the order $order = new WC_Order($order_id); switch ($result) { // Approved or screening service was down case 0: case 127: $txn_id = !empty($_POST['PNREF']) ? wc_clean($_POST['PNREF']) : ''; // get transaction details $details = $this->get_transaction_details($txn_id); // check if it is captured or authorization only [transstate 3 is authoriztion only] if ($details && strtolower($details['TRANSSTATE']) === '3') { // Store captured value update_post_meta($order->id, '_paypalpro_charge_captured', 'no'); add_post_meta($order->id, '_transaction_id', $txn_id, true); // Mark as on-hold $order->update_status('on-hold', sprintf(__('PayPal Pro (PayFlow) charge authorized (Charge ID: %s). Process order to take payment, or cancel to remove the pre-authorization.', 'woocommerce-gateway-paypal-pro'), $txn_id)); // Reduce stock levels $order->reduce_order_stock(); } else { // Add order note $order->add_order_note(sprintf(__('PayPal Pro (Payflow) payment completed (PNREF: %s)', 'woocommerce-gateway-paypal-pro'), $parsed_response['PNREF'])); // Payment complete $order->payment_complete($txn_id); } // Remove cart WC()->cart->empty_cart(); $redirect = $order->get_checkout_order_received_url(); break; // Under Review by Fraud Service // Under Review by Fraud Service case 126: $order->add_order_note($_POST['RESPMSG']); $order->add_order_note($_POST['PREFPSMSG']); $order->update_status('on-hold', __('The payment was flagged by a fraud filter. Please check your PayPal Manager account to review and accept or deny the payment and then mark this order "processing" or "cancelled".', 'woocommerce-gateway-paypal-pro')); WC()->cart->empty_cart(); $redirect = $order->get_checkout_order_received_url(); break; default: // Mark failed $order->update_status('failed', $_POST['RESPMSG']); $redirect = $order->get_checkout_payment_url(true); $redirect = add_query_arg('wc_error', urlencode(wp_kses_post($_POST['RESPMSG'])), $redirect); if (is_ssl() || get_option('woocommerce_force_ssl_checkout') == 'yes') { $redirect = str_replace('http:', 'https:', $redirect); } break; } wp_redirect($redirect); exit; }
function payment_callback($request) { global $woocommerce; if (!empty($request['trans_id']) && !empty($request['order_id'])) { $order = new WC_Order(intval($request['order_id'])); $resp = $this->merchant->getTransResult(urlencode($request['trans_id']), $this->get_the_user_ip()); if (strstr($resp, 'RESULT:')) { $result = explode('RESULT: ', $resp); $result = preg_split('/\\r\\n|\\r|\\n/', $result[1]); $result = $result[0]; } else { $result = ''; } if (strstr($resp, 'RESULT_CODE:')) { $result_code = explode('RESULT_CODE: ', $resp); $result_code = preg_split('/\\r\\n|\\r|\\n/', $result_code[1]); $result_code = $result_code[0]; } else { $result_code = ''; } if ($result === 'OK') { //if (strpos($resp, "RESULT: OK") === true) { ? if ($order->status !== 'completed') { $woocommerce->cart->empty_cart(); $order->add_order_note(__('Payment completed', 'woocomerce')); $order->payment_complete(); wp_redirect($order->get_checkout_order_received_url()); } } else { $order->add_order_note(__('Payment failed. Error code: ' . $result_code, 'woocomerce')); wc_add_notice('Payment failed. Error code: ' . $result_code, 'error'); wp_redirect($order->get_cancel_order_url()); } echo 3; } else { if (isset($request['close_day'])) { $resp = $this->merchant->closeDay(); var_dump($resp); echo strstr($resp, 'RESULT:') ? 'OK' : 'NOK'; } else { echo 2; } } exit; }
/** * Receipt page * * @param int $order_id */ public function receipt_page($order_id) { echo '<p>' . __('Thank you for your order! Follow the GetFinancing process to finish the payment.', 'getfinancing') . '</p>'; if (empty($this->redirectok)) { $order = new WC_Order($order_id); $gf_ok_url_final = $order->get_checkout_order_received_url(); } else { $gf_ok_url_final = get_permalink($this->redirectok); } $gf_ko_url_final = get_permalink($this->redirectko); $gfjs = ' var onComplete = function() { window.location.href="' . $gf_ok_url_final . '"; }; var onAbort = function() { window.location.href="' . $gf_ko_url_final . '"; }; new GetFinancing("' . WC()->session->getfinancing_process_url . '", onComplete, onAbort);'; wc_enqueue_js($gfjs); }
/** * This part is returnurl function for epayph * * @global mixed $woocommerce */ function check_epayph_response_returnurl($posted) { global $woocommerce; if (!empty($_POST) && $this->validate_ipn()) { $order = new WC_Order($_POST['invoice']); switch ($_REQUEST['payment_status']) { case 'Completed': $order->add_order_note('ePay.ph Payment Status: SUCCESSFUL' . '<br>Transaction ID: ' . $tranID . $referer); $order->payment_complete(); wp_redirect($order->get_checkout_order_received_url()); break; case 'Pending': if ($order->has_status('completed')) { exit; } else { $order->add_order_note('ePay.ph Payment Status: PENDING'); $order->update_status('pending', __('Awaiting Payment Approval', 'woocommerce')); //wp_redirect($order->get_checkout_order_received_url()); } break; case 'Cancelled': $order->add_order_note('ePay.ph Payment Status: FAILED'); $order->update_status('failed', __('Payment Failed', 'woocommerce')); //wp_redirect($order->get_cancel_order_url()); break; case 'Refunded': $order->add_order_note('ePay.ph Payment Status: Refunded'); $order->update_status('refunded', __('Payment Refunded', 'woocommerce')); //wp_redirect($order->get_cancel_order_url()); break; case 'Display': break; default: $order->add_order_note('ePay.ph Payment Status: Invalid Transaction'); $order->update_status('on-hold', __('Invalid Transaction', 'woocommerce')); //wp_redirect($order->get_cancel_order_url()); } exit; } }
function yith_wc_get_page_id($page) { global $woocommerce; if (version_compare(preg_replace('/-beta-([0-9]+)/', '', $woocommerce->version), '2.1', '<')) { return woocommerce_get_page_id($page); } else { if ($page == 'pay' || $page == 'thanks') { $wc_order = new WC_Order(); $page = $wc_order->get_checkout_order_received_url(); } return wc_get_page_id($page); } }
function receipt_page($order_id) { global $woocommerce; $order = new WC_Order($order_id); $order_received_url = add_query_arg('wc-api', 'WC_Nom_EPDQ', $order->get_checkout_order_received_url()); $fields = array('PSPID' => $this->access_key, 'ORDERID' => $order_id, 'AMOUNT' => $order->order_total * 100, 'CURRENCY' => get_woocommerce_currency(), 'LANGUAGE' => get_bloginfo('language'), 'CN' => $order->billing_first_name . ' ' . $order->billing_last_name, 'EMAIL' => $order->billing_email, 'OWNERZIP' => $order->billing_postcode, 'OWNERADDRESS' => $order->billing_address_1, 'OWNERADDRESS2' => $order->billing_address_2, 'OWNERCTY' => $woocommerce->countries->countries[$order->billing_country], 'OWNERTOWN' => $order->billing_city, 'OWNERTELNO' => $order->billing_phone, 'ACCEPTURL' => $order_received_url, 'DECLINEURL' => $order_received_url, 'EXCEPTIONURL' => $order_received_url, 'CANCELURL' => $order_received_url, 'BACKURL' => get_permalink($this->back_url), 'HOMEURL' => get_permalink($this->home_url), 'CATALOGURL' => get_permalink($this->cat_url)); if ($this->pp_format == 'yes') { $fields['TITLE'] = $this->TITLE; $fields['BGCOLOR'] = $this->BGCOLOR; $fields['TXTCOLOR'] = $this->TXTCOLOR; $fields['TBLBGCOLOR'] = $this->TBLBGCOLOR; $fields['TBLTXTCOLOR'] = $this->TBLTXTCOLOR; $fields['BUTTONBGCOLOR'] = $this->BUTTONBGCOLOR; $fields['BUTTONTXTCOLOR'] = $this->BUTTONTXTCOLOR; $fields['FONTTYPE'] = $this->FONTTYPE; $fields['LOGO'] = $this->LOGO; } $shasign = ''; $shasign_arg = array(); ksort($fields); foreach ($fields as $key => $value) { if ($value == '') { continue; } $shasign_arg[] = $key . '=' . $value; } if ($this->sha_method == 0) { $shasign = sha1(implode($this->sha_in, $shasign_arg) . $this->sha_in); } elseif ($this->sha_method == 1) { $shasign = hash('sha256', implode($this->sha_in, $shasign_arg) . $this->sha_in); } elseif ($this->sha_method == 2) { $shasign = hash('sha512', implode($this->sha_in, $shasign_arg) . $this->sha_in); } else { } $epdq_args = array(); foreach ($fields as $key => $value) { if ($value == '') { continue; } $epdq_args[] = "<input type='hidden' name='{$key}' value='{$value}'/>"; } if (isset($this->status) and ($this->status == 'test' or $this->status == 'live')) { if ($this->status == 'test') { $url = $this->test_url; } if ($this->status == 'live') { $url = $this->live_url; } echo '<p>' . __('Thank you for your order, please click the button below to pay securely', 'woocommerce') . '</p>'; echo '<form action="' . $url . '" method="post" id="epdq_payment_form">'; echo implode('', $epdq_args); echo '<input type="hidden" name="SHASIGN" value="' . $shasign . '"/>'; echo '<input type="submit" class="button alt" id="submit_epdq_payment_form" value="' . __('Pay securely', 'woocommerce') . '" />'; echo ' '; echo '<a class="button cancel" href="' . $order->get_cancel_order_url() . '">' . __('Cancel order & restore cart', 'woocommerce') . '</a></form>'; } else { echo '<p class="error">' . $this->error_notice . '</p>'; } }
/** * This part is returnurl function for the payment gateway * * @global mixed $woocommerce */ function check_dragonpay_response_returnurl() { global $woocommerce; $amount = $_POST['amount']; $orderid = $_POST['orderid']; $appcode = $_POST['appcode']; $tranID = $_POST['tranID']; $domain = $_POST['domain']; $status = $_POST['status']; $currency = $_POST['currency']; $paydate = $_POST['paydate']; $channel = $_POST['channel']; $skey = $_POST['skey']; $vkey = $this->password; $order = new WC_Order($orderid); $key0 = md5($tranID . $orderid . $status . $domain . $amount . $currency); $key1 = md5($paydate . $domain . $key0 . $appcode . $vkey); $referer = "<br>Referer: ReturnURL"; if ($status == "00") { // Invalid transaction if ($skey != $key1) { $order->add_order_note('Dragonpay Payment Status: FAILED' . '<br>Transaction ID: ' . $tranID . $referer); $order->update_status('failed', sprintf(__('Payment %s via Dragonpay.', 'woocommerce'), $tranID)); $woocommerce->cart->empty_cart(); wp_redirect($order->get_view_order_url()); //wp_redirect($order->get_cancel_order_url()); } else { $order->add_order_note('Dragonpay Payment Status: SUCCESSFUL' . '<br>Transaction ID: ' . $tranID . $referer); $order->payment_complete(); wp_redirect($order->get_checkout_order_received_url()); } exit; } else { if ($status == "22") { $order->add_order_note('Dragonpay Payment Status: Invalid Transaction' . '<br>Transaction ID: ' . $tranID . $referer); $order->update_status('pending', sprintf(__('Payment %s via Dragonpay.', 'woocommerce'), $tranID)); $order->payment_complete($tranID); wp_redirect($order->get_view_order_url()); exit; } else { if ($status == "11") { //status 11 which is failed $order->add_order_note('Dragonpay Payment Status: FAILED' . '<br>Transaction ID: ' . $tranID . $referer); $order->update_status('failed', sprintf(__('Payment %s via Dragonpay.', 'woocommerce'), $tranID)); //$order->payment_complete(); $woocommerce->cart->empty_cart(); wp_redirect($order->get_view_order_url()); //wp_redirect($order->get_cancel_order_url()); exit; } else { //invalid transaction $order->add_order_note('Dragonpay Payment Status: FAILED' . '<br>Transaction ID: ' . $tranID . $referer); $order->update_status('failed', sprintf(__('Payment %s via Dragonpay.', 'woocommerce'), $tranID)); $woocommerce->cart->empty_cart(); wp_redirect($order->get_view_order_url()); //wp_redirect($order->get_cancel_order_url()); exit; } } } }
/** * Generates the EBANX button link * @return string */ public function generate_ebanx_form($order_id) { global $woocommerce; $servername = DB_HOST; $username = DB_USER; $password = DB_PASSWORD; $database = DB_NAME; // Set EBANX configs \Ebanx\Config::set(array('integrationKey' => $this->merchant_key, 'testMode' => $this->test_mode, 'directMode' => true)); // Loads the current order $order = new WC_Order($order_id); // If is GET, do nothing, otherwise process the request if ($_SERVER['REQUEST_METHOD'] === 'GET') { $this->_renderCheckout($order_id); return; } $order = new WC_Order($order_id); $streetNumber = isset($order->billing_number) ? $order->billing_number : '1'; $paymentMethod = isset($_POST['ebanx']['method']) ? $_POST['ebanx']['method'] : ''; $countryCode = $order->billing_country; // Append timestamp on test mode $orderId = $this->test_mode ? $order_id . time() : $order_id; $params = array('mode' => 'full', 'operation' => 'request', 'payment' => array('merchant_payment_code' => $orderId, 'order_number' => $order_id, 'amount_total' => $order->order_total, 'currency_code' => get_woocommerce_currency(), 'name' => $order->billing_first_name . ' ' . $order->billing_last_name, 'email' => $order->billing_email, 'birth_date' => $this->getBirthdateFromRequest(true), 'address' => $order->billing_address_1, 'street_number' => $streetNumber, 'city' => $order->billing_city, 'state' => $order->billing_state, 'zipcode' => $order->billing_postcode, 'country' => $order->billing_country, 'phone_number' => $order->billing_phone, 'payment_type_code' => $_POST['ebanx']['cc_type'], 'document' => $order->billing_cpf)); $ccExpiration = str_pad($_POST['ebanx']['cc_expiration_month'], 2, '0', STR_PAD_LEFT) . '/' . $_POST['ebanx']['cc_expiration_year']; try { $token = \Ebanx\Ebanx::doToken(['payment_type_code' => $_POST['ebanx']['cc_type'], 'creditcard' => ['card_number' => $_POST['ebanx']['cc_number'], 'card_name' => $_POST['ebanx']['cc_name'], 'card_due_date' => $ccExpiration, 'card_cvv' => $_POST['ebanx']['cc_cvv']]]); } catch (Exception $e) { $_SESSION['ebanxError'] = $e->getMessage(); $this->_renderCheckout($order_id); return; } if ($token->status == "ERROR") { $_SESSION['ebanxError'] = "Erro ao processar pagamento: " . $token->status_message; $this->_renderCheckout($order_id); return; } $customer = wp_get_current_user(); $customer_id = $customer->data->ID; $order_id_from_object = $order->id; $currency_code = $params['payment']['currency_code']; $payment_type_code = $params['payment']['payment_type_code']; $birth_date = $params['payment']['birth_date']; try { $conn = new PDO("mysql:host={$servername};dbname={$database}", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { echo "Connection failed: " . $e->getMessage(); } try { $params['payment']['creditcard'] = array('token' => $token->token); $response = \Ebanx\Ebanx::doRequest($params); if ($response->status == 'SUCCESS') { $sql = "CREATE TABLE IF NOT EXISTS `ebanx_token` (\n `id` INT AUTO_INCREMENT NOT NULL,\n `data` datetime NOT NULL,\n `token` varchar(200),\n `customer_id` varchar(200),\n `order_id` varchar(200),\n `currency_code` varchar(200),\n `birth_date` varchar(200),\n `payment_type_code` varchar(200),\n PRIMARY KEY (`id`)) "; $conn->query($sql); date_default_timezone_set('America/Sao_Paulo'); $month = date('m'); $year = date('Y'); $day = date('d'); if ($day > '28' && $month == '02') { $day = '28'; } else { if ($day == '31') { $day = '01'; } } $date = $year . '-' . $month . '-' . $day; $sql = "INSERT INTO ebanx_token (data, token, customer_id, order_id, currency_code, birth_date, payment_type_code)\n VALUES ('{$date}', '{$token->token}', '{$customer_id}', '{$order_id_from_object}', '{$currency_code}', '{$birth_date}', '{$payment_type_code}')"; $conn->query($sql); // Clear cart $woocommerce->cart->empty_cart(); if ($paymentMethod == 'boleto') { $boletoUrl = $response->payment->boleto_url; $orderUrl = $order->get_checkout_order_received_url($order); $tplDir = dirname(__FILE__) . '/view/'; $template = file_get_contents($tplDir . 'success/boleto.php'); echo eval(' ?>' . $template . '<?php '); } else { if ($paymentMethod == 'pagoefectivo') { $cipUrl = $response->payment->cip_url; $cipCode = $response->payment->cip_code; $orderUrl = $order->get_checkout_order_received_url($order); $tplDir = dirname(__FILE__) . '/view/'; $template = file_get_contents($tplDir . 'success/pagoefectivo.php'); echo eval(' ?>' . $template . '<?php '); } else { if ($paymentMethod == 'tef') { wp_redirect($response->redirect_url); } else { wp_redirect($this->get_return_url($order)); } } } } else { $_SESSION['ebanxError'] = $this->getEbanxErrorMessage($response->status_code, $countryCode); $this->_renderCheckout($order_id); } } catch (Exception $e) { $_SESSION['ebanxError'] = $e->getMessage(); $this->_renderCheckout($order_id); } $conn = null; }
/** * Process the checkout after the confirm order button is pressed * * @access public * @return void */ public function process_checkout() { global $wpdb, $current_user; wp_verify_nonce($_POST['_wpnonce'], 'woocommerce-process_checkout'); if (!defined('WOOCOMMERCE_CHECKOUT')) { define('WOOCOMMERCE_CHECKOUT', true); } // Prevent timeout @set_time_limit(0); do_action('woocommerce_before_checkout_process'); if (sizeof(WC()->cart->get_cart()) == 0) { wc_add_notice(sprintf(__('Sorry, your session has expired. <a href="%s" class="wc-backward">Return to homepage</a>', 'woocommerce'), home_url()), 'error'); } do_action('woocommerce_checkout_process'); // Checkout fields (not defined in checkout_fields) $this->posted['terms'] = isset($_POST['terms']) ? 1 : 0; $this->posted['createaccount'] = isset($_POST['createaccount']) ? 1 : 0; $this->posted['payment_method'] = isset($_POST['payment_method']) ? stripslashes($_POST['payment_method']) : ''; $this->posted['shipping_method'] = isset($_POST['shipping_method']) ? $_POST['shipping_method'] : ''; $this->posted['ship_to_different_address'] = isset($_POST['ship_to_different_address']) ? true : false; if (isset($_POST['shiptobilling'])) { _deprecated_argument('WC_Checkout::process_checkout()', '2.1', 'The "shiptobilling" field is deprecated. THe template files are out of date'); $this->posted['ship_to_different_address'] = $_POST['shiptobilling'] ? false : true; } // Ship to billing only option if (WC()->cart->ship_to_billing_address_only()) { $this->posted['ship_to_different_address'] = false; } // Update customer shipping and payment method to posted method $chosen_shipping_methods = WC()->session->get('chosen_shipping_methods'); if (isset($this->posted['shipping_method']) && is_array($this->posted['shipping_method'])) { foreach ($this->posted['shipping_method'] as $i => $value) { $chosen_shipping_methods[$i] = wc_clean($value); } } WC()->session->set('chosen_shipping_methods', $chosen_shipping_methods); WC()->session->set('chosen_payment_method', $this->posted['payment_method']); // Note if we skip shipping $skipped_shipping = false; // Get posted checkout_fields and do validation foreach ($this->checkout_fields as $fieldset_key => $fieldset) { // Skip shipping if not needed if ($fieldset_key == 'shipping' && ($this->posted['ship_to_different_address'] == false || !WC()->cart->needs_shipping())) { $skipped_shipping = true; continue; } // Ship account if not needed if ($fieldset_key == 'account' && (is_user_logged_in() || $this->must_create_account == false && empty($this->posted['createaccount']))) { continue; } foreach ($fieldset as $key => $field) { if (!isset($field['type'])) { $field['type'] = 'text'; } // Get Value switch ($field['type']) { case "checkbox": $this->posted[$key] = isset($_POST[$key]) ? 1 : 0; break; case "multiselect": $this->posted[$key] = isset($_POST[$key]) ? implode(', ', array_map('wc_clean', $_POST[$key])) : ''; break; case "textarea": $this->posted[$key] = isset($_POST[$key]) ? wp_strip_all_tags(wp_check_invalid_utf8(stripslashes($_POST[$key]))) : ''; break; default: $this->posted[$key] = isset($_POST[$key]) ? wc_clean($_POST[$key]) : ''; break; } // Hooks to allow modification of value $this->posted[$key] = apply_filters('woocommerce_process_checkout_' . sanitize_title($field['type']) . '_field', $this->posted[$key]); $this->posted[$key] = apply_filters('woocommerce_process_checkout_field_' . $key, $this->posted[$key]); // Validation: Required fields if (isset($field['required']) && $field['required'] && empty($this->posted[$key])) { wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is a required field.', 'woocommerce'), 'error'); } if (!empty($this->posted[$key])) { // Validation rules if (!empty($field['validate']) && is_array($field['validate'])) { foreach ($field['validate'] as $rule) { switch ($rule) { case 'postcode': $this->posted[$key] = strtoupper(str_replace(' ', '', $this->posted[$key])); if (!WC_Validation::is_postcode($this->posted[$key], $_POST[$fieldset_key . '_country'])) { wc_add_notice(__('Please enter a valid postcode/ZIP.', 'woocommerce'), 'error'); } else { $this->posted[$key] = wc_format_postcode($this->posted[$key], $_POST[$fieldset_key . '_country']); } break; case 'phone': $this->posted[$key] = wc_format_phone_number($this->posted[$key]); if (!WC_Validation::is_phone($this->posted[$key])) { wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is not a valid phone number.', 'woocommerce'), 'error'); } break; case 'email': $this->posted[$key] = strtolower($this->posted[$key]); if (!is_email($this->posted[$key])) { wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is not a valid email address.', 'woocommerce'), 'error'); } break; case 'state': // Get valid states $valid_states = WC()->countries->get_states($_POST[$fieldset_key . '_country']); if ($valid_states) { $valid_state_values = array_flip(array_map('strtolower', $valid_states)); } // Convert value to key if set if (isset($valid_state_values[strtolower($this->posted[$key])])) { $this->posted[$key] = $valid_state_values[strtolower($this->posted[$key])]; } // Only validate if the country has specific state options if ($valid_states && sizeof($valid_states) > 0) { if (!in_array($this->posted[$key], array_keys($valid_states))) { wc_add_notice('<strong>' . $field['label'] . '</strong> ' . __('is not valid. Please enter one of the following:', 'woocommerce') . ' ' . implode(', ', $valid_states), 'error'); } } break; } } } } } } // Update customer location to posted location so we can correctly check available shipping methods if (isset($this->posted['billing_country'])) { WC()->customer->set_country($this->posted['billing_country']); } if (isset($this->posted['billing_state'])) { WC()->customer->set_state($this->posted['billing_state']); } if (isset($this->posted['billing_postcode'])) { WC()->customer->set_postcode($this->posted['billing_postcode']); } // Shipping Information if (!$skipped_shipping) { // Update customer location to posted location so we can correctly check available shipping methods if (isset($this->posted['shipping_country'])) { WC()->customer->set_shipping_country($this->posted['shipping_country']); } if (isset($this->posted['shipping_state'])) { WC()->customer->set_shipping_state($this->posted['shipping_state']); } if (isset($this->posted['shipping_postcode'])) { WC()->customer->set_shipping_postcode($this->posted['shipping_postcode']); } } else { // Update customer location to posted location so we can correctly check available shipping methods if (isset($this->posted['billing_country'])) { WC()->customer->set_shipping_country($this->posted['billing_country']); } if (isset($this->posted['billing_state'])) { WC()->customer->set_shipping_state($this->posted['billing_state']); } if (isset($this->posted['billing_postcode'])) { WC()->customer->set_shipping_postcode($this->posted['billing_postcode']); } } // Update cart totals now we have customer address WC()->cart->calculate_totals(); // Terms if (!isset($_POST['woocommerce_checkout_update_totals']) && empty($this->posted['terms']) && wc_get_page_id('terms') > 0) { wc_add_notice(__('You must accept our Terms & Conditions.', 'woocommerce'), 'error'); } if (WC()->cart->needs_shipping()) { if (!in_array(WC()->customer->get_shipping_country(), array_keys(WC()->countries->get_shipping_countries()))) { wc_add_notice(sprintf(__('Unfortunately <strong>we do not ship to %s</strong>. Please enter an alternative shipping address.', 'woocommerce'), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country()), 'error'); } // Validate Shipping Methods $packages = WC()->shipping->get_packages(); $this->shipping_methods = WC()->session->get('chosen_shipping_methods'); foreach ($packages as $i => $package) { if (!isset($package['rates'][$this->shipping_methods[$i]])) { wc_add_notice(__('Invalid shipping method.', 'woocommerce'), 'error'); $this->shipping_methods[$i] = ''; } } } if (WC()->cart->needs_payment()) { // Payment Method $available_gateways = WC()->payment_gateways->get_available_payment_gateways(); if (!isset($available_gateways[$this->posted['payment_method']])) { $this->payment_method = ''; wc_add_notice(__('Invalid payment method.', 'woocommerce'), 'error'); } else { $this->payment_method = $available_gateways[$this->posted['payment_method']]; $this->payment_method->validate_fields(); } } // Action after validation do_action('woocommerce_after_checkout_validation', $this->posted); if (!isset($_POST['woocommerce_checkout_update_totals']) && wc_notice_count('error') == 0) { try { // Customer accounts $this->customer_id = apply_filters('woocommerce_checkout_customer_id', get_current_user_id()); if (!is_user_logged_in() && ($this->must_create_account || !empty($this->posted['createaccount']))) { $username = !empty($this->posted['account_username']) ? $this->posted['account_username'] : ''; $password = !empty($this->posted['account_password']) ? $this->posted['account_password'] : ''; $new_customer = wc_create_new_customer($this->posted['billing_email'], $username, $password); if (is_wp_error($new_customer)) { throw new Exception($new_customer->get_error_message()); } $this->customer_id = $new_customer; wc_set_customer_auth_cookie($this->customer_id); // As we are now logged in, checkout will need to refresh to show logged in data WC()->session->set('reload_checkout', true); // Add customer info from other billing fields if ($this->posted['billing_first_name'] && apply_filters('woocommerce_checkout_update_customer_data', true, $this)) { $userdata = array('ID' => $this->customer_id, 'first_name' => $this->posted['billing_first_name'] ? $this->posted['billing_first_name'] : '', 'last_name' => $this->posted['billing_last_name'] ? $this->posted['billing_last_name'] : '', 'display_name' => $this->posted['billing_first_name'] ? $this->posted['billing_first_name'] : ''); wp_update_user(apply_filters('woocommerce_checkout_customer_userdata', $userdata, $this)); } } // Do a final stock check at this point $this->check_cart_items(); // Abort if errors are present if (wc_notice_count('error') > 0) { throw new Exception(); } $order_id = $this->create_order(); do_action('woocommerce_checkout_order_processed', $order_id, $this->posted); // Process payment if (WC()->cart->needs_payment()) { // Store Order ID in session so it can be re-used after payment failure WC()->session->order_awaiting_payment = $order_id; // Process Payment $result = $available_gateways[$this->posted['payment_method']]->process_payment($order_id); // Redirect to success/confirmation/payment page if ($result['result'] == 'success') { $result = apply_filters('woocommerce_payment_successful_result', $result, $order_id); if (is_ajax()) { echo '<!--WC_START-->' . json_encode($result) . '<!--WC_END-->'; exit; } else { wp_redirect($result['redirect']); exit; } } } else { if (empty($order)) { $order = new WC_Order($order_id); } // No payment was required for order $order->payment_complete(); // Empty the Cart WC()->cart->empty_cart(); // Get redirect $return_url = $order->get_checkout_order_received_url(); // Redirect to success/confirmation/payment page if (is_ajax()) { echo '<!--WC_START-->' . json_encode(array('result' => 'success', 'redirect' => apply_filters('woocommerce_checkout_no_payment_needed_redirect', $return_url, $order))) . '<!--WC_END-->'; exit; } else { wp_safe_redirect(apply_filters('woocommerce_checkout_no_payment_needed_redirect', $return_url, $order)); exit; } } } catch (Exception $e) { if (!empty($e)) { wc_add_notice($e->getMessage(), 'error'); } } } // endif // If we reached this point then there were errors if (is_ajax()) { ob_start(); wc_print_notices(); $messages = ob_get_clean(); echo '<!--WC_START-->' . json_encode(array('result' => 'failure', 'messages' => $messages, 'refresh' => isset(WC()->session->refresh_totals) ? 'true' : 'false', 'reload' => isset(WC()->session->reload_checkout) ? 'true' : 'false')) . '<!--WC_END-->'; unset(WC()->session->refresh_totals, WC()->session->reload_checkout); exit; } }
/** * Check for valid Authorize.net server callback to validate the transaction response. **/ function check_authorize_response() { global $woocommerce; $temp_order = new WC_Order(); if (count($_POST)) { $redirect_url = ''; $this->msg['class'] = 'error'; $this->msg['message'] = $this->failed_message; $order = new WC_Order($_POST['x_invoice_num']); $hash_key = $this->hash_key != '' ? $this->hash_key : ''; if ($_POST['x_response_code'] != '' && $_POST['x_MD5_Hash'] == strtoupper(md5($hash_key . $this->login . $_POST['x_trans_id'] . $_POST['x_amount']))) { try { $amount = $_POST['x_amount']; $hash = $_POST['x_MD5_Hash']; $transauthorised = false; if ($order->status != 'completed') { if ($_POST['x_response_code'] == 1) { $transauthorised = true; $this->msg['message'] = $this->success_message; $this->msg['class'] = 'success'; if ($order->status == 'processing') { } else { $order->payment_complete($_REQUEST['x_trans_id']); $order->add_order_note('Autorize.net payment successful<br/>Ref Number/Transaction ID: ' . $_REQUEST['x_trans_id']); $order->add_order_note($this->msg['message']); $woocommerce->cart->empty_cart(); } } else { $this->msg['class'] = 'error'; $this->msg['message'] = $this->failed_message; $order->add_order_note($this->msg['message']); $order->update_status('failed'); //extra code can be added here such as sending an email to customer on transaction fail } } if ($transauthorised == false) { $order->update_status('failed'); $order->add_order_note($this->msg['message']); } } catch (Exception $e) { // $errorOccurred = true; $msg = "Error"; } } $redirect_url = $order->get_checkout_order_received_url(); $this->web_redirect($redirect_url); exit; } else { $redirect_url = $temp_order->get_checkout_order_received_url(); $this->web_redirect($redirect_url . '?msg=Unknown_error_occured'); exit; } }
/** * Check for Veritrans Web Response * Method ini akan dipanggil untuk merespon notifikasi yang * diberikan oleh server Veritrans serta melakukan verifikasi * apakah notifikasi tersebut berasal dari Veritrans dan melakukan * konfirmasi transaksi pembayaran yang dilakukan customer * * update: sekaligus untuk menjadi finish/failed URL handler. * @access public * @return void */ function veritrans_vtweb_response() { global $woocommerce; @ob_clean(); global $woocommerce; $order = new WC_Order($order_id); Veritrans_Config::$isProduction = $this->environment == 'production' ? true : false; if ($this->environment == 'production') { Veritrans_Config::$serverKey = $this->server_key_v2_production; } else { Veritrans_Config::$serverKey = $this->server_key_v2_sandbox; } // check whether the request is GET or POST, // if request == GET, request is for finish OR failed URL, then redirect to WooCommerce's order complete/failed // else if request == POST, request is for payment notification, then update the payment status if (!isset($_GET['order_id'])) { // Check if POST, then create new notification $veritrans_notification = new Veritrans_Notification(); if (in_array($veritrans_notification->status_code, array(200, 201, 202))) { header('HTTP/1.1 200 OK'); if ($order->get_order($veritrans_notification->order_id) == true) { $veritrans_confirmation = Veritrans_Transaction::status($veritrans_notification->order_id); do_action("valid-veritrans-web-request", $veritrans_notification); } } } else { // else if GET, redirect to order complete/failed // error_log('status_code '. $_GET['status_code']); //debug // error_log('status_code '. $_GET['transaction_status']); //debug if (isset($_GET['order_id']) && isset($_GET['transaction_status']) && ($_GET['transaction_status'] == 'capture' || $_GET['transaction_status'] == 'pending' || $_GET['transaction_status'] == 'settlement')) { $order_id = $_GET['order_id']; // error_log($this->get_return_url( $order )); //debug $order = new WC_Order($order_id); wp_redirect($order->get_checkout_order_received_url()); } else { if (isset($_GET['order_id']) && isset($_GET['transaction_status']) && $_GET['transaction_status'] == 'deny') { $order_id = $_GET['order_id']; $order = new WC_Order($order_id); wp_redirect($order->get_checkout_payment_url(false)); } else { if (isset($_GET['order_id']) && !isset($_GET['transaction_status'])) { // if customer click "back" button, redirect to checkout page again $order_id = $_GET['order_id']; $order = new WC_Order($order_id); wp_redirect($order->get_checkout_payment_url(false)); } } } } }
/** * Test: get_checkout_order_received_url */ function test_get_checkout_order_received_url() { $object = new WC_Order(); $object->set_order_key('xxx'); $id = $object->save(); $this->assertEquals('http://example.org?order-received=' . $id . '&key=' . $object->get_order_key(), $object->get_checkout_order_received_url()); }
function triveneto_response_interface($template) { global $wp_query; // If the 'triveneto_response_interface' query var isn't appended to the URL, // don't do anything and return default if (!isset($wp_query->query['triveneto_response_interface'])) { return $template; } // .. otherwise, if ($wp_query->query['triveneto_response_interface'] == '1') { // Load basics require_once 'wp/wp-load.php'; require_once plugin_dir_path(__FILE__) . '/classes/PgConsTriv.php'; // Check if we have the $_POST vars if (!isset($_POST) || empty($_POST)) { // if not ... nothing to see here header('Location:' . get_home_url()); } // Log the $_POST vars received $postvars = print_r($_POST, true); PgConsTriv::triveneto_log('[PostVars] ' . $postvars); // Log Errors if any if (isset($_POST['Error']) && isset($_POST['ErrorText'])) { // Get vars $Error = $_POST['Error']; $ErrorText = $_POST['ErrorText']; // record to log PgConsTriv::triveneto_log('Detected error: ' . $Error . ' => ' . $ErrorText); } // Process the order if (isset($_POST['trackid'])) { // Get vars $trackid = intval($_POST['trackid']); // Create the Order object $order = new WC_Order($trackid); // Mark as 'Processing' $order->update_status('processing', __('Received successful TrivenetoBassilichi payment', 'woocommerce_gateway_tvb')); // log PgConsTriv::triveneto_log('Received successful TrivenetoBassilichi payment'); // Order successful URL $url = $order->get_checkout_order_received_url(); // Command the redirection to the ThankYou page echo "REDIRECT=" . $url; } exit; } return $template; }