#xPaghkman
1 messages · Page 1 of 1 (latest)
Hi there, you can specify the customer when creating a promo code, so that only this customer can use this promo code https://stripe.com/docs/api/promotion_codes/create?lang=ruby#create_promotion_code-customer
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
@trim acorn I want the opposite. Since if a user signs up, it will have own referral code to share, but he should not be able to use that code for him self
Would be good to have this functionality, otherwise I am not gonna be able to integrate referral code system.
there's not really any way to do that without adding a layer of your own logic on top. How would the promo codes get redeemed, what's your frontend payment integration?
I am using Stripe Checkout flow. I create a checkout seesion by customer id.
ok, then there isn't really any option since we simply don't support this kind of restriction to apply to the promo code object
Hmm. So looks like it is not possible to do that with Stripe at the moment. What would you suggest as alternative flow or something to make it work with Stripe ?
And is it possible that if this can be considered as feature request for Stripe? Maybe you could forward this use case to Stripe teams. At least for future, would be really good to have it.
there's no good answer beyond "don't use Promo Codes, build your own thing". So e.g. before sending a customer to Checkout, collect a code from them on your own page. Check that code against your own logic and restrictions, and if you allow it, then create the CheckoutSession with a coupon applied, and if not, create it without
best way to raise a feature request is via https://support.stripe.com/?contact=true since otherwise it's just me raising anonymous feedback
So, then ideally, I should be able to pass allow_promotion_codes: false and discounts: [{coupon: '{{COUPON_ID}}',}] in create session . And with this I can fully restrict that who can use the promo code. right ?
yes
Thank you for explanations.
And I have one more additional question
About which webhook really I should listen to exactly know that subscription is paid and active and get the applied promo code for it.
checkout.session.created
to get the promo code used, you have to look at https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-total_details-breakdown
note that field is not included by default or in the webhook body, you have to retrieve the CheckoutSession object from the API and pass expand:["total_details.breakdown.discounts"] I think, to get it returned
There is no checkout.session.created event I can find.
Okay, and, I believe, I will also need to listen for subscription update event to get the actions happening on customer portal.
Is there any race condition for receiving the events ? for example, when user completes checkout, I will get session.completed, but in the meantime I will probably get some subscription.update event, so is there any chance that this can overwrite the data in my database ?
there can be yes https://stripe.com/docs/webhooks/best-practices#event-ordering
Your endpoint shouldn’t expect delivery of these events in this order and should handle this accordingly. This is so general. I am not sure how am I supposed to compare the events by priority. For example checkout.session.completed vs subscription updated event. How do I know which one to consider as top priority.
generally you treat the event as a notification that something changed, and retrieve the related object from the API to get the latest state, and sync your system with that rather than the body in the event
Yes, make sense. Thank you!
So I can put like an internal function like syncSubscription and for any incoming webhooks related to subscription events, I can just call sync function, and I would make sure that I will have always latest data.
Hi! I'm taking over this thread.
It depends what exactly you want to sync. For subscription you could listen to customer.subscription.updated, and when you receive that event sync the subscription with your own database.
Basically I want to sync every update about when subscription details changes. So what @wise sierra saying makes sense I think. Because Like I can listen 4-5.. events for subscription details change, and in every webhook calling, I can just directly fetch subscription details by id instead of using the data coming with webhook
yes agreed.
And I believe it would be really good to see some strategies in the stripe documentation, otherwise it is so general. And might lead to wrong way for some people.
Thanks for the feedback!
@zenith warren Question, is checkout.session.completed triggered when also checkout session fails ? or it is just triggered when it is successful ?
https://stripe.com/docs/api/events/types#event_types-checkout.session.completed
Occurs when a Checkout Session has been successfully completed.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
@zenith warren Another question 🙂
Does this customer.subscription.updated event webhook covers any change in subscription object ?
For example there also these events
Since every one of them is an update in subscription, and would it trigger every time customer.subscription.updated, or this event is specific for just for some fields change ?
I could not find much about this topic in the doc.
I'm not 100% sure. I would recommend to update the subscription yourself and see which events are triggered