Disable shipping address option in PayPal Express Checkout
Asked Answered
C

8

32

Working with the PayPal API and using the Name-Value Pair Interface PHP source codes from SDKs and Downloads: Simplify Integrations with Downloads and SDKs.

My question is similar to "Removing (or prefilling) the address details for PayPal Express Checkout" but I don't want shipping cost/address or anything related about shipping at all.

I keep all shipping details on my system (even sometimes shipping doesn't even apply and there is no charge for it) and I just want user to pay through PayPal without shipping address and shipping cost.

How can I disable shipping part of checkout?

Charie answered 26/11, 2010 at 7:24 Comment(0)
S
32

If you're using the newer API, you could also pass NOSHIPPING=1 (not no_shipping)

Further details about all possible parameters to the SetExpressCheckout here:

https://developer.paypal.com/docs/nvp-soap-api/nvp/

Or lookup for Payment experience in new REST API

Schaal answered 9/12, 2010 at 22:16 Comment(2)
I've added here full request examples to start a transaction, commit and read payment details, with item details be displayed on paypal site and merchant transaction history. https://mcmap.net/q/454048/-missing-amount-and-order-summary-in-paypal-express-checkoutJealous
It appears that this works also with the old api, at least it behaves so in the sandbox.Tarton
N
21

For others looking for this, because PayPals documentation is so GREAT (cough, cough).

NO web experience profile REQUIRED!

Using REST API V2 with Javascript/JQuery and turning "Ship To" off for an ORDER, here is the correct code example:

    createOrder: function(data, actions) {
        $('#paypalmsg').html('<b>' + 'WAITING ON AUTHORIZATION TO RETURN...' + '</b>');
        $('#chkoutmsg').hide()
        return actions.order.create({
            purchase_units: [{
                description: 'GnG Order',
                amount: {
                    value: cartTotal
                }
            }],
            application_context: {
              shipping_preference: 'NO_SHIPPING'
            }

        });
    },
Neogothic answered 20/5, 2020 at 19:57 Comment(4)
Thank you oh soo much for this! saved my day! any chance you could point me to where you got this?Demibastion
I wrote it, gleaming it from their horrible docsNeogothic
Thank you for sharing! I was stuck on this for a good while. It is almost impossible not to land on docs labelled 'Legacy' , which do not work. I certainly did not spot application_context. Saved my day.Reginareginald
Used to create an order for client-side integrations. Accepts the same options as the request body of the /v2/checkout/orders api.Blighter
W
15

Hey Ergec, just pass along the no_shipping parameter with a value of 1.

From PayPal's documentation:

no_shipping

Do not prompt payers for shipping address. Allowable values:
0 – prompt for an address, but do not require one
1 – do not prompt for an address
2 – prompt for an address, and require one
The default is 0.
Whap answered 26/11, 2010 at 7:28 Comment(5)
I put no_shipping=1 into $nvpstr but still it asks for shipping. And I just noticed that it's adding tax too. All prices include tax already so I need to get rid of tax field too. Please help!!Charie
ok here is what I did and worked. It's not adding shipping cost and tax anymore. Just commented out current $nvpstr variable in ReviewOrder and put this line $nvpstr = "&AMT=" . $amount . "&ReturnUrl=".$returnURL."&CANCELURL=".$cancelURL ."&CURRENCYCODE=" . $currencyCodeType; $amount is sent from modified SetExpressCheckout.php . Removed all input boxes and left paymentType, currencyCodeType and amount only.Charie
Yes. 7 years later, tried the new NOSHIPPING =1 didn't work. Tried no_shipping = 1, it worked. August 2017.Himeji
Sept 2017, something changed this month at paypal, some of my payments started failing saying invalid address, but the address was fine, so I tried &address_override=1&no_shipping=1, it worked! yes i am using the older API at paypal.com/cgi-bin/webscr?Diapedesis
Provided link is absoleteThant
S
8

The current right answer is depracated. To fix the issue in new API we should create Payment web experience profile resource with needed parameters and attach it to request Payment .

Example in PHP:

/** Note: Define some variables yourself. */

$inputFields = new InputFields();
$inputFields->setAllowNote(true)
    ->setNoShipping(1) // Important step
    ->setAddressOverride(0);

$webProfile = new WebProfile();
$webProfile->setName(uniqid())
    ->setInputFields($inputFields)
    ->setTemporary(true);

$createProfile = $webProfile->create($apiContext);

$payment = new Payment();

$payment->setPayer($payer);
$payment->setIntent($intent);
$payment->setRedirectUrls($redirectUrls)
$payment->setTransactions(array($transaction));
$payment->setExperienceProfileId($createProfile->getId()); // Important step.

$payment->create($apiContext);

if ($payment->getState() === "created") {
    $approvalLink = $payment->getApprovalLink()

    header("Location: $approvalLink"); // Redirects user to PayPal page.
}

Note: You can find all above used classes by link: https://github.com/paypal/PayPal-PHP-SDK/tree/master/lib/PayPal/Api

Squall answered 1/12, 2017 at 15:7 Comment(1)
Yes, it works perfectly fine. FYI, you can also create a web profile once and use the same id for future payments: #32735409Unaneled
D
6

To solve for this from current (2019) web client .JS, add the application_context block to the request body.

Below is an example for createSubscription() call; and I'm thinking this will work with createOrder() as well

paypal.Buttons({
          createSubscription: function (data, actions) {

              return actions.subscription.create({

                  'plan_id'            : 'P-123',
                  'application_context': {
                      'shipping_preference': 'NO_SHIPPING'
                  }
              });
          },

          onApprove: function (data, actions) {

              // ...
          }
      })
      .render('#paypal-button-container');

Thanks to the example code here:

Here's where the field enums are listed:

Danseuse answered 25/8, 2019 at 22:34 Comment(4)
for createOrder() it is not showing the address fields but the transaction is getting failedFrigid
I did not actually try this with createOrder(), so do not have any insight on an implementation with that call; or if it is in fact possible with the solution I describe here. I would share your issue via a new post, where you can provide the code snippet(s) you are attempting to implement along with any relevant notes. stackoverflow.com/help/minimal-reproducible-exampleDanseuse
I am attempting to write a code for paypal smart button implementation with address disabled. developer.paypal.com/demo/checkout/#/pattern/client here is the extact code where I am trying to disable the address on click of credit cardFrigid
same solution is give here: #55632279 but again the issue is payment is rejected without address.Frigid
E
2

Create a web profile based on the example found in the API: CreateWebProfile.php.

$createProfileResponse = require  __DIR__ . '/CreateWebProfile.php';
$payment = new Payment(); 
$payment->setExperienceProfileId($createProfileResponse->getId());

File path: paypal/rest-api-sdk-php/sample/payment-experience/CreateWebProfile.php

Exception answered 16/9, 2015 at 21:57 Comment(0)
P
2

2022 and beyond

The documentation for V2 of the PayPal API, currently the latest version, and which seems to have been cleaned up a lot over the past year or so, states the following:

shipping_preference

Displays the shipping address to the customer. Enables the customer to choose an address on the PayPal site. Restricts the customer from changing the address during the payment-approval process.

The possible values are:

GET_FROM_FILE. Use the customer-provided shipping address on the PayPal site.
NO_SHIPPING. Redact the shipping address from the PayPal site. Recommended for digital goods.
SET_PROVIDED_ADDRESS. Use the merchant-provided address. The customer cannot change this address on the PayPal site.

Therefore, simply adding:

"application_context" => [
    "shipping_preference" => "NO_SHIPPING"
]

or if using JavaScript:

"application_context": {
    "shipping_preference" => "NO_SHIPPING"
}

...to your order creation should disable any shipping options.

As an example, my PHP code to create an order using PayPal's Standard Checkout Integration (which in turn makes use of the Smart Buttons) now looks like this:

$order = $paypal->createOrder([
    "intent"=> "CAPTURE",
    "purchase_units"=> [
         [
            "amount"=> [
                "currency_code" => "GBP",
                "value"=> 4.99
            ],
             'description' => 'My product description',
        ],            
    ],               
    "application_context" => [
        "shipping_preference" => "NO_SHIPPING"
    ]
]);
Pali answered 18/2, 2022 at 1:5 Comment(1)
And... apparently now in Feb 2023 they are changing the API yet again. Now it says "application_context" is DEPRECATED, and we should use the "experience_context" instead. However, for the record, "application_context...shipping_preference...NO_SHIPPING" still seems to work, at least for now.Ragan
B
1

@Ergec : I tried this:

$nvpstr = "&ADDRESSOVERRIDE=1".$shiptoAddress."&L_NAME0=".$L_NAME0."&L_NAME1=".$L_NAME1."&L_AMT0=".$L_AMT0."&L_AMT1=".$L_AMT1."&L_QTY0=".$L_QTY0."&L_QTY1=".$L_QTY1."&MAXAMT=".(string)$maxamt."&ITEMAMT=".(string)$itemamt."&AMT=".$itemamt."&ReturnUrl=".$returnURL."&CANCELURL=".$cancelURL."&CURRENCYCODE=".$currencyCodeType;

It works. Here we can also use shipping address even though we are not charging any amount.

Bamako answered 17/8, 2011 at 6:17 Comment(1)
i think it will be ok if we are not setting the paymentType argumentBamako

© 2022 - 2024 — McMap. All rights reserved.