取消URL响应PayPal

5
我是新手使用paypal,我在1天内搜索了这个问题。我需要你们的帮助。我已经完成了express结算API的编码,并成功获取了付款交易,但我的问题是取消URL。当我取消付款时,它返回到我的取消URL并且paypal会给出像这样的url令牌:http://www.example.com/?token=EC-75630865LV806263H。
当客户点击取消并返回我的取消URL时,是否可能获得客户的名字、姓氏或任何信息?
如果可能的话,你能给我一个链接或教程,告诉我如何在取消URL时获取客户信息吗?
提前感谢。
4个回答

3

我编写的代码是在运行时生成取消链接。因此,在发送付款交易数据包之前,我设置了取消链接,如下所示:

$settings->cancelurl = 'http://www.example.com';

if($_SESSION['customer_ref']){ //save loggedin customer ref in session.
   $settings->cancelurl .= '&customer_ref='.$_SESSION['customer_ref'];
}

当PayPal上的cancelurl看起来像这样http://www.example.com/?customer_ref=qwuy16436771&token=EC-2Q454WDAE110BD2,您可以从该URL中获取customer_ref并在其到达您的服务器时执行所需的操作。
希望这能对您有所帮助。

2
token 是在创建 payment 后重定向 URL 中的一个参数。因此,您可以像这样将其存储在数据库中(与待处理订单或其他内容相关联),以便稍后检索,而无需依赖 cookie:
$payment->create($apiContext);
$link = $payment->getApprovalLink();
parse_str(parse_url($link, PHP_URL_QUERY), $linkParams);
if (!empty($linkParams['token'])) {
  // Store token in database for possible lookup later
  // Presumably just another column field...
  yourSaveToken($yourOrder, $linkParams['token']);
}
header('Location: ' . $link);

然后,当您的取消URL触发时,您可以检索取消的订单

if (!empty($_REQUEST['token'])) {
  // Match token previousy stored by `yourSaveToken`
  $yourOrder = yourGetOrderFromToken($_REQUEST['token']);
}

2
在结账页面,寻找“cancel_return”隐藏表单元素:
   <input type="hidden" name="cancel_return" id="cancel_return" value="" />

将cancel_return表单元素的值设置为您希望返回的URL:

   <input type="hidden" name="cancel_return" id="cancel_return" value="http://royaltytech.in" />

你可以将用户邮件地址作为URL的参数传递吗?例如,value="http://royaltytech.in?mail=tom@garden.xz"?我在这里读到(http://paypaldev.org/topic/2304-do-ipn-variables-get-posted-to-the-cancel-url/)说无法发布此信息,但也许URL可以使用。 - Avatar
更新:刚试了一下,它可以工作。在您的PayPal处理表单中将用户邮件附加到cancel_url中,您就可以使用您的服务器上的cancelled.php脚本访问该参数。 - Avatar

2
我认为不会,因为通常在验证之前会按下取消按钮,但我也没有尝试过在处理过程中这样做。通常的流程是他们登录,确认付款,然后PayPal将他们弹回您的付款完成页面。但是,如果他们在验证后取消,可能可以调用getExpressCheckoutDetails。再次说明,我从未尝试过。但最糟糕的情况是PayPal无法返回任何内容。

谢谢,我真的需要一些建议,这样我才能说服我的团队领导。 - user3818576

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接