#verox_api
1 messages ยท Page 1 of 1 (latest)
๐ 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/1242438713053806603
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
This is how I create a subscription:
$subscription = Cashier::stripe()->subscriptions->create([
'customer' => $user->stripe_id,
'items' => [
[
'price_data' => [
'currency' => $currency,
'product' => config('cashier.products.server'),
'unit_amount' => $data['amount_due'],
'recurring' => [
'interval' => $data['metadata']['period'] == 'monthly' ? 'month' : 'year'
]
],
],
],
'expand' => ['latest_invoice.payment_intent'],
'proration_behavior' => 'none',
// Customer should have 7 days time to pay an invoice. The subscription should be 7 days longer than the period.
'billing_cycle_anchor' => Carbon::now()->addDays($data['metadata']['period'] == 'monthly' ? 30 - 7 : 365 - 7)->timestamp,
// Add metadata to the subscription invoices
'metadata' => [
'type' => 'server',
'name' => $data['metadata']['name'],
'egg' => $data['metadata']['egg'],
'memory' => $data['metadata']['memory'],
'disk' => $data['metadata']['disk'],
'period' => $data['metadata']['period'],
'default_allocation_id' => $data['metadata']['default_allocation_id'] ?? null,
'allocations' => $data['metadata']['allocations'] ?? null,
],
'currency' => $currency,
'collection_method' => 'charge_automatically',
'payment_behavior' => 'default_incomplete',
'payment_settings' => [
'save_default_payment_method' => 'on_subscription',
'payment_method_types' => config('cashier.charge.' . $currency),
],
]);
// Check if subscription is cancelled. Reactivate it.
$subscription = Cashier::stripe()->subscriptions->retrieve($data['subscription']);
if ($subscription->status === 'canceled' || $subscription->status === 'unpaid') {
}
And here is where I want to make the subscription active again.
hi! well paying the most recent invoice will move a past_due Subscription to active. But here the subscription is cancelled so that doesn't apply. You'd need to create a new Subscription
Oh, okay. But when the customer pays the subscription seven days after it cancelled, wouldn't these days be unpaid, if I just create a new subscription afterwards?
well in theory it's best to not get into this situation, by void-ing all open Invoices when the Subscription is canceled, so they can't be paid.
but yes in this case you'll have to figure out what you want to happen and how much/when to charge the customer again on the new Subscription object.
Okay, but I charge 7 days before the subscription actually ends, so there is enough time for bank payments to arrive. When the subscription is cancelled 7 days before the actual subscription ends, the customer would have paid for these 7 days, without actually getting to use them.
My plan is the following:
- An invoice is created, which the customer has to be to create a server.
- Once the invoice is paid, the subscription is being created with billing_cycle_anchor being 23 days into the feature, so the first invoice for the subscription is being skipped and the payment is requested 7 days, before the subscription actually should end.
The problem is that if the payment fails on the 23rd day, the subscription and server are cancelled. However the subscription should actually go on for an additional number of 7 days.
maybe change your Billing settings? Seems like you have it set up so the Subscription cancels after any payment failure at all.
I get this display in Test-mode
yes you need to switch to live mode since the settings are shared
These are my settings then:
What would I have to change there to make it work and leave the subscription 7 days active after failure?
"if all retries for a payment fail" change it to something else.
note that payments using SEPA Debit(which is what your example is using) never have any retries which is why with those settings you have immediate cancelation on failure
Yes, that's okay. In this case they should pay the invoice I sent via email.
I changed it to: "mark the subscription as unpaid"
Is that correct?
see https://docs.stripe.com/billing/subscriptions/overview#failed-payments for the documentation on what it means. Relevant to you : "Pay the most recent invoice before its due date to update the status of the subscription to active."
Alright, thanks. I'll have a look at it and come back at you after I've tested it.
@wheat fern Can I just leave billing_cycle_anchor out, because it's causing issues with the proration price calculation and instead just listen for invoice.upcoming and call pay() on the upcoming invoice?
hi! I'm taking over this thread.
Ah, hi soma! Thanks for your help!
instead just listen for invoice.upcoming and call pay() on the upcoming invoice?
The upcoming invoice is not a real invoice, so you won't be able topayit. you have to wait for the actual invoice to be created in order to pay it.
one solution is to just use a normal cycle and accept that the Subscription will be past_due for a few days at the start of each cycle, while the payment is processed
Okay, but then the customer would be able to use a few days for free, if the payment fails, right?
true
Hmhm, are there other alternatives to solve this issue?
Okay, but then the customer would be able to use a few days for free, if the payment fails, right?
that's true, but in most case the payment should succeed. so that's really an edge case.
Hmhm, are there other alternatives to solve this issue?
not really. one option would be to not use Subscriptions and manually create the Invoice, but that's a lot of work so I wouldn't recommend this.
Okay, that's probably why a lot of server hosters entitle their pricing schedule with the "fair-use-policy".
Yeah, we implemented manually last time and it was pure pain, but it worked quite well. But this time we want to have Stripe done the work ๐
Yeah, we'll probably leave it like this.