Как получить информацию о транзакции из PayPal SDK на стороне сервера - PullRequest
1 голос
/ 04 марта 2020

Я не могу понять, как мне получить дополнительную информацию из 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 order :

{ 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, но ничего не получилось

Спасибо за помощь!

1 Ответ

1 голос
/ 04 марта 2020
purchase_units: [ [Object] ],

Информация там. Вы просто не распечатываете его.

...