我不明白如何从 PayPal SDK 获取更多信息到我的服务器。
目前,用户从客户端进行交易,然后服务器端验证交易是否真的发生。
这是服务器端路由:
app.get('/', (req, res) => {
res.sendFile('/index.html')
})
app.post('/paypal-transaction-complete', async (req, res) => {
// 1. Get the order ID from the request body
const orderID = req.body.orderID
// 2. Call PayPal to get the transaction details
let request = new paypal.orders.OrdersGetRequest(orderID)
let order
try {
order = await client().execute(request)
console.log(order)
} catch (err) {
// 3. Handle any errors from the call
console.error(err)
return res.status(500).json({
status: 'failed',
message: 'Failed to verify the transaction'
})
}
// 4. Save the transaction in your database
// await database.saveTransaction(orderID);
// 5. Return a successful response to the client
return res.status(200).json({
status: 'success',
message: 'The transaction been verified'
})
})
这是订单的console.log:
{ statusCode: 200,
headers:
{ 'cache-control': 'max-age=0, no-cache, no-store, must-revalidate',
'content-length': '1651',
'content-type': 'application/json',
date: 'Wed, 04 Mar 2020 08:00:28 GMT',
'paypal-debug-id': 'df5886063ee3b',
connection: 'close' },
result:
{ id: '9TX85821HJ5742402',
intent: 'CAPTURE',
purchase_units: [ [Object] ],
payer:
{ name: [Object],
email_address: 'sb-43f9up1139100@personal.example.com',
payer_id: 'GRP7Y74PGJ392',
address: [Object] },
create_time: '2020-03-04T07:59:34Z',
update_time: '2020-03-04T08:00:23Z',
links: [ [Object] ],
status: 'COMPLETED' } }
-- 注意 -- order.result.payer.address 仅检索国家/地区代码 -
{ country_code: 'IL' }
我需要向买家提供完整的运输详细信息和更多信息,但我不明白如何向 Paypal 询问这些信息...我多次查看了 SDK 文档,但仍然一无所获
感谢各位的帮助!
最佳答案
purchase_units: [ [Object] ],
信息就在那里。您只是没有将其打印出来。
关于javascript - 如何从PayPal SDK服务器端获取交易信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60521503/