lunipay
v0.1.0
Published
The official LuniPay server-side SDK for Node.js, Bun, Deno, and Edge runtimes.
Downloads
132
Maintainers
Readme
lunipay
The official LuniPay server-side SDK for Node.js, Bun, Deno, and edge runtimes.
npm install lunipay
# or
pnpm add lunipay
# or
bun add lunipayQuick start
import LuniPay from 'lunipay';
const lunipay = new LuniPay(process.env.LUNIPAY_SECRET_KEY!);
const session = await lunipay.checkout.sessions.create({
amount: 5000,
currency: 'usd',
success_url: 'https://example.com/thanks?session_id={CHECKOUT_SESSION_ID}',
});
console.log(session.url);The SDK is fully typed, includes auto-pagination helpers, typed error classes, and a webhook signature verifier.
Resources
Every LuniPay resource is exposed as a namespace on the client:
await lunipay.customers.create({ email, first_name, last_name });
await lunipay.customers.retrieve(id);
await lunipay.customers.update(id, { phone: '+1-876-555-9999' });
await lunipay.customers.del(id);
for await (const customer of lunipay.customers.list().autoPagingIter()) {
console.log(customer.email);
}Supported resources: checkout.sessions, customers, invoices, payments, paymentLinks, webhookEndpoints, events.
Webhooks
import { Webhook } from 'lunipay';
export async function POST(req: Request) {
const body = await req.text();
const sig = req.headers.get('LuniPay-Signature');
const event = Webhook.constructEvent(body, sig, process.env.LUNIPAY_WEBHOOK_SECRET!);
if (event.type === 'checkout.session.completed') {
// fulfill the order
}
return new Response(null, { status: 200 });
}Throws WebhookSignatureError if the signature is missing, expired, or invalid.
Errors
Every non-2xx response throws a typed error. Branch on error.code for stable, machine-readable logic.
import { InvalidRequestError, RateLimitError } from 'lunipay';
try {
await lunipay.checkout.sessions.create({ amount: 1, currency: 'usd', success_url: '...' });
} catch (err) {
if (err instanceof InvalidRequestError && err.code === 'amount_too_small') {
// ...
}
}Error subclasses: InvalidRequestError, AuthenticationError, PermissionError, RateLimitError, ApiError.
Idempotency
Every mutating request accepts an idempotencyKey option — retries with the same key return the original response instead of creating duplicates.
import { randomUUID } from 'node:crypto';
const key = randomUUID();
await lunipay.checkout.sessions.create(
{ amount: 5000, currency: 'usd', success_url: '...' },
{ idempotencyKey: key },
);Full documentation
See lunipay.io/docs/sdks/javascript for the full reference.
License
MIT
