gpt4 book ai didi

java - 如何在 PayPal REST API 中获取用户信息

转载 作者:太空宇宙 更新时间:2023-11-03 16:23:03 26 4
gpt4 key购买 nike

我正在从 NVP/SOAP PayPal API 集成转移到较新的 REST API。

我的旧网站代码使用了“快速结帐”流程。

简而言之:

  • 您会看到“购物车”摘要页面,其中包含要购买的产品列表;

  • 您点击“使用 PayPal 付款”按钮(无需填写用户数据表);

  • 网站发起支付,用户被重定向到 PayPal;

  • 用户登录并确认发起的付款;

  • 用户被重定向到该网站,该网站调用 PayPal 获取用户个人信息以保存在交易记录中(例如姓名、地址...)

  • 支付最终执行;

我在这里检查了集成模式:https://developer.paypal.com/demo/checkout/#/pattern/server

...但无法弄清楚如何使用新 API 实现完全相同的工作流。

我的意思是,在onAuthorize 回调方法中,我确实有用户授权付款的paymentID 和payerID,等待执行..但没有他的个人数据,我的订单要保存.

是否有某种调用来检索该数据?或者将其包含在响应中?

最佳答案

首先,请让我知道您希望我深入到什么程度。如果您想要工作流程的总体概述、伪代码或代码示例,我会尽力提供这些内容。现在,我将坚持使用引用资料进行总体概述。

查看 Identity API call在 Paypal 引用文档中。这是一个返回“userinfo”对象的 GET 请求,该对象又包含用户配置文件属性,例如姓名、地址等。

但是,我怀疑您想要使用 Invoice API相反,如果您的买家指定的详细信息与其个人资料不同。在这种情况下,您应该实现一个GET /v1/invoicing/invoices/invoice_id 请求,它将您的发票 ID 作为参数并返回用户指定的地址,名字等等。它还包含您需要构建以执行该请求的模板。

编辑:我进一步研究了它,我认为我找到了更好的解决方案。您可以通过调用 return actions.payment.get().then(function(data) 并指定您想要的数据,从您的 Paypal 按钮回调中返回任何交易详情。我提供的例子是我发现如下:

onAuthorize: function(data, actions) {

// Get the payment details

return actions.payment.get().then(function(data) {

// Display the payment details and a confirmation button. You may want to save the queried data to your server, make sure to do this here

var shipping = data.payer.payer_info.shipping_address;

document.querySelector('#recipient').innerText = shipping.recipient_name;
document.querySelector('#line1').innerText = shipping.line1;
document.querySelector('#city').innerText = shipping.city;
document.querySelector('#state').innerText = shipping.state;
document.querySelector('#zip').innerText = shipping.postal_code;
document.querySelector('#country').innerText = shipping.country_code;

document.querySelector('#paypal-button-container').style.display = 'none';
document.querySelector('#confirm').style.display = 'block';

// Listen for click on confirm button

document.querySelector('#confirmButton').addEventListener('click', function() {

// Button click event code

// Execute the payment

return actions.payment.execute().then(function() {

// payment executed code
// display confirmation, thank you notes and whatnot
});
});
});
}

通过这种方式,您可以自动获得所需的信息,而无需创建额外的(和不必要的)大量请求。

关于java - 如何在 PayPal REST API 中获取用户信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45284783/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com