Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 从支付网站重定向回来后,在woocommerce中处理响应和下单_Wordpress_Woocommerce_Payment Gateway_Hook Woocommerce - Fatal编程技术网

Wordpress 从支付网站重定向回来后,在woocommerce中处理响应和下单

Wordpress 从支付网站重定向回来后,在woocommerce中处理响应和下单,wordpress,woocommerce,payment-gateway,hook-woocommerce,Wordpress,Woocommerce,Payment Gateway,Hook Woocommerce,我正在为WooCommerce开发一个支付网关插件(用于Cybersource支付)。我几乎在最后开发了它,但有一件事阻止了我完成,那就是成功付款后从支付网关网站重定向到我的wordpress页面(购买确认页面-使用wp content/themes/my theme/order confirm template.php中的模板创建的新wordpress页面)。但我不知道如何处理来自支付网站的回复。我找了些钩子,但什么也没找到。我发现有一个钩子,谢谢你,但这对我也不起作用 有人能帮我解决以下两点

我正在为WooCommerce开发一个支付网关插件(用于Cybersource支付)。我几乎在最后开发了它,但有一件事阻止了我完成,那就是成功付款后从支付网关网站重定向到我的wordpress页面(购买确认页面-使用wp content/themes/my theme/order confirm template.php中的模板创建的新wordpress页面)。但我不知道如何处理来自支付网站的回复。我找了些钩子,但什么也没找到。我发现有一个钩子,谢谢你,但这对我也不起作用

有人能帮我解决以下两点吗

1) 如何正确处理响应和下单,并在网关网站成功付款后返回购物车时从购物车中移除物品

2) 我应该从网关网站重定向回哪个页面?回到同一个结账页面或一些自定义页面,就像我做的那样


任何代码方面的帮助都将不胜感激。谢谢。

我在插件中使用了以下代码,我希望这也适用于您:)

首先添加此代码

