29
votes

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?

7

7 Answers

32
votes

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/webapps/developer/docs/classic/api/merchant/SetExpressCheckout_API_Operation_NVP/

Or lookup for Payment experience in new REST API

15
votes

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.
11
votes

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'
            }

        });
    },
8
votes

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

5
votes

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:

2
votes

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

1
votes

@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.