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
267 views
in Technique[技术] by (71.8m points)

node.js - Stripe Promotion Code / Coupon code checking client side checking before subscription

I am using React and Stripe payments for subscriptions. I have the checkout all set using Elements. I want to add the possibility for a user to add a promo code set up in stripe that will be added to the subscription on creation.

What i want to do is check that the promo code is valid (after checking the various subscriptions on the code) and show the affect to the customer before they commit to subscribe. I thought there would have been something built into the API but apparently not. And Stripe support desk (which is generally very good) don't don't seem to know why i want to check a code is valid and show customer it is before they actually click subscribe.

const promotionCodes = await stripe.promotionCodes.list({
        active: true,
        code: promoCode,
      });
      if (promotionCodes.data.length > 0) {
        const today = Math.floor(Date.now() / 1000);
        const expiry =
          promotionCodes.data[0].expires_at ||
          Math.floor(Date.now() / 1000) + 20;

        if (today <= expiry) {
          valid = true;
        }
      }

This is retrieving the code (there can only be 1 active result so it gets it fine). I then check its not expired. All fine, the data I cannot get is if the Coupon the Promotion code is attached to, is restricted to only certain products. For example, if i chose gold plan and try to use a code for silver plan then it would be invalid.

question from:https://stackoverflow.com/questions/66062044/stripe-promotion-code-coupon-code-checking-client-side-checking-before-subscri

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

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...