In this episode, we're designing the schema for our referral payments system – basically the database table and model that tracks all the referral payouts we need to make when users bring in new customers.
First, we talk about why it's so important to log every payment that comes in from Stripe via webhook. This isn't just so users can see them, but also so we know exactly how much has been earned and what needs to be paid out (plus, it helps generate a spreadsheet for the admin).
We walk step-by-step through creating the migration and model for the referral_payments
table. Here's what we cover:
available_at
column to delay payments for things like potential refunds (usually a one month delay)paid_at
field (just the date, not the time!) so we can track when each payment was sentWe set up the necessary relationships in the user model for completeness, but explain that, for now, we'll be mostly focused on just inserting these records when a webhook comes in rather than getting too fancy with Eloquent relationships.
By the end, you'll understand why we're tracking all this info, what goes in the table, and the rationale behind every field. Next up, we'll actually wire up listening to Stripe webhooks and persisting referral payments based on real events!