条纹苹果支付如何检测shippingOption更改并获取送货地址?

时间:2018-11-03 08:34:09

标签: javascript stripe-payments shipping-method applepayjs

我正在将Stripe Apple Pay实施到我的客户网站。一切都很好,但是我在以下几点上遇到了困难。

1)如果有多种送货方式,我们如何确定客户选择了哪种送货方式?因为Stripe有助于在此链接https://stripe.com/docs/stripe-js/elements/payment-request-button

中列出多种送货方式

例如,让我说我的shippingOption如下:

    var paymentRequest = stripe.paymentRequest({
      country: 'US',
      currency: 'usd',
      total: {
        label: 'Demo total',
        amount: 1000,
      },

      requestShipping: true,
      // `shippingOptions` is optional at this point:
      shippingOptions: [
        // The first shipping option in this list appears as the default
        // option in the browser payment interface.
        {
          id: 'free-shipping',
          label: 'Free shipping',
          detail: 'Arrives in 5 to 7 days',
          amount: 0,
        },
        {
          id: 'paid-shipping',
          label: 'Paid shipping',
          detail: 'Arrives in 1 to 3 days',
          amount: 2000,
        }
      ],
    });

并且客户选择了第二种运输选项。因此,当他们这样做时,我想触发一些事件,以便更新订单的总价格。

2)用户提交表格后,我们如何收集用户选择的收货地址?

目前,我发现了以下数据,但是在成功付款后获取用户送货地址的正确方法不是。

paymentRequest.on('token', function(ev) {

  $('#debug').html(JSON.stringify(ev));  // this is printing all the selected values in apple pay sheet

})

仅供参考:我的服务器端代码如下:

<?php 
require_once('vendor/autoload.php');
\Stripe\Stripe::setApiKey("sk_test_X1UrHPm0PaB6fOyoxHr9hWyJ");

// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:

$token = $_POST['stripeToken'];
$charge = \Stripe\Charge::create([
    'amount' => 55555,
    'currency' => 'usd',
    'description' => 'Example description',
    'source' => $token,
    'metadata' => ['order_id' => 6735],
]);

0 个答案:

没有答案