PHP code example of moeen-basra / omnipay-jazzcash
1. Go to this page and download the library: Download moeen-basra/omnipay-jazzcash 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-jazzcash example snippets
use Omnipay\Omnipay;
/** @var \Omnipay\Jazzcash\Gateway $gateway */
$gateway = Omnipay::create('Jazzcash');
// initialize with array
$gateway->initialize([
'merchantId' => 'your-merchant-id',
'password' => 'your-password',
'secretKey' => 'your-secret-key',
]);
// or individual properties setter
$gateway->setMerchantId('your-merchant-id')
->setPassword('your-password')
->setSecretKey('your-secret-key');
// set the test mode if needed
$gateway->setTestMode(true);
$date = CarbonImmutable::now('Asia/Karachi');
try {
$parameters = [
[
'paymentMethod' => 'MWALLET', // 'MWALLET' | 'OTC' | 'MPAY'
'transactionTimestamp' => new \DateTime(), // make sure not past date also check your server timezone
'transactionExpiryTimestamp' => new \DateTime(), // cab be future date
'billReference' => (string) $date->timestamp,
'description' => 'Test Order',
'amount' => '20',
'language' => 'EN',
'currency' => 'PKR',
'transactionId' => $date->timestamp,
'extra' => [
'field_1' => 'value_1',
'field_2' => 'value_2',
'field_3' => 'value_3',
'field_4' => 'value_4',
'field_5' => 'value_5'
],
'returnUrl' => 'https://exmpale.com/return',
]
];
$response = $gateway->purchase($parameters)->send();
// var_dump($response->getData());
if ($response->isSuccessful() && $response instanceof RedirectIn) {
// do the redirect here you can do it auto using the following return statement
// return $response->getRedirectResponse();
} else {
// handle failed response
}
} catch (\Throwable $exception) {
var_dump($exception);
}
use Omnipay\Omnipay;
$gateway = Omnipay::create('Jazzcash');
// initialize with array
$gateway->initialize([
'merchantId' => 'your-merchant-id',
'password' => 'your-password',
'secretKey' => 'your-secret-key',
]);
try {
$response = $gateway->completePurchase()->send();
if (!$response->isSuccessful()) {
// handle failed logic
}
// always good option to cross-check the response data with gateway
$inquiryResponse = $gateway->fetchTransaction([
'transactionReference' => $response->getData()['pp_TxnRefNo'],
])
// see next step for more details
} catch (\Throwable $exception) {
var_dump($exception);
}
$response = $gateway->completePurchase()