Quickstart: Hosted checkout
By the end of this page you’ll have redirected a test customer to the Pesepay sandbox payment page and got a transaction reference back — the core loop behind every Pesepay integration.
Prerequisites
Section titled “Prerequisites”- Your test keys, an integration key and an encryption key. They are on the Merchant Control Panel as soon as you register; see Get your test keys.
- One of: Node.js 22.12 or newer, Python 3, PHP, or Java
-
Install the library
Section titled “Install the library”You need a version that can call the sandbox:
pesepay2.x for Node.js, 1.1.0 or newer for Python and Java, 1.0.3 or newer for PHP.Terminal window npm install pesepay@^2Terminal window pip install "pesepay>=1.1.0"Terminal window composer require codevirtus/pesepay:^1.0.3<dependency><groupId>com.pesepay</groupId><artifactId>pesepay</artifactId><version>1.1.0</version></dependency> -
Point the client at the sandbox
Section titled “Point the client at the sandbox”Use your test keys, and tell the library to call the sandbox. Without that switch, every library calls production, where test keys are rejected.
pesepay.mjs import { Pesepay } from 'pesepay';const pesepay = new Pesepay({integrationKey: process.env.PESEPAY_INTEGRATION_KEY,encryptionKey: process.env.PESEPAY_ENCRYPTION_KEY,resultUrl: 'https://example.com/payments/result',returnUrl: 'https://example.com/payments/return',baseUrl: 'https://api.test.sandbox.pesepay.com/payments-engine',});pesepay_client.py import osfrom pesepay import Pesepaypesepay = Pesepay(os.environ["PESEPAY_INTEGRATION_KEY"],os.environ["PESEPAY_ENCRYPTION_KEY"],True, # sandbox)pesepay.result_url = "https://example.com/payments/result"pesepay.return_url = "https://example.com/payments/return"pesepay.php <?phprequire_once 'vendor/autoload.php';use Codevirtus\Payments\Pesepay;$pesepay = new Pesepay(getenv('PESEPAY_INTEGRATION_KEY'),getenv('PESEPAY_ENCRYPTION_KEY'),true // sandbox);$pesepay->returnUrl = 'https://example.com/payments/return';$pesepay->resultUrl = 'https://example.com/payments/result';PesepayClient.java Pesepay pesepay = new Pesepay(integrationKey, encryptionKey, Pesepay.Mode.TEST);pesepay.setResultUrl("https://example.com/payments/result");pesepay.setReturnUrl("https://example.com/payments/return"); -
Create and initiate a transaction
Section titled “Create and initiate a transaction”This is Hosted checkout: create a transaction for an amount and currency, then initiate it to get a
redirectUrl. The sandbox takesUSDonly.const { redirectUrl, referenceNumber } = await pesepay.initiateTransaction({amount: 10,currencyCode: 'USD',reasonForPayment: 'Order #1042 — running shoes',merchantReference: 'order-1042',});console.log(redirectUrl); // send the customer hereconsole.log(referenceNumber); // store this for laterA failed call throws a
PesepayError; see the library’s README for the error classes.transaction = pesepay.create_transaction(10.0, "USD", "Order #1042 — running shoes")response = pesepay.initiate_transaction(transaction)if response.success:print(response.redirectUrl) # send the customer hereprint(response.referenceNumber) # store this for laterelse:print(response.message)$transaction = $pesepay->createTransaction(10.0, 'USD', 'Order #1042 — running shoes');$response = $pesepay->initiateTransaction($transaction);if ($response->success()) {$redirectUrl = $response->redirectUrl(); // send the customer here$referenceNumber = $response->referenceNumber(); // store this for later} else {echo $response->message();}Transaction transaction = pesepay.createTransaction(10.0, "USD", "Order #1042 — running shoes");Response response = pesepay.initiateTransaction(transaction);if (response.isSuccess()) {String redirectUrl = response.getRedirectUrl(); // send the customer hereString referenceNumber = response.getReferenceNumber(); // store this for later} else {System.out.println(response.getMessage());} -
Redirect your customer
Section titled “Redirect your customer”Send the customer’s browser to
redirectUrl. In the sandbox, use the test payment methods to complete or deliberately fail the payment. -
Confirm the result
Section titled “Confirm the result”Pesepay calls your
resultUrlwith the final status as soon as the customer finishes — see The result callback. As a fallback, you can also poll: Check Payment Status using thereferenceNumberyou stored when you initiated the transaction.
Going live
Section titled “Going live”Swap in the live keys of your application
and drop the sandbox switch: remove baseUrl in Node.js, or the third
constructor argument in Python, PHP and Java. Work through the
go-live checklist first.