Disable shipping address option in PayPal Express Checkout

人盡茶涼 提交于 2019-11-28 09:00:36
jbx

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

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

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

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

user869379

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!