Skip to content

Server libraries

Official server libraries wrap the encryption and HTTP calls for you — use one if your language is covered.

Every library calls production unless you tell it otherwise. To use your test keys, switch the library to the sandbox:

LibraryVersion with a sandbox switchHow to switch
Node.js (pesepay)2.0.0baseUrl: 'https://api.test.sandbox.pesepay.com/payments-engine' in the constructor options
Python (pesepay)1.1.0True as the third constructor argument
PHP (codevirtus/pesepay)1.0.3true as the third constructor argument
Java (com.pesepay:pesepay)1.1.0Pesepay.Mode.TEST (or true) as the third constructor argument
Ruby (pesepay)NoneCalls production only. Test with the REST API instead

The samples below set the switch. For live payments, drop it and use your application’s live keys.

Terminal window
npm install pesepay@^2
import { Pesepay } from 'pesepay';
const pesepay = new Pesepay({
integrationKey: process.env.PESEPAY_INTEGRATION_KEY,
encryptionKey: process.env.PESEPAY_ENCRYPTION_KEY,
resultUrl: 'https://example.com/result',
returnUrl: 'https://example.com/return',
baseUrl: 'https://api.test.sandbox.pesepay.com/payments-engine', // sandbox
});

Version 2 needs Node.js 22.12 or newer. Coming from 1.x? The migration guide covers each method.

const { redirectUrl, referenceNumber, pollUrl } = await pesepay.initiateTransaction({
amount,
currencyCode: 'CURRENCY_CODE',
reasonForPayment: 'PAYMENT_REASON',
merchantReference: 'MERCHANT_REFERENCE',
});
// send the customer to redirectUrl; store referenceNumber for tracking

Failures throw a PesepayError subclass.

const result = await pesepay.makeSeamlessPayment({
amount,
currencyCode: 'CURRENCY_CODE',
paymentMethodCode: 'PAYMENT_METHOD_CODE',
reasonForPayment: 'PAYMENT_REASON',
customer: { email: 'CUSTOMER_EMAIL', phoneNumber: 'CUSTOMER_PHONE_NUMBER' },
requiredFields: { customerPhoneNumber: '0777777777' },
});
const { referenceNumber, pollUrl, transactionStatus } = result;

Running WooCommerce, PrestaShop, Moodle or WHMCS? Install the plugin instead — no integration code at all.