如何解决几次尝试后,Woocommerce结帐重定向无法正常工作
我正在使用WordPress 5.4.2版和WooCommerce 3.8.0版开发WooCommerce付款网关插件。
插件很少能进行3-4次试用,但是在此之后我无法重定向到结帐页面。它一直重定向到购物车或购物篮页面。
我还检查了日志,但在此未找到任何内容。
我不是WordPress专业人士。
该插件具有live demo
您可以在下面看到代码
// Submit payment and handle response
public function process_payment($order_id) {
global $woocommerce;
global $current_user;
//get user details
$current_user = wp_get_current_user();
$user_email = $current_user->user_email;
$first_name = $current_user->shipping_first_name;
$last_name = $current_user->shipping_last_name;
$phone_number = $current_user->billing_phone;
$country = $current_user->shipping_country;
$state = $current_user->shipping_state;
$city = $current_user->shipping_city;
$postcode = $current_user->shipping_postcode;
$address_1 = $current_user->shipping_address_1;
$address_2 = $current_user->shipping_address_2;
$udf1 = $first_name." ".$last_name;
$udf2 = $user_email;
$udf3 = $phone_number;
$udf4 = $country." ".$state." ".shipping_city." ".$address_1." ".$address_2." ".$postcode;
$user_email = $_POST['billing_email'];
$first_name = $_POST['billing_first_name'];
$last_name = $_POST['billing_last_name'];
$phone_number = $_POST['billing_phone'];
$country = $_POST['billing_country'];
$state = $_POST['billing_state'];
$city = $_POST['billing_city'];
$postcode = $_POST['billing_postcode'];
$address_1 = $_POST['billing_address_1'];
$address_2 = $_POST['billing_address_2'];
$udf1 = $first_name." ".$last_name;
$udf2 = $user_email;
$udf3 = $phone_number;
$udf4 = $country." ".$state." ".shipping_city." ".$address_1." ".$address_2." ".$postcode;
$order = new WC_Order( $order_id );
$atom_login_id = $this->login_id;
$atom_password = $this->password;
$atom_prod_id = $this->atom_product_id;
$amount = $order->get_total();
$currency = "INR";
$custacc = "1234567890";
$txnid = $order_id;
$clientcode = urlencode(base64_encode(007));
$datenow = date("d/m/Y h:m:s");
$encodedDate = str_replace(" ","%20",$datenow);
if(!function_exists('wc_get_checkout_url')){
require_once '/includes/wc-core-functions.php';
}
$ru = wc_get_checkout_url();
$data["login"] = $atom_login_id;
$data["pass"] = $atom_password;
$data["prodid"] = $atom_prod_id;
$data['txnid']=$txnid;
$data['amt'] = $amount;
$data['reqHashCode'] = $this->req_hash_code;
$data['requestEncypritonKey'] = $this->req_enc_key;
$data['salt'] = $this->req_salt_key;
$signature = $this->getChecksum($data);
$param = "login=".$atom_login_id."&pass=".$atom_password."&ttype=NBFundTransfer"."&prodid=".$atom_prod_id."&amt=".$amount."&txncurr=".$currency."&txnscamt=0"."&clientcode=".$clientcode."&txnid=".$txnid."&date=".$encodedDate ."&custacc=".$custacc."&udf1=".$udf1."&udf2=".$udf2."&udf3=".$udf3."&udf4=".$udf4."&ru=".$ru;
$param = $param."&signature=".$signature;
$atomenc = new AtomAES();
$encData = $atomenc->encrypt($param,$data['requestEncypritonKey'],$data['salt']);
global $wpdb,$woocommerce;
return array('result' => 'success','redirect' => $this->url."?" ."login=".$atom_login_id."&encdata=".strtoupper($encData));
exit;
}
// checking response from payment gateway and show messages on checkout page
function check_atom_response(){
global $woocommerce;
global $wpdb,$woocommerce;
$atomenc = new AtomAES();
$decrypted = $atomenc->decrypt($_POST['encdata'],$this->res_enc_key,$this->res_salt_key);
$array_response = explode('&',$decrypted); //change & to | for production
$equalSplit = array();
foreach ($array_response as $ar) {
$equalSub = explode('=',$ar);
if(!empty($equalSub[1]) && !empty($equalSub[0])){
$temp = array(
$equalSub[0] => $equalSub[1],);
$equalSplit += $temp;
}
}
if(isset($equalSplit['f_code']) && $this->validateResponse($equalSplit)){
$order = new WC_Order($equalSplit['mer_txn']);
$order_id = $equalSplit['mer_txn'];
$VERIFIED = $equalSplit['f_code'];
if($VERIFIED == 'Ok'){
$VERIFIED = 'complete';
}else{
$VERIFIED = 'pending';
}
$bank_name = $equalSplit['bank_name'];
$bank_txn = $equalSplit['bank_txn'];
$discriminator = $equalSplit['discriminator'];
if($equalSplit['f_code']=='Ok'){
$order->update_status('completed');
$this -> msg['message'] = "Thank you for shopping with us. Your account has been charged <b>Rs".$equalSplit['amt']."</b> for order id <b>".$order_id."</b> and your transaction is successful. Bank Transaction ID is : <b>".$equalSplit['bank_txn']."</b>.";
$this->msg['class'] = 'woocommerce-message';
$this->msg['order'] = $order;
} else if($equalSplit['f_code'] == 'F') {
$return_url = $this->get_return_url($order);
$order->update_status('failed');
$this->msg['class'] = 'woocommerce-error';
$this->msg['message'] = "<b style='color:red;font-size:20px'>The transaction has been failed or declined.</b>";
$this->msg['order'] = $order;
} else {
$order->update_status('cancelled');
$this->msg['class'] = 'woocommerce-error';
$this->msg['message'] = "<b style='color:red;font-size:20px'>The transaction has been cancelled or declined.</b>";
$this->msg['order'] = $order;
}
add_action('the_content',array(&$this,'showMessage'));
add_filter('cron_schedules','new_intervals');
function new_intervals($interval) {
$interval['minutes_30'] = array('interval' => 30*60,'display' => 'Once 30 minutes');
return $interval;
}
function InitiateMyCron() {
wp_schedule_event(time(),'minutes_30','update_ransaction_status');
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。