Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

330
Visualizações
How to update Stripe coupon "times_redeemed" manually from api ? NodeJS

I am trying to apply a coupon while I am creating a payment Intent in stripe. Every thing is going well but I cant manually update the number of times that coupon had been used.

I have checked the stripe doc, but found nothing. Can Someone help?

This is the stripe coupon specific doc: Stripe Coupon Object API Doc

enter image description here

This is my code where I am changing the price according to the percent_off of the coupon. Everything goes well, but at the end when I am calling updateCoupon function its showing me error.

import { stripe } from "../utils/stripeInstance";

export const createPaymentIntent = async (req, res) => {
  try {
    const { tplan, couponCode, cust_id } = req.body;
    console.log("Coupon Code==>", couponCode);

    let price = 0;
    //coupon redeemed
    let cr = 0;

    if (tplan === "smash") price = 599 * 100;
    else if (tplan === "smash+") price = 999 * 100;
    else return res.status(400).send("Invalid plan");
    console.log("Price Before Coupon==>", price);

    if (couponCode) {
      const coupon = await stripe.coupons.retrieve(couponCode);
      if (coupon.valid) {
        price = price - (price * coupon.percent_off) / 100;
        cr = coupon.times_redeemed;
      }
    }
    console.log("Price After Coupon==>", price);
    const paymentIntent = await stripe.paymentIntents.create({
      amount: price,
      currency: "inr",
      payment_method_types: ["card"],
      customer: cust_id,
    });
    
   
    const updateCoupon = await stripe.coupons.update(couponCode, {
     times_redeemed: cr + 1,
      metadata: {
        used: true,
      },
    });

    return res.status(200).send({
      paymentId: paymentIntent.id,
      status: paymentIntent.status,
      clientSecret: paymentIntent.client_secret,
    });
  } catch (err) {
    res.status(500).json({ statusCode: 500, message: err.message });
  }
};

Error is only when I am updating the coupon by calling updateCoupon function above.This is showing in error.

Stripe Coupon Update Error

Basically what I am assuming that it does not getting proper attributes, may be there is any other correct way to do it. Can anyone help me , Thank You ❤️

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The only things about a coupon you can update once it is created are the metadata and the name properties, as specified here.

The times_redeemed is incremented by Stripe when a coupon is applied to a customer's purchase as part of an invoice.

However, it appears there is a larger confusion here. The reason you are having to write all these functions (fetching the coupon, modifying the amount to charge, etc.) is you are trying to apply coupons to one-off charges with Payment Intents.

Also why Stripe does not allow manual updating of times_redeemed. It's intended as an internal counter and only incremented as it processes a charge where the coupon code was applied.

Coupons do not work with conventional one-off charges.

-- Stripe API Ref

You can review how Stripe Coupons are supposed to function with Subscriptions here.

If you want to offer your customers a way to apply your own coupon discounts to the amount you charge, you will need to maintain those records in your own data models. You could use the Stripe Coupon object as a starting point and design your own database records.

But at present Stripe does not support coupons for one-off purchases

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda