-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subscription gets renewed while ended #233
Comments
Hi @voicecode-bv , What package version are you using? |
Hi @sandervanhooft, We're on v2.11.0 currently |
I was able to narrow it down. When doing some more research, I noticed this happens when for whatever reason a payment fails (chargeback, refund, revoked mandate, etc). We listen to such events using the class below. In both cases we won't retry the payment for obvious reasons. Is this a glitch in the cancelNow() method maybe?
|
Hi @voicecode-bv, I am currently looking into this. So far I wasn't able to find anything odd regarding the |
@voicecode-bv I've tested the setup locally and also listened to It's odd. The exception you describe is only triggered when a new
Do you call any of this methods in your code? |
@Naoray thanks for your efforts so far, appreciate it! I only use the cancelNow() method, as you can see in my previous post. |
@voicecode-bv maybe you use a custom It's hard to find the cause for this without having all the details of the config you use or any custom models. |
@Naoray I fully understand, here you go: In AppServiceProvider:
CashierPlanHelper.php
Subscription.php (model)
Plan.php (model)
|
I am sorry @voicecode-bv, I still don't know why you experience this glitch on your side. 🙈 Do you have any observers or other code snippets that interact with the Some findings that you might be interested in:
Neat! But be aware that this could break in future releases when we add the return types to those methods! You should add the use Laravel\Cashier\Order\OrderItemPreprocessorCollection as Preprocessors;
$plan
//...
->setOrderItemPreprocessors(Preprocessors::fromArray(config('cashier_plans.defaults.order_item_preprocessors'))); another small optimisation... class ExpireSubscription
{
/**
* Handle the event.
*/
public function handle(ChargebackReceived|RefundProcessed $event)
{
// When refund received.
if ($event instanceof RefundProcessed) {
// Get user and expire subscription immediately.
$this->expireSubscription($event->refund->owner_id); // owner is a relation
}
// When chargeback received.
if ($event instanceof ChargebackReceived) {
// Get user and expire subscription immediately.
$this->expireSubscription($event->payment->owner); // owner is a relation
}
}
/**
* Expire a subscription with immediate effect.
*/
public function expireSubscription(User $user)
{
$user->subscription('main')->cancelNow();
}
} |
Thanks for all your efforts @Naoray, really appreciate it! For now I've manually updated the database records so cashier:run no longer crashes. Let's see if it was just a sort of "one-time-glitch". Also, thanks for the suggestions, I've implemented them accordingly. Maybe you can change the $event->refund->owner_id to $event->refund->owner too in your comment for other people reading this topic in the future? Cheers! Michael |
Thanks @voicecode-bv, I'll close the issue for now. Feel free to open it if you have further insights or the problem appears again! |
Hi @Naoray, I'm reopening this as we still having issues. I found a good example: We have this customer that has an active subscription, but because of his credit card has insufficient fundings, the renewal has failed. We receive a webhook from Mollie and we will cancel the subscription immediately using the cancelNow() method. What I see happening is that the subscription is actually being cancelled. Comparing the timestamps with the webhook timestamp from Mollie it's all looking just fine. Here we have the record in the orders table of which the payment has failed: I would expect the order items that are scheduled would be removed from the database, but as you can see, record 138182 still exists. This record is the reason cashier:run crashes, it thinks the subscription is still active because of that scheduled order item. Update: |
Hi @voicecode-bv, I am trying to understand what happened here. What I noticed is that prior subscription cycles went from 15th to the 15th of the next month and according to your timestamps shown in the screenshot they were updated on the 15th as I would expect. Then starting with Following the data, that leads me to believe that there was an Another thing that is odd to me is that the Another thing that doesn't match my expectation is the
When a payment fails the |
Hey everyone, We also experienced the same behaviour when a payment fails: Sometimes a payment of a customer failes due to an invalid mandate and gets cancelled immediately. So far so good. But when the customer updates his mandate, we have the following listener: public function handleMandateUpdated(MandateUpdated $event)
{
if ($event->owner->validMollieMandate()) {
$event->owner->retryFailedOrders();
}
} This should automatically retry all failed orders when the mandate is restored. And in maybe 1/1000 cases the As a workaround we periodically search for subscriptions with no Thanks for your effort! Mike |
Hi team,
To be honest, I'm not sure if this is an actual bug in the package, but there's something weird going on. For a number of days I'm facing quite a lot of issues with subscriptions that seem to be be cancelled, but the cashier:run command is still trying to renew it, which causes an error
src/Subscription.php:552 - Call to a member function format() on null
(it's about the from value)
The cycle_started_at timestamp is NULL because on line 542 it's being set to the current cycle_ends_at timestamp which is NULL.
In the database I see:
cycle_started_at = 2024-04-10 21:23:10
cycle_ends_at = NULL
ends_at = 2024-03-14 13:48:41
To cancel a subscription we simply use:
How is it possible that the cycle_started_at timestamp is a date after the ends_at timestamp?
The text was updated successfully, but these errors were encountered: