【问题标题】:How to get transaction information from PayPal SDK, server-side如何从 PayPal SDK、服务器端获取交易信息
【发布时间】:2020-06-16 16:14:33
【问题描述】:

我无法理解如何从 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'
  })
})

这是order的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 文档很多次,但仍然一无所获

感谢帮助!

【问题讨论】:

    标签: javascript node.js paypal paypal-rest-sdk


    【解决方案1】:
    purchase_units: [ [Object] ],
    

    信息就在里面。你只是没有打印出来。

    【讨论】:

    • 谢谢!那解决了!我试图 console.log the result.payer.address... 我不认为购买单位有任何与地址相关的东西。再次感谢您!
    • 我认为这是付款人的 PayPal 账户所在的国家/地区,可能与收货地址所在的国家/地区相同,也可能不同
    • 酷。谢谢!我打开另一个问题,如果你也能回答这个问题,我会很高兴 =)
    猜你喜欢
    • 2011-01-26
    • 2012-06-25
    • 2020-10-14
    • 2014-08-21
    • 2023-02-07
    • 2011-06-16
    • 2014-05-11
    • 2015-01-31
    • 2014-11-09
    相关资源
    最近更新 更多