validating form before paypal simple checkout

后端 未结 2 1912
挽巷
挽巷 2021-01-24 05:14

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

相关标签:
2条回答
  • 2021-01-24 05:28

    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')
    

    There also onApproval and onError functions... (handle the result of the PayPal process...)

    Hope I helped, Naveh

    0 讨论(0)
  • 2021-01-24 05:44

    There's a full example here:

    https://developer.paypal.com/demo/checkout/#/pattern/validation

    In the validate() function you need to listen for the form changing and enable/disable the button.

    0 讨论(0)
提交回复
热议问题