#abishek-proration

1 messages · Page 1 of 1 (latest)

keen vault
#

@lucid marsh you should be able to use the upcoming invoice endpoint (https://stripe.com/docs/api/invoices/upcoming) for that, like preview the update and set subscription_proration_date to the current time, the response will contain the line items for proration

lucid marsh
#

ok, thank you let me try that. Appreciate it

#

can I get back to you on this thread if I have any other questions regarding this before you close it

keen vault
#

sure

lucid marsh
#

is amount_due /amount_remaining the value that indicates what is the prorated amount?

keen vault
#

no

#

the prorated amount is in the lines

lucid marsh
#

but the line item on the invoice object is set to false

keen vault
#

can you share the exact JSON response you are looking at?

lucid marsh
#

The above response is from a test environment

keen vault
#

looks like the change you made didn't require any proration!

#

maybe share the exact code you're using to call the endpoint as well so we can see what parameters you passed.

lucid marsh
#

ok, my proration behavior is set to always_invoice is this why I don't see it prorating?

#

Here is the code I use to update my current subscription

POST /v1/subscriptions/sub_1Jsi3KF0Vcy0LXqEeNvNceZQ

{
  "items": {
    "0": {
      "plan": "price_1JVe0LF0Vcy0LXqEREx14T3f",
      "quantity": "1"
    },
    "1": {
      "deleted": "true",
      "id": "si_KYehYt3R7tW43c"
    }
  },
  "payment_behavior": "error_if_incomplete",
  "proration_behavior": "always_invoice",
  "expand": {
    "0": "latest_invoice.payment_intent"
  },
  "cancel_at_period_end": "false",
  "trial_end": "now"
}
#

Here is the code I am using to get the upcoming Invoice to get the prorate value

return \Stripe\Invoice::upcoming(
            [
                'customer' => $this->stripe_id,
                'subscription' => $this->subscription('default')->stripe_id,
                'subscription_proration_date' => time()
            ],
            $this->stripeOptions()
        );
keen vault
#

yeah that call doesn't do anything

#

it's just getting the next invoice.

#

you have to pass details of the change you're making, using the subscription_items parameter to Invoice::upcoming

#

like pass the items that you have in that call you mentioned above(where you delete one item and add a new one, if that is what it is doing)

lucid marsh
#

ah, that is going to be tricky to pass that, because the new change isn't going to be a subscription item but an invoice item. I am basically trying to find what is the value pending as of today before a user can switch to a lifetime plan, so I can only invoice them for the difference. Since Stripe doesn't have the option to do this.

#

so if a user paid $149 on 5th Nov for the yearly plan and wants to switch to $399 lifetime plan, I am just trying to figure out what is the used amount from 5th Nov to today, (lets say $5), then I only charge $399 - ($149 - $5)

#

just trying to see if there is a way to figure $5 amount from stripe

#

let me know if it makes sense

#

I want to get that value before I cancel the current subscription.

#

can you advice what is the best way to do this?

#

offering a refund evertime is going to affect the rate of my account which is why I am trying to find the prorate difference

keen vault
#

if you preview the change it will be one of the proration items

#

so if you pass a subscription_items where you move to the lifetime plan(or any plan, you just want to preview removing the existing one), you will see in the response a line that is proration:true and has a description like "Unused time on Yearly Plan", which would be ($149-$5) so you can calculate $5 from that

#

sorry, I have to get lunch, can't reply any more

lucid marsh
#

but the lifetime plan is not a subscription, its a onetime fee

keen vault
#

my colleague can help

#

then I don't think you can really do this or it make sense, but I'll let my colleague take over

lucid marsh
#

ok

ashen snow
#

Sincere apologies for not getting here sooner, getting caught up.

#

Ah, this is a really interesting scenario, please bear with me while I think through it.

lucid marsh
#

hey @ashen snow , thanks. been at this for the last few days to see what is the best way to do this

#

I know there is a lot of devs who have reinvented the wheel to do this, but I wanted to keep that the last and see what best I can achieve with what stripe has before I can build my own stuff

#

I just need to figure out what amount the subscription has used or what is pending on the customers account that can be taken into consideration when upgrading to a one time price plan from recurring

#

@paper gulch, @ashen snow seems away from the room, any chance you can help me with this?

#

Please, let me know if you have any questions

#

actually I think I figured out a way, can you please let me know if it is right?

paper gulch
#

How are you going to make this switch? Cancel the subscription?

lucid marsh
#

Yes, I am going to cancel the subscription and then invoice for a one time price plan on the Product

#
        return \Stripe\Invoice::upcoming(
            [
                'customer' => $this->stripe_id,
                'subscription' => $this->subscription('default')->stripe_id,
                'subscription_cancel_at' => time() + 1
            ],
            $this->stripeOptions()
        );
paper gulch
lucid marsh
#

I am using subscription_cancel_at instead of subscription_proration_date. This gives me the following response on the invoice line item

   Stripe\InvoiceLineItem {#5493
           +saveWithParent: false,
           id: "il_tmp_1JtaMmF0Vcy0LXqE5PTSOBnN",
           object: "line_item",
           amount: -1892,
           currency: "usd",
           description: "Unused time on BB Binge Video Subscription after 08 Nov 2021",
           discount_amounts: [],
           discountable: false,
           discounts: [],
           invoice_item: "ii_1JtaMmF0Vcy0LXqE5PTSOBnN",
           livemode: false,
           metadata: Stripe\StripeObject {#5498},
           period: Stripe\StripeObject {#5499
             end: 1638968744,
             start: 1636387600,
           },
           plan: Stripe\Plan {#5503
             +saveWithParent: false,

so the amount -1892 is the amount that I need to subtract from the lifetime plan on the invoice right?

#

is this correct?

paper gulch
#

Maybe, not sure what your business needs are

#

does the amount seem right to you?

#

That's the credit for the unused time from Nov 8 to end of paid cycle

lucid marsh
#

correct. actually the amount doesn't seem to be right, is there a way to see on the Stripe Web UI, what is the credit amount that I owe for the customer. Lets say the customer subscribes to a $149 plan and then downgrades to a $19 plan. The system owes the customer $130.

#

Is this the amount upcoming would show?

#

what happens to $130, will it still be in the system and stripe will automatically prorate this amount for the next 9 months without charging the customer?

#

actually something is definitely wrong. For some reason, when I try to subscribe the customer to $149 recurring plan, it does show on stripe that the customer is on the $149 plan, but the payment received is only $19

#

Is there a way to check why this is happening?

#

could you help me understand what is going on here?

#

All previous payments have already been refunded before subscribing the customer to the new plan

#

Here is the request to create the subscription

POST /v1/subscriptions

{
  "customer": "cus_KV22RXNgG2Udwq",
  "expand": {
    "0": "latest_invoice.payment_intent"
  },
  "items": {
    "0": {
      "price": "price_1JVe0LF0Vcy0LXqEaD1eFMAs",
      "quantity": "1"
    }
  },
  "payment_behavior": "allow_incomplete",
  "proration_behavior": "create_prorations",
  "off_session": "true"
}

and here is the response

#

the response does show the the pricing plan is for $149, but the latest invoice show a charge of $19

#

@paper gulch any chance you can look into this?

paper gulch
#

Yep looking

#

Its because you're re-using a test customer with a balance from prior invoice/subscription adjustments

#

I'd suggest testing with a new customer to avoid this and ensure its working like you expect

#

Customer balances will change the amount of the payment

#

look at the actual invoice though and you'll see its correctly $149

#

but $130 of credit is applied

lucid marsh
#

where can I find the credit for the customer? is that something there on the Stripe UI?

paper gulch
#

Yes, look at the customer in your dashboard, or you cna use the customer balance api

#

If you want to re-use a test customer without this effect you shoudl ensure you clear their balance

lucid marsh
#

ok

#

when using upcoming will the number of lines on the Invoice returns always be 1 or can there be more?

paper gulch
#

There can be many lines, it depends on the parameters you send and the current state of the invoice/subscription

lucid marsh
#

is there a good way to filter only the line item that has the Unused time frm the collection?

fleet fractal
#

hello, just catching up here, you would need to look at the line items returned on the UpcomingInvoice

lucid marsh
#

how can I get the credit balance for a customer?