Woocommerce自定义支付网关未执行form.submit [英] Woocommerce custom payment gateway is not executing form.submit
问题描述
先谢谢了.我正在为woocommerce建立自定义的支付网关.我正在努力的事情是我的付款网关的服务器仅在我提交表格时才接受请求.因此,我确实将表单提交与重定向到付款网关的网址.问题是woocommerce没有在process_payment方法中执行我的form.submit.
thanks in advance. I am building a custom payment gateway for woocommerce. The thing i am struggling with is that the server of my payment gateway only accepts request when i submit a form. So i do form submit with redirect to payment gateway url. The problem is that woocommerce is not executing my form.submit in process_payment method.
所以我尝试使用wp_remote_post,使用curl,但是这些都不对我有用,因为我需要使用数据重定向到我的支付网关,就像在form.submit中一样.
So i tried using wp_remote_post, using curl but none of these work for me because i need to redirect to my payment gateway with data, as if in form.submit.
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 );
//Here i take some data and put it inside $a
echo '<form name="customForm" action="https://gateway.com/web" method="post" id="customForm">
<input type="hidden" name="token" id="token" value="<?php echo $token;?>">
<input type="hidden" name="key" id="key" value="<?php echo $a->key;?>">
<input type="hidden" name="callbackUrl" id="callbackUrl" value="<?php echo $a->callbackUrl;?>">
<!-- callback url where alif sends information about status of transactions -->
<input type="hidden" name="returnUrl" id="returnUrl" value="<?php echo $a->returnUrl;?>">
<input type="hidden" name="amount" id="amount" value="<?php echo $a->amount;?>" required>
<input type="hidden" name="orderId" id="orderId" value="<?php echo $a->orderid;?>">
<input type="hidden" name="info" id="info" value="<?php echo $a->info;?>">
<input type="hidden" name="email" id="email" value="<?php echo $a->email;?>">
<input type="hidden" name="phone" id="phone" value="<?php echo $a->phone;?>">
</form>';
?><script type="text/javascript">
document.getElementById('customForm').submit();
</script><?php
}
我希望将其重定向到支付网关url,但是在woocommerce中,我不会被重定向到无效的表单消息.
I expected to be redirected to payment gateway url, but i dont get redirected and get invalid form message in woocommerce.
推荐答案
我认为您首先需要创建钩子过滤器,如下所示:
I think you need first create hook filter like this:
add_filter('woocommerce_receipt_' . $this->id, array(&$this, 'receipt_page'));
然后:
public function receipt_page($order_id)
{
// Get this Order's information so that we know
// who to charge and how much
$customer_order = new WC_Order($order_id);
//Here i take some data and put it inside $a
echo '<form name="customForm" action="https://gateway.com/web" method="post" id="customForm">
<input type="hidden" name="token" id="token" value="<?php echo $token;?>">
<input type="hidden" name="key" id="key" value="<?php echo $a->key;?>">
<input type="hidden" name="callbackUrl" id="callbackUrl" value="<?php echo $a->callbackUrl;?>">
<!-- callback url where alif sends information about status of transactions -->
<input type="hidden" name="returnUrl" id="returnUrl" value="<?php echo $a->returnUrl;?>">
<input type="hidden" name="amount" id="amount" value="<?php echo $a->amount;?>" required>
<input type="hidden" name="orderId" id="orderId" value="<?php echo $a->orderid;?>">
<input type="hidden" name="info" id="info" value="<?php echo $a->info;?>">
<input type="hidden" name="email" id="email" value="<?php echo $a->email;?>">
<input type="hidden" name="phone" id="phone" value="<?php echo $a->phone;?>">
</form>';
}
这篇关于Woocommerce自定义支付网关未执行form.submit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!