Wordpress 支付网关未向URL发送请求参数?

Wordpress 支付网关未向URL发送请求参数?,wordpress,plugins,payment-gateway,Wordpress,Plugins,Payment Gateway,这是我的以下自定义支付网关代码。 当我试图在签出页面下订单时,它会显示连接到我创建的服务器异常。当我们在firebug中检查参数时,它只显示签出和响应失败。 我正在尝试将请求参数发送到网关URL,但没有成功。 请告诉我哪里出的错? 提前谢谢 public function process_payment( $order_id ) { global $woocommerce; // Get this Order's information so that we know

这是我的以下自定义支付网关代码。 当我试图在签出页面下订单时,它会显示连接到我创建的服务器异常。当我们在firebug中检查参数时,它只显示签出和响应失败。 我正在尝试将请求参数发送到网关URL,但没有成功。 请告诉我哪里出的错? 提前谢谢

    public function process_payment( $order_id ) {
    global $woocommerce;

    // Get this Order's information so that we know
    // who to charge and how much
    $customer_order = new WC_Order( $order_id );

    // Are we testing right now or is it a real transaction
    $environment = ( $this->environment == "yes" ) ? 'TRUE' : 'FALSE';

    // Decide which URL to post to
    $environment_url = ( "FALSE" == $environment ) 
                       ? 'https://www.qpayindia.com/wwws/Payment/PaymentDetails.aspx'
                       : 'https://www.qpayindia.com/wwws/Payment/PaymentDetails.aspx';

    $QPayID = $this->QPayID.'`'.$this->order_total;

    // This is where the fun stuff begins
    $payload = array(
        // Authorize.net Credentials and API Info
        "QPayID"            => $this->QPayID.'`'.$this->order_total,
        "QPayPWD"               => $this->QPayPWD,
        "CaseNumber"                => $this->CaseNumber,

        "Currency"                  => $this->Currency,
        "TransactionType"               => $this->TransactionType,
        "ResponseURL"               => $this->ResponseURL,

        "Mode"                  => $environment,
        "Amount"                => $customer_order->order_total,
        "OrderID"               => $customer_order->get_order

    );

    // Send this payload to Authorize.net for processing
    $response = wp_remote_post( $environment_url, array(
        'method'    => 'POST',
        'body'      => http_build_query( $payload ),
        'timeout'   => 90,
        'sslverify' => false,
    ) );

    if ( is_wp_error( $response ) ) 
        throw new Exception( __( 'We are currently experiencing problems trying to connect to this payment gateway. Sorry for the inconvenience.', 'spyr-authorizenet-aim' ) );
    else
    {
        throw new Exception( __( 'Connecting to server.', 'spyr-authorizenet-aim' ) ); 
    }
    if ( empty( $response['body'] ) )
        throw new Exception( __( 'Authorize.net\'s Response was empty.', 'spyr-authorizenet-aim' ) );


    // Retrieve the body's resopnse if no errors found
    $response_body = wp_remote_retrieve_body( $response );

    // Parse the response into something we can read
    foreach ( preg_split( "/\r?\n/", $response_body ) as $line ) {
        $resp = explode( "|", $line );
    }

    // Get the values we need
    $r['ResponseCode']             = $resp[0];
    $r['Message']         = $resp[1];
    //$r['response_reason_code']      = $resp[2];
    //$r['Message']      = $resp[3];

    // Test the code to know if the transaction went through or not.
    // 1 or 4 means the transaction was a success
    if ( ( $r['ResponseCode'] == 100 )  ) {
        // Payment has been successful
        $customer_order->add_order_note( __( 'Authorize.net payment completed.', 'spyr-authorizenet-aim' ) );

        // Mark order as Paid
        $customer_order->payment_complete();

        // Empty the cart (Very important step)
        $woocommerce->cart->empty_cart();

        // Redirect to thank you page
        return array(
            'result'   => 'success',
            'redirect' => $this->get_return_url( $customer_order ),
        );
    } else {
        // Transaction was not succesful
        // Add notice to the cart
        wc_add_notice( $r['Message'], 'error' );
        // Add note to the order for your reference
        $customer_order->add_order_note( 'Error: '. $r['Message'] );
    }

}

// Validate fields
public function validate_fields() {
    return true;
}

我想你把逻辑搞糊涂了:

if ( is_wp_error( $response ) ) 
    throw new Exception(....);
else
{
    throw new Exception(....); 
}
因此,不管响应如何,都会抛出异常,这样就永远无法深入代码。异常总是中断当前流,除非用“try…catch”捕获,否则它将中断程序。要快速测试,请尝试以下方法(顺便注意花括号):


谢谢,让我试试这个。
if ( is_wp_error( $response ) ) {
    throw new Exception( __( 'We are currently experiencing problems trying to connect to this payment gateway. Sorry for the inconvenience.', 'spyr-authorizenet-aim' ) );
} else if ( empty( $response['body'] ) ) {
    throw new Exception( __( 'Authorize.net\'s Response was empty.', 'spyr-authorizenet-aim' ) );
} 

// Retrieve the body's resopnse if no errors found
// ...