' . __( 'Settings', 'aba-payway-aim' ) . '', ); return array_merge( $plugin_links, $links ); } function aba_render_checkout_frm($woocommerce, $transactionId, $amount, $items, $shipping_fee){ $first_name = ''; $last_name = ''; $email = ''; $phone = ''; if(!empty($woocommerce->customer->billing)){ $first_name = $woocommerce->customer->billing['first_name'] ?? ""; $last_name = $woocommerce->customer->billing['last_name'] ?? ""; $email = $woocommerce->customer->billing['email'] ?? ""; $phone = $woocommerce->customer->billing['phone'] ?? ""; } $cart_url = get_permalink( wc_get_page_id( 'cart' ) ); echo '
'; echo '
'; echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'; echo '
'; echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } //Add Payway form in checkout page add_action('woocommerce_after_checkout_form','aba_woocommerce_after_after_woocommerce_pay',10,1); add_action('after_woocommerce_pay','aba_woocommerce_after_after_woocommerce_pay',10,1); function aba_woocommerce_after_after_woocommerce_pay(){ global $woocommerce; $order_id = get_query_var('order-pay') ?: $woocommerce->session->order_awaiting_payment; $_SESSION['aba_transaction_id'] = $order_id; $order = new WC_Order($order_id); $items_result = $order->get_items(); $shipping_fee = $order->get_shipping_total(); $discount = $order->get_discount_total(); $amount = sprintf("%.2f", $order->get_total() - $shipping_fee); $shipping_fee = sprintf("%.2f", $shipping_fee); $key = 0; $total_no_discount = $order->get_total() + $discount; $items = []; foreach ($items_result as $order_item_id => $order_item) { $product = $order_item->get_product(); if(!empty($product)){ $items[$key]['name'] = $order_item->get_name(); $items[$key]['quantity'] = $order_item->get_quantity(); $items[$key]['price'] = sprintf("%.2f", $product->get_price()); if( $discount > 0 ){ $items[$key]['discount'] = (($product->get_price() * $order_item->get_quantity() * 100)/$total_no_discount) * $discount/100; } $key++; } } $item = base64_encode(json_encode($items)); aba_render_checkout_frm($woocommerce, $order_id, $amount, $item, $shipping_fee); } add_action( 'wp_enqueue_scripts', 'aba_payway_scripts_basic' ); function aba_payway_scripts_basic() { $loadScript = false; if(strlen(strstr($_SERVER['HTTP_USER_AGENT'] ?? '','ABAMobile')) > 0){ $loadScript = true; }else if(is_page(array('checkout')) || (function_exists( 'is_checkout' ) && is_checkout())){ $loadScript = true; } if($loadScript){ $pay_js = aba_PAYWAY_AIM::getJssend(); $hide_close = aba_PAYWAY_AIM::getHideclose(); wp_deregister_script('wc-checkout'); wp_enqueue_script('wc-checkout', ABA_PAYMENT_PLUGIN_PATH . 'js/checkout.js', array('jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n'), time(), true); wp_enqueue_script( 'aba-payway-custom-script', ABA_PAYMENT_PLUGIN_PATH. 'js/custom.js', array( 'jquery' ), time(), true ); $query_url = parse_url($pay_js, PHP_URL_QUERY); if ($query_url) { $pay_js .= '&'.$hide_close; } else { $pay_js .= '?'.$hide_close; } wp_enqueue_script( 'checkout-popup', $pay_js, false ); wp_localize_script( 'aba-payway-custom-script', 'frontend_ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), ) ); wp_enqueue_style('aba-payway-checkout-style-icon', plugins_url('css/payway.css?v=1.1',__FILE__ )); } } add_action( 'wp_footer', 'aba_payway_dynamic_js' ); function aba_payway_dynamic_js() { if(strlen(strstr($_SERVER['HTTP_USER_AGENT'] ?? '','ABAMobile')) > 0){ ?> status == 'pending') { $order->update_status('cancelled'); } } exit; } // add a wp query variable to redirect to add_action('query_vars','set_aba_query_var'); function set_aba_query_var($vars) { array_push($vars, 'aba_payway_pushback'); // ref url redirected to in add rewrite rule return $vars; } // Create a redirect add_action('init', 'custom_add_rewrite_rule'); function custom_add_rewrite_rule(){ add_rewrite_rule('^abapayway/pushback$','index.php?aba_payway_pushback=1','top'); //flush the rewrite rules, should be in a plugin activation hook, i.e only run once... flush_rewrite_rules(); } // return the file we want... add_filter('template_include', 'plugin_include_template'); function plugin_include_template($template) { if (get_query_var('aba_payway_pushback')) { global $woocommerce; $tran_id = ''; $response_data = [ "pw_version" => esc_html(!empty(PW_PLUGIN_VERSION) ? PW_PLUGIN_VERSION : '') ]; if (isset($_REQUEST['response'])) { $response_raw = stripslashes($_REQUEST['response']); $response = json_decode($response_raw, TRUE); // Sanitize the decoded response if (is_array($response)) { $response = array_map('sanitize_text_field', $response); } $response_data["request"] = $response; if (isset($response['status']) && ($response['status'] == 0 || $response['status'] === "0")) { $tran_id = isset($response['tran_id']) ? sanitize_text_field($response['tran_id']) : ''; } } elseif (isset($_REQUEST['payway_token'])) { $payway_token_raw = sanitize_text_field($_REQUEST['payway_token']); $response = json_decode(aba_PAYWAY_AIM::pwDecrypt($payway_token_raw, aba_PAYWAY_AIM::getApiKey()), TRUE); // Sanitize the decoded response if (is_array($response)) { $response = array_map('sanitize_text_field', $response); } $response_data["payway_token"] = $response; if (!empty($response["tran_id"])) { if (!empty($response["time"]) && $response["time"] > time() - 1800) { $tran_id = sanitize_text_field($response['tran_id']); } else { $response_data["error"] = esc_html("token expired"); } } else { $response_data["error"] = esc_html("invalid payway_token"); } } if (!empty($tran_id)) { if (aba_PAYWAY_AIM::checkTransaction($tran_id)) { $response_data["check_transaction"] = esc_html("success"); $order = new WC_Order($tran_id); $order->update_status('completed'); $woocommerce->cart->empty_cart(); } else { $response_data["check_transaction"] = esc_html("failed"); } } // Escape the output before returning it echo wp_json_encode($response_data); exit; } return $template; }