You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过PayPal JS移除PayPal Credit按钮并添加借记卡/信用卡按钮

解决方案:替换PayPal Credit按钮为借记卡/信用卡黑色按钮

只需修改script标签内的两处配置即可实现需求,无需改动页面其他部分:

1. 调整允许的资金来源

在funding.allowed数组中移除paypal.FUNDING.CREDIT,仅保留paypal.FUNDING.CARD,这样PayPal Credit按钮会被移除,只保留借记卡/信用卡支付选项。

2. 修改按钮样式

将style.color设置为'black',同时可选择开启fundingicons: true(用于显示卡类图标),让按钮呈现黑色的借记卡/信用卡样式。

修改后的完整JavaScript代码

<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script type="text/javascript">
  paypal.Button.render({
            // Set your environment
            env: '<?= PAYPAL_ENVIRONMENT ?>',

            // Set style of buttons
            style: {
                layout: 'vertical',   // horizontal | vertical
                size:   'medium',   // medium | large | responsive
                shape:  'pill',         // pill | rect
                color:  'black',         // 修改为black,显示黑色按钮
                fundingicons: true,    // 开启显示卡图标(可选)
                tagline: false,          // true | false,
            },
       // Set allowed funding sources
            funding: {
                allowed: [
                    paypal.FUNDING.CARD  // 移除paypal.FUNDING.CREDIT
                ],
                disallowed: [ ]
            },

            // Show the buyer a 'Pay Now' button in the checkout flow
            commit: false,
          // payment() is called to start the payment flow when a button is clicked
            payment: function() {
                const postData = {
                    'original': JSON.parse('<?= json_encode($orderDetails) ?>'),
                    'update': null,
                    'flow': 'shortcut'
                };
                return request.post(
                    '<?= $rootPath.URL['services']['orders']['create'] ?>',
                    postData
                ).then(function(returnObject) {
                    return returnObject.data.id;
                });
            },

            // onAuthorize() is called when the buyer approves the payment
            onAuthorize: function(data) {
                const postData = {
                    key: "order_id",
                    value: data.orderID
                };
                submitForm('<?= $baseUrl.URL['redirect']['orders']['return_url'] ?>?flow=shortcut', postData);
            },
// onCancel() is called when the buyer cancels payment authorization
            onCancel: function(data) {
                let url = "<?= $baseUrl ?>pages/orders/error?type=error",
                    postData = {
                        key: "error",
                        value: data
                    };
                submitForm(url, postData);
            },

            // onError() is called when there is an error in this Checkout.js script
            onError: function (error) {
                let url = "<?= $baseUrl ?>pages/orders/error?type=error",
                    postData = {
                        key: "error",
                        value: error
                    };
                submitForm(url, postData);
            }

        }, '#paypalCheckoutContainer');
</script>

说明

  • 移除paypal.FUNDING.CREDIT后,PayPal Credit按钮会消失,页面仅展示支持借记卡/信用卡的支付按钮。
  • 设置style.color: 'black'后,按钮会呈现黑色的信用卡样式,符合需求。
  • fundingicons: true用于在按钮上显示卡类图标,若不需要可以保持为false。

内容的提问来源于stack exchange,提问作者user19165954

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 21:31:01