cashfree-pg
TypeScript icon, indicating that this package has built-in type declarations

4.3.1 • Public • Published

Cashfree PG Node SDK

GitHub Discord GitHub last commit (branch) GitHub release (with filter) npm GitHub forks Coverage Status

The Cashfree PG Node SDK offers a convenient solution to access Cashfree PG APIs from a server-side JavaScript applications.

Documentation

Cashfree's PG API Documentation - https://docs.cashfree.com/reference/pg-new-apis-endpoint

Learn and understand payment gateway workflows at Cashfree Payments here

Try out our interactive guides at Cashfree Dev Studio !

Getting Started

Installation

npm i cashfree-pg

Configuration

import { Cashfree } from "cashfree-pg"; 

Cashfree.XClientId = "<x-client-id>";
Cashfree.XClientSecret = "<x-client-secret>";
Cashfree.XEnvironment = Cashfree.Environment.SANDBOX;

Generate your API keys (x-client-id , x-client-secret) from Cashfree Merchant Dashboard

Basic Usage

Create Order

var request = {
    "order_amount": 1,
    "order_currency": "INR",
    "order_id": "order_34692745",
    "customer_details": {
        "customer_id": "walterwNrcMi",
        "customer_phone": "9999999999"
    },
    "order_meta": {
        "return_url": "https://www.cashfree.com/devstudio/preview/pg/web/checkout?order_id={order_id}"
    }
};
Cashfree.PGCreateOrder("2022-09-01", request).then((response) => {
    console.log('Order Created successfully:',response.data)
}).catch((error) => {
    console.error('Error:', error.response.data.message);
});

Get Order

Cashfree.PGFetchOrder("2022-09-01", "<order_id>").then((response) => {
    console.log('Order fetched successfully:', response.data);
}).catch((error) => {
    console.error('Error:', error.response.data.message);
});

Validate Webhook

app.post('/webhook', function (req, res) {
    try {
        Cashfree.PGVerifyWebhookSignature(req.headers["x-webhook-signature"], req.rawBody, req.headers["x-webhook-timestamp"]))
    } catch (err) {
        console.log(err.message)
    }
})

Supported Resources

Licence

Apache Licensed. See LICENSE.md for more details

Package Sidebar

Install

npm i cashfree-pg

Weekly Downloads

1,004

Version

4.3.1

License

Apache

Unpacked Size

4.33 MB

Total Files

50

Last publish

Collaborators

  • cashfree-payments