#xzel_api

1 messages ยท Page 1 of 1 (latest)

vestal lindenBOT
#

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

fathom etherBOT
#

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.

solemn charm
#

Hi, my current code looks like this:

forest halo
#

Exactly what I was about to ask!

solemn charm
#
      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
        }
      });
forest halo
#

And can you give me more specifics on what exactly is double what you are expecting?

solemn charm
#

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

forest halo
#

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?

solemn charm
#

The two products are 79 and 299

#

79: price_1PToEzI9XpkbIXSJ5xzabioU

forest halo
#

Do you have the ID of a specific subscription that you tested this with?

solemn charm
#

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

forest halo
#

Thank you, taking a look

solemn charm
#

Thank you as well

forest halo
#

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?

solemn charm
#

Yes

forest halo
#

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

solemn charm
#

You want the invoice object correct?

forest halo
#

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

solemn charm
#

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

forest halo
#

Ah I think what may be happening is that this is previewing if the prorations go on the next full invoice

solemn charm
#

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

forest halo
#

I think you just need to specify the proration behavior somewhere but I am still looking

#

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?

solemn charm
#

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

forest halo
#

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

solemn charm
#

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?

forest halo
#

I think amount_due would be the best field to use from the invoice to tell your user how much they will actually pay

#

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

solemn charm
#

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
          },
        }
      );
forest halo
#

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

solemn charm
#

Awesome, thanks.

#

I think that might be it then

forest halo
#

Glad I could help, let us know if you run in to anything else!