TypeScript SDK
Install, configure, and use the @spare-technologies/spare-api npm package.
The TypeScript SDK targets Node.js 18+ and works with Bun. It is the recommended client for new integrations.
Now available (v1.0.0)
The TypeScript SDK is published on npm as @spare-technologies/spare-api. It currently targets the UAE tenant. The other language SDKs are still under review; until they ship, integrate those over the REST API.
Installation
Install
npm install @spare-technologies/spare-apiConfiguration
import { Configuration, SpareApiClient } from "@spare-technologies/spare-api";
const config = new Configuration({
appId: process.env.SPARE_APP_ID!,
apiKey: process.env.SPARE_API_KEY!,
tenant: "UAE",
environment: "sandbox",
});
const client = new SpareApiClient({ authProvider: config });Configuration caches access tokens and refreshes them before expiry.
Common operations
// List providers
const providers = await client.providers.list();
// Payment request
const pr = await client.paymentRequests.create({
amount: 100_00,
currency: "AED",
description: "Invoice #1",
redirectUrl: "https://yourapp.com/callback",
});
// Consent from payment request
const consent = await client.paymentConsents.createFromPaymentRequest({
paymentRequestId: pr.data.id,
});Error handling
import { SpareApiError, SpareApiTimeoutError } from "@spare-technologies/spare-api";
try {
await client.paymentRequests.get({ paymentRequestId: "invalid" });
} catch (error) {
if (error instanceof SpareApiError) {
console.error(error.status, error.message);
}
}Types
Import types from the SpareApi namespace:
import type { SpareApi } from "@spare-technologies/spare-api";Resources
- Quickstart
- API Reference
- npm package:
@spare-technologies/spare-api