I have been playing around with cURL trying to pass POST data to a page payment gateway page...
I haven't been able to emulate a submit form action... I would like to forward the client to the payment gateway page (together with the POST data) but I can not find the way of doing this...
I do manage to pass the POST data, but the resulting page loads within my domain (instead of forwarding 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);
How should this be done?
Nearly all low-end payment gateway solutions expect you to actually carry out a POST to their server, at which point they'll take the payment details from the end user prior to returning the user to a designated page(s) with some status information. As such, using CURL is liable to cause problems.
What you probably need to do is output the relevant form via PHP into a (very) minimal HTML page with automatically causes the form to be submitted via the use of onload.
For example, if your form had an id of "checkoutform", you could use:
This is, of course, pretty poor. (Yet sadly inevitable.)