Billing combine recurring charge and usage charge

Hello everyone, I’m facing some issue with billing API

My app is combine recurring plan and usage plan following docs here , But I’m facing with one problem, when shopify automatic charge successfully, my app need to remove old usage records of last month, but now I can find anyway to implement this, the webhook APP_SUBSCRIPTION_UPDATE not fired in this case.

Please help me some solutions for this?

Thanks in advanced guys.

Hi Danhho,

The APP_SUBSCRIPTION_UPDATE webhook doesn’t fire when a charge is successful, it only fires when a subscription is updated (for example, if a user changes their plan or cancels their subscription).

Unfortunately, there isn’t a direct way to delete usage records through the Shopify API once they have been charged. Usage records are typically used for tracking and therefore Shopify doesn’t provide a way to delete them via the API.

However, you can create a system on your end to ignore the usage charges of the previous month. You can do this by storing the date when the charge was made and then compare this date with your usage records. This way, you can “ignore” the usage records of the previous month by not including them in your calculations.

Remember to always keep track of your usage records on your end, so you have a backup of your data and can handle situations like this more easily. Hope this helps!

Hi @Liam , thanks for your advise, I store records of usage plan in my database it included date field
But now how can I know the current date (maybe next_billing_date if I right) of recurring plan? now I have a plan like this:

{
    "recurring_application_charge": {
        "id": xxxxxx,
        "name": "Silver",
        "price": "99.90",
        "billing_on": "2023-09-15",
        "status": "active",
        "created_at": "2023-09-14T23:41:14-04:00",
        "updated_at": "2023-09-14T23:41:42-04:00",
        "activated_on": "2023-09-15",
        "return_url": "xxxx",
        "test": true,
        "cancelled_on": null,
        "trial_days": 0,
        "trial_ends_on": "2023-09-15",
        "api_client_id": 53565095937,
        "decorated_return_url": "xxxx",
        "capped_amount": "500.00",
        "balance_used": 1.0,
        "balance_remaining": 499.0,
        "risk_level": 0.0,
        "currency": "USD"
    }
}

Can I use billing_on field to compare with old usage record in my database?
Field billing_on will update if shopify charge success in last month?
Example: my current billing_on is 2023-09-05, and 30 days pass and they are charged again, now billing_on will update to 2023-10-05?

Hi again Danhho,

Yes, you can use the billing_on field to keep track of when the next billing cycle will occur. This field indicates the date of the next charge that is scheduled to be made to the customer.

In a recurring billing setup, Shopify will update the billing_on field to reflect the date of the next scheduled charge each time a successful charge occurs. So, if the current billing_on date is “2023-09-05” and the charge recurs every 30 days, after a successful charge, it should update to “2023-10-05”.

To ensure that you are correctly tracking and managing billing cycles, you should regularly check the billing_on field and update the records in your database accordingly. You can do this by setting up a system that automatically checks the billing_on field at regular intervals and updates your database with the new date.

You can compare the billing_on field with the old usage record in your database to know the current billing cycle and to manage your app’s billing effectively.

However, always ensure to test this thoroughly in different scenarios to confirm the behavior, as sometimes there might be slight variations based on different settings or configurations in the billing setup.

Hope this helps!