1

我想通过单击 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 () {

            });
        });
    });
4

1 回答 1

0

全面披露:我在布伦特里工作。如果您还有其他问题,请随时联系支持人员

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

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);
  });
于 2019-07-23T16:52:41.170 回答