Automate Recurring Billing Operations
The first of the month arrives, and you open your payment dashboard with the small dread every subscription owner knows. Eleven cards declined overnight. Two customers upgraded mid-cycle and you are not sure what they were charged. One refund was issued twice. Your bookkeeper will ask on Friday why the payout does not match the invoices, and you will not have a clean answer.
Recurring billing looks simple from the outside. A customer pays the same amount every month. Inside, it is a small machine with many states, many clocks, and a steady stream of exceptions. When you run a small subscription business, that machine is usually held together by your own attention. This article is about moving that attention from watching to designing, so the system handles the ordinary cases and shows you only the unusual ones.
Everything here applies whether you bill through Stripe, a similar payment processor, an invoicing tool, or a mix. Where details differ by tool I will say so.
Start with a map of billing states
Before you automate anything, write down every state a subscription can be in and every event that moves it. Most billing bugs are really missing transitions, a customer stuck in a state nobody planned for.
A typical set of states looks like this.
- Trialing. The customer has access and has not yet been charged.
- Active. The most recent invoice was paid and access continues.
- Past due. A payment failed and retries are running. Access usually continues for a grace period.
- Unpaid or suspended. Retries ran out. Access is limited or removed, but the customer record and data remain.
- Paused. The customer or you asked to stop billing for a time without ending the relationship.
- Canceled. The subscription ended, either immediately or at the end of the paid period.
Then list the events. A payment succeeds, a payment fails, a plan changes, a card expires, a refund is issued, a dispute is opened, a customer cancels. For each event, write what state the subscription moves to and what should happen next, such as an email, an access change, or an internal task.
This sheet becomes the specification. When you buy a tool or write code, you are checking it against this map.
Billing events arrive as messages, so treat them carefully
Payment processors tell your systems what happened by sending webhooks. A webhook is an automatic message from the processor to an address you provide, saying that an invoice was paid or a charge failed. Three properties of webhooks decide whether your automation is trustworthy.
They can arrive twice. Processors retry when they do not get a quick success reply. Your handler must be idempotent, meaning that processing the same event again changes nothing. The usual method is to store each event identifier you have handled and ignore repeats.
They can arrive out of order. A message saying the subscription was updated may reach you before the one saying it was created. Do not assume sequence. Fetch the current state from the processor when it matters, or compare timestamps before overwriting.
They must be verified. Each message carries a signature, a value computed from the body and a secret that only you and the processor know. Recompute it on your side and reject anything that does not match. Otherwise anyone who guesses your endpoint can claim that an invoice was paid.
Reply quickly to the webhook, then do slow work in the background. A handler that sends emails and updates three systems before replying will time out, and the processor will retry into a mess.
Proration without arguments
Proration is the adjustment made when a customer changes plans partway through a billing period. Customers do not understand it until it goes wrong, and then they remember it.
Here is a hypothetical example. A customer pays $60 per month on the first and upgrades to a $120 plan on day 11 of a 30 day month. They used 10 days of the lower plan and have 20 days left.
- Credit for unused time on the old plan is 20 divided by 30 times $60, which is $40.
- Charge for the new plan for the remaining time is 20 divided by 30 times $120, which is $80.
- Net charge today is $80 minus $40, which is $40.
Your processor can compute this for you, and many do it per second rather than per day. What you must decide is policy, and policy should be written before the first upgrade.
- Do upgrades take effect immediately with a prorated charge, or at the next renewal?
- Do downgrades take effect at the end of the period, with no refund for the unused part of the higher plan?
- If a customer upgrades and downgrades repeatedly, is there a limit?
- What shows on the invoice, so the customer can follow the arithmetic?
Pick the simplest policy that matches how customers think. Upgrade now, downgrade at renewal is common because it feels fair and is easy to explain.
Dunning, the polite art of collecting failed payments
Dunning is the process of following up on failed payments. In subscription businesses, a large share of cancellations are involuntary. The customer wanted to keep the service, but the card expired, the bank flagged the charge, or the balance was short. Good dunning recovers these quietly.
Failure reasons matter. A soft decline, such as insufficient funds, may succeed a few days later. A hard decline, such as a closed account, never will. Your retry logic should treat them differently.
A sensible sequence, which you should adapt to your product, might be the following.
| Day | Action | Access |
|---|---|---|
| 0 | Payment fails, send a friendly notice with a link to update the card | Normal |
| 3 | Retry the charge, send a reminder if it fails | Normal |
| 7 | Retry again, send a clearer notice with the date access will be limited | Normal |
| 10 | Final retry, final notice | Limited |
| 14 | Suspend and keep data | Suspended |
Some practical points make this work better.
- Send the card update link by email and, where you have consent, by text. Make the link go straight to a payment form, not a login wall.
- Schedule retries away from the first of the month, when many other merchants retry the same banks. Retrying a few days after paydays can help.
- Use your processor's card updater features where offered, since they can refresh expired card details through the card networks.
- Write the messages in the customer's language. Your customers in Puerto Rico may prefer Spanish, and a billing notice in a language they read slowly is a notice they ignore.
- Never threaten. The tone should be that of a helpful front desk.
Track the recovery rate, the share of failed payments that eventually succeed. If it is low, the problem is usually timing or unclear messages, not the customers.
Tax is a rules problem, not a rounding problem
Sales tax and similar taxes on subscriptions depend on what you sell, where the customer is, and where you have obligations. Puerto Rico has its own sales and use tax, called IVU, with rules that differ from the states. Some digital services and subscriptions are taxable in some places and not in others, and the rules change.
I cannot tell you what you owe, and this is not tax advice. A qualified accountant or tax adviser has to answer that. What I can tell you is how to build billing so their answer is easy to apply.
- Store the customer's billing address and, where relevant, their exempt status and certificate.
- Store the tax rate and tax amount on every invoice line, not only the total. You will need this for returns.
- Keep tax separate from revenue in your records. It is a liability you collect for someone else.
- Decide whether you charge tax inclusive or exclusive prices, and show it clearly.
- If you use an automatic tax feature from your processor or a tax service, check how it determines location, and test with real addresses from your customer list.
Do not edit tax on an issued invoice. Issue a credit note and a new invoice, so the trail stays intact.
Reconcile every payout to the invoices behind it
Money reaches your bank in batches called payouts. A single payout may combine dozens of payments, subtract refunds and fees, and arrive days after the sales. This is why the bank balance never matches the dashboard on any given day.
Reconciliation is the discipline of proving that the numbers agree. For subscriptions, the useful chain has four links.
- Invoices you issued.
- Payments the processor collected against them.
- Payouts that bundle those payments, net of fees and refunds.
- Deposits that appear in your bank account.
Here is a small hypothetical payout. It contains 40 payments totaling $4,800, refunds of $120, processing fees of $168, and a dispute fee of $15. The expected deposit is 4,800 minus 120 minus 168 minus 15, which is $4,497. If the bank shows $4,497, the batch reconciles. If it shows $4,512, you are $15 off, and you know to look for the dispute fee.
Automation can fetch the payout report, list the payments inside it, and match each to an invoice by the processor's identifier. Anything that does not match goes into an exception queue for a human. The goal is not zero exceptions. The goal is that exceptions are few, visible, and have an owner.
Fees deserve their own account in your books, since they are a cost and not a reduction in revenue. Your bookkeeper will appreciate that the data arrives already separated.
A short note on revenue recognition
Cash collected and revenue earned are different things. If a customer pays $1,200 on January 1 for an annual plan, you have received cash on January 1, but under common accounting rules you generally earn the revenue gradually over the twelve months of service. The unearned part sits as deferred revenue, a liability, until delivered.
Monthly plans are simpler, since billing and service roughly align. Annual plans, setup fees, and bundles with multiple deliverables are where it gets tricky. The rules depend on your accounting framework and your circumstances, and you should have your accountant define the treatment. From the automation side, your job is to give them clean data such as plan start and end dates, amounts, credits, and refunds, so the schedule can be built without retyping.
Failure modes worth designing for
Some problems appear in almost every small billing setup.
- Duplicate customers. Two records for one person, with two subscriptions. Match on a stable identifier and treat email as a hint, not a key.
- Orphaned access. A subscription ends but the account keeps working, or the reverse. Reconcile access lists against active subscriptions monthly.
- Silent webhook failure. Your endpoint breaks and nothing is processed for days. Alert when no events arrive in a normal window, and use the processor's event log to replay.
- Manual overrides that never get undone. A free month granted by hand and forgotten. Give every override an expiry date.
- Currency and rounding. Store amounts as whole minor units, such as cents, never as floating point numbers.
- Test mode confusion. Keep test and live credentials clearly separated, and never let one point at the other.
What to ask a billing vendor
If you are choosing a billing or subscription tool, ask these questions.
- Which billing states does it model, and can I see how it handles past due and paused?
- How does it handle proration, and can I choose the policy?
- Does it offer configurable retries and customer-facing payment update pages?
- How are webhooks signed, retried, and logged, and can I replay them?
- What tax support exists, and what does it assume about my obligations?
- Can I export every invoice, customer, and event in a standard format, so I am not trapped?
- What fees apply per transaction, per failed attempt, per dispute, and per feature?
Monday morning checklist
- Draw the state map on one page and share it with whoever answers billing questions.
- Write your proration and cancellation policy in plain language.
- Check whether your webhook handler is idempotent and verifies signatures.
- Review your last 30 failed payments and note why each failed.
- Set up a retry schedule and three short notices, in English and Spanish if your customers need both.
- Pull last month's payout and reconcile it by hand once, so you know what the automation must do.
- Send your accountant a sample of the data you can export and ask what they would change.
For small teams in a place where a storm can cut power for a week, one more habit helps. Make sure billing runs on a hosted service and not on a machine in your office, and that you know how to reach the dashboard from a phone.
If you would like help designing this, Ozcorp InfraOps builds and maintains this kind of operational plumbing, and InfraOps Base starts at $500 per month with vendor and license charges billed separately. If you prefer to do it yourself, the map and the reconciliation routine above are the two pieces that pay off the fastest.
Discuss your infrastructure requirements
Review the current service offer or schedule a conversation about the scope you need.
Stay in touch
Follow Ozcorp
Leave your details for occasional notes about new articles and Ozcorp updates.