Search code examples
javascriptpaypal

Disable shipping in paypal checkout button integration


I want to hide the shipping address from a PayPal checkout integration. i am using "checkout with checkout.js" option from the following link: https://developer.paypal.com/docs/archive/checkout/integrate/ my current codes look like this:

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');


Solution

  • checkout.js is and old/archived solution, so I would recommend you switch to the latest PayPal checkout instead; here's a demo pattern: https://developer.paypal.com/demo/checkout/#/pattern/server

    The syntax is the same as v2/orders, which has an application_context object: https://developer.paypal.com/docs/api/orders/v2/#orders_create

    Basically after its purchase_units array you need to add:

     application_context: {
        shipping_preference: 'NO_SHIPPING'
      }
    

    2024 edit: the application_context object is deprecated, use payment_source.paypal.experience_context instead. Again see the API reference https://developer.paypal.com/docs/api/orders/v2/#orders_create