#alexelba

1 messages ยท Page 1 of 1 (latest)

brazen lionBOT
#

Hello! We'll be with you shortly. 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.

fringe wasp
remote quiver
#

Hm, still digging

#

Are you sure that's the right response for request req_ROYUZLsbvjGjm5?

fringe wasp
#

yup ๐Ÿ˜ฆ $totalUpcomingInvoice = \Stripe\Invoice::upcoming([
'customer' => $accountPaymentProvider->vendor_id,
'subscription' => $accountMembership->vendor_subscription_id,
'subscription_items' => $new_phases,
'subscription_proration_behavior' => 'none'
]);
var_dump($totalUpcomingInvoice);

#

basically call and dump

#

the same items, if I do 'subscription_proration_behavior' => 'create_prorations' it will change it and do calculations correctly

remote quiver
#

Interesting, okay.

fringe wasp
#

should I do proration none or always_invoice if I want to get full amount

#

I thought none will do it, but maybe I should switch to always_invoice?

#

homm nope that did not work

#

if I do always_invoice, it should prorated value

#

instead of full

remote quiver
#

Before we dig into prorations and what the value should be here, let me make sure I understand what you're trying to do

fringe wasp
#

540x50=27000

remote quiver
#

Given an existing subscription that currently has a single line item (for a quantity of 100 at a price of 168) , you want to update that item to a quantity of 50 at a price of 540.

fringe wasp
#

yup

remote quiver
#

Do you want to create prorations for any unused time on the old and new price?

fringe wasp
#

nope, I want to show them what will be there next full invoice amount

#

this why trying to use upcoming invoice end point

#

Thank you for upgrading your full amount will be $X dollars starting N days

#

Prorated charge(s) for the remaining 363 days in your billing cycle.
You're changing to Enterprise. We'll charge you $10121.48 now, which is prorated for the current billing period. Starting on November 15, 2024 and until you cancel, we'll bill you once a year and your new yearly total will be $10121.48. If you cancel, previous charges won't be refunded unless it's legally required. We'll charge your credit card.

#

new yearly total is wrong

#

$10121.48. when I try to do always_invoice

#

and it 8400 when I do none

#

should I switch the line_item id

remote quiver
#

I'm looking into why the upcoming invoice response you receivd still has the old price ID (price_1OCZQuHxrjf17jEDtQ9QRsxd)

fringe wasp
#

and why if I turn proration on it works

#

I am gonna run this two calls one with proration one without

#

$new_phases = array_map(function ($item) use ($membership_plan, $stripePrice, $payment_seat_count) {
'price' => $item->price->product == $membership_plan->membership_plan_id ? $stripePrice->id : $item->price->id ,
'quantity' => $item->price->product == $membership_plan->membership_plan_id ? $membership_plan->license_count : $item->quantity
];
}, $stripe_subscription->items->data);

                                                $upcomingInvoice = \Stripe\Invoice::upcoming([
                                                    'customer' => $accountPaymentProvider->vendor_id,
                                                    'subscription' => $accountMembership->vendor_subscription_id,
                                                    'subscription_items' => $new_phases,
                                                    'subscription_proration_behavior' => 'create_prorations'
                                                ]);

                                                vvar_dump($upcomingInvoice);

                                                $totalUpcomingInvoice = \Stripe\Invoice::upcoming([
                                                    'customer' => $accountPaymentProvider->vendor_id,
                                                    'subscription' => $accountMembership->vendor_subscription_id,
                                                    'subscription_items' => $new_phases,
                                                    'subscription_proration_behavior' => 'always_invoice'
                                                ]);
                                                vvar_dump($totalUpcomingInvoice);
#

only difference between this two calls is proration

remote quiver
#

Okay, I follow that you passed create_prorations for the first call so you should see two line items: a credit for the remaining time on $168 and a charge for the remaining time on $540

#

For the second call, there's also unused time for both the old and new price

fringe wasp
#

1st call makes sense

#

2nd and 3 does not

#

basacally I want to show user how much will they be charged next time if they change to 50 and 540

#

what do you think will be best way to do so

remote quiver
#

The third call is what's stumping me

fringe wasp
#

I am probably doing something wrong, but not sure

#

I try looping and adding line item amounts, but they are not correct either

remote quiver
#

Give me a few minutes please!

#

I'm trying to reproduce on my end but I'm able to retrieve an upcoming invoice with the correct new price, new quantity, without prorations

safe abyss
#

@fringe wasp Can you quickly try to

  1. Fetch the upcoming Invoice
  2. Update the Subscription for real
  3. Fetch the upcoming Invoice again

I want to see if at #3 you get the right Price id

fringe wasp
#

ok let me do it one need to add logic for update ๐Ÿ˜„ it not implemented yet . brb in 15 minutes

safe abyss
#

Like your current code is logging the upcoming Invoice multiple times and I worry you're maybe mixing up the responses

fringe wasp
#

dumps are right after the call, so should not be, I wander is it because there is subscription_schedule

#

attached to subscription

#

it makes it show wrong value

safe abyss
#

I'm fairly certain that's impossible

#

Let me just give you a simple end to end script

fringe wasp
#

so scenario I am testing now, is this client had 100 subscription and they change seat count to 50, which is scheduled end of the term

#

