codevirtus/pesepay

Pesepay online payment integration package

1.0.1 2021-10-22 10:10 UTC

This package is auto-updated.

Last update: 2024-04-22 15:54:42 UTC


README

You can install the package via composer:

composer require codevirtus/pesepay

Getting Started

Import the library into your project/application

require_once 'path/to/vendor/autoload.php';
use Codevirtus\Payments\Pesepay

Create an instance of the Pesepay class using your integration key and encryption key as supplied by Pesepay.

$pesepay = new Pesepay("INTEGRATION KEY", "ENCRYPTION KEY");

Set return and result urls

$pesepay->returnUrl = "http://example.com/gateway/return";
$pesepay->resultUrl = "http://example.com/gateway/return";

Make seamless payment

Create the payment

NB: Customer email or number should be provided
$payment = $pesepay->createPayment('CURRECNCY_CODE', 'PAYMENT_METHOD_CODE', 'CUSTOMER_EMAIL(OPTIONAL)', 'CUSTOMER_PHONE_NUMBER(OPTIONAL)', 'CUSTOMER_NAME(OPTIONAL)');

Create an object of the required fields (if any)

$requiredFields = ['requiredFieldName'=>'requiredFieldValue'];

Send of the payment

$response = $pesepay->makeSeamlessPayment($payment, 'Online Transaction', $AMOUNT, $requiredFields, 'MERCHANT_REFERENCE(OPTIONAL)');

if ($response->success()) {
    # Save the reference number and/or poll url (used to check the status of a transaction)
    $referenceNumber = $response->referenceNumber();
    $pollUrl = $response->pollUrl();

} else {
    #Get Error Message
    $errorMessage = $response->message();
}

Make redirect payment

Create a transaction

$transaction = $pesepay->createTransaction($amount, 'CURRENCY_CODE', 'PAYMENT_REASON', 'MERCHANT_REFERENCE(OPTIONAL)');

Initiate the transaction

$response = $pesepay->initiateTransaction($transaction);

if ($response->success()) {
    # Save the reference number and/or poll url (used to check the status of a transaction)
    $referenceNumber = $response->referenceNumber();
    $pollUrl = $response->pollUrl();
    # Get the redirect url and redirect user to complete transaction   
    $redirectUrl = $response->redirectUrl();
    
} else {
    # Get error message
    $errorMessage = $response->message();
}

Check Payment Status

Method 1: Using referenceNumber

$response = $pesepay->checkPayment($referenceNumber);

if ($response->success()) {

    if ($response->paid()) {
        # Payment was successfull
    }

} else {
    # Get error message
    $errorMessage = $response->message();
}

Method 2: Using poll url

$response = $pesepay->pollTransaction($pollUrl);

if ($response->success()) {

    if ($response->paid()) {
        # Payment was successfull
    }

} else {
    # Get error message
    $errorMessage = $response->message();
}