Reputation: 7515
There is a case in which a user can swap from a monthly subscription to an annual subscription.
This can be done using the following code:
$company->subscription('annual')
->withCoupon($couponCode)
->swapAndInvoice(1); // 1 is the quantity
This works, however what I have noticed is that it immediately invoices and charges the user at the same instant, which closes the invoice right away. This means that webhooks cannot modify the invoice to add line items such as tax.
I even modified swapAndInvoice
to make it so that payment is not made right away to allow for the invoice to have the usual ~1 hour modification period that Stripe allows for invoices. However, it still charges the user right away. I'm thinking this is because of the change from monthly to annual billing. But not sure.
//Stripe_Invoice::create(['customer' => $customer->id], $this->getStripeKey())->pay();
Stripe_Invoice::create(['customer' => $customer->id], $this->getStripeKey());
Any ideas are appreciated.
Stripe's own documentation says the following:
When a customer switches subscription plans in the middle of a billing period, here's what happens:
If the new plan has a different billing frequency from the old plan (for example, monthly to yearly, active to trialing, free to active, and so on)
The first full period of the new plan begins immediately (or after a trial period, as desired), and the customer is charged for the first period less the account balance.
Upvotes: 0
Views: 2686
Reputation: 17523
What you could do is create the invoice items you need before updating the subscription to switch to the new plan (the invoice that's automatically created will include all pending invoice items).
Alternatively, you could update the subscription with a very short trial period (i.e. set trial_end
to be a few seconds in the future). When the trial ends, a new invoice will be created but won't be closed immediately -- it'll be treated like a recurring payment, and the invoice will stay open for ~one hour before payment is attempted. The invoice.created
event will be sent to your webhook endpoint and you could add the invoice items you need then.
No sample code provided as I'm not familiar with Laravel Cashier, sorry!
Upvotes: 2