function receipt_page($order){
    echo $this -> ResponceHandler($order);
}
现在是ResponceHandler($order)函数的代码

 public function ResponceHandler($order_id){




            if(!isset($_POST['ResponseCode'])){

            global $woocommerce;
        echo '<p>'.__('Thank you for your order, please click the button below to pay with XYZ', 'woocommerce').'</p>';
            $order = new WC_Order($order_id);

            $order_id = $order_id.'_'.date("ymds");



            $post_data = get_post_meta($order_id,'_post_data',true);

            update_post_meta($order_id,'_post_data',array());
###Your Form Code HERE###
   echo '<form><input value="Proceed To Payment" type="submit" /> </form>'; 
}
###Haandle the response###
 if(isset($_POST['ResponseCode']))
            {
             if($_POST['ResponseCode']==0){
                                    global $woocommerce;
                                    session_start();
                                    $_SESSION['post']=$_POST;

                                    $order = new WC_Order($order_id);

                                    $order_id = $order_id.'_'.date("ymds");



                                    $post_data = get_post_meta($order_id,'_post_data',true);

                                    update_post_meta($order_id,'_post_data',array());
                                                if($order->status != 'processing'){

                                                $order ->status ='Processing';
                                                $order->payment_complete();

                                                $order -> add_order_note('XYZ Payment Gateway <br>Response message :'.$_POST['ResponseMessage'].'<br>Payment ID :'.$_POST['PaymentID'].'<br>Merchant Reference Number :'.$_POST['MerchantRefNo'].'<br>Transaction ID :'.$_POST['TransactionID'].'');

                                                add_post_meta( $order->id, '_paymentid', sanitize_text_field( $_POST['PaymentID'] ) );
                                                add_post_meta( $order->id, '_trno', sanitize_text_field( $_POST['TransactionID'] ) );
                                                $woocommerce -> cart -> empty_cart();
                                                wp_redirect( $order->get_checkout_order_received_url());

                                            }
                                }
            else {

                                                if($order->status != 'failed'){
                                                $order ->status ='failed';
                                echo "Payment failed!<br><br><br>Possible Error : ".$_POST['ResponseMessage']."<br>PaymentID: ".$_POST['PaymentID']."<br><br><br>We request you to save these details for further reference. <br>You can always pay for this order by clicking on your name in the top right corner and visiting your orders section."; }
                }

            }





}
public function ResponceHandler($order\u id){
如果(!isset($_POST['ResponseCode'])){
全球商业;
echo“”。uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu;
$order=新WC\U订单($order\U id);
$order_id=$order_id.''日期(“ymds”);
$post\u data=get\u post\u meta($order\u id,“post\u data”,true);
更新发布元($order\u id,“'u post\u data',array());
###您的表单代码在这里###
回声';
}
###汉德尔的回答###
如果(isset($_POST['ResponseCode']))
{
如果($_POST['ResponseCode']==0){
全球商业;
会话_start();
$\u会话['post']=$\u post;
$order=新WC\U订单($order\U id);
$order_id=$order_id.''日期(“ymds”);
$post\u data=get\u post\u meta($order\u id,“post\u data”,true);
更新发布元($order\u id,“'u post\u data',array());
如果($order->status!=“正在处理”){
$order->status='Processing';
$order->payment_complete();
$order->add_order_note('XYZ Payment Gateway
响应消息:'.$u POST['ResponseMessage'.'.
支付ID:'.$u POST['PaymentID'.'.
商户参考号:'.$u POST['MerchantRefNo'.
交易ID:'.$u POST['TransactionID'.'); 添加帖子元($订单->id,''.'paymentid',清理文本字段($帖子['paymentid']); 添加发布元($订单->id,'.'trno',清理文本字段($发布['TransactionID']); $woocommerce->cart->empty_cart(); wp_重定向($order->get_checkout_order_received_url()); } } 否则{ 如果($order->status!=“failed”){ $order->status='failed'; echo“付款失败!

可能的错误:“.$\u POST['ResponseMessage']”“
付款ID:“.$\u POST['PaymentID']”。”

我们请求您保存这些详细信息以供进一步参考。
您始终可以通过单击右上角的姓名并访问您的订单部分来支付此订单。“;” } } }
我在插件中使用了以下代码,我希望这也适用于您:)

首先添加此代码

function receipt_page($order){
    echo $this -> ResponceHandler($order);
}
现在是ResponceHandler($order)函数的代码

 public function ResponceHandler($order_id){




            if(!isset($_POST['ResponseCode'])){

            global $woocommerce;
        echo '<p>'.__('Thank you for your order, please click the button below to pay with XYZ', 'woocommerce').'</p>';
            $order = new WC_Order($order_id);

            $order_id = $order_id.'_'.date("ymds");



            $post_data = get_post_meta($order_id,'_post_data',true);

            update_post_meta($order_id,'_post_data',array());
###Your Form Code HERE###
   echo '<form><input value="Proceed To Payment" type="submit" /> </form>'; 
}
###Haandle the response###
 if(isset($_POST['ResponseCode']))
            {
             if($_POST['ResponseCode']==0){
                                    global $woocommerce;
                                    session_start();
                                    $_SESSION['post']=$_POST;

                                    $order = new WC_Order($order_id);

                                    $order_id = $order_id.'_'.date("ymds");



                                    $post_data = get_post_meta($order_id,'_post_data',true);

                                    update_post_meta($order_id,'_post_data',array());
                                                if($order->status != 'processing'){

                                                $order ->status ='Processing';
                                                $order->payment_complete();

                                                $order -> add_order_note('XYZ Payment Gateway <br>Response message :'.$_POST['ResponseMessage'].'<br>Payment ID :'.$_POST['PaymentID'].'<br>Merchant Reference Number :'.$_POST['MerchantRefNo'].'<br>Transaction ID :'.$_POST['TransactionID'].'');

                                                add_post_meta( $order->id, '_paymentid', sanitize_text_field( $_POST['PaymentID'] ) );
                                                add_post_meta( $order->id, '_trno', sanitize_text_field( $_POST['TransactionID'] ) );
                                                $woocommerce -> cart -> empty_cart();
                                                wp_redirect( $order->get_checkout_order_received_url());

                                            }
                                }
            else {

                                                if($order->status != 'failed'){
                                                $order ->status ='failed';
                                echo "Payment failed!<br><br><br>Possible Error : ".$_POST['ResponseMessage']."<br>PaymentID: ".$_POST['PaymentID']."<br><br><br>We request you to save these details for further reference. <br>You can always pay for this order by clicking on your name in the top right corner and visiting your orders section."; }
                }

            }





}
public function ResponceHandler($order\u id){
如果(!isset($_POST['ResponseCode'])){
全球商业;
echo“”。uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu;
$order=新WC\U订单($order\U id);
$order_id=$order_id.''日期(“ymds”);
$post\u data=get\u post\u meta($order\u id,“post\u data”,true);
更新发布元($order\u id,“'u post\u data',array());
###您的表单代码在这里###
回声';
}
###汉德尔的回答###
如果(isset($_POST['ResponseCode']))
{
如果($_POST['ResponseCode']==0){
全球商业;
会话_start();
$\u会话['post']=$\u post;
$order=新WC\U订单($order\U id);
$order_id=$order_id.''日期(“ymds”);
$post\u data=get\u post\u meta($order\u id,“post\u data”,true);
更新发布元($order\u id,“'u post\u data',array());
如果($order->status!=“正在处理”){
$order->status='Processing';
$order->payment_complete();
$order->add_order_note('XYZ Payment Gateway
响应消息:'.$u POST['ResponseMessage'.'.
支付ID:'.$u POST['PaymentID'.'.
商户参考号:'.$u POST['MerchantRefNo'.
交易ID:'.$u POST['TransactionID'.'); 添加_post_meta($