[英]How to get user info in PayPal REST API
我正在從NVP / SOAP PayPal API集成轉移到更新的REST API。
我的舊網站代碼使用“快速結帳”流程。
簡而言之:
您會看到“購物車”摘要頁面,其中包含要購買的產品列表;
您單擊“使用貝寶付款”按鈕(無需填寫用戶數據表格);
網站開始付款,用戶被重定向到貝寶;
用戶登錄並確認已啟動付款;
用戶被重定向到該網站,該網站調用PayPal獲取用戶個人信息以保存在交易記錄中(例如姓名,地址等) ;
支付最終完成;
我在這里簽出了集成模式: https : //developer.paypal.com/demo/checkout/#/pattern/server
...但是無法弄清楚如何使用新的API實施完全相同的工作流程。
我的意思是,在onAuthorize回調方法中,我確實具有用戶授權付款的paymentID和payerID,正在等待執行..但是沒有他的個人數據來保存我的訂單。
是否有某種調用來檢索該數據? 還是將其包括在響應中?
首先,請讓我知道您想讓我深入研究哪些細節。 如果您需要工作流的一般概述,偽代碼或代碼示例,我會盡力提供這些內容。 現在,我將堅持使用參考進行總體概述。
在Paypal參考文檔中查看Identity API調用 。 這是一個GET請求,返回一個“ userinfo”對象,該對象又包含用戶配置文件屬性,例如名稱,地址等。
但是,如果您的買家指定的詳細信息與他們的個人資料不同,我懷疑您想使用Invoice API 。 在這種情況下,您應該實現GET / v1 / invoicing / invoices / invoice_id請求,該請求將您的發票ID作為參數,並返回用戶指定的地址,名稱等。 它還包含您需要執行的請求模板。
編輯 :我已經研究了更多,我想我找到了一個更好的解決方案。 您可以通過調用return actions.payment.get().then(function(data)
並指定所需的數據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
});
});
});
}
這樣,您無需創建其他(和不必要的)大量請求即可自動獲取所需的信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.