@dhanyatra/checkout-js
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

Dhanyatra Checkout JS

A web checkout module to invoke instant payment.


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



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">

Package Sidebar

Install

npm i @dhanyatra/checkout-js

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

69 kB

Total Files

12

Last publish

Collaborators

  • brighthustle