PHP code example of sudiptpa / omnipay-esewa

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/ */

    

sudiptpa / omnipay-esewa example snippets


    use Omnipay\Omnipay;
    use Exception;

    $gateway = Omnipay::create('Esewa_Secure');

    $gateway->setMerchantCode('epay_payment');
    $gateway->setTestMode(true);

    try {
        $response = $gateway->purchase([
            'amount' => 100,
            'deliveryCharge' => 0,
            'serviceCharge' => 0,
            'taxAmount' => 0,
            'totalAmount' => 100,
            'productCode' => 'ABAC2098',
            'returnUrl' => 'https://merchant.com/payment/1/complete',
            'failedUrl' => 'https://merchant.com/payment/1/failed',
        ])->send();

        if ($response->isRedirect()) {
            $response->redirect();
        }
    } catch (Exception $e) {
        return $e->getMessage();
    }

    $gateway = Omnipay::create('Esewa_Secure');

    $gateway->setMerchantCode('epay_payment');
    $gateway->setTestMode(true);

    $response = $gateway->verifyPayment([
        'amount' => 100,
        'referenceNumber' => 'GDFG89',
        'productCode' => 'gadfg-gadf',
    ])->send();

    if ($response->isSuccessful()) {
        // Success
    }

    // Failed