1

I am trying to rebuild a site that currently presents a form to the user, has the user click a button to post to a page that does some calcs based on the data entered, and has them hit another button to post to a payment vendor that presents a secure payment form utilizing the non-sensitive data entered.

I am trying to do the following. I have written a page that presents the form for customer data entry, they click a submit button, that posts to a php file on my site, I make the calculations needed, and then post to the site using Curl.

I have only used cURL in the past to post to a site, check for a good process status, and continue on. Can I use Curl to post to and then go to the other page in the browser, just like I do when I submit the form directly to it?

In Summary:

  1. Can I post to a form in Curl and have it act just as if I posted from HTML form with the action set to the external site url.

  2. If so, what I have I missed?

Here is the code from the cUrl call in the php file:

$fields = array(
    'x_invoice_num' => urlencode($x_invoice_num),
    'x_phone' => urlencode($x_phone),
    'x_email' => urlencode($x_email),
    'x_ship_to_address' => urlencode($x_ship_to_address),
    'x_first_name' => urlencode($x_first_name),
    'x_last_name' => urlencode($x_last_name),
    'x_address' => urlencode($x_address),
    'x_city' => urlencode($x_city),
    'x_state' => urlencode($x_state),
    'x_zip' => urlencode($x_zip),
    'x_amount' => urlencode($x_amount),
    'x_fp_hash' => urlencode($x_fp_hash),
    'x_fp_sequence' => urlencode($x_fp_sequence),
    'x_fp_timestamp' => urlencode($x_fp_timestamp),
    'x_login' => urlencode($x_login),
    'x_show_form' => urlencode($x_show_form),
    'x_description' => urlencode($x_description)
);

        //url-ify the data for the POST
       $fields_string="";
       foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
       rtrim($fields_string, '&');





       //set the url, number of POST vars, POST data

       $ch = curl_init();
       curl_setopt($ch, CURLOPT_URL, $postURL);
       curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
       curl_setopt($ch, CURLOPT_HEADER, FALSE);
       curl_setopt($ch, CURLOPT_POST, TRUE);
       curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

       $headers = array();
   $headers[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
   $headers[] = "Accept-Language: en-us,en;q=0.5";
   $headers[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

       //execute post
       //curl_exec($ch);

       $curl_result = curl_exec($ch);
       $OK = strpos($curl_result, 'OK');
       $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);


       curl_close($ch);
1
  • You can not send a POST request with cURL, and then make the browser follow, as cURL creates it's own request and gets it's own response. What you probably want is to return the calculated data to the browser, then have the browser redirect and post the data, or post the data with cURL and get the response back, and send that to the browser. You can't do a "hybrid" where you send the data with cURL and then the browser just magically gets in on the same request. Commented Feb 27, 2015 at 16:41

1 Answer 1

1

The idea of having the user redirected to the secure payment provider is that he/she will enter some sensitive payment info (CC, expiry, ...) to be processed. I don't think that you have this info, among your "$fields" array, to be able to POST directly to the provider.

What you want to look at is probably a callback from the provider's website once the payment is successful and complete.

Sign up to request clarification or add additional context in comments.

5 Comments

I calculate the fp hash, which has a transaction key, that needs to be hidden. When I submit, the cc processor presents a payment form, I do not handle the payment. So I am doing this intermediate step to calculate the hash while protecting the transaction key, and then want to send them on to the payment handler's webpage.
So you want to redirect the user to the payment handler?
Yes, I collect demographic info and amount to pay, then calc the hash, then I want to post data and redirect to the payment processor's site, where they will present a form to get cc info and process the payment.
I am also trying another tact on the same issue, if you check my other question that is open. On it, same form, I am interupting the submit, sending the amount to a php file to calc hash and 2 other values, and then want to send back to original form, update hidden values then post. I am having trouble getting the value back to the original form.
I see in your other question that you have managed to solve it. Goodluck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.