php 在 PayPal Express Checkout 中禁用送货地址选项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4283251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:31:41  来源:igfitidea点击:

Disable shipping address option in PayPal Express Checkout

phppaypalpaypal-sandbox

提问by Ergec

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.

使用 PayPal API 并使用SDK 和下载中的名称-值对接口 PHP 源代码:简化与下载和 SDK 的集成

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.

我的问题类似于“删除(或预填)PayPal Express Checkout 的地址详细信息”,但我根本不想要运费/地址或任何与运费相关的信息。

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.

我在我的系统上保留了所有运输详细信息(甚至有时甚至不适用运输并且不收取任何费用),我只希望用户通过 PayPal 付款,而无需运输地址和运输费用。

How can I disable shipping part of checkout?

如何禁用结帐的运输部分?

回答by jbx

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

如果您使用较新的 API,您还可以传递 NOSHIPPING=1(不是 no_shipping)

Further details about all possible parameters to the SetExpressCheckout here:

有关 SetExpressCheckout 的所有可能参数的更多详细信息,请访问:

https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/SetExpressCheckout_API_Operation_NVP/

https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/SetExpressCheckout_API_Operation_NVP/

Or lookup for Payment experiencein new REST API

或者在新的 REST API 中查找支付体验

回答by James Skidmore

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

嘿 Ergec,只需传递no_shipping值为1.

From PayPal's documentation:

来自 PayPal 的文档

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.

回答by Akmal

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

当前正确答案已弃用。要解决新 API 中的问题,我们应该使用所需参数创建Payment Web 体验配置文件资源并将其附加到请求Payment

Example in PHP:

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

注意:您可以通过链接找到上述所有使用的类:https: //github.com/paypal/PayPal-PHP-SDK/tree/master/lib/PayPal/Api

回答by Gene Bo

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

要从当前(2019 年)Web 客户端 .JS 解决此问题,请将application_context块添加到请求正文中。

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

下面是一个createSubscription()调用示例;我想这将与工作createOrder()以及

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:

以下是列出字段枚举的位置:

回答by elkrari

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

根据 API 中的示例创建 Web 配置文件: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

文件路径: paypal/rest-api-sdk-php/sample/payment-experience/CreateWebProfile.php

回答by user869379

@Ergec : I tried this:

@Ergec:我试过这个:

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

有用。即使我们不收取任何费用,我们也可以在这里使用送货地址。

回答by Dave Nugent

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

对于其他正在寻找此内容的人,因为 PayPal 的文档非常棒(咳嗽、咳嗽)。

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:

将 REST API V2 与 Javascript/JQuery 结合使用,并为订单关闭“Ship To”,这是正确的代码示例:

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

        });
    },