首页 > 解决方案 > 在贝宝结帐按钮集成中禁用运输

问题描述

我想从 PayPal 结账集成中隐藏收货地址。我正在使用以下链接中的“使用 checkout.js 结帐”选项:https ://developer.paypal.com/docs/archive/checkout/integrate/ 我当前的代码如下所示:

paypal.Button.render({
  env: 'production',
  commit: false,
  style: {
    color: 'gold',
    size: 'responsive',
    label: 'pay',
    shape: 'rect'
  },
  client: {
    sandbox:    'yurtyfcnvmghjlgfjgsdfbvbxcvbsdffjdfcbngfetrrurteytrwgfsdgs',
    production: 'werutpoeirutoputpoyuowieupoweutpwoeiuiouwrepotiwuperoldkfs'
  },
  payment: function(data, actions) {
    return actions.payment.create({
      payment: {
        transactions: [
          {
            amount: { total: pmt, currency: 'USD' }
          }
        ]
      }
    });
  },
  onAuthorize: function(data, actions) {
    return actions.payment.execute().then(function(payment) {
      window.location = 'some url';
    });

  },
  onCancel: function(data, actions) {
     window.location = 'some url';
  },
  onError: function(err) {
    /* do something */
  }
}, '#pwpl_m');

标签: javascriptpaypal

解决方案


checkout.js 是旧的/存档的解决方案,所以我建议您改用最新的 PayPal 结帐;这是一个演示模式:https ://developer.paypal.com/demo/checkout/#/pattern/client

语法和v2/orders一样,有一个application_context对象:https ://developer.paypal.com/docs/api/orders/v2/#definition-order_application_context

基本上在它的purchase_units数组之后你需要添加:

 application_context: {
    shipping_preference: 'NO_SHIPPING'
  }

我在这里有一个例子:https ://stackoverflow.com/a/59384563/2069605


推荐阅读