简体   繁体   English

Paypal REST API返回页面

[英]Paypal REST API Return Page

I'm currently using the Paypal REST API to process billing agreements for users with multiple plans. 我目前正在使用Paypal REST API为具有多个计划的用户处理计费协议。

When a user signs up for a plan, it takes them to PayPal to pay. 当用户注册计划时,它将带他们到PayPal进行支付。 After they finish that step, PayPal redirects them to a return URL that I have supplied. 他们完成该步骤后,PayPal将其重定向到我提供的返回URL。

The problem is, sometimes the user's session does not persist when they return from PayPal! 问题是, 有时用户的会话从PayPal返回时不会持续!

I have session_start() as the first line in all of my files, so the sessions are being created. 我曾经session_start()在我所有的文件的第一行,因此正在创建的会话。 I have verified, before taking the user to PayPal, that the $_SESSION array is being populated - it's just when they are brought back after PayPal. 在将用户带到PayPal之前,我已经验证了$_SESSION数组被填充-只是在将它们带回PayPal之后。

Is there a better way to persist data like that so I can update a users account on return back from PayPal? 有没有更好的方法来保存这样的数据,以便我可以在从PayPal退回时更新用户帐户? Or maybe there is a way to pass the email with the PayPalrequest so that it is returned in the object they send back to my website on return? 也许有一种方法可以通过PayPalrequest传递电子邮件,以便将其返回给他们在返回时发送回我的网站的对象?

If you're properly starting the session via session_start() on both your sign-up page and the page that PayPal redirects back to, your session should be starting properly. 如果您在注册页面和PayPal重定向回的页面上都通过session_start()正确启动了会话,则会话应该可以正常启动。

Assuming that you're not inadvertently closing the session , or regenerating the ID , it sounds like there isn't an actual "session management" issue, but perhaps it has to do with the URL that PayPal is redirecting back to. 假设您没有无意间关闭会话重新生成ID ,这听起来好像没有实际的“会话管理”问题,但可能与PayPal重定向回的URL有关。

A common issue with PHP sessions is that, with a default PHP config, they don't carry between subdomains. PHP会话的一个常见问题是,使用默认的PHP配置,它们不会在子域之间传递。

For example, if I visit your domain domain at example.com , my session will only be active on example.com . 例如,如果我在example.com访问您的域域,则我的会话将仅在example.com上处于活动状态。 If I then go to www.example.com , I will receive a new session. 如果然后转到www.example.com ,我将收到一个会话。

You can verify this by going to your site at example.com or www.example.com and checking what domain the PHPSESSID cookie is set for. 您可以通过访问example.comwww.example.com上的站点并检查PHPSESSID cookie设置为哪个域来进行验证。 If it is not .example.com (note the leading . ), then this is the issue =] 如果不是 .example.com (请注意以. .example.com ),那么这就是问题=]

To help resolve this, you can modify your server's config to set the .example.com as the cookie's domain. 为了帮助解决此问题,您可以修改服务器的配置,以将.example.com设置为cookie的域。 Taken from this answer : 这个答案中得出

session.cookie_domain = ".example.com"

The same answer I gave to a recent question should work here as well: 我对最近一个问题的回答也应该在这里起作用:

The solution I used for this same problem was to set override_merchant_preferences on the billing agreement, with the return_url containing the user id in the query, like www.domain.com/api/handler.php?uid=42&action=return . 我针对同一问题的解决方案是在计费协议上设置override_merchant_preferences ,其中return_url包含查询中的用户ID,例如www.domain.com/api/handler.php?uid=42&action=return

Though of course you can pass any identifiers you'd like through the $_GET that way. 当然,您可以通过$_GET传递想要的任何标识符。

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

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