Server libraries
Official server libraries wrap the encryption and HTTP calls for you — use one if your language is covered.
-
Node.js
npm install pesepay -
Python
pip install pesepay -
PHP
composer require codevirtus/pesepay -
Java
Maven Central — com.pesepay:pesepay -
Ruby
gem install pesepay
Sandbox or production
Section titled “Sandbox or production”Every library calls production unless you tell it otherwise. To use your test keys, switch the library to the sandbox:
| Library | Version with a sandbox switch | How to switch |
|---|---|---|
Node.js (pesepay) | 2.0.0 | baseUrl: 'https://api.test.sandbox.pesepay.com/payments-engine' in the constructor options |
Python (pesepay) | 1.1.0 | True as the third constructor argument |
PHP (codevirtus/pesepay) | 1.0.3 | true as the third constructor argument |
Java (com.pesepay:pesepay) | 1.1.0 | Pesepay.Mode.TEST (or true) as the third constructor argument |
Ruby (pesepay) | None | Calls 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.
Install and initialise
Section titled “Install and initialise”npm install pesepay@^2import { 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.
pip install "pesepay>=1.1.0"from pesepay import Pesepay
pesepay = Pesepay("INTEGRATION_KEY", "ENCRYPTION_KEY", True) # True = sandboxpesepay.result_url = "https://example.com/result"pesepay.return_url = "https://example.com/return"composer require codevirtus/pesepay:^1.0.3<?phprequire_once 'vendor/autoload.php';use Codevirtus\Payments\Pesepay;
$pesepay = new Pesepay("INTEGRATION_KEY", "ENCRYPTION_KEY", true); // true = sandbox$pesepay->returnUrl = "https://example.com/return";$pesepay->resultUrl = "https://example.com/result";<dependency> <groupId>com.pesepay</groupId> <artifactId>pesepay</artifactId> <version>1.1.0</version></dependency>Pesepay pesepay = new Pesepay(integrationKey, encryptionKey, Pesepay.Mode.TEST);pesepay.setResultUrl("https://example.com/result");pesepay.setReturnUrl("https://example.com/return");Hosted checkout
Section titled “Hosted checkout”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 trackingFailures throw a PesepayError subclass.
transaction = pesepay.create_transaction(amount, "CURRENCY_CODE", "PAYMENT_REASON")
response = pesepay.initiate_transaction(transaction)
if response.success: redirect_url = response.redirectUrl # send the customer here reference_number = response.referenceNumber # store for trackingelse: error_message = response.message$transaction = $pesepay->createTransaction($amount, 'CURRENCY_CODE', 'PAYMENT_REASON', 'MERCHANT_REFERENCE');
$response = $pesepay->initiateTransaction($transaction);
if ($response->success()) { $redirectUrl = $response->redirectUrl(); $referenceNumber = $response->referenceNumber();} else { $errorMessage = $response->message();}Transaction transaction = pesepay.createTransaction(amount, "CURRENCY_CODE", "PAYMENT_REASON");
Response response = pesepay.initiateTransaction(transaction);
if (response.isSuccess()) { String redirectUrl = response.getRedirectUrl(); String referenceNumber = response.getReferenceNumber();} else { String errorMessage = response.getMessage();}Direct API
Section titled “Direct API”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;payment = pesepay.create_payment( "CURRENCY_CODE", "PAYMENT_METHOD_CODE", "CUSTOMER_EMAIL", "CUSTOMER_PHONE_NUMBER", "CUSTOMER_NAME")required_fields = {"customerPhoneNumber": "0777777777"}
response = pesepay.make_seamless_payment(payment, "PAYMENT_REASON", amount, required_fields)
if response.success: poll_url = response.pollUrl reference_number = response.referenceNumberelse: error_message = response.message$payment = $pesepay->createPayment('CURRENCY_CODE', 'PAYMENT_METHOD_CODE', 'CUSTOMER_EMAIL', 'CUSTOMER_PHONE_NUMBER', 'CUSTOMER_NAME');$requiredFields = ['customerPhoneNumber' => '0777777777'];
$response = $pesepay->makeSeamlessPayment($payment, 'PAYMENT_REASON', $amount, $requiredFields, 'MERCHANT_REFERENCE');
if ($response->success()) { $referenceNumber = $response->referenceNumber(); $pollUrl = $response->pollUrl();} else { $errorMessage = $response->message();}Payment payment = pesepay.createPayment("CURRENCY_CODE", "PAYMENT_METHOD_CODE", "CUSTOMER_EMAIL");Map<String, String> requiredFields = new HashMap<>();requiredFields.put("customerPhoneNumber", "0777777777");
Response response = pesepay.makeSeamlessPayment(payment, "PAYMENT_REASON", amount, requiredFields);
if (response.isSuccess()) { String pollUrl = response.getPollUrl(); String referenceNumber = response.getReferenceNumber();} else { String errorMessage = response.getMessage();}Plugins
Section titled “Plugins”Running WooCommerce, PrestaShop, Moodle or WHMCS? Install the plugin instead — no integration code at all.