Skip to content

Commit 56472ff

Browse files
authored
Merge pull request #20 from pralhadstha/v2-docs
Epay v2 updated guide with code snippets
2 parents 865b997 + 13d479c commit 56472ff

File tree

4 files changed

+160
-9
lines changed

4 files changed

+160
-9
lines changed

README.md

+34-8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply
1818
composer require league/omnipay sudiptpa/omnipay-esewa
1919
```
2020

21+
**Looking for ePay v1? Check [this documentation](./docs/README-v1.md) for installation instructions.**
22+
2123
## Basic Usage
2224

2325
### Purchase
@@ -52,29 +54,53 @@ composer require league/omnipay sudiptpa/omnipay-esewa
5254
}
5355
```
5456

55-
After successful payment and redirect back to merchant site, you need to now verify the payment with another API request.
57+
After successful payment and redirect back to merchant site, you need to verify the payment response.
5658

5759
### Verify Payment
5860

5961
```php
6062
$gateway = Omnipay::create('Esewa_Secure');
6163

6264
$gateway->setMerchantCode('epay_payment');
65+
$gateway->setSecretKey('secret_key_provided_by_esewa');
66+
$gateway->setTestMode(true);
67+
68+
$payload = json_decode(base64_decode($_GET['data']), true);
69+
70+
$signature = $gateway->generateSignature(generateSignature($payload));
71+
if ($signature === $payload['signature']) {
72+
// Verified
73+
} else {
74+
// Unverified
75+
}
76+
```
77+
78+
You can also check the status of payment if no any response is received when redirected back to merchant's site.
79+
80+
### Check Status
81+
82+
```php
83+
$gateway = Omnipay::create('Esewa_Secure');
84+
85+
$gateway->setMerchantCode('epay_payment');
86+
$gateway->setSecretKey('secret_key_provided_by_esewa');
6387
$gateway->setTestMode(true);
6488

65-
$response = $gateway->verifyPayment([
66-
'amount' => 100,
67-
'referenceNumber' => 'GDFG89',
68-
'productCode' => 'gadfg-gadf',
69-
])->send();
89+
$payload = [
90+
'totalAmount' => 100,
91+
'productCode' => 'ABAC2098',
92+
];
7093

94+
$response = $gateway->checkStatus($payload)->send();
7195
if ($response->isSuccessful()) {
7296
// Success
7397
}
74-
75-
// Failed
7698
```
7799

100+
## Working Example
101+
102+
Want to see working examples before integrating them into your project? View the examples **[here](https://github.com/pralhadstha/payment-gateways-examples)**
103+
78104
## Laravel Integration
79105

80106
Please follow the [eSewa Online Payment Gateway Integration](https://sujipthapa.com/blog/esewa-payment-gateway-integration-with-laravel) and follow step by step guidlines.

composer.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,19 @@
1616
{
1717
"name": "Sujip Thapa",
1818
"email": "[email protected]"
19+
},
20+
{
21+
"name": "Pralhad Kumar Shrestha",
22+
"email": "[email protected]"
1923
}
2024
],
2125
"autoload": {
2226
"psr-4": {
2327
"Omnipay\\Esewa\\": "src/"
24-
}
28+
},
29+
"files": [
30+
"src/helpers.php"
31+
]
2532
},
2633
"require": {
2734
"omnipay/common": "^3",

docs/README-v1.md

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Omnipay: eSewa
2+
3+
**eSewa driver for the Omnipay PHP payment processing library**
4+
5+
[Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment
6+
processing library for PHP. This package implements eSewa support for Omnipay.
7+
8+
[![StyleCI](https://github.styleci.io/repos/75586885/shield?branch=master&format=plastic)](https://github.styleci.io/repos/75586885)
9+
[![Latest Stable Version](https://poser.pugx.org/sudiptpa/omnipay-esewa/v/stable)](https://packagist.org/packages/sudiptpa/omnipay-esewa)
10+
[![Total Downloads](https://poser.pugx.org/sudiptpa/omnipay-esewa/downloads)](https://packagist.org/packages/sudiptpa/omnipay-esewa)
11+
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/sudiptpa/esewa/master/LICENSE)
12+
13+
## Installation
14+
15+
Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply require `league/omnipay` and `sudiptpa/omnipay-esewa` with Composer:
16+
17+
```
18+
composer require league/omnipay sudiptpa/omnipay-esewa
19+
```
20+
21+
## Basic Usage
22+
23+
### Purchase
24+
25+
```php
26+
use Omnipay\Omnipay;
27+
use Exception;
28+
29+
$gateway = Omnipay::create('Esewa_Secure');
30+
31+
$gateway->setMerchantCode('epay_payment');
32+
$gateway->setTestMode(true);
33+
34+
try {
35+
$response = $gateway->purchase([
36+
'amount' => 100,
37+
'deliveryCharge' => 0,
38+
'serviceCharge' => 0,
39+
'taxAmount' => 0,
40+
'totalAmount' => 100,
41+
'productCode' => 'ABAC2098',
42+
'returnUrl' => 'https://merchant.com/payment/1/complete',
43+
'failedUrl' => 'https://merchant.com/payment/1/failed',
44+
])->send();
45+
46+
if ($response->isRedirect()) {
47+
$response->redirect();
48+
}
49+
} catch (Exception $e) {
50+
return $e->getMessage();
51+
}
52+
```
53+
54+
After successful payment and redirect back to merchant site, you need to now verify the payment with another API request.
55+
56+
### Verify Payment
57+
58+
```php
59+
$gateway = Omnipay::create('Esewa_Secure');
60+
61+
$gateway->setMerchantCode('epay_payment');
62+
$gateway->setTestMode(true);
63+
64+
$response = $gateway->verifyPayment([
65+
'amount' => 100,
66+
'referenceNumber' => 'GDFG89',
67+
'productCode' => 'gadfg-gadf',
68+
])->send();
69+
70+
if ($response->isSuccessful()) {
71+
// Success
72+
}
73+
74+
// Failed
75+
```
76+
77+
## Laravel Integration
78+
79+
Please follow the [eSewa Online Payment Gateway Integration](https://sujipthapa.com/blog/esewa-online-payment-gateway-integration-with-php) and follow step by step guidlines.
80+
81+
## Official Doc
82+
83+
Please follow the [Official Doc](https://developer.esewa.com.np) to understand about the parameters and their descriptions.
84+
85+
## Contributing
86+
87+
Contributions are **welcome** and will be fully **credited**.
88+
89+
Contributions can be made via a Pull Request on [Github](https://github.com/sudiptpa/esewa).
90+
91+
## Support
92+
93+
If you are having general issues with Omnipay Esewa, drop an email to [email protected] for quick support.
94+
95+
If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/sudiptpa/esewa/issues),
96+
or better yet, fork the library and submit a pull request.
97+
98+
## License
99+
100+
This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

src/helpers.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
if (!function_exists('generateSignature')) {
4+
/**
5+
* Generates the signature string from the provided parameters for verification.
6+
*
7+
* @return string
8+
*/
9+
function generateSignature(array $parameters)
10+
{
11+
$filteredParameters = array_intersect_key(
12+
$parameters,
13+
array_flip(explode(',', $parameters['signed_field_names']))
14+
);
15+
16+
return implode(',', array_map(fn ($key) => "$key=".$filteredParameters[$key], array_keys($filteredParameters)));
17+
}
18+
}

0 commit comments

Comments
 (0)