#xzel_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/1265029210825556090
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- xzel_customerportal-upgrade, 3 days ago, 109 messages
Hi, my current code looks like this:
Exactly what I was about to ask!
const previousSubscription = await stripeClient.subscriptions.retrieve( key.subscriptionId );
request.log.info({ previousSubscription }, 'Previous Subscription.');
// const prorationDate = Math.floor(Date.now() / 1000);
const items = [{
id: previousSubscription.items.data[0].id,
price: STRIPE_AGENCY_PRICE_ID
}];
const invoice = await stripeClient.invoices.retrieveUpcoming({
customer: user.stripeCustomerId,
subscription: key.subscriptionId,
subscription_details: {
items
},
// subscription_proration_date: prorationDate,
automatic_tax: {
enabled: true
}
});
And can you give me more specifics on what exactly is double what you are expecting?
Yeah so simply the results I'm getting are like this:
Your final total will be 550.13
Tax: 31.14
Subtotal: 550.13
which is from this http response
return reply.code(200).send({
status: 'success',
data: {
total: invoice.total / 100,
tax: invoice.tax / 100,
subtotal: invoice.amount_due / 100,
// prorationDate: prorationDate
}
The code I have to do the actual subscrption upgrade seems to be working fine already
We have had to abandon the billing config because we cannot allow downgrading
Can you send me the price ID that you are using for these tests?
And to be clear, that preview says $550 but when you actually do the upgrade it costs roughtly $225?
Do you have the ID of a specific subscription that you tested this with?
299: price_1PTpTsI9XpkbIXSJ27eJ9kML
sub_1PfQPrI9XpkbIXSJveezdEmz
probably
would have done it correctly with the upgrade code
and then you could use sub_1PfRfkI9XpkbIXSJsLeV1KDQ which is currently at the cheaper price
Thank you, taking a look
Thank you as well
Yeah I am not sure why that may be the final calculation. Can you make the preview call on that subscription again, print out the full object that the API sends back to you, and paste the text of that output here?
Yes
One thing I thought of is that that Customer might have extra pending invoice items that were getting added to the invoice but that does not appear to be the case for this customer
You want the invoice object correct?
Yep yep
I can see that you are making the call right but I can't see the response that we send back to you for that call
It seems to be adding the more expensive item to the line items twice
Its possible its not prorating it correctly and then its doing this years + next years
Ah I think what may be happening is that this is previewing if the prorations go on the next full invoice
and I just need to make sure to pull out the data from line item #2, but that just doesn't seem very straight forward
I think you just need to specify the proration behavior somewhere but I am still looking
Can you try that call again but specify subscription_proration_behavior='always_invoice' https://docs.stripe.com/api/invoices/upcoming#upcoming_invoice-subscription_proration_behavior
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I think that should solve the issue of the overall total.
Question, when you say you just need data from line #2, is there a reason that line #1 with the credited time is not also relevant here?
lol yep its literally jsut that...
That page needs to be updated ๐
subscription_details: {
items,
proration_behavior: 'always_invoice'
},
that should be the correct one for the newer API
looks like all the subscrption based things got put into that area
Yeah it is tricky, I think create_prorations is the default behavior for the update method as well so that is what the preview endpoint defaults to
yeah you're right
im reading through the typescript stuff now
Okay I think I have one follow up
Your final total will be 233.18
Tax: 13.2
Subtotal: 219.98
well 2 I guess
Total = subtotal + tax correct?
And then second question, for doing the actual upgrade, is there an invoice # or something I can check to see if the payment went through?
From our API ref for subtotal:
Total of all subscriptions, invoice items, and prorations on the invoice before any invoice level discount or exclusive tax is applied. Item discounts are already incorporated
https://docs.stripe.com/api/invoices/object#invoice_object-subtotal
I think amount_due would be the best field to use from the invoice to tell your user how much they will actually pay
And for question #2, you can check the invoice's status to see if it is paid. The invoice has two numbers, one that begins with in_ and is how the API refers to the invoice, there is also a user-facing one that starts with #
https://docs.stripe.com/api/invoices/object#invoice_object-id
https://docs.stripe.com/api/invoices/object#invoice_object-number
You can use whichever to track and display things in your integration but the ID (in_1234) is definitely the important one to keep for API purposes at least.
Also definitely listen to the invoice.paid event if you are not already as that will notify you about these payments as they are being made
Ah so I'm talking about getting the info from this call
const subscription = await stripeClient.subscriptions.update(
key.subscriptionId,
{
items: [
{
id: previousSubscription.items.data[0].id,
price: STRIPE_AGENCY_PRICE_ID
},
// {
// id: '{{SUB_ITEM_ID}}',
// deleted: true,
// },
],
proration_behavior: 'always_invoice',
payment_behavior: 'error_if_incomplete',
automatic_tax: {
enabled: true
},
}
);
Gotcha. Yes, that will create a new invoice and you can get it's ID by checking the latest_invoice property on the subscription object that you get back
Though if you do want that number, you can expand latest_invoice when making that update and get the full invoice object https://docs.stripe.com/api/expanding_objects
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Glad I could help, let us know if you run in to anything else!