### Install Cashfree.js using npm Source: https://github.com/cashfree/cashfree-js/blob/master/README.md Use npm to install the Cashfree.js module. This is the first step before using the library in your project. ```sh npm install @cashfreepayments/cashfree-js ``` -------------------------------- ### Install Cashfree.js using npm, yarn, or pnpm Source: https://context7.com/cashfree/cashfree-js/llms.txt Installs the Cashfree.js module using package managers. Supports CommonJS and ES Module formats for compatibility with various build tools. ```bash # Install using npm npm install @cashfreepayments/cashfree-js # Install using yarn yarn add @cashfreepayments/cashfree-js # Install using pnpm pnpm add @cashfreepayments/cashfree-js ``` -------------------------------- ### Initialize Cashfree SDK using load function Source: https://context7.com/cashfree/cashfree-js/llms.txt Asynchronously loads the Cashfree SDK in sandbox mode for testing. Ensure this is called only in browser environments; it returns null in server-side environments. ```javascript import { load } from '@cashfreepayments/cashfree-js'; // Initialize Cashfree in sandbox mode for testing const initializeCashfree = async () => { try { const cashfree = await load({ mode: "sandbox" // Use "production" for live payments }); if (cashfree) { console.log("Cashfree SDK loaded successfully"); // SDK is ready to use for payment operations return cashfree; } else { console.log("Running in server environment - SDK not loaded"); return null; } } catch (error) { console.error("Failed to load Cashfree SDK:", error); throw error; } }; // Usage const cashfree = await initializeCashfree(); ``` -------------------------------- ### Import Cashfree.js using ES Module or CommonJS Source: https://context7.com/cashfree/cashfree-js/llms.txt Demonstrates importing the load function from Cashfree.js using ES Module syntax (recommended) or CommonJS require. ```javascript // ES Module import (recommended) import { load } from '@cashfreepayments/cashfree-js'; // CommonJS require const { load } = require('@cashfreepayments/cashfree-js'); // Complete setup example import { load } from '@cashfreepayments/cashfree-js'; class PaymentService { constructor() { this.cashfree = null; } async initialize(mode = 'sandbox') { this.cashfree = await load({ mode }); return this.cashfree; } isReady() { return this.cashfree !== null; } } // Initialize payment service const paymentService = new PaymentService(); await paymentService.initialize('sandbox'); ``` -------------------------------- ### Configure Content Security Policy for Cashfree.js Source: https://context7.com/cashfree/cashfree-js/llms.txt Meta tag configuration for Content Security Policy (CSP) to allow Cashfree.js domains. For production, configuring CSP via HTTP headers is recommended. ```html ``` -------------------------------- ### Load Cashfree.js in JavaScript Source: https://github.com/cashfree/cashfree-js/blob/master/README.md Import and load the Cashfree object using the `load` function. This function returns a Promise that resolves with a Cashfree object. It will resolve to `null` if called in a server environment. Specify 'sandbox' or 'production' mode. ```js import {load} from '@cashfreepayments/cashfree-js'; const cashfree = await load({ mode: "sandbox" //or production }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.