#nshah_promo-codes-elements
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can 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/1246158276589260833
๐ Have more to share? Add details, code, screenshots, videos, etc. below.
HI ๐
For the first question, are you trying to perform the check yourself? Or do you want to know how Stripe checks for a first time transaction?
For both questions my initial recommendation is to test this out. Do you have a test integration built out yet?
Im trying to perform the check myself, but knowing how Stripe checks for the first time transaction will also help me perform the check i guess.
Is there a better (easier) way for me to tackle the problem of wanting to building out a custom form with stripe elements and have promo code functionality? (dont want to use checkout)
What do you mean by test integration?
I mean do you have code that you can run to make API calls using your Test API key?
Im essentially building an endpoint that takes in the code, price_id of the current product and an optional customer_id - i want to be able to figure out whether the code can be applied without applying it
ANd yes, i have that
Okay. Got it. You could make a List call to the Payment Intents API and filter on the Customer ID: https://docs.stripe.com/api/payment_intents/list
And, with respect to the free trial, I think we would not consider the coupon to have been expired because it was not applied. So you would need to capture that yourself.
and that would be exhaustive? (in the sense that this is the logic that stripe use to determine first time txn)
Got it re free trial
That I cannot speak to, specifically. There may be some other approaches depending on internal architecture. But, for your integration, if you really wanted to be exhaustive you could use the Charges List API: https://docs.stripe.com/api/charges/list#list_charges-customer
Since every Payment Intent will create a Charge but not all Charges are the result of a Payment Intent
right right, i just want to emulate what happens on stripe checkout say when a code is applied, you can see whether its valid or not
I'm probably better off using Charges list then? unless theres some downside to that?
Yeah, I think checking the Charges should work. I don't see any clear downside there.
Okay thanks, btw any idea if/when stripe elements will support promo codes ๐
Are you creating Invoices and collecting payment method details with stripe elements?
Yes, collecting payment methods and confirming the intent via client secret
Okay so you are creating Invoice objects?
Well I'm not, I'm creating subscriptions
Okay, same situation
The subscriptions create the the invoices init
Honestly the answer comes down to "it's too complicated for the Payment Element". The Subscription is what has the discounts property that would need to get updated but the Payment Element only interacts with the Payment Intent.
Okay i get that - what you're saying is payment element only deals with collecting payment info for a given intent? Is there another element (or even a method in the sdk) available to handle checking whether a code can be applied for a certain customer/product/etc.?
Unfortunately we have only built that into front-end surfaces like Checkout.
OOC, were you aware you can embed the checkout form into your site, rather than redirect users?
Sad, im surprised this hasnt come up more often tbh. i would assume a lot of people would be writing this same piece of logic in their own backend...
Yeah i am aware of that (also the currently in beta Custom Checkout i believe has promo codes as well) but we wanted a more integrated registration flow for our customers hence opting for elements
That's fair. I'm trying to reason through how it would work though. In order to check, the element would need to know both the Customer and the details of the Subscription/Invoice along with the promo code. Since we have restrictions on number of times used in general, by customer, and restrictions by product.
Im not super versed on elements so feel free to disregard what i say next ๐ - i was thinking that perhaps the element would be aware of the current "basket" and an optional customer (if logged in). That would provide all the information required to be able to perform validation on any customer-inputted promo code
But even if its not a frontent element, a method in the sdk that accepts a list of products/prices + optional customer id would be super helpful
Yeah the problem there is we (Stripe.js) doesn't have any way to know those things. You would likely need to stick to the objects that exist in the API
Fair enough, i guess a method in the stripe sdk or endpoint in the api could work?
then could either return an error or some information regarding the result of the application of the code
Not sure but I don't think this is a feature that is currently being looked at.
Yeah fair, well ive taken enough of your time! Thanks for your help!
Happy to shed what ๐ก I can ๐