简体   繁体   English

PayPal IPN返回购物车或订单ID进行后处理

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

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. 我已经成功地将我的自定义购物车发布到PayPal上,它可以很好地处理订单,收到付款后,它会将数据发布回我在配置中指定的URL。 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/ 该代码基于此处的库: 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. 因此,我通过将数据发布回PayPal来成功验证IPN,这一切都很棒。 Here's my dilemma -- how do I know what order the IPN is confirming? 这是我的难题–我怎么知道IPN正在确认哪个订单?

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. 它在我的数据库中有它自己的购物车ID,当我收到该购物车的IPN时,我想“关闭”购物车并将其保存为订单以便以后查询。

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. 我尝试将附加的自定义字段与重定向一起传递给填充购物车的PayPal,但该值不会在IPN中返回给我。 The documentation on x.com is just plain lacking so I've found no help there. x.com上的文档非常缺乏,所以我在那儿找不到任何帮助。

Does anyone have any experience with PayPal and IPN? 有没有人有使用PayPal和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! 不一定必须使用PHP-我可以解释代码-但如果您可以通过订单将值发送到PayPal,然后用IPN返回该值,那就太好了!

If this isn't possible with PayPal's API (which I would find hard to believe) -- any other suggestions on how to handle this? 如果使用PayPal的API无法做到这一点(我很难相信),关于如何处理此问题还有其他建议吗?

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. 我非常怀疑这是否会对原始海报有所帮助,但是PayPal已添加或最终记录了“发票”选项,该选项使您可以发布OrderID,并通过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 有关更多信息,请参阅《 网站付款标准集成指南》(PDF) :附录A,表A.4

You can create and post a custom pass-through variable that's 255 characters long that could hold any data. 您可以创建并发布一个长度为255个字符的自定义传递变量,该变量可以保存任何数据。 More info on page 44 in the official Paypal IPN Guide. 官方Paypal IPN指南第44页的更多信息。

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. 答:对项目1使用第一套on1 / os1,然后在其中添加订单ID。

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 | B:在自定义字段中,我不确定您那里有什么,但是您可以在此处输入诸如orderidhere41 | otheritems之类的内容,然后通过在| |处进行分解将其解析出来。 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. 作为on / os进行操作会将其放在用户的贝宝收据上,因此这是我的首选方法。

If someone else has a better solution, I would be interested in it as well! 如果其他人有更好的解决方案,我也会对此感兴趣。

EDIT: 编辑:

Clarifying on1 os1. 澄清on 1 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. 这些是通常用于“大小/颜色”等的“选项”。有关它们的更多信息,请参见option_name1 option_selection(sp)下的IPN PDT Paypal变量 The name of course is the title which would be "Order ID" the os would be the actual id. 当然,名称是标题,标题将是“订单ID”,而os将是实际ID。

EDIT: 编辑:

Looking through that documentation $my2CO->addField('cart_order_id', rand(1, 100)); 浏览该文档$my2CO->addField('cart_order_id', rand(1, 100)); is where I would put my own cart order id. 是我要放置自己的购物车订单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. 最后,有一个用于Paypal IPN的自定义字段,称为“自定义”,将向其中添加数据,这将在您之间来回传递订单ID。 It must be called custom on both sides. 双方都必须将其称为“自定义”。

(this may be different for the other API's). (这可能与其他API有所不同)。

My experience has been with the Express checkout via C#, but the process should be the same even in PHP. 我的经验是通过C#进行Express checkout,但是即使在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. 如果您在将用户重定向到PayPal之前正在使用名称/值对(NVP)界面,请点击PayPal网站以获取重定向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. 发生IPN回发时,您会获得相同的令牌,以便您查找原始订单。

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 您的网站收到请求,将数据发送到PayPal
  • You get an initial response from PayPal which contains a token 您会从PayPal获得包含令牌的初始响应
  • You save this token along with this user's shopping cart. 您将此令牌与该用户的购物车一起保存。
  • You redirect the user to the link returned by PayPal 您将用户重定向到PayPal返回的链接
  • User is redirected to PayPal and enters payment info 用户被重定向到PayPal并输入付款信息
  • Payment info is validated by PayPal 付款信息已通过贝宝验证
  • User is redirected back to your site 用户被重定向回您的站点
  • PayPal sends IPN response back to your site 贝宝将IPN响应发送回您的站点
  • 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. 您可能想尝试PHP SDK-向下滚动到“名称/值对”接口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM