Skip to main content

SDK Reference

The AccruPay Node.js SDK provides a type-safe, developer-friendly interface to the AccruPay API.

Features

  • Type Safety - Full TypeScript support with autocomplete
  • Error Handling - Built-in error handling with callbacks
  • BigInt Support - Native BigInt support for currency amounts
  • GraphQL Codegen - Auto-generated types from GraphQL schema

Installation

npm install @accrupay/node

Quick Start

import AccruPay, { TRANSACTION_PROVIDER, CURRENCY } from '@accrupay/node';

const sdk = new AccruPay({
apiSecret: process.env.ACCRUPAY_API_SECRET,
environment: 'production',
});

// Start a client payment session
const session = await sdk.transactions.clientSessions.payments.start({
transactionProvider: TRANSACTION_PROVIDER.NUVEI,
data: {
amount: 10000n,
currency: CURRENCY.USD,
// ... other fields
},
});

Core Services

Transactions Service

Manage payment transactions and client sessions:

// List transactions
const transactions = await sdk.transactions.getMany({
take: 10,
skip: 0,
currency: CURRENCY.USD,
});

// Start payment session
const session = await sdk.transactions.clientSessions.payments.start({/* ... */});

// Verify session
const transaction = await sdk.transactions.clientSessions.payments.verify({/* ... */});

Payment Methods Service

Manage stored payment methods:

// List payment methods
const paymentMethods = await sdk.paymentMethods.getMany({
merchantInternalCustomerCode: 'customer-123',
});

// Sync payment method
const synced = await sdk.paymentMethods.syncOne({
id: 'payment-method-id',
});

Payment Plans Service

Manage recurring payments:

// List payment plans
const plans = await sdk.paymentPlans.getMany({
merchantInternalCustomerCode: 'customer-123',
});

// Create payment plan
const plan = await sdk.paymentPlans.createOne({
// ... plan configuration
});

// Cancel plan
const canceled = await sdk.paymentPlans.cancelOne({
merchantPaymentPlanId: 'plan-id',
});

Payment Plan Templates Service

Manage payment plan templates:

// List templates
const templates = await sdk.paymentPlanTemplates.getMany({});

// Create template
const template = await sdk.paymentPlanTemplates.createOne({
// ... template configuration
});

Transaction Providers Service

Query available transaction providers:

// List providers
const providers = await sdk.transactionProviders.getMany({});

// Get provider details
const provider = await sdk.transactionProviders.getOne({
id: 'provider-id',
});

Merchants Service

Access merchant information:

// Get current merchant details
const merchant = await sdk.merchants.getCurrent({});

Configuration

Basic Configuration

const sdk = new AccruPay({
apiSecret: 'your-api-secret',
environment: 'production', // or 'qa'
});

Advanced Configuration

const sdk = new AccruPay({
apiSecret: 'your-api-secret',
environment: 'production',

// Error handling
onAuthError: () => console.error('Auth failed'),
onGraphQLError: (errors) => console.error('GraphQL errors:', errors),
onNetworkError: (error) => console.error('Network error:', error),
});

Type Safety

All methods are fully typed with TypeScript:

import AccruPay, { CURRENCY, TRANSACTION_STATUS, TRANSACTION_PROVIDER } from '@accrupay/node';

// Type-safe enums
const session = await sdk.transactions.clientSessions.payments.start({
transactionProvider: TRANSACTION_PROVIDER.NUVEI, // autocomplete
data: {
currency: CURRENCY.USD, // type-checked
amount: 10000n, // BigInt type
},
});

// Strongly typed responses
const transaction = await sdk.transactions.getOne({ id: '123' });
// transaction.status is TRANSACTION_STATUS

Error Handling

const sdk = new AccruPay({
apiSecret: process.env.ACCRUPAY_API_SECRET,
environment: 'production',

onAuthError: () => {
// Handle 401/403 errors
console.error('Authentication failed');
},

onGraphQLError: (errors) => {
// Handle validation and business logic errors
errors.forEach(error => {
console.error('GraphQL Error:', error.message);
console.error('Code:', error.extensions?.code);
});
},

onNetworkError: (error) => {
// Handle network issues
console.error('Network Error:', error.message);
},
});

Services Documentation

Next Steps