WP API挂钩的Woocommerce POST请求不起作用

时间:2019-03-28 07:19:39

标签: woocommerce woocommerce-rest-api

我制作了自定义的Woocommerce付款网关,一切正常,直到必须返回带有外部付款链接的api响应的网站。我得到-1空白页,并且网络状态为400错误(错误请求)。任何帮助都感激不尽。谢谢

$this->notify_url           = str_replace( 'https:', 'http:', add_query_arg( 'wc-api', 'pm_wc_ncm', home_url( '/' ) ) );

add_action( 'woocommerce_api_pm_wc_ncm', array( $this, 'check_notify_response' ) );

function check_notify_response(){
        if (isset($_POST['txtIndex'])) {

            $order_id = $_POST['txtIndex'];
            $order = new WC_Order($order_id);
            $order_total = $order->get_total();

            $amount_paid = $_POST['txtAmount'];
            $RespVal = $_POST['RespVal'];
            $RespMsg = $_POST['RespMsg'];
            $txtIndex = $_POST['txtIndex'];
            $txtMerchNum = $_POST['txtMerchNum'];
            $txtNumAut = $_POST['txtNumAut'];
            $Signature = $_POST['signature'];

            $txtCurrency = $_POST['txtCurrency'];
            $sha = $this->sha_key;
            $SignatureElts = $txtMerchNum . $order_id . $amount_paid . $txtCurrency . $txtNumAut . $RespVal . $RespMsg . $sha;
            $ReturnSignature = hash('sha256', $SignatureElts);

            if ($ReturnSignature != $Signature) {
                echo "Security violation was detected! <br>";
                echo "Order ID: ".$txtIndex."<br>";
                $message1 = "Signature error";
                if (function_exists('wc_add_notice')) {
                    wc_add_notice($message1, 'error');

                }
            }else{
                if($RespVal=="1")
                {
                    echo "Your Transaction was successful <br>";
                    echo "Order ID: ".$txtIndex."<br>";
                    echo "Authorization no.: ".$txtNumAut."<br>";
                    echo "Amount: ".$amount_paid."<br>";
                }
                elseif ($RespVal=="0")
                {
                    echo "Unfortunately your transaction was refused <br>";
                    echo "Order ID: ".$txtIndex."<br>";
                    echo "Amount: ".$amount_paid."<br>";
                }

            }
        }
    }

0 个答案:

没有答案
相关问题