Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/es6 support and readme update #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion PaytmChecksum.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var crypto = require('crypto');

class PaytmChecksum {

static iv;

static encrypt(input, key) {
var cipher = crypto.createCipheriv('AES-128-CBC', key, PaytmChecksum.iv);
var encrypted = cipher.update(input, 'binary', 'base64');
Expand Down Expand Up @@ -90,5 +92,11 @@ class PaytmChecksum {
return PaytmChecksum.encrypt(hashString,key);
}
}

PaytmChecksum.iv = '@@@@&&&&####$$$$';
module.exports = PaytmChecksum;

if(typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
module.exports = PaytmChecksum;
} else {
window.PaytmChecksum = PaytmChecksum;
}
108 changes: 106 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,106 @@
# Checksum - Node Language
* More Details: **https://developer.paytm.com/docs/checksum/#node**
# Paytm Checksum - Node Language

This library provides a simple way to generate and verify checksums for Paytm transactions in Node.js. It ensures the integrity and authenticity of transaction data exchanged between your application and the Paytm gateway.

For more details and comprehensive documentation, please refer to the official [Paytm Checksum documentation](https://developer.paytm.com/docs/checksum/#node).

## Prerequisites

Before you can use the Paytm Checksum library, make sure you have the following prerequisites in place:

- Node.js version 6.0 or higher installed on your system.
- The crypto module, which is a built-in Node.js module.

## Installation

To get started with the Paytm Checksum library, you can install it using npm:

```bash
npm install paytmchecksum
```

## Usage

To use the Paytm Checksum library in your Node.js application, follow these steps:

### Import the paytmchecksum module

You can import the paytmchecksum module using either CommonJS or ES6 syntax, depending on your project's configuration.

For CommonJS:

```javascript
var paytmChecksum = require('paytmchecksum');
```

For ES6:

```javascript
import paytmChecksum from 'paytmchecksum';
```

## Generate Checksum

To generate a checksum, you need to provide the necessary parameters and your merchant key.

Example: Generate Checksum via Array

```javascript
var paytmParams = {
"MID": "YOUR_MID_HERE",
"ORDERID": "YOUR_ORDER_ID_HERE"
};

var merchantKey = "YOUR_MERCHANT_KEY";

var checksum = paytmChecksum.generateSignature(paytmParams, merchantKey);

checksum.then(function(result){
console.log("generateSignature Returns: " + result);
}).catch(function(error){
console.log(error);
});
```

Example: Generate Checksum via JSON String

```javascript
var body = "{\"mid\":\"YOUR_MID_HERE\",\"orderId\":\"YOUR_ORDER_ID_HERE\"}";

var merchantKey = "YOUR_MERCHANT_KEY";

var checksum = paytmChecksum.generateSignature(body, merchantKey);

checksum.then(function(result){
console.log("generateSignature Returns: " + result);
}).catch(function(error){
console.log(error);
});
```

## Verify Checksum

To verify a checksum, you need the original parameters, your merchant key, and the checksum to be verified.

```javascript
var paytmParams = {
"MID": "YOUR_MID_HERE",
"ORDERID": "YOUR_ORDER_ID_HERE"
};

var merchantKey = "YOUR_MERCHANT_KEY";

var checksum = "CHECKSUM_TO_BE_VERIFIED";

var verifyChecksum = paytmChecksum.verifySignature(paytmParams, merchantKey, checksum);

verifyChecksum.then(function(result){
console.log("verifySignature Returns: " + result);
}).catch(function(error){
console.log(error);
});
```

## More Information

For more detailed information and advanced usage, please refer to the official [Paytm Checksum documentation](https://developer.paytm.com/docs/checksum/#node).
2 changes: 1 addition & 1 deletion sample.js → examples/sample.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* More Details: https://developer.paytm.com/docs/checksum/#node */

var PaytmChecksum = require("./PaytmChecksum");
var PaytmChecksum = require("../PaytmChecksum");

var paytmParams = {};

Expand Down