Quickstart: Your first payment
By the end of this page you’ll have redirected a test customer to the Pesepay sandbox payment page and gotten a transaction reference back — the core loop behind every Pesepay integration.
Prerequisites
Section titled “Prerequisites”- A Pesepay account with a sandbox integration key and encryption key
- Node.js, Python, PHP, or Java installed locally
-
Install the SDK
Section titled “Install the SDK”Terminal window npm install pesepayTerminal window pip install pesepayTerminal window composer require codevirtus/pesepay<dependency><groupId>com.pesepay</groupId><artifactId>pesepay</artifactId><version>1.0.0</version></dependency> -
Initialize the client
Section titled “Initialize the client”Use your sandbox integration key and encryption key from Onboarding.
pesepay.js const { Pesepay } = require('pesepay');const pesepay = new Pesepay('YOUR_INTEGRATION_KEY', 'YOUR_ENCRYPTION_KEY');pesepay.resultUrl = 'https://example.com/payments/result';pesepay.returnUrl = 'https://example.com/payments/return';pesepay_client.py from pesepay import Pesepaypesepay = Pesepay("YOUR_INTEGRATION_KEY", "YOUR_ENCRYPTION_KEY")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('YOUR_INTEGRATION_KEY', 'YOUR_ENCRYPTION_KEY');$pesepay->returnUrl = 'https://example.com/payments/return';$pesepay->resultUrl = 'https://example.com/payments/result';PesepayClient.java Pesepay pesepay = new Pesepay(integrationKey, encryptionKey);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 the redirect flow: create a transaction for an amount and currency, then initiate it to get a
redirectUrl.const transaction = pesepay.createTransaction(10.0,'USD','Order #1042 — running shoes');pesepay.initiateTransaction(transaction).then((response) => {console.log(response.redirectUrl); // send the customer hereconsole.log(response.referenceNumber); // store this for later}).catch((error) => console.error(error));transaction = pesepay.create_transaction(10.0, "USD", "Order #1042 — running shoes")try:response = pesepay.initiate_transaction(transaction)print(response.redirect_url) # send the customer hereprint(response.reference_number) # store this for laterexcept Exception as err:print(err)$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 in step 3.