#ingeniousambivert-subscriptions

1 messages · Page 1 of 1 (latest)

wise moon
#

@undone cedar what do you mean exactly by "idempotent" in this context?

undone cedar
#

I mean that in this example, the server uses the subscriptions and customers api, in which I can use the maxRetries option to make it idempotent, but the client simply uses the confirmCardPayment from the payment intents api (I think), and I am not sure if that is idempotent

#

Is it ?

wise moon
#

the maxRetries option is to retry API requests that fail due to network errors.
On the frontend there are no retries, if there was a network error calling confirmCardPayment the Promise resolves with an error and the customer can try again. Not sure if that answers your question.

undone cedar
#

Okay, it kinda does, so I just want to know what caused this - I am using invoice and subscription events in webhooks ( invoice.payment_succeeded, invoice.payment_failed, customer.subscription.updated ) to update the status in my db, and for some reasons even after my payment completed in the frontend, the webhook didnt receive the events and did not update my db.

wise moon
#

if you have an example of the sub_xxx subscription ID or other object you were using I can check if we sent the event or not

undone cedar
#

I dont have that currently, but this happened a couple of times, the listener wouldnt recieve events after it has been idle for some time, I need to restart it for it to work. Is there something I am doing wrong ?

#

stripe listen --forward-to localhost:3030/stripe/webhook

wise moon
#

oh that's a known bug unfortunately

undone cedar
#

Any fixes or workarounds ?

#

This will create an issue in production.

wise moon
#

well in production you wouldn't be using stripe-cli

#

we would send the events to normal endpoints correctly, there's a bug in stripe-cli unfortunately where sometimes it stops forwarding some events

#

so I think your code/implementation is probably fine, it's just this really annoying bug.

undone cedar
#

Okay can you please walk me through, how exactly will the above mentioned example work in production ?

#

With events and webhooks ?

#

Not an elaborate walkthrough, just enough that I get an idea how things work

wise moon
#

which example?

undone cedar
#
GitHub

Create subscriptions with fixed prices or usage based billing. - subscription-use-cases/fixed-price-subscriptions/client/react at master · stripe-samples/subscription-use-cases

GitHub

Create subscriptions with fixed prices or usage based billing. - subscription-use-cases/fixed-price-subscriptions/server/node at master · stripe-samples/subscription-use-cases

#

Basically how would webhooks work in production ?

#

Sorry if this sounds stupid I am new to this

wise moon
#

I can definitely answer but I'm not sure what level of answer or detail you're looking for.

#

when something happens on your Stripe account an event object is generated. You can set up a webhook endpoint as a URL on your server to which Stripe will send those events so you can react to them.

#

For creating subscriptions you're most just interested in the invoice.payment_succeeded event type as that signals to your backend that the first payment succeeded so you can now give the customer access to the service they are subscribing to for example.
https://stripe.com/docs/billing/subscriptions/elements#provision-access
https://github.com/stripe-samples/subscription-use-cases/blob/master/fixed-price-subscriptions/server/node/server.js#L212-L234

Learn how to offer multiple pricing options to your customers and charge them a fixed amount each month.

GitHub

Create subscriptions with fixed prices or usage based billing. - subscription-use-cases/server.js at master · stripe-samples/subscription-use-cases

undone cedar
#

Okay this is great, but one last questiono where do I register the webhook endpoint of my server with stripe ? in cli I would do this - stripe listen --forward-to localhost:3030/stripe/webhook

wise moon
undone cedar
#

Oh okay so I would need to register via dashboard, wasnt aware of that.