Skip to main content

Settlement Flows

This section documents the technical flows for different settlement patterns.

Direct Settlement Flow​

Standard settlement via the REST API.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Client β”‚ β”‚ Lightning Enableβ”‚ β”‚ Provider β”‚ β”‚Lightningβ”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
β”‚ β”‚ β”‚ β”‚
β”‚ POST /api/payments β”‚ β”‚ β”‚
│───────────────────>β”‚ β”‚ β”‚
β”‚ β”‚ Create charge β”‚ β”‚
β”‚ │───────────────────>β”‚ β”‚
β”‚ β”‚ β”‚ Invoice β”‚
β”‚ β”‚<───────────────────│ β”‚
β”‚ Invoice + ID β”‚ β”‚ β”‚
β”‚<───────────────────│ β”‚ β”‚
β”‚ β”‚ β”‚ β”‚
β”‚ [Client pays invoice via Lightning wallet] β”‚
β”‚ β”‚ β”‚ β”‚
β”‚ β”‚ Webhook: paid β”‚ β”‚
β”‚ β”‚<───────────────────│ β”‚
β”‚ Webhook: settled β”‚ β”‚ β”‚
β”‚<───────────────────│ β”‚ β”‚
β”‚ β”‚ β”‚ β”‚

Endpoints​

Settlements ride on the Payments API β€” there is no separate settlements endpoint:

  • POST /api/payments - Create an invoice (a settlement request)
  • GET /api/payments/{invoiceId} - Check settlement status
  • POST /api/payments/{invoiceId}/sync - Force a status sync from your payment provider
  • POST /api/webhooks/strike / POST /api/webhooks/opennode - Where your payment provider notifies Lightning Enable; Lightning Enable then forwards a signed webhook to your callback URL

L402 Settlement Flow​

Per-request settlement using HTTP 402 challenges.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Client β”‚ β”‚ Lightning Enableβ”‚ β”‚ Provider β”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
β”‚ β”‚ β”‚
β”‚ GET /resource β”‚ β”‚
│───────────────────>β”‚ β”‚
β”‚ β”‚ Create charge β”‚
β”‚ │───────────────────>β”‚
β”‚ β”‚<───────────────────│
β”‚ 402 + Invoice β”‚ β”‚
β”‚<───────────────────│ β”‚
β”‚ β”‚ β”‚
β”‚ [Client pays, receives preimage] β”‚
β”‚ β”‚ β”‚
β”‚ GET /resource β”‚ β”‚
β”‚ Auth: L402 token β”‚ β”‚
│───────────────────>β”‚ β”‚
β”‚ β”‚ Verify preimage β”‚
β”‚ 200 + Content β”‚ β”‚
β”‚<───────────────────│ β”‚
β”‚ β”‚ β”‚

L402 Header Format​

Request:

Authorization: L402 <macaroon>:<preimage>

Challenge response (402):

WWW-Authenticate: L402 macaroon="<base64>", invoice="<bolt11>"

Webhook Flow​

Settlement confirmation via webhooks.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Provider β”‚ β”‚ Lightning Enableβ”‚ β”‚ Your App β”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
β”‚ β”‚ β”‚
β”‚ POST /webhooks β”‚ β”‚
β”‚ (settlement event) β”‚ β”‚
│────────────────────>β”‚ β”‚
β”‚ β”‚ Verify signature β”‚
β”‚ β”‚ Update state β”‚
β”‚ β”‚ β”‚
β”‚ β”‚ POST /your-webhook β”‚
β”‚ │────────────────────>β”‚
β”‚ β”‚ β”‚ Process
β”‚ β”‚ 200 OK β”‚
β”‚ β”‚<────────────────────│
β”‚ 200 OK β”‚ β”‚
β”‚<────────────────────│ β”‚
β”‚ β”‚ β”‚

Webhook Signature Verification​

X-LightningEnable-Signature: t={unix_timestamp},v1={hmac_sha256_hex}

Verify by computing HMAC-SHA256 of {timestamp}.{payload} using your webhook secret. Reject signatures older than 5 minutes. See Webhook Verification for full details and code examples.

Settlement States​

StateDescriptionTerminal
unpaidInvoice created, awaiting settlementNo
processingSettlement detected, confirmingNo
paidSettlement completeYes
expiredInvoice expiredYes
refundedSettlement was refundedYes

These are the same status values returned by the Payments API and forwarded in webhooks.

Further Reading​