Code Monkey home page Code Monkey logo

sudiptpa / esewa Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 2.0 43 KB

Integrate eSewa payment gateway for online payments. A php library to comsume eSewa payment gateway API, built on top of Omnipay Payment processing library. Read the blog post to follow the step by step guide on how to integrate esewa with Laravel PHP framework.

Home Page: https://sujipthapa.co/blog/esewa-online-payment-gateway-integration-with-php

License: MIT License

PHP 100.00%
omnipay php esewa esewa-api esewa-driver composer esewa-epay esewa-gateway esewa-nepal esewa-pnp gateway payment payment-gateway payments

esewa's Introduction

Omnipay: eSewa

eSewa driver for the Omnipay PHP payment processing library

Omnipay is a framework agnostic, multi-gateway payment processing library for PHP. This package implements eSewa support for Omnipay.

StyleCI Latest Stable Version Total Downloads GitHub license

Installation

Omnipay is installed via Composer. To install, simply require league/omnipay and sudiptpa/omnipay-esewa with Composer:

composer require league/omnipay sudiptpa/omnipay-esewa

Basic Usage

Purchase

    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();
    }

After successful payment and redirect back to merchant site, you need to now verify the payment with another API request.

Verify Payment

    $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

Laravel Integration

Please follow the eSewa Online Payment Gateway Integration and follow step by step guidlines.

Official Doc

Please follow the Official Doc to understand about the parameters and their descriptions.

Contributing

Contributions are welcome and will be fully credited.

Contributions can be made via a Pull Request on Github.

Support

If you are having general issues with Omnipay Esewa, drop an email to [email protected] for quick support.

If you believe you have found a bug, please report it using the GitHub issue tracker, or better yet, fork the library and submit a pull request.

License

This package is open-sourced software licensed under the MIT license.

esewa's People

Contributors

stylecibot avatar sudiptpa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

esewa's Issues

Issue with Epay::Payment Verification - https://developer.esewa.com.np/#/epay?id=payment-verification

I just noticed a bug in this package on verify transaction after successful payment is made.

How to recreate?

The docs says, to verify the transaction we need to send GET request like below.

<body>
    <form action="https://uat.esewa.com.np/epay/transrec" method="GET">
    <input value="100" name="amt" type="hidden">
    <input value="epay_payment" name="scd" type="hidden">
    <input value="ee2c3ca1-696b-4cc5-a6be-2c40d929d453" name="pid" type="hidden">
    <input value="000AE01" name="rid" type="hidden">
    <input value="Submit" type="submit">
    </form>
</body>

The Javascript, PHP, PYTHON code snippet over the docs says POST request.

This package implements the PHP version of the API.

I tried with CURL like below.

$url = "https://uat.esewa.com.np/epay/transrec";

$data =[
    'amt' => 24.0,
    'rid' => '00008FU',
    'pid' => 'TEST2019',
    'scd' => 'epay_payment',
];

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($curl);

curl_close($curl);

var_dump($response);

// output

<response>
<response_code>
Success
</response_code>
</response>

But, this package consumes the Guzzle HTTP library for HTTP request.

$url = 'https://uat.esewa.com.np/epay/transrec';

$data = [
    'amt' => 24.0,
    'rid' => '00008FU',
    'pid' => 'TEST2019',
    'scd' => 'epay_payment',
];

$response = $this->httpClient->request('POST', $url, [
     'Accept' => 'application/json',
     'Content-Type' => 'application/json',
 ], json_encode($data));
 
$output = $response->getBody()->getContents();

var_dump($output);

// output
// "<html><head><title>Request Rejected</title></head><body>The requested URL was rejected. Please consult with your administrator.<br><br>Your support ID is: <15212239662342379704><br><br><a href='javascript:history.back();'>[Go Back]</body></html>"

If anyone has gone through this error before, feel free to submit a PR with a fix.

Note: Issue description was updated later while testing and debugging.

Can I use it for core(basic) PHP developed website?

I am going to develop a core php with as simple setup as you can imagine based on my limited knowledge . Just simple cart for few products and checkout with Esewa. What are your experiences regarding this and About Omnipay , this sounds good!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.