On this page:
money
offer
payment-event
order-projection
rights-intent
empty-commerce-state
ingest-payment-event
commerce-state-order
commerce-state-intents
exn:  fail:  commerce

1 Core values and the pure facade🔗ℹ

The (require commerce) facade is pure and product-safe: values, deterministic projections, and the typed exception. It contains no network, storage, or signing.

struct

(struct money (currency minor-units))

  currency : string?
  minor-units : exact-nonnegative-integer?
Represents money exactly in the currency’s smallest configured unit. Currency is an uppercase three-letter ISO 4217 code. Floating-point amounts are rejected by the constructor guard.

struct

(struct offer (id product-id kind price entitlement-policy-id))

  id : string?
  product-id : string?
  kind : (or/c 'one-time 'subscription)
  price : money?
  entitlement-policy-id : string?
Describes one stable thing a customer may buy. Identifiers are lowercase kebab-case. Provider product and price identifiers are mappings owned by the service and are not part of this value.

struct

(struct payment-event (provider
    event-id
    payload-digest
    kind
    order-id
    offer-id
    subject-id
    amount
    occurred-at
    paid-through))
  provider : string?
  event-id : string?
  payload-digest : string?
  kind : symbol?
  order-id : string?
  offer-id : string?
  subject-id : string?
  amount : money?
  occurred-at : exact-nonnegative-integer?
  paid-through : (or/c exact-nonnegative-integer? #f)
One authenticated provider fact. payment-event? and the accessors above are exported by the facade; the raw constructor is not — adapters build events through make-verified-payment-event in commerce/provider. For a one-time fact, paid-through stays #f; a subscription payment reports the epoch second through which the provider says access is paid.

struct

(struct order-projection (provider
    order-id
    offer-id
    subject-id
    amount
    paid?
    refunded?
    paid-at
    refunded-at
    paid-through))
  provider : string?
  order-id : string?
  offer-id : string?
  subject-id : string?
  amount : money?
  paid? : boolean?
  refunded? : boolean?
  paid-at : (or/c exact-nonnegative-integer? #f)
  refunded-at : (or/c exact-nonnegative-integer? #f)
  paid-through : (or/c exact-nonnegative-integer? #f)
The deterministic commercial state of one provider order.

struct

(struct rights-intent (idempotency-key
    action
    provider
    order-id
    offer-id
    subject-id
    occurred-at))
  idempotency-key : string?
  action : symbol?
  provider : string?
  order-id : string?
  offer-id : string?
  subject-id : string?
  occurred-at : exact-nonnegative-integer?
One deterministic instruction for the Permit issuance boundary, emitted by projection and consumed through the issuance outbox.

procedure

(empty-commerce-state) → commerce-state?

Returns an empty immutable projection state.

procedure

(ingest-payment-event state event)

 → 
commerce-state? (listof rights-intent?)
  state : commerce-state?
  event : payment-event?
Applies one previously verified provider event. Exact replay returns the same state and an empty intent list. Conflicting replay or changed order identity raises an exn:fail:commerce value.

procedure

(commerce-state-order state    
  provider    
  order-id) → (or/c order-projection? #f)
  state : commerce-state?
  provider : string?
  order-id : string?
Returns the current projection for one provider order.

procedure

(commerce-state-intents state) → (listof rights-intent?)

  state : commerce-state?
Returns all emitted rights intents sorted by their idempotency keys.

struct

(struct exn:fail:commerce (message continuation-marks code data))

  message : string?
  continuation-marks : continuation-mark-set?
  code : symbol?
  data : any/c
The typed failure for every commercial refusal. Codes are kebab-case symbols; data is a redaction-safe hash. Raw provider bytes, signatures, and key material never appear in the message or data.