从PayPal SDK客户端的OnError和OnApproval重定向到成功/错误页面

问题描述 投票:0回答:1

我正在尝试将客户端重定向到成功页面或错误页面来自服务器。我该如何使用OnError和OnApproval函数?

这是我试图做的:

paypal
  .Buttons({
    style: {
      color: 'blue',
    },
    onInit: function(data, actions) {
      actionStatus = actions
      actionStatus.disable()
    },
    onClick: function(data, actions) {
      url = searchInput.value
      const isURL = validURL(url)
      if (isURL) {
        // Remove Existing Error message
        if (searchInput.nextElementSibling.classList[1]) {
          searchInput.nextElementSibling.classList.remove('err-message--show')
        }

        // Calculate the price
        const photoAmount = document.querySelector('.header__photos').value * 1
        price = String(0.9 * photoAmount)        

        // Enable The Paypal Button
        actionStatus.enable()
      } else {
        searchInput.nextElementSibling.classList.add('err-message--show')
      }
    },
    enableStandardCardFields: true,
    createOrder: function(data, actions) {
      return actions.order.create({
        purchase_units: [
          {
            amount: {
              value: price,
              currency_code: 'ILS'
            }
          }
        ]
      })
    },
    onApprove: function(data, actions) {
      // Where is should redirect?
      return actions.order.capture().then(function(details) {
        alert('Transaction completed by ' + details.payer.name.given_name)
        // Call your server to save the transaction
        return axios.post('/paypal-transaction-complete', {
          orderID: data.orderID,
        })
      })
    },
    onError: function(err) {
      // Show an error page here, when an error occurs
      console.log('error')
     // Redirect to an Error Page...
     // ???
      }
  })
  .render('#paypal-button-container')

这是节点服务器端(服务器中有更多代码可以批准该订单,等等:] >>

app.get('/error', (req,res) => {
  res.sendFile('/error.html')
})
app.get('/success', (req,res) => {
  res.sendFile('/success.html')
})

谢谢! =)

我正在尝试将客户端从服务器重定向到成功或错误页面。我该如何使用OnError和OnApproval函数呢?这是我尝试做的事情:paypal .Buttons({style:{...

javascript node.js paypal paypal-rest-sdk
1个回答
0
投票

res.sendFile('/error.html')

© www.soinside.com 2019 - 2024. All rights reserved.