BILLING LAYER

Subscriptions

Recurring payments enforced at the blockchain consensus layer. No payment processor, no webhook infrastructure, no failed-charge handling.

BLOCK-HEIGHT PRECISIONCONSENSUS-ENFORCEDAI AGENT GOVERNANCEANY ASSET TYPEZERO FAILED CHARGES
100%
On-chain billing with no external payment processor required
Any
Asset type: coin / currency / Totem
0
Webhooks, callbacks, or off-chain logic required
Auto
Lapse on insufficient funds with no dunning process
01
HOW IT WORKS
Subscriptions as first-class protocol state

Subscriptions in Shamwari are stored as first-class account entities in blockchain state which do not rely on smart contract state. The protocol manages subscription automatically at each configured block height via the AFTER_BLOCK_APPLY handler. Only user transaction triggers renewal.

BILLING LIFECYCLE
Service Registration
The service provider submits a SERVICE_CREATION transaction defining price, billing period (in blocks), accepted asset type, and any account type restrictions. The SubscriptionServiceEntity is written to blockchain state which is discoverable by all potential subscribers via the REST API.
First Payment at Subscription
SUBSCRIBE transaction executes atomically: (1) first billing period payment deducted from subscriber balance, (2) SubscriptionEntity created with expirationHeight = currentHeight + billingPeriod, (3) provider balance credited. Both parties are bound from the next block.
SUBSCRIBE → first debit + entity creation
Automatic Lapse
Cancellation
A subscriber can cancel a subscription at any time. Effective at the next block. No notice period ambiguity, no pro-rata refund obligation, no chargeback mechanism. The SubscriptionEntity is removed from active state and archived in history.
CANCEL_SUBSCRIPTION → effective next block

Why Consensus Billing Beats Webhooks

Traditional subscription billing is a webhook problem. When the payment processor fires a webhook, the application must: authenticate the webhook, update its database, handle retries, manage idempotency, and reconcile failures. None of this exists in Shamwari.

  • No webhook endpoint to maintain or secure
  • No race conditions between webhook and database update
  • No idempotency keys or duplicate payment handling
  • No reconciliation between processor and application state
  • No PCI DSS scope for card data since no card data exists
  • Billing state is the blockchain a publicly verifiable source of proof
  • Protocol upgrade required to change billing logic ensuring transparency

AFTER_BLOCK_APPLY Billing Engine

Subscription billing is registered as an AFTER_BLOCK_APPLY listener which is one of Shamwari's six automatic post-block operations. The listener processes all subscriptions reaching their expirationHeight in that block as a batch, in a single database transaction.

  • All renewals in the same block are atomic together
  • Partial block execution is impossible meaning no interrupted lapses or payments
  • Zero-cost renewal processing for service providers
  • Batch processing scales linearly with subscription count
  • State consistent across all network nodes simultaneously
02
SUBSCRIPTION ENTITY
Full state machine in blockchain state

Every active subscription is a typed entity in the blockchain state, with all authority needed for renewal processing held by the subscriber account.

FieldTypeDescription
subscriptionIdlongUnique subscription identifier. Derived from transaction hash. Immutable.
serviceIdlongReferences the SubscriptionServiceEntity. Links to service name, provider, and configuration.
subscriberAccountIdlongAccount ID of the subscriber. Only this account can cancel the subscription.
providerAccountIdlongAccount ID of the service provider. Credited on each renewal.
billingAmountlongPayment amount per billing period in smallest digital unit (QNT). Immutable after creation.
billingPeriodintBilling period in blocks. The protocol adds this to expirationHeight after each successful renewal.
expirationHeightintBlock height at which the next billing attempt occurs. Updated by AFTER_BLOCK_APPLY on renewal.
assetTypeenumCOIN / CURRENCY / TOTEM determines which balance to debit on renewal.
assetIdlongAsset ID for CURRENCY and TOTEM types. 0 for COIN type.
statusenumACTIVE / LAPSED / CANCELLED. Transitions are protocol-enforced.
latestBlockintBlock height of last renewal. Used for history queries and analytics.

Versioned State

Like all Shamwari entities, SubscriptionEntity is stored in a versioned table keyed by (subscriptionId, height). Every state change from creation, renewal, lapse to cancellation is preserved at the block height it occurred.

  • Query subscription state at any historical block height
  • Full renewal history queryable via REST API
  • Lapse events recorded at time of lapse
  • Cancellation timestamp and initiator permanently recorded
  • Analytics: total revenue per service, churn rate, ARPU

SubscriptionServiceEntity

