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

dany68's avatar
Level 15

Monthly user virtual credits

Hi everyone,

Can someone help me a bit to implement the following with Cashier for stripe ?

Here is the scenario:

There are 3 plan levels. Each plan has a monthly or yearly interval. I want to add virtual credits to a user every month (even if he selected a yearly interval) depending on the plan he selected.

  • In case a user downgrade to a lower plan, he must keep the higher level plan until the end of the cycle and will not get additional credits until a new cycle start. However if he upgrade to a higher plan he should receive the additional credits immediately (along the additional features).

  • In case a user stay on the same plan but change the interval, everything should stay the same and receive credit every month.

Current options:

  • Use the webhook on SubscriptionRenewed and SubscriptionUpdated, but it will not work correctly with yearly subscription.
  • Create a daily cron job that will check active subscription and the cycle start date to add credits. But this solution might be not really performant as it will check everyday for every subscribed user.

Thanks for your help,

0 likes
1 reply
LaryAI's avatar
Level 58

To implement a system where users receive virtual credits based on their subscription plan using Laravel Cashier for Stripe, you can follow these steps:

  1. Define Your Plans and Credits: First, define the number of credits each plan should provide monthly. This can be stored in a configuration file or a database table.

  2. Handle Subscription Changes: Use Stripe webhooks to handle subscription changes. Specifically, you can listen to invoice.payment_succeeded for monthly credit allocation and customer.subscription.updated for plan changes.

  3. Implement Webhook Logic: Create a webhook controller to handle these events. You can use Laravel's built-in webhook handling capabilities.

  4. Daily Cron Job: While a daily cron job might seem inefficient, it can be optimized. You can run a job that checks only users whose subscription cycle is due for credit allocation.

  5. Code Implementation:

    • Webhook Controller:

    • Cron Job:

      You can set up a daily cron job to check for users whose subscription cycle is due for credit allocation. This can be done by checking the created_at or updated_at fields of the subscription.

  6. Register Webhooks: Ensure that your Stripe account is set up to send webhooks to your application. You can do this in the Stripe Dashboard under Developers > Webhooks.

  7. Testing: Test your implementation thoroughly to ensure that credits are allocated correctly and that plan changes are handled as expected.

By using a combination of webhooks and a cron job, you can efficiently manage credit allocation while handling plan changes appropriately.

Please or to participate in this conversation.