#thibault_api

1 messages ¡ Page 1 of 1 (latest)

wise jacinthBOT
#

👋 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/1445409137042133165

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

heady glacier
#

Our python code look like:

    async def run(self):
        if not self.invoice.subscription:
            logger.info(f"No subscription attached to invoice {self.invoice.id} to manage immediate payment failed")
            return
        await self.stripe_client.v1.invoices.void_invoice_async(self.invoice.id)
        subscription = await self.subscription_service.get_subscription(self.invoice.subscription)
        await self.subscription_service.update_subscription(
            [{"price_id": self.invoice.lines.data[0].price.id, "quantity": self.invoice.lines.data[0].quantity}],
            [{"price_id": self.invoice.lines.data[0].price.id, "quantity": self.invoice.lines.data[0].quantity}],
            "none",
        )
#

According to your colleague, Thanks for waiting! If you make a change to phase 0, charge the customer automatically, the update to the quantity will still take place even if the payments fails. If you want to revert back, you will need to update the quantity back manually. updating the quantity back seems to have some unexpected side effects

wise jacinthBOT
exotic compass
#

hey there sorry about the delay, looking into this for you

heady glacier
#

np

exotic compass
#

You mention upgrades and phases. Is this an upgrade happening due to a phase change on a subscription schedules, or are you making the update synchronously and its failing?

#

It sounds like from the quoted text you are in fact using schedules

heady glacier
#

yes we're using schedules.

exotic compass
#

updating the quantity back seems to have some unexpected side effects
rollback to the previous phases state and void the unpaid invoice but it seems that stripe consider this as a "gift" which means that if the customer buy a new licence, we cannot charge him completely
can you say more about what the problem / unexpected state/behaviour is after your "rollback"?

heady glacier
#

Ok

#

We have a subscription using schedules with a phase 0 of a product A equal to 1. If a customer wants to buy 2 items of this product A, we're upgrading the phase 0 of the schedule from 1 to 3. In this situation, we're invoicing directly the customer of 2 items.

#

If the payment fail for any reason, we'd like to rollback the phase 0 from 3 to 1, void the invoice

#

Like a "SGBD transaction"

#

In our scenario, it works like this but if after the rollback, the customer try to buy 2 new items going from 1 to 3 (again), Stripe does not charge anymore.

#

Idk if i'm clear enough

exotic compass
#

Ah i see, so you effectively only want the update to happen if the payment succeeds

#

You can do what you currently have, but its not really a "rollback" like db transaction

#

its two sequential changes

#

both with their own prorations

#

If you want to holdback the upgrade for successful payment we have a concept of "pending updates" you can use for this:

heady glacier
#

Does pending updates work with schedules?

exotic compass
#

Yep!

#

Just note the caveat that if you have a pending update & invoice and phase transition happens, that pending update will be cancelled/voided

#

you'd have to update again after the phase transition completes

#

I think this is likely going to be the fix you need here