Skip to main content

Quick Start

Get up and running with AccruPay in 5 minutes.

Initialize SDK

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

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

Complete Payment Flow

1. Get Session Configuration

const config = await sdk.transactions.clientSessions.getBaseConfig({
transactionProvider: TRANSACTION_PROVIDER.NUVEI,
merchantTransactionProviderId: 'your-provider-id', // optional
});

2. Start Payment Session

const session = await sdk.transactions.clientSessions.payments.start({
transactionProvider: TRANSACTION_PROVIDER.NUVEI,
merchantTransactionProviderId: 'your-provider-id', // optional
data: {
amount: 10000n, // Amount in cents ($100.00)
currency: CURRENCY.USD,
merchantInternalCustomerCode: 'customer-123',
merchantInternalTransactionCode: `txn-${Date.now()}`,
billing: {
billingFirstName: 'John',
billingLastName: 'Doe',
billingEmail: 'john@example.com',
billingAddressCountry: COUNTRY_ISO_2.US,
billingAddressLine1: '123 Main St',
billingAddressCity: 'New York',
billingAddressState: 'NY',
billingAddressPostalCode: '10001',
},
storePaymentMethod: false, // Set to true to save payment method
},
});

3. Frontend Integration

Use the session token and provider code in your frontend to complete the payment:

// Frontend JavaScript example
const response = await fetch('https://your-frontend-api.com/process-payment', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
sessionToken: session.token,
providerCode: session.providerCode,
}),
});

4. Verify Payment

After payment completion, verify the transaction:

const transaction = await sdk.transactions.clientSessions.payments.verify({
id: session.id, // or use token, providerCode, or merchantInternalTransactionCode
});

console.log('Transaction:', {
id: transaction.id,
status: transaction.status,
amount: transaction.amount,
currency: transaction.currency,
});

Error Handling

const sdk = new AccruPay({
apiSecret: process.env.ACCRUPAY_API_SECRET,
onAuthError: () => {
console.error('Authentication failed');
// Handle re-authentication
},
onGraphQLError: (errors) => {
console.error('GraphQL errors:', errors);
// Handle validation or business logic errors
},
onNetworkError: (error) => {
console.error('Network error:', error);
// Handle network issues
},
});

List Transactions

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

console.log('Transactions:', transactions.items);
console.log('Total:', transactions.totalCount);

Next Steps