Node.js SDK
The official Node.js SDK for the EukaPay API
The official Node.js SDK for the EukaPay API, published on npm as @eukapay/node-sdk. It wraps the REST API described in these docs with typed methods, client-side parameter validation, typed errors, webhook verification and request signing.
- Requires Node.js 20 or later
- Written in TypeScript; type definitions are included
- Use it on your server only. It needs your secret API key.
Installation
npm install @eukapay/node-sdk
# or
yarn add @eukapay/node-sdkInitialization
import { EukaPay } from "@eukapay/node-sdk";
const eukapay = new EukaPay({ apiKey: process.env.EUKAPAY_API_KEY! });The API URL is chosen from the key prefix:
| Key prefix | Environment | API URL |
|---|---|---|
sk_live_ | Production | https://api.eukapay.com |
sk_test_ | Staging | https://api-stg.eukapay.com |
Options:
| Option | Description |
|---|---|
apiKey | Secret API key (required). Keep it on your server. |
baseURL | Overrides the API URL chosen from the key prefix. |
timeout | Request timeout in milliseconds. Default: 60000. |
signingSecret | Signing secret of the API key. Set it when the key has Require signed requests enabled; every request is then signed. |
CommonJS works too:
const { EukaPay } = require("@eukapay/node-sdk");Usage
Every method returns a promise. List methods return one page:
interface ListResponse<T> {
data: T[];
has_more: boolean;
}See Pagination for the underlying parameters. Pass limit (the API caps it at 100) and the code of an item as starting_after (older items) or ending_before (newer items) to move between pages:
let startingAfter: string | undefined;
do {
const page = await eukapay.invoices.list({ limit: 100, starting_after: startingAfter });
page.data.forEach((invoice) => console.log(invoice.code, invoice.status));
startingAfter = page.has_more ? page.data.at(-1)?.code : undefined;
} while (startingAfter);create, update and other POST/PUT methods accept an optional idempotency key. Retrying with the same key within 24 hours returns the stored response instead of performing the operation again:
await eukapay.invoices.create(params, { idempotencyKey: "order_123" });Invoices
const invoice = await eukapay.invoices.create({
price: 1000,
currency: "CAD", // or currencyId
message: "Invoice for premium service",
invoiceItems: [{ name: "Premium Service", price: 1000, quantity: 1 }],
metadata: { orderId: "order_123" },
});
console.log(invoice.paymentUrl);
await eukapay.invoices.retrieve(invoice.code);
await eukapay.invoices.list({ limit: 10 });
await eukapay.invoices.update(invoice.code, { message: "Updated message" });
await eukapay.invoices.delete(invoice.code);Customers
const customer = await eukapay.customers.create({
firstName: "Jane",
lastName: "Doe",
email: "[email protected]",
types: ["invoicing"],
});
await eukapay.customers.retrieve(customer.code);
await eukapay.customers.list({ email: "[email protected]" });
await eukapay.customers.update(customer.code, { phone: "+14165550100" });
await eukapay.customers.delete(customer.code);Subscriptions
const subscription = await eukapay.subscriptions.create({
price: 50,
currency: "USD",
customerCode: customer.code,
interval: "Monthly",
startImmediately: true,
endDate: "2027-12-31",
});
await eukapay.subscriptions.retrieve(subscription.code);
await eukapay.subscriptions.list();
await eukapay.subscriptions.update(subscription.code, { message: "Thanks!" });
await eukapay.subscriptions.delete(subscription.code);Checkouts
const checkout = await eukapay.checkouts.create({
title: "Donations",
description: "Support our project",
currency: "USD",
type: 1, // 0: fixed price, 1: payer enters the amount, 2: event tickets
emailRequired: 2, // 0: hidden, 1: optional, 2: required
});
await eukapay.checkouts.retrieve(checkout.code);
await eukapay.checkouts.list();
await eukapay.checkouts.update(checkout.code, { title: "Donations 2026" });
await eukapay.checkouts.delete(checkout.code);Receive addresses (beta)
A deposit address quoted for a fixed amount in your settlement currency, without an invoice. See Receive Addresses for the flow. Receive addresses are enabled per account; until they are enabled for yours, these methods throw an AuthenticationError (403) whose response.type is feature_disabled.
const receiveAddress = await eukapay.receiveAddresses.create({
cryptocurrencySymbol: "USDT", // USDT on Ethereum or Tron, USDC on Ethereum
blockchainNetwork: "Tron",
price: 100, // in your settlement currency
metadata: { externalId: "player-1029" },
});
console.log(receiveAddress.address, receiveAddress.cryptoAmount, receiveAddress.expiresAt);
await eukapay.receiveAddresses.retrieve(receiveAddress.code);
await eukapay.receiveAddresses.list({ limit: 10 });Each deposit is reported in payments and sends a receiveAddressPaid webhook.
Transactions
const transactions = await eukapay.transactions.list({
created_after: "2026-01-01",
status: "completed", // pending | completed | action_required | in_review | rejected
type: "payment", // payment | refund
});Refunds
const refund = await eukapay.refunds.create({ invoiceCode: "inv_xxx" });
console.log(refund.refundUrl); // send to the payer to collect their refund address
await eukapay.refunds.retrieve(refund.code);
await eukapay.refunds.list();
await eukapay.refunds.delete(refund.code); // cancels a refund that has not startedBalance and payouts
const balance = await eukapay.balance.get();
const transfer = await eukapay.balance.transfer({ amount: 100 }); // to your bank account
const payouts = await eukapay.payouts.list(); // fiat settlementsCrypto payouts
await eukapay.cryptoPayouts.balance();
const estimate = await eukapay.cryptoPayouts.estimate({
cryptocurrencySymbol: "USDT",
blockchainNetwork: "tron",
sourceAmount: 100,
});
// To a new recipient: wallet address plus the recipient's name and address.
const payout = await eukapay.cryptoPayouts.create({
cryptocurrencySymbol: "USDT",
blockchainNetwork: "tron",
sourceAmount: 100, // or destinationAmount, not both
walletAddress: "TXYZ...",
firstName: "Jane",
lastName: "Doe",
address1: "123 Main St",
city: "Toronto",
state: "ON",
country: "CA",
zip: "M5V 2T6",
});
// To a saved customer: the API uses the customer's details and whitelisted
// wallet address, so omit walletAddress and the recipient fields.
await eukapay.cryptoPayouts.create({
cryptocurrencySymbol: "USDT",
blockchainNetwork: "tron",
sourceAmount: 100,
customerCode: "cus_xxx",
});
// Recipients in high-risk countries need a supporting document (PDF, JPG or
// PNG). The SDK then sends multipart/form-data and signs it when a signing
// secret is configured.
await eukapay.cryptoPayouts.create({
cryptocurrencySymbol: "USDT",
blockchainNetwork: "tron",
sourceAmount: 100,
customerCode: "cus_xxx",
supportingDocument: {
data: fs.readFileSync("invoice.pdf"),
filename: "invoice.pdf",
contentType: "application/pdf",
},
});
await eukapay.cryptoPayouts.retrieve(payout.code);
await eukapay.cryptoPayouts.list({ status: "processing" });
await eukapay.cryptoPayouts.update(payout.code, { sourceAmount: 120 }); // re-prices
await eukapay.cryptoPayouts.update(payout.code, { walletAddress: "TABC..." }); // no amount needed
await eukapay.cryptoPayouts.delete(payout.code); // revokes the payoutOTC trades
const quote = await eukapay.otcTrades.quote({
baseCurrency: "BTC",
quoteCurrency: "CAD",
tradeSide: "buy",
deliverQuantity: 1000,
});
const trade = await eukapay.otcTrades.order({
baseCurrency: "BTC",
quoteCurrency: "CAD",
tradeSide: "buy",
deliverQuantity: 1000,
strategy: "MKT",
});
await eukapay.otcTrades.retrieve(trade.code);
await eukapay.otcTrades.list({ limit: 10 });Webhook events
Delivery history of the webhooks sent to your endpoints (kept for 90 days):
const failed = await eukapay.webhookEvents.list({ status: "failed" });
const detail = await eukapay.webhookEvents.retrieve(failed.data[0].webhookId);
console.log(detail.attempts);Error handling
Every error thrown by the SDK extends EukaPaySDKError. The API error codes are listed in Errors.
| Error class | When |
|---|---|
ValidationError | Invalid parameters, detected by the SDK before sending or returned by the API (400) |
AuthenticationError | Missing or invalid API key, or the account is not yet verified (401, 403) |
PermissionError | A restricted API key lacks the scope the endpoint needs, e.g. invoices:write (403) |
RateLimitError | Too many requests (429) |
InternalServerError | EukaPay server error (5xx) |
APIError | Any other API error, e.g. 404 not found |
APIConnectionError | Network error or timeout; no response received |
WebhookSignatureVerificationError | A webhook signature did not verify (see below) |
Errors carry statusCode, type, code (the API's machine-readable code, such as insufficient_scope) and response (the API's error body):
import { PermissionError, ValidationError, EukaPaySDKError } from "@eukapay/node-sdk";
try {
await eukapay.invoices.create({ price: 1000, currency: "CAD" });
} catch (error) {
if (error instanceof PermissionError) {
console.error("Grant the scope to this API key:", error.message);
} else if (error instanceof ValidationError) {
console.error("Invalid parameters:", error.message);
} else if (error instanceof EukaPaySDKError) {
console.error(error.statusCode, error.message, error.response);
}
}Webhook verification
See Webhooks for the events and payloads. EukaPay signs every webhook with your endpoint's webhook secret and sends the signature in the x-eukapay-signature header: a hex HMAC-SHA512 of the request body. Verify it against the raw request body, before any JSON parsing; parsing and re-serializing can change the bytes and make a genuine webhook fail verification.
constructEvent verifies the signature (with a constant-time comparison) and returns the parsed payload, or throws WebhookSignatureVerificationError:
import express from "express";
import { constructEvent, WebhookSignatureVerificationError } from "@eukapay/node-sdk";
const app = express();
app.post("/webhooks/eukapay", express.raw({ type: "application/json" }), (req, res) => {
try {
const event = constructEvent(
req.body, // Buffer, because of express.raw()
req.headers["x-eukapay-signature"],
process.env.EUKAPAY_WEBHOOK_SECRET!
);
switch (event.event) {
case "paymentCompleted":
// ...
break;
case "cryptoPayoutSent":
// ...
break;
}
res.sendStatus(200);
} catch (error) {
if (error instanceof WebhookSignatureVerificationError) {
return res.sendStatus(400);
}
throw error;
}
});To only check the signature, use verifySignature(rawBody, signatureHeader, secret), which returns a boolean. Both helpers are also available as eukapay.webhooks.constructEvent / eukapay.webhooks.verifySignature.
Each delivery has a unique webhookId; use it to ignore duplicate deliveries, since failed deliveries are retried.
Request signing
signingSecret is optional. If an API key has Require signed requests enabled (see Request signing), pass its signing secret and the SDK computes and attaches the x-eukapay-timestamp / x-eukapay-signature headers to every request, including multipart crypto payouts. You do not build the signature yourself:
const eukapay = new EukaPay({
apiKey: process.env.EUKAPAY_API_KEY!,
signingSecret: process.env.EUKAPAY_SIGNING_SECRET!,
});Signing uses the current time, so keep the server clock in sync (within 5 minutes of EukaPay's).
Support
- Questions and bug reports: [email protected]
This SDK follows Semantic Versioning.
Updated 2 days ago
