Ramp-up: what changed from docs PR #163
This page is for the engineer who designed docs PR #163 and now builds the spend interface under Billing D18.
- It lists each place where the ruled design differs from PR #163, with the reason and where to read more.
- It names what stays from PR #163 unchanged, and the end state of the error classes.
Words used on this page
| Word | Meaning |
|---|---|
| PR #163 | The docs pull request of 2026-10-20 that designed the spend interface in parallel with the design Ali ruled |
| Billing D18 | The decision entry that records every ruling, on Billing D18 — Product domains spend credits only through SpendService |
| The interface page | Billing interface for product domains, the spec that this folder implements |
The class SpendService | Billing::SpendService, the public class that writes a spend |
The class SpendValidator | Billing::SpendValidator, the public class that a product validator runs before the transaction |
| Deliverable | The product record that one spend pays for, such as one Ads::CampaignPlacement |
| Deliverable route | A Team Portal web route that loads one deliverable and redirects to the page that shows it |
| The guard | The second credit check inside a write method, under lock('FOR UPDATE') on the balance row |
Read in this order
- Billing D18, the rulings, the reasons and the options not taken.
- Billing interface for product domains, the methods, the rules and the worked example.
- The list below, to see what moved from your design.
- Design Plan, Use Cases and Implementation Plan, your pages rewritten under D18.
- jodapp-api#2204, the first issue, which is yours.
What changed from PR #163
Each item names your design first, then the ruling, the reason, and where to read it.
- Billing data on a product page.
- PR #163:
Ads::Campaigns::TeamShowManagercalls read methods ofSpendService, and serializers outside Billing may read Billing models. - Now: a product endpoint carries no Billing data, and the Team Portal campaign page reads Billing endpoints.
- Why: a response carries its own domain's data, and the page loader composes the rest, per jodapp-api#2200.
- Read: jodapp-api#2204.
- PR #163:
- Read methods on
SpendService.- PR #163:
available_units,units_consumed,units_by_deliverable,release_would_expire_units?andbilling_account_for. - Now: none.
- Why: the four reads served only the Ads response above, and the pre-check moved into
SpendValidator. - Read: the interface page, "Product code calls four write methods".
- PR #163:
- The daily consume.
- PR #163:
consume_reserved(deliverable:, units:), and the job readsunits_consumedfirst. - Now:
consume_reserved(deliverable:, target_units_consumed:), and Billing subtracts the consumed units after the lock. - Why: a target can be sent twice with the same result, and a delta cannot.
- Read: the interface page, "A daily consume passes the total".
- PR #163:
- The transaction.
- PR #163: "runs inside the caller's transaction", stated in prose.
- Now: each write method raises when
ActiveRecord::Base.current_transaction.open?is false. - Why: a test fails where a comment does not.
- Read: D18, "Transactions".
- Return values.
- PR #163:
reserve,consume_nowandconsume_reservedreturn aLedgerEntry, andreleasereturns one ornil. - Now: the four write methods return nothing.
- Why: product code never holds a Billing row.
- Read: D18, "Return values".
- PR #163:
- The idempotency key.
- PR #163: not stated.
- Now:
consume_nowwritesconsume_now_<source_type>_<source_id>. - Why: one deliverable is paid once.
- Read: D18, "A direct consume".
- The lock rule.
- PR #163: not stated.
- Now: a ledger calculation that decides a write runs after the balance row lock.
- Why: no race, and no drift between the ledger and the balance row.
- Read: D18, "Locks".
billing_ledger_entries.description.- PR #163: nullable, and null on
grantandexpire. - Now:
NOT NULL, and Billing writes the text of its own entries. - Why: a statement line with no text is a bug the database can catch.
- Read: D18, "Billing's own entries".
- PR #163: nullable, and null on
- Where the text lives.
- PR #163: an inline string in the submit manager.
- Now: a template constant on the deliverable model,
Ads::CampaignPlacement::BILLING_LEDGER_ENTRY_DESCRIPTION, filled withformat. - Why: two submit managers write the same line, so it has one home.
- Read: the interface page, "The product writes the ledger entry description".
link_typeandlink_id.- PR #163: two columns, a CHECK, a
link_record:argument, copied on consume and release. - Now: no columns, and the ledger row links to a deliverable route from
source_typeandsource_id. - Why: which page shows a deliverable is a web decision, and the list pays nothing for its links.
- Read: D18, "The ledger link", and UC-7.
- PR #163: two columns, a CHECK, a
consume_now.- PR #163: a stub that raises
Errors::UnimplementedError, with no test. - Now: jodapp-api#2211 adds a skeleton of every method on
feature/backend-billing-interface, and jodapp-api#2216 buildsconsume_nowwith its tests. - Why: the skeleton lives only on the work branch, so no product code ever calls a method that only raises.
- Read: Implementation Plan, API-2.
- PR #163: a stub that raises
- The error class
code.- PR #163: the class name,
"Billing::InsufficientCreditsError". - Now, ruled on 2026-10-28:
not_enough_credits, from one frozen hashBilling::Error::DEFINITIONS. - Why: a Ruby rename must not break a web constant.
- Read: D18, "The error code".
- PR #163: the class name,
- The error classes.
- PR #163: one class,
Billing::InsufficientCreditsError. - Now, ruled on 2026-10-27: a base class
Billing::Error, withInsufficientCreditsErrorunder it. - Why: one parent class gives every Billing rejection its 422, and
ApplicationControllerrenders it. - Read: D18, "The error class", and the interface page.
- PR #163: one class,
- A company with no billing account.
- PR #163:
SpendValidatoradds an error underplacement_creditsthat asks the employer to contact Jod support. - Now, ruled on 2026-10-27:
SpendServiceandSpendValidatorraiseErrors::InternalServerError, and the request ends with a 500. - Why: every company is created with its own account, so a missing account is a data bug.
- Read: D18, "The paying account", and the interface page, "Rules".
- PR #163:
- The Team Portal actor.
- PR #163: Ops, a Jod admin.
- Now: Marketing, the one person who runs Ads campaigns for clients.
- Why: the real role, ruled 2026-10-20.
- Read: UC-6.
- The Careers deliverable.
- PR #163:
Careers::JobCharge, tablecareers_job_charges. - Now:
Careers::JobListingPeriod, tablecareers_job_listing_periods. - Why: the row holds what the company bought, and the ledger entry is the charge.
- Read: the interface page, "Each product domain owns a price list and a deliverable".
- PR #163:
- The decision number.
- PR #163: D17.
- Now: D18.
- Why: docs PR #158 holds D17, the Careers listing period, dated 2026-10-15.
- Read: Billing D18.
- Other public Billing classes.
- PR #163: a list,
CreateService, the JodGig sync services, and serializers outside Billing. - Now: one rule, Org may call Billing, because Org is not a product domain.
- Why: a list grows with every exception.
- Read: the interface page, "Rules".
- PR #163: a list,
- The spec page.
- PR #163:
overview/billing-public-interface.md. - Now:
overview/interface.md. - Why: one spec page per interface.
- Read: the interface page.
- PR #163:
What stays from PR #163
Billing::SpendValidator, run by the product validator withorg_company:,instrument:andunits:, and merged witherrors.merge!.- Billing writes the credit error words, under the key
<instrument>_credits. - The write checks the balance again under the lock, and
ApplicationControllerrenders the error with no rescue in product code. - The daily Ads consume job rescues
StandardErrorfor each placement, and reports it to Sentry with the placement id. - The product passes the company and the deliverable record, never a
Billing::Account,source_typeorsource_id. - Billing reads no product table: the daily job lives in Ads, and
SOURCE_TYPESlists only Billing records. - Ads moves first, before Careers.
- The eight use cases, the build order, the manual test plan, the risks table and the boundary search.
The error end state
The parent of Billing::Error is Errors::UnprocessableContentError for now, and its end state is Errors::BaseError.
- Billing interface for product domains — Future end state holds that design.
- The interface page, Billing D18 and the Implementation Plan name the same two classes,
Billing::ErrorandBilling::InsufficientCreditsError. - The change to the parent class touches one line in
app/domains/billing/error.rband nothing else you write.
Open questions
| Question | Who answers | Status |
|---|---|---|
| Does the boundary search run in CI, or only in review? | Ali | open |
Is Billing::NoBillingAccountError a warning or an error in Sentry? | Ali | decided by Ali (CTO) on 2026-10-27: the class does not exist, and a missing account raises Errors::InternalServerError, which Sentry reports as an error |
| Which Billing read returns the paying account to the Team Portal campaign page? | Ali, in jodapp-api#2204 Q1 | answered: GET /team/billing/org-companies/:org_company_id/account, in jodapp-api#2256 |