Paypal Checkout - 不要求非会员的送货地址?

时间:2017-02-10 13:41:30

标签: paypal

我刚刚开始玩这个模块:

https://github.com/paypal/paypal-checkout

我正试图找出如何关闭客户的送货地址。我知道在订购版本中您可以在网址中&NOSHIPPING=1进行操作,但我无法找到有关API 4版本的任何信息。我的代码是:

paypal.Button.render({

    // Pass the client ids to use to create your transaction on sandbox and production environments
    locale: 'fr_FR',

    //env: 'production',
    env: 'sandbox',

    client: {
        sandbox: "...",
        production: "..."
    },

    // Pass the payment details for your transaction
    // See https://developer.paypal.com/docs/api/payments/#payment_create for the expected json parameters

    payment: function() {
        return paypal.rest.payment.create(this.props.env, this.props.client, {
            transactions: [
                {
                    amount: {
                        total:    window.my_config.grand_total,
                        currency: 'EUR',
                        details: {
                              "subtotal": window.my_config.price,
                              "tax": window.my_config.vat_amount
                        }
                    },
                }
            ]
        });
    },

    // Display a "Pay Now" button rather than a "Continue" button

    commit: true,

    // Pass a function to be called when the customer completes the payment

    onAuthorize: function(data, actions) {
        return actions.payment.execute().then(function() {
            console.log('The payment was completed!');
            console.log(data, actions)

            if (error === 'INSTRUMENT_DECLINED') {
                actions.restart();
            }

        });
    },

    // Pass a function to be called when the customer cancels the payment

    onCancel: function(data) {
        console.log('The payment was cancelled!');
    },
    style: {
      shape:  'rect',
      size: "medium"
    }

}, '#paypalContainerEl');

5 个答案:

答案 0 :(得分:2)

您需要在no_shipping函数中的experience下传递payment选项,如下所示:

return actions.payment.create(
{
    payment:
    {
        transactions: [
        {
            amount:
            {
                total: "10",
                currency: 'EUR'
            }
        }]
    },
    experience:
    {
        input_fields:
        {
            no_shipping: 1
        }
    }
});

在文档中,herehere。但请注意,即使不再询问他们的送货地址,仍会要求客人提供其帐单邮寄地址。

答案 1 :(得分:1)

使用“ shipping_preference:'NO_SHIPPING'。”

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

    });
},

答案 2 :(得分:0)

答案 3 :(得分:0)

对于不幸的小伙子们,使用C#通过PayPal REST API集成此功能,这有点棘手。

您可以像Paypal Repo Example一样创建WebProfile

    var experienceProfile = new WebProfile()
    {
        name = Guid.NewGuid().ToString(), // required field
        input_fields = new InputFields()
        {
            no_shipping = 1
        }
    };

    var experienceId = experienceProfile .Create(_apiContext).id;

    new Payment
        {
            intent = "sale",
            payer = new Payer
            {
                payment_method = "paypal"
            },
            transactions = new List<Transaction>
            {
              // ...
            },
            redirect_urls = new RedirectUrls
            {
                return_url = "..",
                cancel_url = ".."
            },
            experience_profile_id = experienceId
        };

答案 4 :(得分:0)

对于那些通过 PayPal REST API在PHP中集成的用户,可以设置no_shipping属性:

          apiContext = $this->apiContext;

          $payer = new \PayPal\Api\Payer();
          $payer->setPaymentMethod('paypal');

          $inputFields = new \PayPal\Api\InputFields();
          $inputFields->setNoShipping(1); //<-- NO SHIPPING!!!!!!!!!!

          $webProfile = new \PayPal\Api\WebProfile();
          $webProfile->setName($uid); // <-- UNIQUE NAME FOR THE TRANSACTION
          $webProfile->setInputFields($inputFields);

          $createProfileResponse = $webProfile->create($apiContext);
          $webProfile = \PayPal\Api\WebProfile::get($createProfileResponse->getId(), $apiContext);

          $amount = new \PayPal\Api\Amount();
          $amount->setCurrency('EUR')
            ->setTotal($this->deposit_eur);

          $transaction = new \PayPal\Api\Transaction();
          $transaction->setAmount($amount);


          $redirectUrls = new \PayPal\Api\RedirectUrls();
          $redirectUrls->setReturnUrl($this->return_url)
          ->setCancelUrl($this->cancel_url);


          $payment = new \PayPal\Api\Payment();
          $payment->setIntent('sale')
            ->setPayer($payer)
            ->setRedirectUrls($redirectUrls)
            ->setTransactions(array($transaction))
            ->setExperienceProfileId($webProfile->getId()); //<-- SET EXPERIENCE PROFILE

          try{
            $payment->create($apiContext);
          } catch (\Exception $ex) {
            debug($ex);
            exit;
          }

          $approvalUrl = $payment->getApprovalLink();