before end of the term they come in and upgrade their account from 50 basic to 50 enterprise

safe abyss
#

wait

#

your Subscription has a Schedule attached?

safe abyss
#

ah yeah so upcoming Invoice works a bit differently with a schedule

fringe wasp
#

how should I do it show the client what will be their next total bill

safe abyss
#

sorry I think we didn't realize you had a Schedule that completely changed the logic. I'm not even sure you can do this today. We're looking but will take a while

fringe wasp
#

I mean I can do manually get the price and qunaitty and do math without using stripe

#

๐Ÿ˜„

brazen lionBOT
fringe wasp
#

but I am not sure if stripe will charge that amount or wrong one

amber helm
#

๐Ÿ‘‹ I'm hopping in to take a look as well - give me a minute to catch up

fringe wasp
#

summary Subscription $168 -> 100, Schedule create to change to ->50 in the end of the billing period, before next billing period client comes upgrades this 50 from 168 to 540 per month. I want to get next full amount 27000

safe abyss
#

I'm super confused by your summary lol

#

what is ->100 ->50 -> 168 to 540

fringe wasp
#

$168 -> 100seats

#

schedule created to change

safe abyss
#

yeah sorry please pause for a sec

fringe wasp
#

$168 -> 50 seats

safe abyss
#

Write a clear summary all in one message with exact dates and transition + price amount + price id and dates of the change so that we understand the full timeline

fringe wasp
#
  1. November 2023 Subscription created: $168 yearly -> 100 seats Next Billing Period Feb 12, 2024
  2. November 2023 Subscription schedule created to update after Feb 12, 2024 $168 yearly -> 50 seats
  3. November 2023 Subscription updated is going to happen and upcoming invoice requested without proration: $540 yearly -> 50 seats (27000)
safe abyss
#

why is the next period Feb 12 if it's a yearly Price?

fringe wasp
#

copy wrong field

#

should be nov 14th

#

did not read the value ๐Ÿ™‚

safe abyss
#

Okay so as far as I can tell, what you're doing is previewing the Subscription's next Invoice which would be when the second Phase starts right? Whatever you pass in subscription_items is irrelevant because you're doing no proration at all and you'd be modifying the current phase. And the Invoice we simulate is next year's Nov 15 2024 - Nov 15 2025 which is still on the Price A price_1OCZQuHxrjf17jEDtQ9QRsxd

fringe wasp
#

I am trying to modify items -> $totalUpcomingInvoice = \Stripe\Invoice::upcoming([
'customer' => $accountPaymentProvider->vendor_id,
'subscription' => $accountMembership->vendor_subscription_id,
'subscription_items' => $new_phases,
'subscription_proration_behavior' => 'none'
]);

safe abyss
#

that switch would be only on the current phase though.

fringe wasp
#

what are my correct steps, if I want it work?

safe abyss
#

Right now we're still unclear what you are asking unfortunately

fringe wasp
#

I just want to get next total bill client will be charged if they upgrade now

safe abyss
#

My understanding is this
You have a Subscription that has 2 phases
Phase 1: Nov 15 2023 - Nov 15 2024 on Price A and quantity X
Phase 2: Nov 15 2024 - Nov 15 2025 on Price A and quantity Y

Now on Nov 16 you decide to switch their current phase to Price B and quantity Z. This only applies to the current phase Nov 15 2023 - Nov 15 2024
You are disabling proration entirely so really they would be on Price B with quantity Z moving forward without paying anything

Then at that point you're saying "show me the next Invoice" which would be on Nov 15 2024 (next year). At that point the second phase come into play and switches the customer to Price A and quantity Y

Your change isn't "propagating to future Phases" because the whole point of the SubscriptionSchedule API is to plan future sequential changes to the Subscription

So when you get "price A back" it's totally normal and not a bug

fringe wasp
#

how can I pass subscription schedule to upcoming without applying it

safe abyss
#

impossible ๐Ÿ™‚

fringe wasp
#

only way I see is doing math manually on my side

safe abyss
#

The Schedules API is quite complex and we unfortunately do not support the ability to pass all the phases today

#

My advice when debugging things like this: always use different Price ids and quantities for each parts so that it's easy to see what happens in the response

fringe wasp
#

I was testing use case where quantity stays the same after downgrade ๐Ÿ™‚ but plan gets upgraded

#

need to talk with product person maybe there is something we can do

safe abyss
#

yeah I get that but when stuck it's best to temporarily try with completely different values so taht you can more easily reverse-engineer the situation

fringe wasp
#

like when is upgrade really upgrade

safe abyss
#

yeah

#

Also random but function stripeDump($obj, $extraString = "") { echo "$extraString<br><pre>\n" . json_encode($obj, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES) . "\n</pre><br>"; }
I use this to pretty print Stripe objects in PHP

#

you can do stripeDump($invoice, "My upcoming Invoice"); and it pretty prints for you better than var-dump

fringe wasp
#

thanks

#

for function

#

does stripe have any definition of upgrade , I can send to my product person

safe abyss
#

I don't really get what that question could mean unfortunately

fringe wasp
#

like when is subscription considered upgraded

#

this one if you have 168 changed to 540 it will upgrade, at the same time if 168 was 1000 but 20 540

#

it is really a downgrade

#

anyway its not really stripe problem more business