#justwatch_api

1 messages ยท Page 1 of 1 (latest)

coarse archBOT
#

๐Ÿ‘‹ 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/1290378004694044763

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

silver spruce
#

Hello

graceful charm
#

Hey @silver spruce I'm happy to try and help but I will need a clear question from you with all the details provided in one message. Right now your question is "I need special help" which doesn't really tell me much!

silver spruce
#

I am creating a subscription that will automatically collect payments this way, but the issue is that the UTC scheduling done by Stripe makes it unclear when I will receive the payment, causing the subscription on my website to expire prematurely.

It seems a bit complex, but I will explain it to you:

#
Codes:

  createStripeSubscription: async (amount, duration, planName) => {
    try {
      const amountFloat = parseFloat(amount);
      const roundedAmount = parseFloat(amountFloat.toFixed(2));
      const amountInCents = Math.round(roundedAmount * 100);

      const price = await stripe.prices.create({
        currency: "usd",
        unit_amount: amountInCents,
        recurring: { interval: duration },
        product_data: { name: planName },
      });

      const session = await stripe.checkout.sessions.create({
        billing_address_collection: "auto",
        line_items: [
          {
            price: price.id,
            quantity: 1,
          },
        ],
        mode: "subscription",
        success_url: env.xxx,
        cancel_url: env.xxx,
      });

      if (env.ENABLE_TESTING == "true") {
        console.log("Payment link created:", session);
      }

      console.log(JSON.stringify(session, null, 2));

      return session;
    } catch (error) {
      console.error("Error creating payment link:", error.message);
    }
  },

#

event type:
case "invoice.payment_succeeded":

graceful charm
#

Subscriptions are used to accept recurring payments for example month over month. Why are you canceling a Subscription on October 10 if it starts on Sep 30?

silver spruce
#

No, you are a customer.
You purchased a 1-day subscription and started automatic billing.

#

We don't know when Stripe will receive this payment and send the webhook.

#

I want to receive the payment through Stripe and the webhook to be sent when there is 1 hour left for the subscription period.

#

Did you understand?

graceful charm
#

Not at all I'm sorry. What is a "1-day subscription"? Like I pay $1 every day or something?

silver spruce
#

yes

#

You can think of it like a Netflix subscription

#

or any site

graceful charm
#

Hum okay so what's the issue with the "one hour left"? Sorry this is still not making sense for me

Like I go on Checkout I pay $1 for today and now have a daily Subscription that will renew around the same time each day. And then each day the new cycle starts around that same time and we send you an invoice.created Event and you can do whatever you want there.

silver spruce
#

The last hour doesn't matter; I just don't know the exact minute and date when the payment will be received. That's why we sometimes experience delays due to time zone differences.

coarse archBOT
graceful charm
#

the timezone is not really relevant. The Subscription renews based on when it was created.

silver spruce
#

If I am using GMT +5, what will happen? How will I track it? Because you are using UTC +0

#

"stripe api timezone"

mystic python
#

Hello
Using GMT +5 for what exactly?

Timestamps on Stripe are always UTC. If you're trying to set custom billing cycle date/time, you should convert that time to UTC and set the billing cycle anchor in UTC

silver spruce
#

I understand you, sir, but I am using a third-party API. This means that the product is created by a third server, and the end_date is determined there. If the payment date from Stripe and the end_date from the third server are at the same time, or if Stripe is delayed by a few minutes, I will encounter issues.

#

@mystic python

mystic python
#

Sorry, I'm not really grasping what you mean by end_date here.. I think the overflow you're using is a bit convoluted.. Especially with third-party APIs being involved which we know nothing about.

Based on the description you've provided, you'd want to work with the third-party API provider to make sure that the timestamp they send, doesn't fall before Stripe's charging attempt.

Sorry we're talking about vague things right now so it is very possible that above is confusing..

silver spruce
#

I'm explaining the steps.

  • The customer goes to the subscription page and purchases a daily subscription.
  • We send a request to a third-party API, and a subscription is created on their side. Additionally, there is an expiration date: 01.10.2024 - 05:05.
  • For Stripe, a similar date or the same date is generated to collect the next payment, so there is no issue.
    However, if the Stripe API webhook sends a request at 05:06 instead of 05:05 to my site, it will be too late for everything.
    What I mean is that I need to be well aware of the next collection time sent by the Stripe webhook.
mystic python
#

You can listen to invoice.created webhook event to get a notification when the renewal invoice is drafted. This invoice is generated based on the billing cycle anchor that's set on the subscription when subscription was created.

#

We finalize invoices and charge the payment method automatically after an hour of sending invoice.created event

silver spruce
#

So, are you sending the invoice.created webhook one hour before receiving the payment collection?

mystic python
#

yup

silver spruce
#

oh

#

let me check

silver spruce
#

@mystic python
If I use this instead of waiting for the webhook API a few minutes ago, what will happen? Because I can't manage the webhook timing well, and subscriptions on my site are getting canceled

mystic python
silver spruce
#

Nice man!

#

finally

mystic python
#

You'd want to make sure you account for proration as the invoice that gets generated will automatically try to calculate proration

silver spruce
#

When you purchase a 1-day subscription, I'm thinking of triggering this code a few minutes before the subscription expires the next day. What do you think?

#

good idea or not

mystic python
#

I don't really understand your usecase 100% so I don't know ๐Ÿ˜…
Best way to know would be to test this out in test mode

silver spruce
#

The webhook was a bit late, and this happened:

#

The subscription has been canceled

silver spruce
mystic python
silver spruce
#

Alright

#

Thank you for everything.