我正在尝试将客户端重定向到成功页面或错误页面来自服务器。我该如何使用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:{...
res.sendFile('/error.html')