#queen-subscription-proration

1 messages ยท Page 1 of 1 (latest)

ashen boneBOT
lunar finch
#

queen-subscription-proration

#

@waxen thorn what you can do is calculate proration, create an InvoiceItem https://stripe.com/docs/api/invoiceitems/create for that amount and then update the Subscription to the new Price and create an Invoice for that specific proration to charge separately

waxen thorn
#

Thanks. I tryed this way. I created an invoiceItem but this item was added to the next invoice which is at next year. I want to charge immediately. Is there anything I can do ?

lunar finch
#

Yes you do exactly what I said above: Create the Invoice after to invoice the customer for that amount

waxen thorn
#

$stripe->invoiceItems->create([
'customer' => $user->stripe_customer_id,
'amount' => $firstTimePayment * 100,
]);

$subscription = $stripe->subscriptions->update(
$subscription->id,
[
'cancel_at_period_end' => false,
'proration_behavior' => 'None',
'items' => [
[
...
],
],
'metadata' => [
...
],
]
);

Like this ?

lunar finch
#

yes and no. That creates an InvoiceItem, then updates the Subscription. You never created an Invoice.

#

1/ the InvoiceItem should have subscription: 'sub_123' so that it's associated with it

waxen thorn
#

$stripe->invoiceItems->create([
'customer' => 'cus_9s6XKzkNRiz8i3'
'amount' => $firstTimePayment * 100,
'subscription' => $subscription->id,
]);

            $stripe->invoices->create([
              'customer' => 'cus_9s6XKzkNRiz8i3',
              'subscription' => $subscription->id,
            ]);

$subscription->update(...)

how about this ?

lunar finch
#

yes that should work, try it in Test mode end to end really!

waxen thorn
#

Sure, thanks

ashen boneBOT
waxen thorn
#

Hi, this create a draft invoice successfully but can I auto charge that invoice as well?

restive scaffold
#

Hey there

#

Stepping in as koopajah needed to step away

#

So you can hit the /pay endpoint if you want to charge it immediately

waxen thorn
#

$stripe->invoiceItems->create([
'customer' => 'cus_xxx',
'amount' => $firstTimePayment * 100,
'subscription' => $subscription->id,
'currency' => 'usd',
]);

$invoice = $stripe->invoices->create([
'customer' => 'cus_xxx',
'subscription' => $subscription->id,
]);

$stripe->invoices->pay($invoice->id);

like this ?

restive scaffold
#

Yep that looks good to me

waxen thorn
#

thanks. That works

restive scaffold
#

๐Ÿ‘