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 quest
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
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:
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
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
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'
}
});
},
@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.