🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@dhanyatra/checkout-js

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dhanyatra/checkout-js

Check Js Module For Instant Web Checkout

1.0.4
latest
Source
npm
Version published
Weekly downloads
26
73.33%
Maintainers
0
Weekly downloads
 
Created
Source

Dhanyatra Checkout JS

A web checkout module to invoke instant payment.


gh-workflow-image npm-image license-image synk-image

Usage | Checkout Dhanyatra


Dhanyatra Checkout-JS is a JavaScript library tailored for seamless integration with Dhanyatra's payment gateway. It empowers developers to effortlessly incorporate Dhanyatra's payment features into their applications. By offering a clean and intuitive API, Dhanyatra Checkout-JS simplifies the process of handling payments, providing businesses with a robust solution for processing transactions and enhancing the checkout experience for customers.

Table of Contents

Installation

Install the package from the npm registry as follows:

npm i @dhanyatra/checkout-js

# yarn
yarn add @dhanyatra/checkout-js

# pnpm
pnpm add @dhanyatra/checkout-js

Usage

The module exposes a Dhanyatra class, which can be used to payment server and listen for payments events.

import { Dhanyatra } from '@dhanyatra/checkout-js';

const options = {
    key: 'Mw.9BnMszEkdEOE8OYmSPA0-IvISRHJCkUUKalSR_keJ2zWT9vFQtUsgfXM2ryn', // Enter the Key ID generated from the Dashboard
    amount: '500', // Any amount can be float
    currency: 'INR', // Currently only INR accepted
    organization: "Hustler's Academy", // Name to be displayed of organization
    image: 'https://i.imgur.com/n5tjHFD.png', // Logo to be displayed of organization
    handler: function (response) {
        //response after payment event either Success or Failed
        alert(response.dhanyatra_payment_id);
    },
    modal: {
    //Modal Handler inside payment gateway
      ondismiss: function () {
        //Dismiss Modal Handler
        let txt = '';
        if (confirm('Are you sure, you want to close the form?')) {
          txt = 'You pressed OK!';
          console.log('Checkout form closed by the user');
          rzp1.close();
        } else {
          txt = 'You pressed Cancel!';
          console.log('Complete the Payment');
        }
      },
    },
}

// Setup Dhanyatra options
const dhanyatra = new Dhanyatra(options)
// Trigger Payment
dhanyatra.open();

Using the package as script tag on HTML

<script type="module">
    import { Dhanyatra } from 'https://www.unpkg.com/@dhanyatra/checkout-js@0.0.2/build/checkout.modern.js';

    const options = {
        key: 'Mw.9BnMszEkdEOE8OYmSPA0-IvISRHJCkUUKalSR_keJ2zWT9vFQtUsgfXM2ryn', // Enter the Key ID generated from the Dashboard
        amount: '500', // Any amount can be float
        currency: 'INR', // Currently only INR accepted
        organization: "Hustler's Academy", // Name to be displayed of organization
        image: 'https://i.imgur.com/n5tjHFD.png', // Logo to be displayed of organization
        handler: function (response) {
            //response after payment event either Success or Failed
            alert(response.dhanyatra_payment_id);
        },
        modal: {
        //Modal Handler inside payment gateway
          ondismiss: function () {
            //Dismiss Modal Handler
            let txt = '';
            if (confirm('Are you sure, you want to close the form?')) {
              txt = 'You pressed OK!';
              console.log('Checkout form closed by the user');
              rzp1.close();
            } else {
              txt = 'You pressed Cancel!';
              console.log('Complete the Payment');
            }
          },
        },
    }

    // Setup Dhanyatra options
    const dhanyatra = new Dhanyatra(options)
    // Trigger Payment
    dhanyatra.open();
<script type="module">

Keywords

client

FAQs

Package last updated on 22 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts