Go to the payment gateway along with the POST data using cURL (or any other PHP server-side solution)

I played with cURL trying to pass POST data to the page gateway page ...

I could not emulate the action of the submit form ... I would like to forward the client to the payment gateway page (along with the POST data), but I can not find a way to do this ...

I manage to transfer POST data, but the resulting page loads in my domain (instead of redirecting the user to the payment gateway).

$connection = curl_init("https://paymentgateway.com/script"); curl_setopt($connection, CURLOPT_RETURNTRANSFER, 0); curl_setopt($connection, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($connection, CURLOPT_POST, 1); curl_setopt($connection, CURLOPT_POSTFIELDS, $postdata); curl_exec($connection); curl_close($connection); 

How to do it?

+4
source share
1 answer

Almost all low-cost solutions for payment gateways assume that you are actually performing POST on your server, after which they will receive payment data from the end user before he returns the user to the designated pages using some status information. Therefore, using CURL can cause problems.

What you probably need to do is output the appropriate form via PHP to a (very) minimal HTML page, automatically forcing the form to submit using onload.

For example, if your form has the identifier "checkoutform", you can use:

 <body onload="document.getElementById(\'checkoutform\').submit();"> 

This, of course, is pretty bad. (But, unfortunately, inevitably.)

+5
source

Source: https://habr.com/ru/post/1335897/


All Articles