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.
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
}
I expected to be redirected to payment gateway url, but i dont get redirected and get invalid form message in woocommerce.
2
Answers
I think you need first create hook filter like this:
And then:
I think the issue with wrong syntax. Try using this syntax: