Skip to main content

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​

FieldTypeRequiredDescription
orderIdstringYesYour order reference, 1 to 100 characters
amountdecimalYesAmount in currency
currencystringNoThree-letter code, default USD. Strike: USD, EUR, GBP, BTC. NWC: BTC only
descriptionstringNoUp to 500 characters; trimmed to the provider's invoice limit
customerEmailstringNoCustomer email
customerNamestringNoCustomer name
successUrlstringNoWhere hosted checkout sends the buyer after payment
metadataobjectNoString key-value pairs, returned in the webhook as a JSON string
expiresInSecondsintegerNoInvoice 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​

FieldTypeDescription
invoiceIdstringLightning Enable invoice ID (numeric string). Use it for status calls
statusstringunpaid, processing, paid, expired, or refunded
amount / currencyAs requested
lightningInvoicestringBOLT11 invoice to pay
paymentHashstringThe invoice's payment hash
onchainAddressstringBitcoin address, when the provider offers one (Strike, OpenNode)
payUrlstringHosted checkout link, https://api.lightningenable.com/pay/{token}
providerChargeIdstringThe provider's ID for this invoice (openNodeChargeId carries the same value for older clients)
createdAt / expiresAtdatetimeexpiresAt 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;
Treat payUrl as a payment link

Anyone 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​

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:

StatuserrorWhat to do
400invalid_expiry, payment_provider_not_configured, or field validationFix the request, or save a provider credential
401API key required / Invalid API keyCheck X-API-Key
403Subscription not active and relatedRoute on action_required
429Rate limited; wait and retry with the same X-Idempotency-Key
502payment_provider_rejectedThe provider refused the invoice; message gives its reason. Not retryable as is
502payment_provider_unavailableThe provider is down; retry later
503payment_provider_busyNWC 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 invoiceId against 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 expired as final; create a new payment for a retry.

Next Steps​