Skip to main content

PaysGator Client for Node.js

Official JavaScript/TypeScript client library for the PaysGator API.

Installation

Install the package using npm:

npm install paysgator-clientjs

Configuration

Import and configure the client with your credentials:

const { PaysGator } = require('paysgator-clientjs');

const client = new PaysGator({
apiKey: 'YOUR_API_KEY'
});

For TypeScript/ES Modules:

import { PaysGator } from 'paysgator-clientjs';

const client = new PaysGator({
apiKey: 'YOUR_API_KEY'
});

Usage

Create Payment

const payment = await client.payments.create({
amount: 100,
currency: 'MZN', // or USD, AOA
payment_methods: ['MPESA', 'CARD'],
returnUrl: 'https://example.com/callback',
fields: ['name', 'email']
});

console.log('Payment Link:', payment.data.checkoutUrl);
console.log('Transaction ID:', payment.data.transactionId);

Confirm Payment (Server-side)

const confirmation = await client.payments.confirm({
paymentLinkId: 'payment_link_id',
paymentMethod: 'MPESA',
payment_fields: {
phoneNumber: '841234567'
}
});

console.log('Payment Confirmed:', confirmation.data.transactionId);

Check Balance

const balance = await client.wallet.getBalance();
console.log('Balance:', balance.balance, balance.currency);

Get Transaction

const transaction = await client.transactions.get('transaction_id');
console.log('Transaction Status:', transaction.status);

Manage Subscriptions

// Pause a subscription
await client.subscriptions.update('subscription_id', 'pause');

Support

For more information or support, please contact info@paysgator.com.