【问题标题】:PayPal Debit or Credit Card not render when empty value is provided提供空值时,PayPal 借记卡或信用卡不呈现
【发布时间】:2022-01-12 16:09:55
【问题描述】:

我正在集成 PayPal,但我确实有一个问题:在下面的代码中,如果 $("#DonorEmailID").val() 为空,则不再呈现表单

paypal.Buttons({
            style: {
                layout:  'vertical',
                shape: 'rect',
                height: 36
            },
            createOrder: function (data, actions) {
                return actions.order.create({
                    //https://developer.paypal.com/docs/checkout/integration-features/standard-card-fields/
                    payer: {
                        email_address: $("#DonorEmailID").val(),
                        phone: {
                            phone_type: "MOBILE",
                            phone_number: {
                                national_number: "14082508100"
                            }
                        }
                    },
                    application_context: {
                        shipping_preference: 'NO_SHIPPING'
                    },
                    purchase_units: [{
                        description: getPurchaseDescription(),
                        amount: {
                            value: $("#Amount").val()
                        }
                    }]
                });
            },

演示视频:https://www.screencast.com/t/xdENMuUbcbWu 有没有办法有条件地将 email_address 属性添加到付款人?或者您对此问题有其他解决方案吗?

谢谢。

【问题讨论】:

    标签: paypal paypal-sandbox


    【解决方案1】:
            paypal.Buttons({
                style: {
                    layout:  'vertical',
                    shape: 'rect',
                    height: 36
                },
                createOrder: function (data, actions) {
                    var order = {
                        //https://developer.paypal.com/docs/checkout/integration-features/standard-card-fields/
                        payer: {
                            phone: {
                                phone_type: "MOBILE",
                                phone_number: {
                                    national_number: "14082508100"
                                }
                            }
                        },
                        application_context: {
                            shipping_preference: 'NO_SHIPPING'
                        },
                        purchase_units: [{
                            description: getPurchaseDescription(),
                            amount: {
                                value: $("#Amount").val()
                            }
                        }]
                    };
                    var email = email_address: $("#DonorEmailID").val();
                    if(email) order.payer.email_address = email;
                    return actions.order.create(order);
                },
    

    【讨论】:

    • 谢谢,它按预期工作!
    猜你喜欢
    • 2011-07-18
    • 2014-09-05
    • 2016-09-28
    • 2015-01-26
    • 2015-02-17
    • 2022-09-20
    • 2018-06-16
    • 2016-05-24
    • 2021-07-19
    相关资源
    最近更新 更多