Skip to main content

Phase 3.1 — Implementation Plan

This page splits Phase 3.1 into issues for jodapp-api and jodapp-web, in build order.

Where the code goes​

Phase 3 is not on main yet, and it lives on two feature branches.

RepoBase branch for Phase 3.1 PRs
jodapp-apifeature/backend-billing-phase-3
jodapp-webfeature/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 main with 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::BillingAccountUpsertAllService stops skipping companies with parent_company_id set.
  • 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::EntitlementBalance rows for any account.
    • Billing::InvoicePostingService creates the balance row on the first grant.
  • JodGig::Companies::SyncService passes every new account to JodGig::Companies::BillingAgreementUpsertAllService.
    • So each child company also gets a gig Billing::Agreement from its JodGig data.
    • The issue checks that the JodGig data of a child company holds its own agreement terms.

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=1 writes.
  • 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=1 in each environment, and checks it again after.

API-3 — ResolveService returns the company's own account​

  • ResolveService.execute(org_company:) returns org_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.rb and employers_submit_validator.rb;
    • app/domains/billing/entitlement_balances/employers_index_manager.rb;
    • app/domains/ads/campaigns/team_show_manager.rb and app/domains/ads/team_campaign_detail_serializer.rb.
  • Billing::EntitlementLotService does 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.jsx computes billing_parent_org_company when 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 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.
#StepExpected
1Run the backfill dry runThe report lists C2 as a company with no account, and no open reserve on another company's account
2Run the backfill with APPLY=1C2 owns a new account with zero balances, and the report lists no company without an account
3Run the backfill with APPLY=1 againNothing is written
4Submit a 100-credit campaign as C1Fails: you need 100 placement credits, but you only have 0 available
5Grant 300 trial credits to C1's account, then submit againReserves on C1's account, and P's balance does not change
6Let the campaign from step 5 run the consume jobConsumes from C1's account
7Log in as C1's HQ managerThe navbar shows C1's balance: 200 available
8Log in as P's HQ manager and submit a 100-credit campaignReserves on P's account
9Run the JodGig company sync for a new child company C3C3 owns one account
10Open C1's campaign in the Team PortalThe page shows C1's account and no parent-credits note

Risks​

RiskWhat we do
API-3 deploys before the backfill ran, so a JodGig child gets "no billing account" on submitThe deploy order is API-1, API-2 run, then API-3
A client wanted one shared pool for all its divisionsThe client becomes one company with many outlets, and Sales confirms this with the client
A division has leftover credits that another division needsA transfer between accounts is planned for a later phase
A child's campaign reserved on the parent's account before API-3Consume and release follow the reserve ledger entry, so the campaign keeps using the parent's account until it ends