Skip to content

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.

  • A Pesepay account with a sandbox integration key and encryption key
  • Node.js, Python, PHP, or Java installed locally
  1. Terminal window
    npm install pesepay
  2. 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';
  3. 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 here
    console.log(response.referenceNumber); // store this for later
    })
    .catch((error) => console.error(error));
  4. Send the customer’s browser to redirectUrl. In the sandbox, use the test payment methods to complete or deliberately fail the payment.

  5. Pesepay calls your resultUrl with the final status as soon as the customer finishes — see The Result Callback. As a fallback, you can also poll: Check Payment Status using the referenceNumber you stored in step 3.