Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

raphadko's avatar

Cashier - How to execute a function once, when account expires?

I'm using Cashier on my application.

Cashier has a simple way of verifying if the user is subscribed:

$user->subscribed();

Cashier stores on the users table a field "stripe_active" to check if the user has an active subscription. Now, I'm trying to do something kinda simple, but didn't find in the documentation.

When the user subscription expires, I want to run a function that will disable some stuff on his account and save it to the database. I don't want to check and run it at every login , I want it to fire only once, when the account expires.

Stripe has a webhook that does that when payment fails. But I did not find one when the account expires. Can someone help out?

0 likes
2 replies
raphadko's avatar

So I looked into Cashier's StripeGateway file, which has this function :

public function cancel($atPeriodEnd = true)
{
    $customer = $this->getStripeCustomer();

if ($customer->subscription) {
    if ($atPeriodEnd) {
        $this->billable->setSubscriptionEndDate(
            Carbon::createFromTimestamp($this->getSubscriptionEndTimestamp($customer))
        );
    }

    $customer->cancelSubscription(['at_period_end' => $atPeriodEnd]);
}

if ($atPeriodEnd) {
    $this->billable->setStripeIsActive(false)->saveBillableInstance();
} else {
    $this->billable->setSubscriptionEndDate(Carbon::now());

    $this->billable->deactivateStripe()->saveBillableInstance();
} 
}

Now it appears that when the account is canceled, two functions run - cancelSubscription and deactivateStripe. I didn't find a documented way to run something on account expire, so I figured I might have to extend these methods and run it myself, but I'm a bit lost on how to do it.

vengiss's avatar

You could create a cron job that runs once a day and check for all expired accounts and then run the functionality you need on them.

Please or to participate in this conversation.