Integration Guide
This guide covers the Core Payments API end to end: create a payment, show it to the buyer, confirm it was paid, and fulfill the order. It works on every plan.
Authentication
Send your merchant API key in the X-API-Key header. Keep it server-side; never put it in browser code.
curl https://api.lightningenable.com/api/payments/1042 \
-H "X-API-Key: $LIGHTNING_ENABLE_API_KEY"
Creating Payments
const response = await fetch('https://api.lightningenable.com/api/payments', {
method: 'POST',
headers: {
'X-API-Key': process.env.LIGHTNING_ENABLE_API_KEY,
'Content-Type': 'application/json',
'X-Idempotency-Key': 'order-12345-attempt-1' // optional: safe retries
},
body: JSON.stringify({
orderId: 'ORDER-12345',
amount: 99.99,
currency: 'USD',
description: 'Premium Widget',
successUrl: 'https://yourapp.com/success',
metadata: { customerId: 'cust_123' }
})
});
const payment = await response.json(); // 201 Created
Request Fields
| Field | Type | Required | Description |
|---|---|---|---|
orderId | string | Yes | Your order reference, 1 to 100 characters |
amount | decimal | Yes | Amount in currency |
currency | string | No | Three-letter code, default USD. Strike: USD, EUR, GBP, BTC. NWC: BTC only |
description | string | No | Up to 500 characters; trimmed to the provider's invoice limit |
customerEmail | string | No | Customer email |
customerName | string | No | Customer name |
successUrl | string | No | Where hosted checkout sends the buyer after payment |
metadata | object | No | String key-value pairs, returned in the webhook as a JSON string |
expiresInSeconds | integer | No | Invoice lifetime, 60 to 86400. Omit for the provider default (about 24 hours on Strike). Out of range returns 400 invalid_expiry |
Send X-Idempotency-Key (up to 256 characters) to make retries safe: repeating a request with the same key returns the original payment instead of creating a second invoice.
Response Fields
| Field | Type | Description |
|---|---|---|
invoiceId | string | Lightning Enable invoice ID (numeric string). Use it for status calls |
status | string | unpaid, processing, paid, expired, or refunded |
amount / currency | As requested | |
lightningInvoice | string | BOLT11 invoice to pay |
paymentHash | string | The invoice's payment hash |
onchainAddress | string | Bitcoin address, when the provider offers one (Strike, OpenNode) |
payUrl | string | Hosted checkout link, https://api.lightningenable.com/pay/{token} |
providerChargeId | string | The provider's ID for this invoice (openNodeChargeId carries the same value for older clients) |
createdAt / expiresAt | datetime | expiresAt is the BOLT11 invoice's own deadline |
Showing the Payment
Hosted checkout (simplest)
Redirect the buyer to payUrl. The page shows the QR code, Lightning and on-chain options, a countdown, and redirects to successUrl once paid.
window.location.href = payment.payUrl;
payUrl as a payment linkAnyone holding it can view that invoice. Send it to the buyer, but don't log it or publish it where a crawler can find it. It cannot be rebuilt from invoiceId; if you lose it, read it again from GET /api/payments/{invoiceId}.
For a ready-made button, see checkout.js.
Your own UI
Render lightningInvoice as a QR code with any QR library (prefix it with lightning: for wallet deep links), show a copy button, and count down to expiresAt.
Confirming Payment
Webhooks (recommended)
Set a callback URL and secret with PUT /api/merchant/webhook-url, verify the X-LightningEnable-Signature header, and fulfill on status === 'paid'. See Webhooks.
Polling
GET /api/payments/{invoiceId} (with your API key) is the authoritative status. POST /api/payments/{invoiceId}/sync re-checks the provider immediately. Poll no more than every few seconds:
async function waitForPayment(invoiceId) {
for (;;) {
const res = await fetch(`https://api.lightningenable.com/api/payments/${invoiceId}`, {
headers: { 'X-API-Key': process.env.LIGHTNING_ENABLE_API_KEY }
});
const payment = await res.json();
if (payment.status === 'paid' || payment.status === 'expired') return payment;
await new Promise(r => setTimeout(r, 3000));
}
}
The unauthenticated GET /api/payments/{invoiceId}/status returns only { "status": "..." }. Use it for browser-side UX, never to decide fulfillment.
On the NWC lane, payment is detected by polling your wallet once a minute, so allow up to 60 seconds.
Error Handling
Most error bodies carry error and message; a request that fails field validation returns a problem-details body naming the field. Common cases on POST /api/payments:
| Status | error | What to do |
|---|---|---|
400 | invalid_expiry, payment_provider_not_configured, or field validation | Fix the request, or save a provider credential |
401 | API key required / Invalid API key | Check X-API-Key |
403 | Subscription not active and related | Route on action_required |
429 | Rate limited; wait and retry with the same X-Idempotency-Key | |
502 | payment_provider_rejected | The provider refused the invoice; message gives its reason. Not retryable as is |
502 | payment_provider_unavailable | The provider is down; retry later |
503 | payment_provider_busy | NWC wallet busy; retry after Retry-After seconds |
See Errors for the full list.
Python Example
import os
import requests
BASE_URL = 'https://api.lightningenable.com'
HEADERS = {'X-API-Key': os.environ['LIGHTNING_ENABLE_API_KEY']}
def create_payment(order_id, amount, currency='USD', **fields):
response = requests.post(
f'{BASE_URL}/api/payments',
headers={**HEADERS, 'X-Idempotency-Key': f'{order_id}-1'},
json={'orderId': order_id, 'amount': amount, 'currency': currency, **fields},
timeout=30,
)
response.raise_for_status()
return response.json()
def get_payment(invoice_id):
response = requests.get(f'{BASE_URL}/api/payments/{invoice_id}', headers=HEADERS, timeout=30)
response.raise_for_status()
return response.json()
Best Practices
- Keep the API key server-side and verify every webhook signature.
- Store
invoiceIdagainst your order, and make fulfillment idempotent: webhooks can repeat. - Reconcile pending orders with
GET /api/payments/{invoiceId}on a schedule, so a missed webhook never strands an order. - Treat
expiredas final; create a new payment for a retry.
Next Steps
- Webhooks: real-time notifications
- Payments API Reference: every endpoint