Hi,

I am currently finishing a intergration with a third party payment gateway and my own bespoke shopping cart.

Currently:-
My checkout process page adds all the order and customer data to my database tables. There is an HTML form in the HTML of that page that is submitted by javascript onload that posts the required data I have already collected to the Payment Gateway. On sucsessfull payment, the Order in the database is flaged as paid. Process completed.

It all works fine, But I dont like using javascript to post the form and I dont like having the form data visable. I had a look around and it seems I should be using Curl to post the data to the Payment Gateway.

I can get my curl script to work and post all the data to the payment gateway, but...

It is returning the HTML and displaying it in the page. I would really like it to post to the payment page and follow it to it. The Payment gatway page is on https and my page is not. So is asks for payment details on http not https.

Does anyone know what i should do to make Curl go to the page rather than display it?

Here is the Curl code, I have not put the details in for security reasons. But it all works and displays the page.

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"https://$URL");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookiefile");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookiefile");
curl_exec ($ch);
curl_close ($ch);

Any suggestions would be great.

Thanks very much.

TW

    3 years later

    Hi Team Wolf

    I know this was 3 years ago but did you ever find a solution to this problem cause I am searching every where and there is little documentation about this subject.

    Many Thanks

    Ross

      You need to set CURLOPT_RETURNTRANSFER to 1 instead of 0 in order to collect the result as a string as opposed to outputting it directly:

      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL,"https://$URL");
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
      curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
      curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
      curl_setopt($ch, CURLOPT_COOKIEFILE, "cookiefile");
      curl_setopt($ch, CURLOPT_COOKIEJAR, "cookiefile");
      $result = curl_exec ($ch);
      curl_close ($ch);
      
      print_r($result); // To view the response

        Hi

        thank you for replying to my post but the problem is not how to return the output from the target page but how to phyiscaly go to the target page just as a normal HTML form would behave.

        cURL sends the post data and brings back the response. I just want it to send the post data and the user to the taget website because the content on the target website does not work without their core scripts

          Their server doesn't know if you're a "real" web browser or if you're cUrl. cUrl has no support for javascript, but by inspecting theirs you can emulate whatever it's doing in php. They can't stop you, only make it harder for you.
          But if by "physically go to", you mean point the browser to that page, either a regular anchor link, or header('location: url');
          Just remember that once the user is directed to that page, you no longer know what's going on.

            I have tried to use headers to redirect the browser but it will not load the page with the result of the cURL post it will just load the page as if no data has been past to it.

              Yes, the two are entirely separate. The browser doesn't know what cUrl is doing, and cUrl doesn't know what the browser is doing. The browser request that is the result of a location redirect is identical to one that is the result of a user typing the same address into the address bar or clicking a link. And since this occurs in the browser, your server isn't even aware that the browser requested a new resource - Unless of course that resource is also found on your server, and even then your server not necessarily know that it's the same browser requesting a new resource.

              Either you will have to send the user to this other page, and if so you will know nothing about what happens.
              Or, use cUrl to perform GET and/or POST requests to the other server, handle the responses from it, possibly passing some data back to the user, take their input back for further processing, possibly passing some of that along to the other server... etc.

                I could send and recieve the data like you said but then I am not protecting the user with the https connection that the payment gateway provides on the target page.

                I was hoping there would be a way I could post a html form and keep the integratey of the data (ie not letting the user edit it in the browser).

                I think the real answer is the ether have a proper https connection with the payment gateway or have an encrytion on the html form. But neither of these option are offered by the gateway I am trying to intergrate with beacuse in my opion they are total douche bags. 😃

                  Write a Reply...