The service configuration entity is created once by the provider and referenced by all subscriber entities. Changes to the service (price, period) require a new SERVICE_UPDATE transaction and only apply to new subscriptions and existing subscriptions honour the terms at creation.

  • serviceName, serviceDescription
  • billingAmount, billingPeriod which is immutable per subscriber at creation
  • acceptedAssetType: what payment the service accepts
  • accountTypeRestrictions: who is allowed to subscribe
  • isActive: provider can pause new subscriptions
  • totalSubscribers, totalRevenue: live on-chain analytics
03
BILLING FREQUENCY
Block heights, not calendar dates

Subscription billing frequency is expressed in blocks and not calendar time. This is deterministic, timezone-independent, and unambiguous. A billingPeriod of 7,200 blocks is always exactly 7,200 blocks. There is no concept of "end of month", "daylight saving adjustment", or "leap year edge case" in Shamwari billing.

HOURLY
~300
60s × 300 ≈ 5 min on test / adjust per network
DAILY
~7,200
60s × 7,200 = 12 hrs actual; adjust per target
WEEKLY
~50,400
60s × 50,400 ≈ 35 days; use 43,200 for 30d
MONTHLY
~216,000
60s × 216,000 = 150 days; 144,000 = ~100d
QUARTERLY
~648,000
~450 days; set exactly per network block time
ANNUALLY
~2,628,000
~1,825 days; deterministic regardless of year
CUSTOM
any int > 0
Set any positive integer for precise billing
MICRO
1–300
Sub-minute billing for machine-to-machine metering
Block Time Calibration
The ~60-second target block time means 1 block ≈ 1 minute. For production deployments, providers calibrate their billingPeriod against the observed median block time on the specific chain. A billing period of exactly 30 days (2,592,000 seconds) translates to billingPeriod = 2,592,000 / observedMedianBlockSeconds.
Sub-Day Billing for Machine Commerce
billingPeriod can be set to any positive integer including values less than 300 (sub-5-minute billing at ~60s block times). This enables machine-to-machine usage metering, AI agent service consumption, and API usage billing without any off-chain metering infrastructure.
No Partial Period Proration
Subscription billing is all-or-nothing per period. The full billingAmount is charged to expirationHeight, or the subscription lapses. There is no partial period, no pro-rata calculation, and no refund for unused time within a period. This is the same model as most subscription businesses which is simple and predictable for both parties.

Predictable Cash Flow Modelling

Service providers can calculate expected revenue for any future block range from the live subscription state. The total expected revenue for blocks N through M = sum of billingAmount for all subscriptions with expirationHeight in [N, M] and status = ACTIVE.

  • getSubscriptionsByService?service=ID : live subscriber list
  • getExpiringSubscriptions?fromHeight=N&toHeight=M : future cash flow
  • getSubscriptionRevenue?service=ID&period=monthly : analytics
  • No uncertainty about renewal probability; protocol either renews or lapses
  • Churn prediction: query lapse rate from versioned history table

Multi-Currency Revenue Modelling

If a service accepts multiple payment types (separate service registrations per asset type), revenue is denominated in the relevant asset. Cross-currency revenue aggregation is an off-chain analytics concern wher each asset's revenue is tracked independently on-chain.

  • Separate SubscriptionServiceEntity per accepted asset type
  • ZWG subscribers billed in ZWG; ZAR subscribers in ZAR
  • Protocol never performs currency conversion for billing
  • FX aggregation handled off-chain by provider accounting systems
04
SERVICE CONFIGURATION
Account restrictions and asset flexibility

Service providers configure subscription parameters once at service creation. The protocol enforces all restrictions at the gate with account type checks at consensus, asset validity at attachment validation, and balance checks at renewal.

Account Type Restrictions

Services can restrict subscriptions to specific AccountType values: BUSINESS, DEVELOPER, PERSONAL, SAVINGS, AUTONOMOUS, or any combination. The SUBSCRIBE transaction is rejected at gate 4 (Account Type Gate) for non-permitted account types before any payment is attempted and before the SubscriptionEntity is created.

Any Asset Type Accepted

Services can accept payment in chain coin (WEALTH/FXT), any ShamwariPay currency (ZWG, ZAR, CAPITAL), or any APPROVED Totem digital asset. The billingAmount is denominated in the smallest unit of the accepted asset. Mixed-asset services require separate service registrations.

Automatic Lapse Logic

If subscriber funds are unavailable at renewal, the subscription lapses immediately at that block. No retry logic, no dunning management, no grace period, no failed payment email. The service provider can query lapsed subscribers and offer reinstatement via a new SUBSCRIBE transaction.

Service Pause Capability

Providers can submit SERVICE_UPDATE transactions to pause new subscriptions (isActive = false). Existing active subscriptions continue billing normally. This enables controlled rollout pauses, maintenance windows, and capacity management without disrupting existing subscribers.

Subscriber Account Blocking

If a subscriber's account receives BLOCKED_CHAIN_USER permission (sanctions or AML action), their subscription renewals are rejected at gate 3 (Permission Policy Check), before the balance debit. The subscription transitions to LAPSED at the next renewal attempt.

