Phase 3.1 — Implementation Plan
This page splits Phase 3.1 into issues for jodapp-api and jodapp-web, in build order.
- The rule they implement is Billing D16 — A company spends only its own billing account, never its parent's.
- Every flow is described step by step on Use Cases.
Where the code goes
Phase 3 is not on main yet, and it lives on two feature branches.
| Repo | Base branch for Phase 3.1 PRs |
|---|---|
jodapp-api | feature/backend-billing-phase-3 |
jodapp-web | feature/frontend-billing-phase-3 |
Phase 3.1 changes ResolveService, which only exists on the api feature branch.
- So Phase 3.1 PRs target the feature branches, and ship to
mainwith the rest of Phase 3.
Build order
Legend: lavender = jodapp-api, grey = jodapp-web.
API-3 must deploy only after API-2 has run in that environment.
- Otherwise a child company that owns no account gets the "no billing account" error on submit.
jodapp-api issues
API-1 — The JodGig company sync creates an account for child companies
JodGig::Companies::BillingAccountUpsertAllServicestops skipping companies withparent_company_idset.- It still finds the existing account with
Billing::Account.find_by(org_company_id:), so it never creates a second account. - A child company's account is created the same way as a root company's account in the sync today.
- The sync does not seed
Billing::EntitlementBalancerows for any account. Billing::InvoicePostingServicecreates the balance row on the first grant.
- The sync does not seed
JodGig::Companies::SyncServicepasses every new account toJodGig::Companies::BillingAgreementUpsertAllService.- So each child company also gets a gig
Billing::Agreementfrom its JodGig data. - The issue checks that the JodGig data of a child company holds its own agreement terms.
- So each child company also gets a gig
API-2 — Backfill task with a dry-run report
bin/rails billing:backfill_company_accounts, as described in UC-6.- Dry run by default, and
APPLY=1writes. - It creates an account only for a company that owns none.
- It creates each account with
Billing::Accounts::Shared::CreateService, so the balances are seeded. - The report is the verification artifact.
- A person approves it before
APPLY=1in each environment, and checks it again after.
- A person approves it before
API-3 — ResolveService returns the company's own account
ResolveService.execute(org_company:)returnsorg_company.billing_account.- It raises the same 422 when the account is missing, with the message that names the company.
- It no longer reads
parent_company_id. - Rewrite the code comments that say a child spends its parent's credits:
app/domains/billing/accounts/shared/resolve_service.rb;app/domains/ads/campaigns/team_submit_validator.rbandemployers_submit_validator.rb;app/domains/billing/entitlement_balances/employers_index_manager.rb;app/domains/ads/campaigns/team_show_manager.rbandapp/domains/ads/team_campaign_detail_serializer.rb.
Billing::EntitlementLotServicedoes not change.
The unique index on billing_accounts.org_company_id is already planned in jodapp-api#2132.
- API-3 needs it, so "an account belongs to exactly one company" holds in the database.
jodapp-web issues
WEB-1 — Team Portal campaign page: drop the parent-credits note
app/routes/team/ads-campaigns/team-ads-campaigns-detail-page.jsxcomputesbilling_parent_org_companywhen the paying account's owner is not the campaign's company.- After API-3 the paying account is always the company's own account, so that branch never runs.
- Remove these, because they describe a child that spends its parent's account:
- the value
billing_parent_org_company; - the note "uses its parent company's credits";
- the code comment that says a child always spends its parent's account.
- the value
- The Employer Dashboard needs no change.
Manual test plan
Setup: root company P owns an account with 1,000 placement credits.
- Child company C1 was created in Jod, so it owns an account with 0 credits.
- Child company C2 was synced from JodGig, so it owns no account before API-1.
| # | Step | Expected |
|---|---|---|
| 1 | Run the backfill dry run | The report lists C2 as a company with no account, and no open reserve on another company's account |
| 2 | Run the backfill with APPLY=1 | C2 owns a new account with zero balances, and the report lists no company without an account |
| 3 | Run the backfill with APPLY=1 again | Nothing is written |
| 4 | Submit a 100-credit campaign as C1 | Fails: you need 100 placement credits, but you only have 0 available |
| 5 | Grant 300 trial credits to C1's account, then submit again | Reserves on C1's account, and P's balance does not change |
| 6 | Let the campaign from step 5 run the consume job | Consumes from C1's account |
| 7 | Log in as C1's HQ manager | The navbar shows C1's balance: 200 available |
| 8 | Log in as P's HQ manager and submit a 100-credit campaign | Reserves on P's account |
| 9 | Run the JodGig company sync for a new child company C3 | C3 owns one account |
| 10 | Open C1's campaign in the Team Portal | The page shows C1's account and no parent-credits note |
Risks
| Risk | What we do |
|---|---|
| API-3 deploys before the backfill ran, so a JodGig child gets "no billing account" on submit | The deploy order is API-1, API-2 run, then API-3 |
| A client wanted one shared pool for all its divisions | The client becomes one company with many outlets, and Sales confirms this with the client |
| A division has leftover credits that another division needs | A transfer between accounts is planned for a later phase |
| A child's campaign reserved on the parent's account before API-3 | Consume and release follow the reserve ledger entry, so the campaign keeps using the parent's account until it ends |