PHP code example of moeen-basra / omnipay-easypaisa
1. Go to this page and download the library: Download moeen-basra/omnipay-easypaisa 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/ */
moeen-basra / omnipay-easypaisa example snippets
use Omnipay\Omnipay;
$gateway = Omnipay::create('Easypaisa');
// initialize with array
$gateway->initialize([
'storeId' => 'your-store-id',
'username' => 'your-username',
'password' => 'your-password',
'accountNum' => 'your-account-number',
]);
// or individual properties setter
$gateway->setAcountId('your-store-id')
->setUsername('your-username')
->setPassword('your-password')
->setAccountNum('your-account-number');
// set the test mode if needed
$gateway->setTestMode(true);
try {
$parameters = [
'transactionId' => '<transId>',
'amount' => '<amount>', // float
'paymentMethod' => 'OTC', // OTC or MA
'emailAddress' => 'customer-email',
'mobileNumber' => 'customer-phone', // 10 digits phone 03xxxxxxxxx
'tokenExpiry' => (30 * 60), // 30 minutes
'extra' => [
'field_1' => 'value_1',
'field_2' => 'value_2',
'field_3' => 'value_3',
'field_4' => 'value_4',
'field_5' => 'value_5'
],
];
$response = $gateway->purchase($parameters)->send();
// var_dump($response->getData());
if ($response->isSuccessful()) {
// handle success response
} else {
// handle failed response
}
} catch (\Throwable $exception) {
var_dump($exception);
}
use Omnipay\Omnipay;
$gateway = Omnipay::create('Easypaisa');
// initialize with array
$gateway->initialize([
'storeId' => 'your-store-id',
'username' => 'your-username',
'password' => 'your-password',
'accountNum' => 'your-account-number',
]);
// set the test mode if needed
$gateway->setTestMode(true);
try {
$parameters = [
'transactionId' => '<transId>',
];
$response = $gateway->fetchTransaction($parameters)->send();
// var_dump($response->getData());
if ($response->isSuccessful()) {
// handle success response
} else {
// handle failed response
}
} catch (\Throwable $exception) {
var_dump($exception);
}