Dhanyatra Checkout JS
A web checkout module to invoke instant payment.
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 add @dhanyatra/checkout-js
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',
amount: '500',
currency: 'INR',
organization: "Hustler's Academy",
image: 'https://i.imgur.com/n5tjHFD.png',
handler: function (response) {
alert(response.dhanyatra_payment_id);
},
modal: {
ondismiss: function () {
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');
}
},
},
}
const dhanyatra = new Dhanyatra(options)
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',
amount: '500',
currency: 'INR',
organization: "Hustler's Academy",
image: 'https://i.imgur.com/n5tjHFD.png',
handler: function (response) {
alert(response.dhanyatra_payment_id);
},
modal: {
ondismiss: function () {
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');
}
},
},
}
const dhanyatra = new Dhanyatra(options)
dhanyatra.open();
<script type="module">