【问题标题】:How validate the custom form on click of braintree PayPal checkout button?如何在点击braintree PayPal 结帐按钮时验证自定义表单?
【发布时间】:2019-11-28 01:48:01
【问题描述】:

我想通过单击 Braintree PayPal 结帐按钮来验证自定义 PHP 表单。 目前,如果表单填写不正确,它会重定向到 PayPal 屏幕。

所以如果表单输入无效,我想停止打开 PayPal 弹出窗口。

这是我的代码。

这可能吗,请分享一些想法

braintree.client.create({
        authorization: ''
    }, function (clientErr, clientInstance) {

        // is invalid.
        if (clientErr) {
            console.error('Error creating client:', clientErr);
            return;
        }

        // Create a PayPal Checkout component.
        braintree.paypalCheckout.create({
            client: clientInstance
        }, function (paypalCheckoutErr, paypalCheckoutInstance) {


            if (paypalCheckoutErr) {
                console.error('Error creating PayPal Checkout:', paypalCheckoutErr);
                return;
            }

            // Set up PayPal with the checkout.js library
            paypal.Button.render({
                env: 'sandbox', // or 'sandbox'

                payment: function () {
                    return paypalCheckoutInstance.createPayment({

                    });
                },

                onAuthorize: function (data, actions) {
                    return paypalCheckoutInstance.tokenizePayment(data, function (err, payload) {
                        // Submit `payload.nonce` to your server.                        
                        form.submit();

                    });
                },

                onCancel: function (data) {
                    console.log('checkout.js payment cancelled', JSON.stringify(data, 0, 2));
                },

                onError: function (err) {
                    console.error('checkout.js error', err);
                }
            }, '#paypal-button').then(function () {

            });
        });
    });

【问题讨论】:

    标签: javascript php paypal braintree braintree-vault


    【解决方案1】:

    全面披露:我在 Braintree 工作。如果您还有任何问题,请随时联系support

    执行此操作的最简单方法是以编程方式禁用提交按钮,直到字段正确为止。您可以通过添加以下内容(并添加您自己的自定义逻辑或验证)来做到这一点:

    if (dropinInstance.isPaymentMethodRequestable()) {
        // This will be true if you generated the client token
        // with a customer ID and there is a saved payment method
        // available to tokenize with that customer.
        submitButton.removeAttribute('disabled');
      }
    
      dropinInstance.on('paymentMethodRequestable', function (event) {
        console.log(event.type); // The type of Payment Method, e.g 'CreditCard', 'PayPalAccount'.
        console.log(event.paymentMethodIsSelected); // true if a customer has selected a payment method when paymentMethodRequestable fires
    
        submitButton.removeAttribute('disabled');
      });
    
      dropinInstance.on('noPaymentMethodRequestable', function () {
        submitButton.setAttribute('disabled', true);
      });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-15
      • 2019-01-18
      • 2018-11-30
      • 2020-03-13
      • 2013-05-12
      • 2018-03-09
      • 2014-12-03
      • 2016-08-02
      相关资源
      最近更新 更多