Node.js / TypeScript¶
@oura/sdk · source
Requires Node 18+. It uses the built-in fetch and node:crypto. This SDK holds your secret key, so use it only on a server.
Install¶
Accept a payment¶
import { Oura } from '@oura/sdk';
const oura = new Oura(process.env.OURA_SECRET_KEY!);
const payment = await oura.payments.create({
amount: 245000, // NPR 2,450.00 in paisa
methods: ['esewa', 'khalti'],
reference: 'order_1042',
return_url: 'https://himalstore.com.np/orders/1042',
});
res.redirect(payment.checkout_url);
Other calls¶
await oura.payments.retrieve('pay_123');
await oura.payments.list({ limit: 20, starting_after: 'pay_123' });
await oura.payments.cancel('pay_123');
await oura.payments.create(params, { idempotencyKey: `order_${orderId}` });
An idempotency key is generated for every create. Pass your own, tied to your order, to make retries safe across restarts. See Idempotency.
Configuration¶
Point the client at a local API while developing:
new Oura(key, {
baseUrl: 'http://localhost:8080', // default https://api.ourapayment.com
timeout: 30000,
maxRetries: 2, // retries 429 and 5xx with backoff
});
Webhooks¶
Verify with webhooks.constructEvent(raw, header, secret) and webhooks.verify(raw, header, secret, 300). Both compare in constant time and reject stale timestamps. Always pass the raw request body. Full example: Webhooks.
Errors¶
Every non-2xx response raises OuraError with the error code, HTTP status and message. See Errors.