Skip to main content

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​

WordMeaning
PR #163The docs pull request of 2026-10-20 that designed the spend interface in parallel with the design Ali ruled
Billing D18The decision entry that records every ruling, on Billing D18 — Product domains spend credits only through SpendService
The interface pageBilling interface for product domains, the spec that this folder implements
The class SpendServiceBilling::SpendService, the public class that writes a spend
The class SpendValidatorBilling::SpendValidator, the public class that a product validator runs before the transaction
DeliverableThe product record that one spend pays for, such as one Ads::CampaignPlacement
Deliverable routeA Team Portal web route that loads one deliverable and redirects to the page that shows it
The guardThe second credit check inside a write method, under lock('FOR UPDATE') on the balance row

Read in this order​

  1. Billing D18, the rulings, the reasons and the options not taken.
  2. Billing interface for product domains, the methods, the rules and the worked example.
  3. The list below, to see what moved from your design.
  4. Design Plan, Use Cases and Implementation Plan, your pages rewritten under D18.
  5. 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::TeamShowManager calls read methods of SpendService, 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.
  • Read methods on SpendService.
    • PR #163: available_units, units_consumed, units_by_deliverable, release_would_expire_units? and billing_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".
  • The daily consume.
    • PR #163: consume_reserved(deliverable:, units:), and the job reads units_consumed first.
    • 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".
  • 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_now and consume_reserved return a LedgerEntry, and release returns one or nil.
    • Now: the four write methods return nothing.
    • Why: product code never holds a Billing row.
    • Read: D18, "Return values".
  • The idempotency key.
    • PR #163: not stated.
    • Now: consume_now writes consume_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 grant and expire.
    • 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".
  • 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 with format.
    • 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_type and link_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_type and source_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.
  • 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 builds consume_now with 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.
  • The error class code.
    • PR #163: the class name, "Billing::InsufficientCreditsError".
    • Now, ruled on 2026-10-28: not_enough_credits, from one frozen hash Billing::Error::DEFINITIONS.
    • Why: a Ruby rename must not break a web constant.
    • Read: D18, "The error code".
  • The error classes.
    • PR #163: one class, Billing::InsufficientCreditsError.
    • Now, ruled on 2026-10-27: a base class Billing::Error, with InsufficientCreditsError under it.
    • Why: one parent class gives every Billing rejection its 422, and ApplicationController renders it.
    • Read: D18, "The error class", and the interface page.
  • A company with no billing account.
    • PR #163: SpendValidator adds an error under placement_credits that asks the employer to contact Jod support.
    • Now, ruled on 2026-10-27: SpendService and SpendValidator raise Errors::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".
  • 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, table careers_job_charges.
    • Now: Careers::JobListingPeriod, table careers_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".
  • 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".
  • The spec page.
    • PR #163: overview/billing-public-interface.md.
    • Now: overview/interface.md.
    • Why: one spec page per interface.
    • Read: the interface page.

What stays from PR #163​

  • Billing::SpendValidator, run by the product validator with org_company:, instrument: and units:, and merged with errors.merge!.
  • Billing writes the credit error words, under the key <instrument>_credits.
  • The write checks the balance again under the lock, and ApplicationController renders the error with no rescue in product code.
  • The daily Ads consume job rescues StandardError for 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_type or source_id.
  • Billing reads no product table: the daily job lives in Ads, and SOURCE_TYPES lists 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::Error and Billing::InsufficientCreditsError.
  • The change to the parent class touches one line in app/domains/billing/error.rb and nothing else you write.

Open questions​

QuestionWho answersStatus
Does the boundary search run in CI, or only in review?Aliopen
Is Billing::NoBillingAccountError a warning or an error in Sentry?Alidecided 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 Q1answered: GET /team/billing/org-companies/:org_company_id/account, in jodapp-api#2256