PayPal IPN returning a shopping cart or order ID for post-processing

元气小坏坏 提交于 2019-12-25 14:11:54

问题


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?


回答1:


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.




回答2:


(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.




回答3:


I very much doubt this will help the original poster, but PayPal have either added, or finally documented the option "invoice" which allows you to post the OrderID, and have it posted back via the IPN. I am currently using this and it seems to work as expected.

For further info see the Website Payments Standard Integration Guide (PDF): Appendix A, Table A.4




回答4:


You can create and post a custom pass-through variable that's 255 characters long that could hold any data. More info on page 44 in the official Paypal IPN Guide.



来源:https://stackoverflow.com/questions/3349151/paypal-ipn-returning-a-shopping-cart-or-order-id-for-post-processing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!