views:

237

answers:

2

I have successfully posted my custom shopping cart to PayPal -- it processes the order just beautifully, and when the payment is received, it posts data back to the URL I specified in the config. The code is based on the library found here: http://www.phpfour.com/blog/2009/02/php-payment-gateway-library-for-paypal-authorizenet-and-2checkout/

So I'm successfully verifying the IPN by posting data back to PayPal -- that is all great. Here's my dilemma -- how do I know what order the IPN is confirming?

I am not making use of PayPals shopping cart, I have my own. It has it's own cart ID in my database, and when I receive an IPN for that cart, I'd like to "close" the cart and save it as an order to be looked up at a later date.

I've tried passing an additional custom field along with the redirect to PayPal that populates the cart, but that value isn't returned back to me in the IPN. The documentation on x.com is just plain lacking so I've found no help there.

Does anyone have any experience with PayPal and IPN? Doesn't necessarily have to be with PHP -- I can interpret code -- but if you have a way to send a value to PayPal with an order and then have that value returned with the IPN, that is AWESOME!

If this isn't possible with PayPal's API (which I would find hard to believe) -- any other suggestions on how to handle this?

A: 

I do not know if this is a good idea or not, but here are a couple different options:

A: Use the first set of on1 / os1 for the item 1 and add the order id to that.

B: In the custom field, I am not sure what you have in there, but you can make it something like orderidhere41|otheritems here and then just parse this out by exploding at the | to get them separated.

Paypal does limit this, and I do not know why, but both of those should work. Doing it as an on / os will put it on the paypal receipt for the user, so that is my preferred method.

If someone else has a better solution, I would be interested in it as well!

EDIT:

Clarifying on1 os1. These are "options" generally used for Size / color etc. See IPN PDT Paypal variables under option_name1 option_selection(sp) for more information on them. The name of course is the title which would be "Order ID" the os would be the actual id.

EDIT:

Looking through that documentation $my2CO->addField('cart_order_id', rand(1, 100)); is where I would put my own cart order id. That should be the correct field. Sorry for the confusion :)

EDIT:

In the end there is a custom field for the paypal IPN, called "custom" adding data to this will pass through, this will transfer the orderid for you to and from. It must be called custom on both sides.

Brad F Jacobs
What do you mean "on1 / os1"?
Nathan Loding
See edit notation.
Brad F Jacobs
I don't think those options are available using the "Cart Upload" command that I'm using -- at least not in the terrible documentation on x.com. I'll give it a shot in the Sandbox and see what happens.
Nathan Loding
The `$my2CO` stuff is for 2CheckOut, not for PayPal -- and I've tried passing a custom "myorderid" field, but it wasn't returned on the IPN postback -- unless I did it wrong.
Nathan Loding
"custom" should be the name of the custom field. You cannot name it your own name, it has to be custom and there can only be one. If you have not used that field, I would suggest using that.
Brad F Jacobs
@premiso -- that could be it! I'll try just using the word "custom" and see what happens.
Nathan Loding
Nathan Loding
Added to the answer above.
Brad F Jacobs
A: 

(this may be different for the other API's).

My experience has been with the Express checkout via C#, but the process should be the same even in PHP. If you're using the Name-Value Pair (NVP) interface right before you redirect the user to PayPal you hit the PayPal site to retrieve the redirection URL. As part of their response they pass back a token to you. You save this token along with your order. When the IPN postback occurs you get this same token back which lets you look up the original order.

The process flow looks like this ("You" being your site):

  • User fills cart, clicks button/link to check out
  • Request is sent to your site
  • Your site receives request, sends data to PayPal
  • You get an initial response from PayPal which contains a token
  • You save this token along with this user's shopping cart.
  • You redirect the user to the link returned by PayPal
  • User is redirected to PayPal and enters payment info
  • Payment info is validated by PayPal
  • User is redirected back to your site
  • PayPal sends IPN response back to your site
  • You grab the token included in the response
  • You look up the token you previously saved to find the shopping cart (they are the same value)
  • You close out the initial order/shopping cart.

You might want to try out the PHP SDK - scroll down to the Name-Value Pair Interface.

Paul Mrozowski
But when they return to a confirmation page, how do I know what order I am saving? That's my whole dilemma!
Nathan Loding
I modified my response to include the flow. Maybe this will help explain it better.
Paul Mrozowski
Hmm, this is not the flow that my site takes. Basically the cart is turned into an HTML form with hidden fields that match the variable names, then the form is auto-submitted to PayPal, which takes the user directly to PayPal. From what I understand, that SDK setup won't work for the "Cart Upload" command, but I'm reading the documentation now to see if I'm missing something.
Nathan Loding