简体   繁体   English

Woocommerce自定义支付网关重定向

[英]Woocommerce custom payment gateway redirect

I have a problem. 我有个问题。 I should do a custom gateway. 我应该做一个自定义网关。 I know the basics. 我知道基础知识。 I read the documentation. 我看了文档。 URL data to be transmitted (such as user name, the amount of the transaction). 要传输的URL数据(例如用户名,事务量)。 My question is how to redirect the user to the payment page of the bank? 我的问题是如何将用户重定向到银行的付款页面? What is the command and where to give the exact url? 什么是命令以及在哪里给出确切的URL? And then the returned data must be processed what method? 然后返回的数据必须处理什么方法? cURL or something else? cURL还是其他什么? I could not find any real solution to the problem. 我找不到任何真正的解决方案。

Different gateway's have different needs, if your gateway uses a POST, you can use this to POST the data, and get a response.. it is better than cURL. 不同的网关有不同的需求,如果您的网关使用POST,您可以使用它来POST数据,并获得响应..它比cURL更好。

$response = wp_remote_post( $environment_url, array(
                    'method'    => 'POST',
                    'body'      => http_build_query( $payload ),
                    'timeout'   => 90,
                    'sslverify' => false,
                ) );

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

// Payload would look something like this.
$payload = array(
    "amount" => $order.get_total(), 
    "reference" => $order->get_order_number(),
    "orderid" => $order->id,
    "return_url" => $this->get_return_url($order)  //return to thank you page.
);

//use this if you need to redirect the user to the payment page of the bank.
$querystring = http_build_query( $payload );

return array(
                'result'   => 'success',
                'redirect' => $environment_url . '?' . $querystring,
            );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM