Forward POST data to PayPal

I have a custom checkout page for customers to purchase services. All payments are processed through PayPal.
After I collect customer information (Name, Items ordered, etc.) The customer reviews the order and clicks the make payment button… At this point I need to store this information into my database, and then forward Some of that POST data to PayPal so they can make there payment. I know how to add the data into my database with php but right after that I need the request to be forwarded to paypal. How can I do this?

Note: I need the information recorded in my database prior to paypal payment because i’m using PayPal’s IPN to automate purchases and verify the payment is legit.

Hi,

When the user submits the form, it should FIRST submit to paypal. Therefore, your form’s action attribute should be the paypal url followed by the token string and all necessary data.

Only once the payment is confirmed at the paypal site, THEN ONLY you save the data to your database.

But how would that work? You see, in your form, you should have an input hidden field that goes by the name RETURNURL this value must be supplied with the url of the php page that would insert the data upon successful payment. This means, once the payment is succeesful, paypal will redirect the user to the value supplied to RETURNURL.

This is how i did the payment code few years back. I believe paypal woudln’t change to much how it would work but maybe the attribute name might be slightly different. The idea would be somewhat like this. Hope you understand me.

Regards,
developer.dex2908

I do understand what your saying; however, without recording the price and items in My database prior to them making payment I have no way to verify the payment prices and items match. (to make sure they didn’t change the prices through some exploit. This is PayPals recommendation to verify the prices and things like that. You NEVER just simply rely on the IPN message saying payment complete.

I believe this may be what you are looking for:

If your php is built with curl, it can be used to effectively forward the post variables to multiple scripts or sites.

Here is a test to demonstrate this:[php]

POST to other page using curl <?php if(isset($_POST['firstname'])) $posts['firstname']=$_POST['firstname']; if(isset($_POST['submit'])) { $ch = curl_init('www.yoursite.com/curltest2.php'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $posts); curl_exec($ch);
echo '<pre>';
print_r($_POST);
echo '</pre>';

}
?>

[/php]

This will post the form back to the form’s page for processing. It will also send the same post variables on to a second page as determined by the address in the curlinit line.

To test this, I setup a table called curltest with a single column (VARCHAR 60) named “firstname”
I then put the following (with my db connection header) in the page that is referenced in the curlinit:[php]<?php

if(!empty($_POST[‘firstname’]))
{
$query = “INSERT INTO curltest (firstname) VALUES (’$_POST[firstname]’)”;
mysql_query($query);
}[/php]

I then loaded the first page into the browser, typed a name in the form field, and hit submit.

The form posted back to itself and displayed the $_POST array correctly.

I opened up phpmyadmin and the firstname was correctly added by the curled page.

Please let me know if I have misunderstood what you are looking to do and I will try to come up with a different solution.

jay

That does work either. I not only need to post the variables to paypal but, i need the paypal website to open up for the customer to complete the actual payment transaction… An example of what i want to do… If you goto tirgerdirect.com and and add any item to the shopping… then scroll down you’ll see alternative checkout options… one being paypal… if you click that, the request is forwarded to paypal express checkout. tigerdirect uses asp but thats whats what i am trying to do with php… Hope that clarifies things a bit.

oops. sorry i trying to say that does not work either* LOL

you could have an add to cart and once everything is stored in your database then have a form which you can then output the value to the form.

[code]





[/code]

then when the payment goes through it then notifies the IPN which you can find below which then maybe updates a field to say it is ordered.

The only solution that I can think of would require javascript:

You would send your original form (page 1) to page 2 (an intermediary “handler” page).
Page 2 would create a new form with duplicate $_POST names and matching values (to those passed in from the original form). The action would be set to the paypal page where you need to send the user and $_POST to. The php for this page (page 2) would store the values into your database before the page even loads. You would need to include an onload javascript function to submit the form upon the page loading, effectively redirecting the user to the final paypal page with duplicate $_POST variables.

Other than this option, I cannot think of any other way to do what you need to. If you would like to see an example of this, let me know and I’ll throw something together.

thanks for the replys everyone. I have decided that its not really possable to do this is in the same step so what i decided to do is to insert the customer information, ordered items, prices etc. into the database when they get to the review order page. If they need to make changes, the next time the review order page is requested i’ll then update the information in the database. On the review order page The make payment button will be displayed to POST the information to paypal.

Note: I can’t use an add to cart button. I have a custom shopping cart. I am using paypals upload cart option… Here is the form if anyone else is interested.

[code]






































[/code]
Sponsor our Newsletter | Privacy Policy | Terms of Service