Free Trial Configuration

Providers can configure a trialPeriodBlocks field in the service entity. Trial subscribers get a subscription entity with expirationHeight = currentHeight + trialPeriodBlocks and billingAmount = 0 for the first period. First paid billing period triggers at trial expiry.

05
USE CASES
Six subscription models in production

Every subscription use case below runs entirely on the protocol billing engine with no payment processor, no webhook infrastructure, no external dependency.

USE CASE · SAAS
B2B SaaS Billing
Software-as-a-service subscription for business tools, analytics platforms, and enterprise applications. Monthly or annual billing in ZWG or USD.
accountTypeRestrictions: [BUSINESS, DEVELOPER] billingPeriod: 216,000 blocks (~30 days) billingAmount: 500 ZWG per period assetType: CURRENCY freeTrialPeriod: 43,200 blocks
USE CASE · DATA
Data Feed Access
Real-time or periodic oracle, market data, weather, or satellite feed subscription. Sub-daily billing for high-frequency data consumers.
accountTypeRestrictions: [BUSINESS, AUTONOMOUS] billingPeriod: 7,200 blocks (~24 hrs) billingAmount: 10 ZWG per period assetType: CURRENCY freeTrialPeriod: 0
USE CASE · MEDIA
Consumer Media
Individual streaming, content platform, or digital media subscription. Monthly billing in local currency for consumer accounts.
accountTypeRestrictions: [PERSONAL, SAVINGS] billingPeriod: 216,000 blocks (~30 days) billingAmount: 200 ZWG per period assetType: CURRENCY freeTrialPeriod: 50,400 blocks
USE CASE · MICRO
Microinsurance Premium
Micro-health, funeral, or agricultural insurance premium collection via recurring billing. Weekly or monthly at sub-$1 amounts.
accountTypeRestrictions: [PERSONAL, SAVINGS] billingPeriod: 50,400 blocks (~7 days) billingAmount: 15 ZWG per period assetType: CURRENCY freeTrialPeriod: 0
USE CASE · INFRA
Node Infrastructure
Server, storage, or compute resource subscription for institutional participants running infrastructure. Billed in WEALTH coin.
accountTypeRestrictions: [BUSINESS, BANK, FSP] billingPeriod: 648,000 blocks (~90 days) billingAmount: 1000 WEALTH per period assetType: COIN freeTrialPeriod: 0
USE CASE · AI
AI Agent Service
Machine-to-machine API consumption. AI agent accounts subscribe to data or inference services within their governance-approved spend limits.
accountTypeRestrictions: [AI] billingPeriod: 300 blocks (~5 mins) billingAmount: 1 ZWG per period assetType: CURRENCY freeTrialPeriod: 0
06
AI AGENT SUBSCRIPTIONS
Autonomous agents with governed billing obligations

AccountType.AI accounts can subscribe to services within their AutonomousAccountControl rule set. Subscription payments count toward rolling spend window calculations — the protocol prevents AI agents from silently accumulating recurring obligations that exceed their governance-approved limits.

Subscription in AI Permission Matrix
SUBSCRIBE is included in the isAIAllowed() = true transaction whitelist. An AI account can subscribe to services as long as the provider is on its recipient whitelist, the billingAmount is within its per-transaction cap, and the cumulative subscription load is within its rolling window limit.
Rolling Window Enforcement
Each subscription renewal counts toward the AI account's rolling spend window. If the scheduled renewal would push cumulative spend past the configured window limit, the renewal is rejected and the subscription lapses. The AI cannot accumulate obligations by subscribing to many small services.
Recipient Whitelist
AI accounts can be configured to subscribe only to services provided by whitelisted account IDs. Subscription attempts to non-whitelisted providers are rejected at gate 4. This prevents AI agents from autonomously subscribing to arbitrary services outside their governance-approved provider list.
Governance Override on Lapse
If an AI subscription lapses (no renewal or limit breach), reinstatement requires a new SUBSCRIBE transaction, which itself must pass all AI permission checks. A governance admin cannot reinstate by simply modifying state; the full permission pipeline must pass.

Example: Enterprise AI Treasury Agent

An enterprise deploys an AI treasury agent configured with the following AutonomousAccountControl rule set for subscriptions:

  • Max per-transaction: 500 ZAR
  • Rolling 30-day window: 5,000 ZAR across all subscriptions
  • Permitted transaction types: SUBSCRIBE, CANCEL_SUBSCRIPTION
  • Provider whitelist: [Bloomberg Data ID, ZIMRA API ID, Oracle Feed ID]
  • Min balance floor: 2,000 ZAR (cannot deplete below this)
  • Result: agent manages up to 10 × 500 ZAR subscriptions autonomously within governance bounds

