Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 views
in Technique[技术] by (71.8m points)

Stripe Checkout Shipping Address

I'm using Stripe Checkout API to direct user to make a payment. I want to get the shipping address to ship them as well. Here's the code that I'm using in my WordPress widget:

<!-- 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>

This code is working fine in getting the payments but it doesn't get the shipping address. Also I want the shipping address default country to be United States. Thank you!

question from:https://stackoverflow.com/questions/65831320/stripe-checkout-shipping-address

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...