在贝宝简单结账之前验证表格 [英] validating form before paypal simple checkout
问题描述
我的网站上有一个简单的付款表格,可以选择使用贝宝快速结账付款.我的表单的其余部分使用 jquery 验证进行验证.
I have a simple payment form on my website with an option to pay with paypal express checkout. The rest of my form is validated with jquery validation.
如何设置当您单击贝宝按钮时,它应该在允许贝宝弹出窗口打开之前验证表单?
How can I set it up when you click the paypal button, it should validate the form before allowing the paypal popup to open?
$("#form1").validate();
我有一个简单的 paypal 渲染脚本
I have a simple paypal render script
<script>
paypal.Button.render({ ...
在 paypal 文档中,他们提供了类似的内容,但我不知道如何将两者结合起来
On the paypal documentation they offer something like this, but I don't know how to combine the 2
validate: function(actions) {
.....
},
推荐答案
PayPal 新 API 允许以这种方式验证表单,无需使用 onInit 函数):
the PayPal new API allows to validate a form that way There is no need to use the onInit func):
paypal
.Buttons({
// Run when the user click on the paypal button
onClick: function(data, actions) {
// My validation...
url = searchInput.value
// My validation Function...
const isURL = validURL(url)
if (isURL) {
// Remove Existing Error message
if (searchError.classList[2]) {
searchError.classList.remove('err-message--show')
}
// Enable The Paypal Button
return true
} else {
// Add Error messages
searchError.classList.add('err-message--show')
// The paypak wont continue to the paypal page...
return false
}
},
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [
{
amount: {
value: price,
currency_code: 'ILS'
}
}
]
})
}
.render('#paypal-button-container')
还有 onApproval 和 onError 函数...(处理 PayPal 流程的结果...)
There also onApproval and onError functions... (handle the result of the PayPal process...)
希望我有所帮助,纳维
这篇关于在贝宝简单结账之前验证表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!