#nshah_promo-codes-elements

1 messages ยท Page 1 of 1 (latest)

knotty hearthBOT
#

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

stray mauve
#

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?

hoary sierra
#

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?

stray mauve
#

I mean do you have code that you can run to make API calls using your Test API key?

hoary sierra
#

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

stray mauve
#

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.

hoary sierra
#

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

stray mauve
#

Since every Payment Intent will create a Charge but not all Charges are the result of a Payment Intent

hoary sierra
#

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?

stray mauve
#

Yeah, I think checking the Charges should work. I don't see any clear downside there.

hoary sierra
#

Okay thanks, btw any idea if/when stripe elements will support promo codes ๐Ÿ‘€

stray mauve
#

Are you creating Invoices and collecting payment method details with stripe elements?

hoary sierra
#

Yes, collecting payment methods and confirming the intent via client secret

stray mauve
#

Okay so you are creating Invoice objects?

hoary sierra
#

Well I'm not, I'm creating subscriptions

stray mauve
#

Okay, same situation

hoary sierra
#

The subscriptions create the the invoices init

stray mauve
#

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.

hoary sierra
#

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.?

stray mauve
#

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?

hoary sierra
#

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

stray mauve
#

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.

hoary sierra
#

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

stray mauve
#

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

hoary sierra
#

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

stray mauve
#

Not sure but I don't think this is a feature that is currently being looked at.

hoary sierra
#

Yeah fair, well ive taken enough of your time! Thanks for your help!

stray mauve
#

Happy to shed what ๐Ÿ’ก I can ๐Ÿ™‚