PHP code example of codevirtus / pesepay

1. Go to this page and download the library: Download codevirtus/pesepay library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codevirtus / pesepay example snippets



use Codevirtus\Payments\Pesepay
 
$pesepay = new Pesepay("INTEGRATION KEY", "ENCRYPTION KEY");
 
$pesepay->returnUrl = "http://example.com/gateway/return";
$pesepay->resultUrl = "http://example.com/gateway/return";

$payment = $pesepay->createPayment('CURRECNCY_CODE', 'PAYMENT_METHOD_CODE', 'CUSTOMER_EMAIL(OPTIONAL)', 'CUSTOMER_PHONE_NUMBER(OPTIONAL)', 'CUSTOMER_NAME(OPTIONAL)');

$

$response = $pesepay->makeSeamlessPayment($payment, 'Online Transaction', $AMOUNT, $to check the status of a transaction)
    $referenceNumber = $response->referenceNumber();
    $pollUrl = $response->pollUrl();

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

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

$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();
}

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

if ($response->success()) {

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

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

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

if ($response->success()) {

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

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