1. Go to this page and download the library: Download cixware/esewa-php-sdk 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 RemoteMerge\Esewa\EsewaFactory;
use RemoteMerge\Esewa\Exceptions\EsewaException;
$epay = EsewaFactory::createEpay([/* config */]);
$encodedResponse = $_GET['data'] ?? null;
if ($encodedResponse === null) {
exit('No eSewa response');
}
try {
$payment = $epay->verifyPayment($encodedResponse);
// Signature verified, safe to mark order as paid
$payment['transaction_code']; // eSewa transaction reference
$payment['status']; // "COMPLETE" on success
$payment['total_amount']; // Total charged amount
$payment['transaction_uuid']; // Your original order UUID
} catch (EsewaException $e) {
// Invalid signature or malformed response, do NOT fulfil the order
echo $e->getMessage();
}
$isValid = $epay->verifySignature($responseData, $responseData['signature']);
if ($isValid) {
// Payload is authentic
}
use RemoteMerge\Esewa\Contracts\HttpClientInterface;
use RemoteMerge\Esewa\EsewaFactory;
class CustomHttpClient implements HttpClientInterface
{
public function get(string $url, array $headers = []): string
{
// Your custom implementation
}
public function post(string $url, array $data, array $headers = []): string
{
// Your custom implementation
}
}
$epay = EsewaFactory::createEpay([/* config */], new CustomHttpClient());
$epay->getEnvironment(); // "test" or "production"
$epay->getProductCode(); // Your configured product code
$epay->getFormActionUrl(); // eSewa form submission URL for current environment
use RemoteMerge\Esewa\Exceptions\EsewaException;
try {
$payment = $epay->verifyPayment($encodedResponse);
} catch (EsewaException $e) {
error_log($e->getMessage());
// Do NOT mark the order paid, show a user-friendly error instead
}
bash
composer
bash
git clone [email protected]:remotemerge/esewa-php-sdk.git
cd esewa-php-sdk
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.