Skip to main content

Payments API

Create Lightning invoices and manage payment status.

Create Payment

Create a new Lightning invoice for a customer payment.

POST /api/payments

Request Headers

HeaderRequiredDescription
X-API-KeyYesYour merchant API key
Content-TypeYesapplication/json

Request Body

{
"orderId": "ORDER-12345",
"amount": 49.99,
"currency": "USD",
"description": "Premium Subscription",
"customerEmail": "customer@example.com",
"metadata": {
"productId": "prod_123",
"userId": "user_456"
}
}

Parameters

FieldTypeRequiredDescription
orderIdstringYesYour unique order identifier
amountdecimalYesPayment amount
currencystringYesCurrency code (USD, EUR, GBP, BTC)
descriptionstringNoPayment description
customerEmailstringNoCustomer email for receipt
metadataobjectNoCustom key-value data

Response

{
"invoiceId": "inv_abc123def456",
"orderId": "ORDER-12345",
"status": "unpaid",
"amount": 49.99,
"currency": "USD",
"amountSats": 125000,
"lightningInvoice": "lnbc1250000n1pnxyz...",
"expiresAt": "2024-12-29T13:00:00Z",
"createdAt": "2024-12-29T12:00:00Z"
}

Example

curl -X POST https://api.lightningenable.com/api/payments \
-H "X-API-Key: le_merchant_abc123" \
-H "Content-Type: application/json" \
-d '{
"orderId": "ORDER-12345",
"amount": 49.99,
"currency": "USD",
"description": "Premium Subscription"
}'

Get Payment by Invoice ID

Retrieve payment details by Lightning Enable invoice ID.

GET /api/payments/{invoiceId}

Parameters

ParameterTypeDescription
invoiceIdstringLightning Enable invoice ID

Response

{
"invoiceId": "inv_abc123def456",
"orderId": "ORDER-12345",
"status": "paid",
"amount": 49.99,
"currency": "USD",
"amountSats": 125000,
"paidAt": "2024-12-29T12:05:00Z",
"createdAt": "2024-12-29T12:00:00Z"
}

Example

curl https://api.lightningenable.com/api/payments/inv_abc123def456 \
-H "X-API-Key: le_merchant_abc123"

Get Payment by Order ID

Retrieve payment details by your order ID.

GET /api/payments/order/{orderId}

Parameters

ParameterTypeDescription
orderIdstringYour order identifier

Response

Same as Get Payment by Invoice ID.

Example

curl https://api.lightningenable.com/api/payments/order/ORDER-12345 \
-H "X-API-Key: le_merchant_abc123"

Sync Payment Status

Force sync payment status from OpenNode. Useful if webhook was delayed.

POST /api/payments/{invoiceId}/sync

Parameters

ParameterTypeDescription
invoiceIdstringLightning Enable invoice ID

Response

Returns updated payment object with current status.

Example

curl -X POST https://api.lightningenable.com/api/payments/inv_abc123/sync \
-H "X-API-Key: le_merchant_abc123"

Payment Statuses

StatusDescription
unpaidInvoice created, awaiting payment
processingPayment detected, confirming
paidPayment confirmed
expiredInvoice expired without payment
refundedPayment was refunded

Payment Flow

1. Create Payment
POST /api/payments
Returns: invoiceId, lightningInvoice

2. Display to Customer
Show QR code or invoice string
Customer pays with Lightning wallet

3. Payment Confirmed
Webhook notification sent
Or poll GET /api/payments/{invoiceId}

4. Fulfill Order
When status = "paid", deliver goods/services

Supported Currencies

CurrencyCodeNotes
US DollarUSDConverted to BTC at current rate
EuroEURConverted to BTC at current rate
British PoundGBPConverted to BTC at current rate
BitcoinBTCDirect amount (use decimal, e.g., 0.001)
SatoshissatsDirect amount (integer)

Invoice Expiration

  • Default expiration: 60 minutes
  • After expiration, invoice cannot be paid
  • Create new payment if expired

Error Responses

Invalid Amount

{
"error": "Bad Request",
"message": "Amount must be greater than 0",
"code": "INVALID_AMOUNT"
}

Missing Order ID

{
"error": "Bad Request",
"message": "Order ID is required",
"code": "MISSING_ORDER_ID"
}

Payment Not Found

{
"error": "Not Found",
"message": "Payment not found",
"code": "PAYMENT_NOT_FOUND"
}

Code Examples

JavaScript

async function createPayment(orderId, amount, currency) {
const response = await fetch('https://api.lightningenable.com/api/payments', {
method: 'POST',
headers: {
'X-API-Key': process.env.LIGHTNING_API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({ orderId, amount, currency })
});

if (!response.ok) {
throw new Error(`Payment failed: ${response.statusText}`);
}

return response.json();
}

// Usage
const payment = await createPayment('ORDER-123', 49.99, 'USD');
console.log('Lightning Invoice:', payment.lightningInvoice);

C#

public async Task<PaymentResponse> CreatePaymentAsync(
string orderId,
decimal amount,
string currency)
{
var request = new
{
orderId,
amount,
currency
};

var response = await _httpClient.PostAsJsonAsync("/api/payments", request);
response.EnsureSuccessStatusCode();

return await response.Content.ReadFromJsonAsync<PaymentResponse>();
}

Python

import requests

def create_payment(order_id, amount, currency):
response = requests.post(
'https://api.lightningenable.com/api/payments',
headers={
'X-API-Key': os.environ['LIGHTNING_API_KEY'],
'Content-Type': 'application/json'
},
json={
'orderId': order_id,
'amount': amount,
'currency': currency
}
)
response.raise_for_status()
return response.json()

Next Steps