【问题标题】:Paypal Checkout - don't ask for delivery address for non-members?Paypal Checkout - 非会员不询问收货地址?
【发布时间】:2017-06-28 21:16:09
【问题描述】:

我刚刚开始玩这个模块:

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

我正在研究如何关闭客户的送货地址。我知道在订购版本中您可以在 URL 中执行 &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');

【问题讨论】:

    标签: paypal


    【解决方案1】:

    【讨论】:

    • 谢谢 - 但是您如何使用 PayPal 结帐 JS 做到这一点?它只是作为transactions: [] 部分中的一个选项吗?
    • @AndrewNewby 你知道这是怎么回事吗?
    • @Michał 已经有一段时间了 - 但我似乎记得当时没有选项可以将其放入 PayPal JS API(现在可能不同)
    • @AndrewNewby 有志者事竟成 ;D!
    • @Michał 哈哈是的。我想我放弃了(我们现在使用 Stripe 进行大部分付款,但仍然为想要使用它的人提供 PayPal)
    【解决方案2】:

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

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

    在文档中,herehere。不过请注意,尽管不再询问客人的送货地址,但仍会要求客人提供帐单地址。

    【讨论】:

    • 像魅力一样工作。有没有比您链接到的checkout.js 更好的文档?例子中有很多变量和函数没有很好的定义
    • 嗯,已经有一段时间了,但我发现 Paypals 文档,尤其是第二个链接,并不太简陋。确保单击蓝色对象链接以查看列出的所有变量。
    • 嘿,你会不会碰巧知道如何在 API 的 v2 中做到这一点? developer.paypal.com/docs/api/payments/v2
    【解决方案3】:

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

    您像在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】:

      对于那些通过 PHP 中的 PayPal REST API 进行集成的人,设置 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();
      

      【讨论】:

        【解决方案5】:

        使用“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'
                }
        
            });
        },
        
        猜你喜欢
        • 1970-01-01
        • 2015-10-05
        • 1970-01-01
        • 2014-02-08
        • 1970-01-01
        • 2019-07-11
        • 2015-02-17
        • 1970-01-01
        • 2017-04-17
        相关资源
        最近更新 更多