# Micro-Transaction Service

Processes pay-per-use purchases for meditations, teachings, and live experiences
with token-backed authorization, settlement, ledgering, and refunds.

## Pipeline

1. **Compliance guard** – validates purchase and refund policies per asset type.
2. **Payment gateway** – authorizes micro-payments and executes
   settlements/refunds.
3. **Ledger** – records debit/credit entries for accounting and audit trails.
4. **Batch scheduler** – groups transactions into settlement batches for
   treasury.
5. **Transaction store** – persists micro-payment states and statuses.
6. **Event bus & analytics** – emits lifecycle events and publishes telemetry.

## Usage

```ts
import { createMicroTransactionService } from './service';

const service = createMicroTransactionService({
  paymentGateway,
  ledger,
  batchScheduler,
  eventBus,
  analyticsReporter,
  complianceGuard,
  transactionStore,
  settlementStore,
});

const payment = await service.authorizePurchase({
  accountId: '0xAya',
  assetId: 'meditation-333',
  assetType: 'meditation',
  amount: '50000000000000000',
  currency: 'MATIC',
  paymentMethod: 'token_balance',
});
```

## Tests

```bash
npx jest --config apps/lilith/svc-micro-transaction/jest.config.cjs --runInBand
```