Machine-to-Machine Metering

Sub-5-minute billing periods enable genuine usage-based metering for AI service consumption without off-chain metering infrastructure.

  • AI subscribes to inference API: 1 ZWG per 300 blocks (~5 mins)
  • Protocol deducts billing amount every 300 blocks automatically
  • AI can cancel when task complete with no minimum period
  • Usage cost exactly proportional to active subscription periods
  • Full audit trail: every billing event permanently on-chain
  • No metering server, no usage counter, no reconciliation
07
TAX WITHHOLDING
Subscription tax collected at every billing cycle

If the SUBSCRIPTION tax rate is configured on the chain (0–3500 basis points), tax is automatically withheld from every subscription renewal payment and credited to the Tax Collector account in the same atomic operation — with zero off-chain reporting.

Automatic Withholding at Every Renewal
When AFTER_BLOCK_APPLY processes a subscription renewal, it checks the SUBSCRIPTION tax rate configuration. If non-zero, it: (1) calculates taxAmount = (billingAmount × SUBSCRIPTION_TAX_BPS) / 10,000, (2) debits subscriber for full billingAmount, (3) credits provider with billingAmount − taxAmount, (4) credits Tax Collector with taxAmount. All in one atomic block.
Tax Rate Configurable by Chain
Each jurisdiction chain (ZIMBABWE, SOUTH AFRICA) has its own SUBSCRIPTION tax rate configured by its Tax Collector authority account. ZWG subscriptions are taxed at Zimbabwe's configured rate; ZAR subscriptions at South Africa's rate. The rates are set by the respective revenue authorities.
Permanent CurrencyTaxRecord
Every subscription tax withholding event creates an immutable CurrencyTaxRecord linked to the subscription ID, renewal block height, subscriber account, Tax Collector account, and tax amount. This constitutes a primary tax collection record with no off-chain reporting or reconciliation required.
Zero-Rate for Non-Taxable Services
If SUBSCRIPTION tax rate is set to 0 basis points, no withholding occurs. The provider receives the full billingAmount. Setting the rate to zero does not delete the tax rate configuration record as it is preserved with its effective block height for historical audit queries.

Tax Calculation Example

A ZWG subscription service with billingAmount = 1,000 QNT (100 ZWG at 1 decimal) and SUBSCRIPTION tax rate = 500 bps (5%):

  • Subscriber debited: 1,000 QNT
  • Tax withheld: (1,000 × 500) / 10,000 = 50 QNT
  • Provider credited: 1,000 − 50 = 950 QNT
  • Tax Collector credited: 50 QNT
  • CurrencyTaxRecord created: linked to subscription ID + block height
  • All in one atomic database transaction with no partial state possible

VAT on Digital Services

Value-Added Tax on digital services is a compliance challenge for traditional SaaS providers in emerging markets. Shamwari's protocol-native withholding eliminates the challenge entirely as the protocol calculates and withholds at the point of payment automatically.

  • No VAT invoice generation required
  • No manual remittance to revenue authority
  • Tax Collector balance = total VAT collected in real time
  • Revenue authority queries Tax Collector account for real-time reporting
  • Immutable CurrencyTaxRecord = primary VAT record for audit
08
COMPARISON
Protocol billing vs Stripe / traditional processors

The complete comparison between Shamwari's consensus-native billing and traditional SaaS subscription infrastructure.

SHAMWARI PROTOCOL BILLING
  • Billing enforced by consensus with zero processor dependency or API uptime risk
  • Block-height precision; no timezone, clock synchronisation, or daylight saving ambiguity
  • Automatic lapse on insufficient funds eliminating dunning emails, retry logic, or grace periods
  • AI agent subscriptions with protocol-enforced governance limits
  • Tax withheld automatically at every renewal with zero off-chain reporting obligation
  • Any asset type accepted: coin, currency, or Totem with no payment processor restriction
  • Sub-minute billing periods possible for machine-to-machine metering
  • All billing state permanently on-chain for a full audit trail from subscription creation
TRADITIONAL BILLING
  • Payment processor API dependency with downtime causing billing failures
  • Webhook infrastructure required for authentication, retry, idempotency handling
  • Failed charge handling: dunning emails, retry logic, grace periods, churn management
  • No AI governance controls and an agent can accumulate unlimited obligations
  • Tax calculation middleware which are separate integrations and a compliance burden
  • Card-only or limited payment rails with no native crypto, stablecoin, or digital asset billing
  • Minimum billing period: daily at best for most processors
  • Billing records in processor database subject to processor policies and data requests
DEPLOY SUBSCRIPTION PRODUCTS

No payment processor. Just the protocol.

Create subscription services that bill automatically for SaaS, data feeds, media, microinsurance premiums, or any recurring revenue model.