#enraged-camel_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always 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/1346243920258138223
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi there
You're right, the Subscription object tracks the items and discounts but all amount calculation is handled at the Invoice level
If your goal is to show the customer the latest amount due, I recommend looking at the Subscription's latest_invoice, and expanding this so you can inspect the full Invoice object: https://docs.stripe.com/api/subscriptions/object#subscription_object-latest_invoice
On the Invoice object, you can look at the total: https://docs.stripe.com/api/invoices/object#invoice_object-total
How does this work for accounts that are currently trialing?
Ah good question
For trial Subscriptions, I assume you'll want to show customers the amount of their upcoming Invoice
Correct
As a way to say "here's how much you'll pay once your trial ends" (assuming they have a card on file)
We have an endpoint for retrieving an upcoming invoice: https://docs.stripe.com/api/invoices/upcoming
Hmm, I could have sworn that this used to not work for subscriptions that are currently trialing - we have some code that prevents the endpoint from being called in that scenario. Did that change?
Let's see, give me a few minutes to test
Digging into whether that's changed but I was just able to use the upcoming invoice endpoint to retrieve the next non-zero invoice for a customer who's in trial
OK, here's the error (for a customer who has not yet provided a payment method):
{:error, "The subscription will pause at the end of the trial instead of generating an invoice because the customer has not provided a payment method and trial_settings[end_behavior][missing_payment_method] is set to `pause`."}
So we cannot rely on the upcoming invoice endpoint
Hm, that's slightly different but I see what you mean
As we do not collect payment info upfront. We use various discounts to encourage the customer to do so, but we need to also show them the preview of what they would pay
Can you share the Subscription ID or the Customer ID you're working with?
In test mode, it is this one: sub_1QyhetKvt64dqOba1TNMBMj6
That one is brand new - no coupons or anything, and no payment method
Huh, that's so strange
If you make the same call to retrieve the upcoming Invoice for Customer cus_RsSabLMGiKuroO but omit subscription in your request, you won't receive an error
But if we omit the subscription, and the customer has multiple subscriptions (which is possible in our case), what will the endpoint return?
Got it, not ideal. If you omit subscription and just pass customer, we'll return the next upcoming invoice from their list of Subscriptions (so the one that's set to renew soonest). The response will still include a subscription property so you'll know which Subscription it corresponds to but still not ideal
Let me do a bit more testing
I think what we need is some sort of review_hypothetical_invoice endpoint that works similar to upcoming_invoice but works for all subscriptions ๐
It is the end of the day for me so I need to go. Will try to follow up tomorrow. Thank you
Looks like we return a similar error for the create a preview Invoice endpoint: https://docs.stripe.com/api/invoices/create_preview
Bummer
I'm not seeing a way to be able to do this while the Customer is missing a PaymentMethod and the Subscription is set to pause at trial end
A workaround is to create a preview or get an upcoming Invoice without specifying a Customer. What you'd do instead is pass in all relevant attributes that would apply to the customer in question (i.e., address details under customer_details if tax is involved, line items, any discounts)
Hello! Taking over... yeah, I agree it's probably easier to do this on your end given these conditions.
One more question, unrelated: we have a product with multiple prices: one on the monthly billing cycle and another on the annual billing cycle. We are creating coupons, and see that we can have the coupon apply to specific products - however, we don't see how we can make it apply to specific prices in the products