#goodluckh_api

1 messages ¡ Page 1 of 1 (latest)

onyx roseBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1265359953967845468

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

astral flume
random mesa
# astral flume Hello Have you referred to these docs already? https://docs.stripe.com/billing...

Hi, it sounds like my set up already:

const stripe = new Stripe((args.context.env as any).STRIPE_SECRET_KEY);

  const session = await stripe.checkout.sessions.retrieve(sessionId);

  if (!session.setup_intent) {
    return new Response("Error: Missing setup_intent", { status: 400 });
  }

  const setupIntent = await stripe.setupIntents.retrieve(
    session.setup_intent as string
  );

  if (!setupIntent.metadata?.subscription_id) {
    return new Response("Error: Missing subscription_id", { status: 400 });
  }

  const subscription = await stripe.subscriptions.update(
    setupIntent.metadata.subscription_id,
    {
      default_payment_method: setupIntent.payment_method as string,
      collection_method: "charge_automatically",
    }
  );

  if (subscription.status === "paused") {
    await stripe.subscriptions.resume(subscription.id),
      {
        billing_cycle_anchor: "now",
      };
  }

  // Retrieve the latest invoice for the subscription
  const latestInvoice = await stripe.invoices.retrieve(
    subscription.latest_invoice as string
  );

  // Attempt to pay the latest invoice if it is open
  if (latestInvoice.status === "open") {
    await stripe.invoices.pay(latestInvoice.id);
  }
astral flume
#

Can you share the test invoice ID it generated?

random mesa
#

in_1Pfm1BLw4lMVnwxib7vAUWUT

#

i mean there are a couple

#

the paid one on top is the one i manually clicked on "resume subscription" in Stripe's dashboard

astral flume
#

It looks like your call to resume the subscripiton is voiding the invoice that gets generated.

random mesa
#

yea it appears to be so

astral flume
#

I don't see any calls to pay the invoice, you mentioned you're calling the /pay endpoint correct?