#skoshkarli - present discounted price
1 messages · Page 1 of 1 (latest)
Hello, I think you can have us automatically calculate it. Are you creating your subscriptions here directly or through Checkout?
i am not using checkout
we have a custom payment page where we will be collecting payment info using Stripe Elements and creating a subscription right away
How would i have you guys automatically calculate it?
Apologies, was a bit busy in other threads and accidentally dropped this one. Looking now
If you are creating the subscription from scratch and definitely want to apply the discount, you can provide the promotion code when creating the subscription. The first Invoice will reflect your discount https://stripe.com/docs/api/subscriptions/create#create_subscription-promotion_code
Otherwise, you can use our upcoming invoice call and pass in a coupon to preview what the next payment will look like with the discount https://stripe.com/docs/api/invoices/upcoming#upcoming_invoice-coupon
i dont think this works
this is BEFORE the subscription is created or a customer is created
i am fetching products from Stripe and want to show the prices of those products to a customer and this customer is using a coupon code
so i would like to show the price with the coupon code applied
I think that that upcoming invoice call may still help you. I think you would need to provide the customer ID, a subscription start date, the coupon, and the relevant prices. https://stripe.com/docs/api/invoices/upcoming
customer is required for upcoming invoice, which i wouldn't have still
In this case it would probably be worth it to create a dummy customer and use that. I will test this quickly and get back to you
seems a bit hacky, i'd have thousands of users going through this one customer id to fetch their prices? There has got to be a better way
You can do it with just one Customer object. Like create a Customer named "preview prices", make sure they are never subscribed to anything, and make preview invoices with that customer's ID to show what a new subscription would be like
Just tested it and it properly calculates the price + discount for you
Whoops, I missed a parameter that does exactly what you want. Instead of creating a customer you can use the customer_details parameter https://stripe.com/docs/api/invoices/upcoming#upcoming_invoice-customer_details
So there we go, preview discount and non-hacky
interesting, what would i put into customer_details ?
i don't really know anything about the customer at that point
Actually after testing it more fully, that won't work. It looks like you need either an existing customer or subscription to make the call with. Re-using the same customer ID would probably be the best way to go here. I can put in a feature request to remove that requirement but for now that would be the best way to preview a subscription's price without any pre-existing Customer for the actual user you are creating the subscription for.
ok thank you!
so just to clarify, i'd be using upcoming invoice and passing in this dummy customer id as well as coupon id to coupon param and priceId to invoice_items.price param?
just catching up here. you'll want to pass in a subscription, customer, and coupon. the price should already be associated with the subscription.