tags:

views:

221

answers:

3

I have a paypal button on my site in a form. The form has an additional input called ID, where the user must enter a specific value.

After the sale is complete, Paypal returns the user to domain.com/credits?done

How can i receive the original ID value entered by the user in /credits?done ? need it to modify his database record automatically.

Thanks.

A: 

See the documentation for PayPal's Instant Payment Notification and the IPN PHP code sample on the PayPal Integration Center site.

Christopher Parker
A: 

If the ID you refer to is a unique reference that you use, then pass this back and forth between Paypal and your site using the item_number element.

Set the ID in the HTML form you show to your customer and note you can also specify 3 URLs:

<input type="hidden" name="item_name" value="Box of stuff"></input>
<input type="hidden" name="item_number" value="12345"></input>
<input type="hidden" name="return" value="http://www.blah.com/paypal_thanks.asp"&gt;&lt;/input&gt;
<input type="hidden" name="notify_url" value="http://www.blah.com/paypal_callback.asp"&gt;&lt;/input&gt;
<input type="hidden" name="cancel_return" value="http://www.blah.com/paypal_cancel.asp"&gt;&lt;/input&gt;

Where I have used "paypal_callback.asp" above, this overrides the IPN link which you can set up when you log into Paypal and edit your settings. So this value is optional.

The scrpt paypal_callback.asp (assuming written in ASP) can then just say:

iAdvertId = Request.Form("item_number")

Note that this page is not the one shown to the user! It is hit by Paypals servers behind the scenes. The annoying thing is that paypal_callback.asp will not get called by Paypal immediately. It might be 3 days later...or they might hit it a month later to retract a payment.

The customer will get redirected to either paypal_thanks.asp or paypal_cancel.asp in my example. These pages will not be passed a form or querystring, so the only way to get hold of the number you places in item_number is to also store it in a cookie BEFORE the user submits the form to purchase.

When you get the email from Paypal, the item_number will be mentioned in the subject line, and within the mail body too (on the end of the Description line).

It is also possible to set additional information in custom fields. The Paypal documentation details how to do this, and you can test it with their IPN simulator in the sandbox.

Magnus Smith
and what if i need 2 variables to be sent?
andufo
i tested the whole thing but i have a problem. once the transfer is successful, it redirects me back to domain.com/buy?merchant_return_link=blabla instead of the link that is set in the button as a successful return point.why?
andufo
i'll edit my post to try and answer your questions
Magnus Smith
+1  A: 

You can create a simple cart system that will have a unique invoice to distinguish each transaction. Pass this invoice as parameter when sending payment data to paypal. Any other data can be just stored in your database, no need to sent it to paypal, since you can determine each transaction with the invoice as the unique identifier.

You also need to create a ipn handler page to receive data from paypal when user making the payment there, so you can update the payment status in your database. With this way, the user do not have to click return to your site link after making the payment, but you can still update the related data.

To make integration easier, you can consider using Micah Carrick's Paypal IPN Class. Basically it's the same code with the one provided by paypal, but it's wrapped into a class, so you can just use it in your page.

Donny Kurnia