You can install the package via composer:
composer require codevirtus/pesepay
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";
Create the payment
$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();
}
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();
}
$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();
}