#mochihealth

1 messages · Page 1 of 1 (latest)

solid sleetBOT
random echo
#

Hi there

reef basin
#

so the process is that we have two pages one to choose the price which creates a payment intent and then the next page is where you pay and would apply any discount codes

random echo
#

So sounds like you want to wait to create your Subscription until the second page then

#

Not sure exactly what you mean by checking if the promo code is valid

#

Can you clarify?

reef basin
#

like if someone enters GET20OFF I want to validate that it could be applied and show the updated price

random echo
#

So you want to know ahead of actually creating the Sub?

reef basin
#

well maybe like after the sub is created but before they pay

random echo
#

You won't be able to add the promo code after you create the Sub

#

Since that will finalize the initial invoice

reef basin
#

so how can I make the coupon work in my flow

#

im confused

#

because I need to create a payment intent at least for first time buyers since there isn't any card on file that I can just attach when I would just create a subscription?

reef basin
random echo
#

You can use the above endpoint to simulate creating a Sub via the subscription_items param

reef basin
#

but how about the whole payment intent flow for creating subscriptions

random echo
#

A Subcription creates an invoice which creates a PaymentIntent

#

Can you clarify where you are confused?

reef basin
#

I would have to get rid of it if i only wanted to show the coupon code box after they choose a price and were on the page to pay

random echo
#

Get rid of what?

reef basin
#

that entire flow where a paymentintent is created, returned to the frontend and then confirmed on payment

random echo
#

The Sub creates the PaymentIntent for you

#

You shouldn't be creating a PaymentIntent directly if you are using Subscriptions

#

You would create the Sub and then grab the latest_invoice.payment_intent.client_secret and pass that to the frontend

reef basin
#

yea sorry thats what im talking about

#

but the client secret needs to be returned before the payment page

#

and the coupon code would be on the payments page

#

or would it have to be moved to the first page

random echo
#

Why does it need to be returned before the payment page?

#

No you can just render Payment Element (create the Sub and pass the client_secret) based on some user action on your payment page.

#

Like ask them to confirm their choice from the previous page and offer them to enter promo code

#

Or you can handle the promo code on the previous page

#

Up to you

reef basin
#

this is the first page

#

this is the next

#

whre the coupon code would theoretically live

random echo
#

Yep that's fine

#

So you hide Payment Element and have some sort of button like "add card details" or something

#

And then when they click that you create the Sub and render Payment Element

#

That's just an example

#

But you basically want a user action after they have had the ability to add a promo code to then create the Sub

reef basin
#

gotcha

#

so how about like validating the coupon code

random echo
#

Use the Upcoming Invoice endpoint like I showed above

#

Then you can add the discounted price to your UI

reef basin
#

but the upcoming invoice endpoint can only be used after the subscription was created right

#

so like I want to show an error if the code they entered wasnt valide before the subscription is created

random echo
#

No

#

I said above you can use it before creating a Subscription 🙂

reef basin
#

oh

#

it says retrieve an upcoming invoice though

#

there has to be some invoice created to retrieve right

#

so how do you do that without creating the subscription

random echo
#

Did you look at the above link? It says there under the subscription param:

The identifier of the subscription for which you’d like to retrieve the upcoming invoice. If not provided, but a subscription_items is provided, you will preview creating a subscription with those items. If neither subscription nor subscription_items is provided, you will retrieve the next upcoming invoice from among the customer’s subscriptions.

reef basin
#

oh sorry did not see that

#

that is very helpful

random echo
#

Yep! Should do the trick

reef basin
#

also is there a way to retrieve a promotion code by the name of it because i only see that it can be retrieved by its id

#

like how would I grab the coupon id to apply after someone inputs a promotion code

random echo
#

You can list by its code

reef basin
#

ok and lets say the code had a restriction that it applies to only the first purchase would it throw an error if I tried to preview that with the upcoming invoices endpoint when I put it in for a certain customer?

#

that had previous purchases

random echo
#

I believe so but can't remember off the top of my head. I'd recommend testing that out

reef basin
#

yea ofc just thought id ask if you happened to know 😁

#

thanks for all the help!