PayPal智能支付按钮: setting an invoice id to avoid duplicate transactions

标签 paypal

有时,用户会因为意外点击 paypal 智能支付按钮中的支付按钮而多次扣费。在 paypal 仪表板 > 付款偏好中,我已经启用了选项“是,阻止每个发票 ID 多次付款”。

现在我想在我的智能按钮脚本代码中设置发票ID,如下所示:

function initPayPalButton() {
      paypal.Buttons({
        style: {
          shape: 'rect',
          color: 'gold',
          layout: 'vertical',
          label: 'pay',
        },

        createOrder: function(data, actions) {
          return actions.order.create({
            purchase_units: [{"amount":{"currency_code":"USD","value":total_amount}}],
                            application_context: {
                                shipping_preference: 'NO_SHIPPING'
                            }
          });
        },

        onApprove: function(data, actions) {
          return actions.order.capture().then(function(details) {
            window.location = 'success_url';
          });
        },

        onError: function(err) {
          console.log(err);
                                        alert('Something went wrong. Please refresh the page and try again.');
        }
      }).render('#button_container_id');
    }
    initPayPalButton();

最佳答案

使用系统中的唯一标识符添加invoice_id,以避免重复付款。

参见:https://developer.paypal.com/docs/multiparty/checkout/standard/integrate/#link-addpaymentbuttons

Other useful purchase unit parameters include:

A unique invoice_id that hasn't been used for a previously-completed transaction to identify the order for accounting purposes and to prevent duplicate payments.

A custom_id value of your choice for your system or own reference. This value is not indexed or visible to the buyer.

这就是我的代码:

paypal.Buttons({
    style: {
        shape: 'rect',
        color: 'silver',
        label: 'buynow'
    },
    onError: function (err) {
        // FIXME: show the user an error message
    },
    onClick: function(data)  {
        // FIXME: do something cool when the button is clicked
    },
    // Set up the transaction
    createOrder: function(data, actions) {
        return actions.order.create({
            purchase_units: [{
                description: 'My awesome product',
                amount: {
                    currency_code: "USD",
                    value: 9.99,
                    breakdown: {
                        item_total: {
                            currency_code: 'USD',
                            value: 9.99
                        },
                        discount: {
                            currency_code: "USD",
                            value: 1.25
                        }
                    }
                },
                invoice_id: 'UNIQUE-ID',
                custom_id: 'ANOTHER-SYSTEM-ID'
            }],
            application_context:  { 
                shipping_preference: "NO_SHIPPING"
            }
        });
    },
    // Finalize the transaction
    onApprove: function(data, actions) {
        return actions.order.capture().then(function(details) {
            // FIXME: finalise the order and show the success message
            console.log("order id: "+details.id);
        });
    }
}).render('#paypal-button-container');

}

关于PayPal智能支付按钮: setting an invoice id to avoid duplicate transactions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66936423/

相关文章:

c# - Paypal 定期付款计费频率

paypal - 获取有关增强型定期付款服务的交易详细信息

php - 响应式网站中的 Paypal 集成

iOS:逐步集成 PayPal braintree

php - Paypal 网关为 Magento 商店返回错误

javascript - 我如何通过 Paypal 提交多个产品复选框?

php - paypal 不检查账单地址是否与信用卡匹配

php - 为什么 PayPal GetVerifiedStatus API 不适用于某些帐户

subscr_eot 后的 PayPal,续订?

php - 使用 PayPal 的 BMUpdateButton 方法获取按钮类型无效的 10004 错误