You can install the package via composer:
composer require codevirtus/pesepayImport the library into your project/application
require_once 'path/to/vendor/autoload.php';
use Codevirtus\Payments\PesepayCreate 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)
# visa
requiredFields = [
"creditCardExpiryDate" => "09/23",
"creditCardNumber" => "4867960000005461",
"creditCardSecurityNumber" => "608"
]
# direct mobile payments e.g ecocash, innbucs
requiredFields = [
"customerPhoneNumber" => "0712345678",
]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();
$amount = $response->amount();
$currencyCode = $response->currencyCode();
$transactionFee = $response->transactionServiceFee();
$metaData = $response->transactionMetadata();
# whole response
$data = $response->rawData();
# if using innbucs
$code = $response->metadataCode();
$qrcode = $response->metadataQrCode();
} 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();
}