Billing interface for product domains
Words used in this page
| Word | Meaning |
|---|---|
| Product domain | A domain that sells a service to employers: Careers, Ads, Gig or Workforce. |
| Instrument | One kind of credit in billing_entitlements.instrument, such as :placement or :gig. |
| Price list | The table where Sales sets what one deliverable costs, such as careers_job_posting_prices. |
| Deliverable | The record of one service that Jod owes an employer, such as one Ads::CampaignPlacement. |
| Credit balance | The credits a company can still spend, in billing_entitlement_balances. |
The class SpendService | The public Billing class that writes a spend, which product code calls as ::Billing::SpendService. |
The class SpendValidator | The public Billing class that checks a spend before the transaction, which a product validator runs as ::Billing::SpendValidator. |
| Private class | A Billing class that only Billing code calls, such as EntitlementLotService. |
| Own account | The Account whose billing_accounts.org_company_id is the company, which Billing reads as org_company.billing_account. |
| The reserve entry | The newest LedgerEntry with entry_type: :reserve for one deliverable. |
| The balance row lock | lock('FOR UPDATE') on the billing_entitlement_balances row of one account and one instrument. |
| Statement of account | The list of every credit movement of one company, which the employer downloads. |
What it does
The Billing interface is the one way a product domain spends the credits of a company.
- A product domain decides what it sells, what it costs, and when to spend credits.
- Billing decides which account pays, which lots pay, and when Jod earns the revenue.
- Product code calls two public Billing classes,
SpendServiceto spend andSpendValidatorto check. - Product code names no other Billing class, and never rescues a
Billing::Error. - Billing code never reads a product table, and never names a product.
- A product endpoint carries no Billing data, so a page reads Billing data from a Billing endpoint.
- Billing D18 — Product domains spend credits only through SpendService records these rules and why.
Legend: orange = the two classes that product code calls.
Each product domain owns a price list and a deliverable
A product domain that sells for credits owns two kinds of records.
- The price list says what one deliverable costs.
- The deliverable says what the company bought, and it copies the cost from the price list.
| Product domain | What the company buys | Price list | Deliverable | Paid from |
|---|---|---|---|---|
| Careers | One posting of one job, for a number of days | careers_job_posting_prices | careers_job_postings | Placement credits |
| Ads | Days in one ad placement | ads_placement_prices | ads_campaign_placements | Placement credits |
| Gig | The wages of the workers of one shift | gig_pay_rates, copied to gig_shifts.hourly_rate | gig_shifts | Gig credits |
| Workforce | Seats to manage staff | None, because the price per seat is in billing_product_prices | None | An invoice |
These records are not billing records, even when their names sound like billing.
- They hold no money and no balance.
- They say what the product sells and what it owes the company.
- Billing records what was paid, in a ledger entry that names the deliverable as its source.
- How Workforce reads its seats is not designed yet.
Each question about one purchase has one owner.
| Question | Answered by the product domain | Answered by Billing |
|---|---|---|
| What does one posting of a job cost? | careers_job_posting_prices.unit_cost | No |
| What did the company buy, and when does it end? | One careers_job_postings row | No |
| Which account paid, and from which lots? | No | billing_ledger_entries and billing_entitlement_lot_allocations |
| How many credits are left? | No | billing_entitlement_balances |
| How much revenue did Jod earn today? | No | billing_ledger_entries.recognised_revenue_cents |
The owner of a price depends on how the company pays it
The test is how the company pays, not the unit of the price.
| The company pays | The price lives in | Examples |
|---|---|---|
| By invoice | Billing, in billing_products and billing_product_prices | A placement credit pack A gig credit top-up A Workforce price per seat |
| From a credit balance | The price list of the product domain | "1 Month" for 50 placement credits An Ads placement price A Gig hourly rate |
A deal for one company is always a money price.
- Sales gives one company a cheaper credit pack, in a
billing_product_pricesrow withbilling_account_idset. - A credit price stays the same for every company.
Why the split sits between an invoice and a credit balance
Five reasons keep money in Billing and credit prices in each product domain.
- An invoice is a legal and tax document.
- It needs a seller legal entity, an invoice number, a tax code and a payment proof.
- Only Billing has these records, and only Billing sends them to Xero.
- A spend from a credit balance has no invoice and no tax.
- The invoice for the credits already carried the tax.
- So the only rules left at spend time are product rules.
- Each product rule says what the company gets, for how long, and at what cost.
- A credit price needs the words of its product.
- A Careers price has a number of days that the job is shown.
- An Ads price belongs to one ad placement.
- A Gig rate depends on the job role, the day type and the time of day.
- Billing would need columns for every product, so each price stays with its product.
- A product changes its prices without Finance.
- Sales edits one row in the price list of the product, in the Team Portal.
- No invoice, tax rule or Xero mapping changes.
- Finance reads Billing alone.
- Money comes in through invoices for credit packs and seats.
- Revenue comes from spent and expired credits, and Billing computes it the same way for every product.
- So Finance never needs to know which product spent the credits.
The Gig hourly rate shows why "money or credits" is the wrong test.
- The rate is in SGD per hour.
- It still lives in Gig, because the company pays it from gig credits, not by invoice.
- Gig credits are counted in cents, so Billing sees only the cents that a shift spends.
Product code calls four write methods of SpendService
Product code calls these four methods of SpendService, and no other Billing method.
| Method | A product calls it when | Example |
|---|---|---|
consume_now(org_company:, instrument:, units:, deliverable:, description:) | The service is delivered as soon as it is paid | A Careers job post or renew |
reserve(org_company:, instrument:, units:, deliverable:, description:) | The service is delivered later, or over many days | An Ads campaign submit, or a new Gig shift |
consume_reserved(deliverable:, target_units_consumed:) | Part of a reserved service is delivered | The daily Ads consume, or a worked Gig shift |
release(deliverable:) | A reserved service ends before it is delivered | A rejected Ads campaign, or a cancelled Gig shift |
- Gig also passes
org_outlet:toreserve, for the outlet budgets. SpendServicestoresdeliverable.class.nameanddeliverable.idas the source of the ledger entry.- So Billing keeps no list of product class names.
- The type of
deliverable:is::ApplicationRecord, so a product model includes no Billing module. consume_reservedandreleasetake no account, no instrument and no text.- Billing reads all three from the reserve entry.
- So the units move on the account and the lots that the reserve used.
reserveandconsume_nowraiseBilling::InsufficientCreditsErrorwhen the balance is too low, and the request ends with a 422.consume_reservedandreleasenever check the balance, because they move units that a reserve already set aside.Billing::Erroris the parent of every Billing error, and it inheritsErrors::UnprocessableContentErrorfor now.- Each error takes its
codeandtitlefromBilling::Error::DEFINITIONS, such asnot_enough_credits. - The web matches the code with a constant in
billing-constants.js, when it must branch on it.
reserveandconsume_nowraiseErrors::InternalServerErrorwhenorg_company.billing_accountisnil.- Every company is created with its own account, so a
nilaccount is a data bug. - The request ends with a 500, and Sentry reports it as an error.
- Its
codeisbilling_account_missingfromBilling::Error::DEFINITIONS, so the JSON names the failure, not the class. - Without that
code,ApplicationControllerwould render the class nameErrors::InternalServerErroras thecode.
- Every company is created with its own account, so a
SpendValidator,reserveandconsume_nowraiseErrors::InternalServerErrorwhenunitsis 0 or less, before they read or write a row.- No product costs 0 credits, so a spend of 0 units is a bug in the caller.
- A free service has a normal price, and the company pays it with free credits that an admin grants with a
Billing::CreditAction.
- A Billing bug takes a
codeonly when a program must tell it apart from other bugs.- A program here is a page that shows its own message for the bug.
- An alert or a runbook that searches for the bug also counts.
- Every other Billing bug writes its
titlein the raise and passes nocode:.
- The section Future end state —
Billing::ErrorinheritsErrors::BaseErrorholds the next parent class.
Careers pays for one Careers::JobPosting with one call.
# app/domains/careers/job_postings/shared/create_service.rb
::Billing::SpendService.consume_now(
org_company: careers_job.company,
instrument: :placement,
units: careers_job_posting.unit_cost_snapshot,
deliverable: careers_job_posting,
description: format(
::Careers::JobPosting::BILLING_LEDGER_ENTRY_DESCRIPTIONS.fetch(:post),
job_title: careers_job.title,
price_name: careers_job_posting_price.name
)
)
A product validator runs SpendValidator and merges its errors
A product validator checks that the company can pay by running SpendValidator, and it merges the errors into its own.
- Billing owns the rule "can this company pay", so Billing code runs the check.
- The product passes three values, and Billing never holds a product object.
errors.merge!is theActiveModel::Errorsmethod for this, so no helper is needed.- The check runs before the transaction and takes no lock, so it is for the form, not the guard.
- The write method checks again under the balance row lock, so a product that skips the validator still cannot overspend.
# app/domains/careers/jobs/employers_create_validator.rb
def enough_placement_credits
billing_spend_validator = ::Billing::SpendValidator.new(
org_company: org_company,
instrument: :placement,
units: careers_job_posting_price.unit_cost
)
errors.merge!(billing_spend_validator.errors) if billing_spend_validator.invalid?
end
SpendValidator runs one check, and it adds its error under one key.
| Check | Error key | Message |
|---|---|---|
The lots of the own account that are not past expires_at hold at least units | placement_credits | You need 50 placement credits, but you only have 40 available. Please contact us to top up your placement credits. |
- The key is the instrument name plus
_credits, so gig credits usegig_credits. - Billing writes the message, one per instrument, and a product never writes its own.
- A company with no balance row has 0 units available.
- The check counts the units of the lots that are not past
expires_at.billing_entitlement_balances.units_availablestill holds a lot that expired, untilBilling::ExpireEntitlementLotsJobruns at minute 15.reserveandconsume_nowcount the same lots after the balance row lock, so the check and the spend agree.
SpendValidatorraisesErrors::InternalServerErrorwhenunitsis 0 or less, the same asreserveandconsume_now.- A product validator runs
SpendValidatoronly when the product has something to pay for. Ads::Campaigns::EmployersSubmitValidatorandAds::Campaigns::TeamSubmitValidatorskip it for a campaign with no placement.- So that campaign gets the 422 "Campaign must have at least one placement to be submitted".
- A product validator runs
- So one 422 holds the form errors and the credit error together.
SpendValidatorraisesErrors::InternalServerErrorwhenorg_company.billing_accountisnil, because that is a data bug.- A raise inside
SpendValidator#valid?reachesApplicationControllerlike any other exception. - The request ends with a 500, and Sentry reports it as an error.
- A raise inside
The product writes the ledger entry description, and Billing copies it
reserve and consume_now take description:, the line that the statement of account shows for the movement.
- Billing stores the text in
billing_ledger_entries.description, which is never empty. consume_reservedandreleasecopy the text from the reserve entry.- Billing writes the text of the entries it starts itself, such as a
:grantfrom an invoice. - A later change to the job title or the campaign name never changes a past line.
The deliverable model keeps the text as a template constant, and the caller fills it with format.
# app/domains/careers/job_posting.rb
BILLING_LEDGER_ENTRY_DESCRIPTIONS = {
post: 'Job post: %{job_title}, %{price_name}',
renew: 'Job renew: %{job_title}, %{price_name}'
}.freeze
- The post code and the renew code each pass their own key.
- A
careers_job_postingsrow does not say if it is a post or a renew.
- A
- A missing value raises
KeyError, before Billing writes any row. Ads::CampaignPlacement::BILLING_LEDGER_ENTRY_DESCRIPTIONholds the Ads text, such as "Ad: Year-end hiring, Home Page - Hero Banner, Weekly".
A daily consume passes the total it should have reached
consume_reserved takes target_units_consumed:, the consumed total the deliverable must reach after the call.
- Billing subtracts the units already consumed, after it takes the balance row lock.
- A second run with the same target consumes 0, so the job is safe to run every hour.
- A target below the consumed total raises, because Billing cannot un-consume and the caller has a bug.
- A target above the reserved units raises, because Billing never spends a unit the reserve did not set aside.
- A product that consumes in one step passes the whole reserve as the target, such as a worked Gig shift.
- The target comes from the daily formula of Billing D5 — Spending mechanics: consume now, or reserve first.
# app/domains/ads/campaign_placements/consume_reserved_credits_job.rb:36-41
::ActiveRecord::Base.transaction do
::Billing::SpendService.consume_reserved(
deliverable: campaign_placement,
target_units_consumed: target_units_consumed(campaign_placement: campaign_placement)
)
end
Every ledger calculation that decides a write runs under the balance row lock
Billing takes lock('FOR UPDATE') on the billing_entitlement_balances row before it reads a ledger number that decides a write.
reservechecks that the deliverable has no reserved units, after the lock.reservechecks that the deliverable has no direct spend, after the lock.consume_nowchecks that the deliverable has no reserve entry, after the lock.consume_reservedsubtracts the units already consumed, after the lock.releasesums the reserved units of the deliverable, after the lock.- Only the read of the reserve entry happens before the lock, because it says which balance row to lock.
- A reserve entry never changes, so this read cannot drift.
- A read that decides no write takes no lock, such as the check of
SpendValidator.
Every write runs inside the caller's transaction
The code that calls SpendService opens the database transaction, and each write method raises when none is open.
- The balance row lock holds only until the transaction ends.
- With no transaction, the lock ends with its own statement, and two writes can race.
- Only the caller knows which writes must succeed or fail together, such as a
reserveandcampaign.update!.- So the caller owns the transaction, as principle 3 of
jodapp-api/app/domains/AGENTS.mdsays.
- So the caller owns the transaction, as principle 3 of
- Each write method checks the transaction on its first line.
# app/domains/billing/spend_service.rb
def self.require_open_transaction!
return if ::ActiveRecord::Base.current_transaction.open?
raise Errors::InternalServerError.new(
title: 'SpendService must run inside a database transaction',
messages: { base: [ 'Wrap the call in ActiveRecord::Base.transaction.' ] }
)
end
ActiveRecord::Base.current_transactionhides the transaction that Rails opens around each test.- So a test fails when its caller forgets the transaction.
A direct consume carries an idempotency key
consume_now writes billing_ledger_entries.idempotency_key as consume_now_<source_type>_<source_id>.
consume_nowrefuses a deliverable that already has a direct spend, so one deliverable is never paid twice.- It checks this after the balance row lock and before the balance check.
- So the answer never depends on the balance.
- A second
consume_nowforCareers::JobPosting88 raisesErrors::InternalServerError, a 500 that Sentry reports as an error. - The caller's transaction rolls back, and the engineer learns that the caller has a bug.
- The unique index on the column is the second guard, if the check is ever removed.
- The key does not stop a double click, because each click creates its own
Careers::JobPosting. consume_reservedandreleaseneed no key, because their calculation under the lock makes a second run do nothing.
A write method returns nothing
The write methods reserve, consume_now, consume_reserved and release return nothing, and every failure raises an error.
- Product code never holds a
LedgerEntry, so it never depends on Billing's columns. - Two outcomes do nothing on purpose, and they are not failures.
releaseof a deliverable with no reserved units does nothing.consume_reservedwith a target that the deliverable already reached does nothing.
- A method gets a return value only when a real caller needs one.
A product page reads Billing data from a Billing endpoint
A product endpoint carries no Billing data, so a page loads Billing data from a Billing endpoint.
- Billing data means a Billing record, and any fact that only Billing tables can compute.
- The Ads Team campaign page loads the own account of the company from
GET /team/billing/org-companies/:org_company_id/account.- It needs the placement
units_availableand the accountidfor a link. - Every company is created with its own account, so a company with no account is a data bug.
- The read then raises a 500 with the code
billing_account_missing.
- It needs the placement
- The same page reads the spend of each placement from
GET /team/billing/spends, keyed by the placement ids.- It reads the spend when Marketing opens the reject or cancel dialog, because only those dialogs show it.
- A spend is the units that one deliverable has used and still holds, as the ledger shows them now.
- The request is
?source_type=Ads::CampaignPlacement&source_ids[]=77&source_ids[]=78. - Each row has
source_type,source_idand three numbers. units_reservedis the units the deliverable holds now, with the meaning ofbilling_entitlement_lots.units_reserved.units_consumedis a running total of the units it has used, with the meaning ofbilling_entitlement_lots.units_consumed.units_reserved_in_expired_lotsis the part ofunits_reservedin an expired lot, which a release expires at once.- The request needs
source_typeand at least one id insource_ids[], or it gets a 422. - A
source_typeunderBilling::, such asBilling::InvoicePosting, also gets a 422, because it names no deliverable. - An id with no ledger entries has no row, so a page with no spends gets an empty list.
- The same id twice gives one row for that id.
- Every row comes back in one response, with no paging, because a request has at most 100 ids.
- A failed Billing read stops the action that needs it.
- For example, the Team reject and cancel dialogs open, show the failure, and keep their confirm button disabled.
- Billing D18 — Product domains spend credits only through SpendService says why.
SpendServicehas no read method for a page, because a page reads Billing endpoints.- The employer campaign page reads the balance from
GET /employers/billing/entitlement-balances.- The employer dashboard layout loads it once, for every page.
- The Team Portal ledger list links a spend to its deliverable through
source_typeandsource_id.- Billing stores no page record.
- The row links to a web route for the deliverable, such as
/team/ads/campaign-placements/:id. - That route loads the deliverable from its product endpoint and redirects to the page that shows it.
- For a placement, that page is the campaign page.
- The link text is
billing_ledger_entries.description.
Future end state
This section keeps the end state of the Billing error classes while the current classes ship.
- For now
Billing::ErrorinheritsErrors::UnprocessableContentError, which carries the HTTP status 422. - In the end state,
Errors::BaseErrorkeepstitle,messages,codeandserver, and dropsstatusandstatus_name. ApplicationControllerholds one table from error class to status, and maps an unknownErrors::BaseErrorto 500.Billing::Errorthen inheritsErrors::BaseErrordirectly, and nothing else in Billing changes.- Billing D18 — Product domains spend credits only through SpendService says why the end state is not built yet.
- API error architecture — every option weighed, and the plan holds the full design.
Actors
| Actor | What they do here | Where |
|---|---|---|
| HQ manager | Posts a job, sees the credit balance, and downloads the statement of account | Employer Dashboard |
| Sales | Sets the credit prices of each product, and the money prices of credit packs and seats | Team Portal, the price page of each product, and Billing products |
| Finance | Reads the money in from invoices and the revenue earned each day | Team Portal, Billing pages |
| Engineer of a product domain | Decides when to spend and how many units, then calls SpendService | app/domains/careers/, app/domains/ads/, app/domains/gig/ |
| Engineer of Billing | Owns SpendService and the private classes behind it | app/domains/billing/ |
| The system | Runs the scheduled jobs of each product, such as the daily Ads consume | sidekiq-scheduler |
Rules
| Rule | Applies to | Example |
|---|---|---|
| A price paid by invoice lives in Billing | Sales | A Workforce price per seat in billing_product_prices |
| A price paid from a credit balance lives in the product domain | Sales | "1 Month" for 50 credits in careers_job_posting_prices |
| A deal for one company is a money price for the account of that company | Sales | A cheaper credit pack with billing_product_prices.billing_account_id set |
| A credit price is the same for every company | always | "1 Month" costs 50 credits for every company |
Product code names no Billing class except SpendService and SpendValidator, and never rescues a Billing::Error | Engineer of a product domain | Careers::JobPostings::Shared::CreateService calls consume_now, and Ads::CampaignPlacements::ConsumeReservedCreditsJob rescues only StandardError |
A product validator checks a Billing rule by running SpendValidator and merging its errors, never by reading a Billing table | Engineer of a product domain | errors.merge!(billing_spend_validator.errors) in Careers::Jobs::EmployersCreateValidator |
Billing writes the words of a credit error, under the key <instrument>_credits | Engineer of Billing | placement_credits: You need 50 placement credits, but you only have 40 available. |
| Org code may call a Billing class, because Org is not a product domain | Engineer of Billing | Org::Companies::Shared::CreateService calls Billing::Accounts::Shared::CreateService |
Product code passes the company, never an Account | Engineer of a product domain | org_company: careers_job.company |
Product code passes the deliverable record, never source_type and source_id | Engineer of a product domain | deliverable: careers_job_posting |
| The deliverable copies the cost from the price list | Engineer of a product domain | ads_campaign_placements.credit_cost_snapshot |
| The product decides when to spend, and how many units | Engineer of a product domain | Careers spends on a post and on a renew, never on an edit |
| A service delivered when paid consumes now, and a later service reserves first | Engineer of a product domain | Careers consumes now, and Ads reserves on submit, as Billing D5 — Spending mechanics states |
A deliverable pays one way: reserve refuses a deliverable that has a direct spend, and consume_now refuses one that has a reserve entry | Engineer of a product domain | Careers::JobPosting 88 was paid with consume_now, so a reserve for it raises Errors::InternalServerError, as the row "One way to pay per deliverable" of Billing D18 — Product domains spend credits only through SpendService rules |
| The product writes the ledger entry description from a template constant on the deliverable model | Engineer of a product domain | Careers::JobPosting::BILLING_LEDGER_ENTRY_DESCRIPTIONS.fetch(:post) |
| A reserved consume passes the total to reach, not the units to move | Engineer of a product domain | target_units_consumed: 3 on day 4 of a 5-credit, 7-day placement |
| The caller opens the transaction around its own writes and the Billing write | Engineer of a product domain | The daily Ads consume wraps each placement in ActiveRecord::Base.transaction |
| A write method raises when no transaction is open | always | require_open_transaction! is the first line of reserve |
| A write method returns nothing | Engineer of a product domain | consume_now returns no LedgerEntry |
| A product endpoint carries no Billing data | Engineer of a product domain | The Ads Team campaign page loads the own account of the company from GET /team/billing/org-companies/:org_company_id/account |
| Billing picks the own account and the lots | Engineer of Billing | Acme pays from its own account, soonest-expiring lot first, as Billing D16 — A company spends only its own billing account states |
| A ledger calculation that decides a write runs after the balance row lock | Engineer of Billing | consume_reserved reads the units already consumed after lock('FOR UPDATE') |
A spend counts only the units of lots that are not past expires_at, in the check and in the spend | always | Lot 10 with 20 units expired at 15:00, so at 15:05 a spend of 25 units against 10 units in lot 11 gets not_enough_credits, as the row "The units a spend counts" of Billing D18 — Product domains spend credits only through SpendService rules |
A spend moves at least 1 unit, and SpendValidator, reserve and consume_now raise for 0 or less | always | A free banner costs 30 credits, and Acme pays them from a lot that a Billing::CreditAction granted, as the row "A spend of 0 units" of Billing D18 — Product domains spend credits only through SpendService rules |
| A direct consume writes an idempotency key from its deliverable | Engineer of Billing | consume_now_Careers::JobPosting_88 |
| Billing code never reads a product table and never names a product | Engineer of Billing | The daily Ads consume job lives in Ads |
| Each product runs its own scheduled jobs | The system | Careers::Jobs::CloseJob lives in Careers |
| Every company has its own account, created with the company | always | Org::Companies::Shared::CreateService calls Billing::Accounts::Shared::CreateService |
A missing own account raises Errors::InternalServerError, because it is a data bug | always | SpendValidator and consume_now raise it when org_company.billing_account is nil |
| The employer page reads the balance from the Billing endpoint | HQ manager | GET /employers/billing/entitlement-balances |
| The statement of account is built from ledger entries | HQ manager | One line per ledger entry, with its entry_type, its description and the balance after it |
Worked example: Acme buys credits and posts a Barista job
Acme Pte Ltd has no placement credits on 10 Oct, and 1 placement credit costs SGD 1.
Legend: the orange band is one database transaction, which Careers opens.
- On 10 Oct, Acme pays invoice
SG-INV-000042for a pack of 200 placement credits.- Billing grants the 200 credits to the own account of Acme, as one lot.
- The
:grantentry has the text "Invoice SG-INV-000042: 200 placement credits".
- On 14 Oct, the HQ manager of Acme posts a Barista job with the price "1 Month" for 50 credits.
- Careers runs
SpendValidatorwith 50 units, and it adds no error. - Careers opens a transaction, and saves the
Careers::JobandCareers::JobPosting88, from 14 Oct to 13 Nov. - Careers calls
consume_nowwith 50 units, theCareers::JobPostingas the deliverable, and the text "Job post: Barista, 1 Month". - Billing checks that a transaction is open, locks the balance row of Acme, and takes 50 units from the lot.
- Billing writes one
:consumeentry with the text and the keyconsume_now_Careers::JobPosting_88. - Billing recognises SGD 50 of revenue from the money on the lot.
- Billing writes one
consume_nowreturns nothing, the transaction commits, and the Employer Dashboard shows 150 credits left.- On 13 Nov,
Careers::Jobs::CloseJobcloses the job, and Billing is not called. - Acme downloads its statement of account, and it shows two lines.
| Date | entry_type | description | Credits | Balance |
|---|---|---|---|---|
| 10 Oct | :grant | Invoice SG-INV-000042: 200 placement credits | +200 | 200 |
| 14 Oct | :consume | Job post: Barista, 1 Month | -50 | 150 |
Where the code is
| What | File | Entry point |
|---|---|---|
| The public write class | app/domains/billing/spend_service.rb | consume_now, reserve, consume_reserved, release |
| The public check class | app/domains/billing/spend_validator.rb | valid? and errors |
| The check for an open transaction | app/domains/billing/spend_service.rb | require_open_transaction! |
| The Billing errors | app/domains/billing/error.rbapp/domains/billing/insufficient_credits_error.rb | Billing::ErrorBilling::Error::DEFINITIONSBilling::InsufficientCreditsError |
| Credit movements between lots | app/domains/billing/entitlement_lot_service.rb | reserve, consume, release, expire |
| The own account of a company | app/domains/org/company.rb | billing_account |
| The ledger entry | app/domains/billing/ledger_entry.rb | Billing::LedgerEntry |
| The employer balance | app/controllers/employers/billing/entitlement_balances_controller.rb | index |
| An Ads campaign reserves | app/domains/ads/campaigns/employers_submit_manager.rbapp/domains/ads/campaigns/team_submit_manager.rb | execute |
| An Ads campaign releases | app/domains/ads/campaigns/reject_service.rbapp/domains/ads/campaigns/employers_cancel_manager.rbapp/domains/ads/campaigns/team_cancel_manager.rb | execute |
| The daily Ads consume | app/domains/ads/campaign_placements/consume_reserved_credits_job.rb | perform |
| The Ads ledger entry description | app/domains/ads/campaign_placement.rb | BILLING_LEDGER_ENTRY_DESCRIPTION |
| A Careers job pays | app/domains/careers/job_postings/shared/create_service.rb | execute |
| The Careers ledger entry description | app/domains/careers/job_posting.rb | BILLING_LEDGER_ENTRY_DESCRIPTIONS |
| The Ads Team campaign page loads the account | jodapp-web, app/routes/team/ads-campaigns/team-ads-campaigns-detail-page.jsx | clientLoader |
Related pages
- Billing D18 — Product domains spend credits only through SpendService
- Billing Layers — the four layers of Billing and the tables in each
- Billing Overview — the glossary, with deliverable and source
- Billing D2 — All stored-value credits use entitlement lots
- Billing D5 — Spending mechanics: consume now, or reserve first
- Billing D16 — A company spends only its own billing account
- The model
LedgerEntry— every credit movement and its source - Ads data model — the Ads price list and campaign placements