【问题标题】:Send Shipping Address details with Stripe Custom Checkout使用 Stripe Custom Checkout 发送送货地址详细信息
【发布时间】:2018-07-02 21:58:42
【问题描述】:

我有一个使用现在不受支持的“data-shipping-address="true"" 参数的条带结帐。当使用带有以下代码的简单条带结帐时,这可以按预期工作:

<script 
    src="https://checkout.stripe.com/checkout.js" 
    class="stripe-button"
    data-key="<?php echo $stripe['publishable_key']; ?>"
    data-amount="1000" 
    data-currency="gbp" 
    data-allow-remember-me="true" 
    data-shipping-address="true" 
    data-billing-address="true" 
    data-label="Proceed to payment details" 
    data-image="" 
    data-description="TrillShirts">
</script>

但如果我在 .js 文件中调用它,我无法让它发布从运输详细信息中获取的数据。这是我的代码:

var handler = StripeCheckout.configure({
  key: 'pk_test_JfqHIgPSCG2oWOsJ54PWS0Nl',
  image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
  locale: 'auto',
  billingAddress: 'true',
  shippingAddress: 'true',
  token: function(token) {
    console.log(token.id);
    console.log(token.email);
    // here I try to find the shippingAddress using cosole.log
    console.log(token.shippingAddressLine1);
    console.log(token.stripeShippingAddressLine1);
    // When I eventually have the shipping address, I will insert it in the same way as below
    $(".stripeToken").val(token.id);
    $(".stripeEmail").val(token.email);
    $(".stripe").submit();

    }
});

document.getElementById('pay').addEventListener('click', function(e) {
  // Open Checkout with further options:

    handler.open({
      name: 'TrillShirts',
      description: 'Childcatcher Tee',
      currency: 'gbp',
      amount: 2000
    });
  });
});

以下两个都在控制台中返回 undefined,所以我无法弄清楚运输详细信息返回的格式。

    console.log(token.shippingAddressLine1);
    console.log(token.stripeShippingAddressLine1);        

一旦我知道格式并获得了成功的控制台日志,我就可以在提交之前使用 jQuery 将数据插入到表单中。

谁能帮忙?

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    使用自定义结帐时,当shippingAddress 启用时,运送详细信息将作为函数的second 参数传递给您的token 回调函数。这是token 回调引用in this doc 中显示的args 参数。

    因此,在您的情况下,您需要将令牌回调函数的签名从 function(token) {...} 修改为 function(token, args) {...},然后您应该能够从 args 获取信息。

    这里是一个例子:https://jsfiddle.net/rghpes57/3/ 在此示例中,第二个 console.log 是您要查看的对象,以了解对象的外观。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 2018-02-18
      • 2019-07-11
      • 2017-10-30
      • 2010-11-15
      • 2014-04-16
      相关资源
      最近更新 更多