首页 > 解决方案 > 条纹结帐送货地址

问题描述

我正在使用 Stripe Checkout API 来指导用户付款。我也想获得送货地址来运送它们。这是我在 WordPress 小部件中使用的代码:

<!-- Load Stripe.js on your website. -->
<script src="https://js.stripe.com/v3"></script>

<!-- Create a button that your customers click to complete their purchase. Customize the styling to suit your branding. -->
<button
  style="background-color:#6772E5;color:#FFF;padding:8px 12px;border:0;border-radius:4px;font-size:1em"
  id="checkout-button-price_1HhPY2IT1E1kKJAOCUoQDPxI"
 role="link"
 type="button"
>
 Checkout
</button>

<div id="error-message"></div>

<script>
(function() {
  var stripe =Stripe('pk_live_51H7oCMIT1E1kKJAOeiJKZvF4R2uIJfFCIrOJ1hW8Krned1tfG0abtsQdMD6pRmRyqh5gNNnfxVCzltFc29K7C5Iq00YJyFHBZZ');

  var checkoutButton = document.getElementById('checkout-button-price_1HhPY2IT1E1kKJAOCUoQDPxI');
  checkoutButton.addEventListener('click', function () {
/*
 * When the customer clicks on the button, redirect
 * them to Checkout.
 */
stripe.redirectToCheckout({
  lineItems: [{price: 'price_1HhPY2IT1E1kKJAOCUoQDPxI', quantity: 1}],
  mode: 'payment',
 
  /*
   * Do not rely on the redirect to the successUrl for fulfilling
   * purchases, customers may not always reach the success_url after
   * a successful payment.
   * Instead use one of the strategies described in
   * https://stripe.com/docs/payments/checkout/fulfill-orders
   */
  successUrl: window.location.protocol + '//GLOBESITY.FOUNDATION/success',
  cancelUrl: window.location.protocol + '//GLOBESITY.FOUNDATION/canceled',
})
.then(function (result) {
  if (result.error) {
    /*
     * If `redirectToCheckout` fails due to a browser or network
     * error, display the localized error message to your customer.
     */
    var displayError = document.getElementById('error-message');
    displayError.textContent = result.error.message;
  }
  });
  });
 })();
  </script>

此代码在获得付款时工作正常,但它没有获得送货地址。另外我希望送货地址默认国家是美国。谢谢!

标签: stripe-payments

解决方案


您需要使用 Checkout 的服务器+客户端版本(仅客户端版本不支持此功能),并按照此示例创建 CheckoutSession 。具体来说,您需要shipping_address_collection通过allowed_countries: ['US'].


推荐阅读