PHP cURL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Teamwolf
    New Member
    • Oct 2007
    • 1

    #1

    PHP cURL

    Hi,

    I am currently finishing integration 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 successful payment, the Order in the database is flagged as paid. Process completed.

    It all works fine, But I don’t like using JavaScript to post the form and I don’t like having the form data visible. I had a look around and it seems I should be using cURL to post the data to the Payment Gateway. Unless someone could suggest a better way.

    I can get my cURL code 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 gateway 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 results in the page.

    [CODE=php]
    $ch = curl_init();
    curl_setopt($ch , CURLOPT_URL,"ht tps://$URL");
    curl_setopt($ch , CURLOPT_POST, 1);
    curl_setopt($ch , CURLOPT_POSTFIE LDS, $data);
    curl_setopt($ch , CURLOPT_SSL_VER IFYPEER, FALSE);
    curl_setopt($ch , CURLOPT_USERAGE NT, $user_agent);
    curl_setopt ($ch, CURLOPT_RETURNT RANSFER, 0);
    curl_setopt($ch , CURLOPT_HEADER, 0);
    curl_setopt($ch , CURLOPT_FOLLOWL OCATION, true);
    curl_setopt($ch , CURLOPT_COOKIEF ILE, "cookiefile ");
    curl_setopt($ch , CURLOPT_COOKIEJ AR, "cookiefile ");
    curl_exec ($ch);
    curl_close ($ch);
    [/CODE]

    Any suggestions would be great.

    Thanks very much.

    TW
    Last edited by Atli; Oct 31 '07, 03:02 PM. Reason: Changed [code] tags to [code=php].
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, TeamWolf. Welcome to TSDN!

    Change this line:
    [code=php]
    curl_setopt ($ch, CURLOPT_RETURNT RANSFER, 0);
    [/code]
    to this:
    [code=php]
    curl_setopt ($ch, CURLOPT_RETURNT RANSFER, 1);
    [/code]

    Then use header() redirection to go to the 'payment processed' page.

    Comment

    Working...