1. Go to this page and download the library: Download sudiptpa/omnipay-esewa 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/ */
use Sujip\Esewa\Domain\Verification\CallbackPayload;
use Sujip\Esewa\Domain\Verification\VerificationExpectation;
$payload = CallbackPayload::fromArray([
'data' => $_GET['data'] ?? '',
'signature' => $_GET['signature'] ?? '',
]);
$result = $client->callbacks()->verifyCallback(
$payload,
new VerificationExpectation(
totalAmount: '100.00',
transactionUuid: 'TXN-1001',
productCode: 'EPAYTEST',
)
);
if ($result->state->value === 'replayed') {
http_response_code(409);
exit('Replay detected');
}
if (!$result->isSuccessful()) {
http_response_code(400);
exit('Invalid callback');
}
use Sujip\Esewa\Domain\Transaction\TransactionStatusRequest;
$status = $client->transactions()->fetchStatus(new TransactionStatusRequest(
transactionUuid: 'TXN-1001',
totalAmount: '100.00',
productCode: 'EPAYTEST',
));
if ($status->isSuccessful()) {
// mark paid
}
use Sujip\Esewa\Config\ClientOptions;
use Sujip\Esewa\Esewa;
use Sujip\Esewa\Infrastructure\Idempotency\FilesystemIdempotencyStore;
$client = Esewa::make(
merchantCode: 'EPAYTEST',
secretKey: $_ENV['ESEWA_SECRET_KEY'],
environment: 'uat',
options: new ClientOptions(
preventCallbackReplay: true,
idempotencyStore: new FilesystemIdempotencyStore(__DIR__ . '/storage/esewa-idempotency'),
),
);
use Sujip\Esewa\Config\ClientOptions;
use Sujip\Esewa\Support\FixedDelayRetryPolicy;
$options = new ClientOptions(
retryPolicy: new FixedDelayRetryPolicy(
maxRetries: 3,
delayUs: 250000,
),
);
use Omnipay\Esewa\SecureGateway;
$gateway = new SecureGateway();
$gateway->setMerchantCode('EPAYTEST');
$gateway->setSecretKey($_ENV['ESEWA_SECRET_KEY']);
$gateway->setProductCode('EPAYTEST');
$gateway->setTestMode(true);
$gateway->setReturnUrl('https://merchant.example.com/esewa/success');
$gateway->setFailureUrl('https://merchant.example.com/esewa/failure');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.