Getting error "Cannot find name Cashfree" while using cashfree payment integration in react js

356 views Asked by At

Migrating to 2022-09-01 Cashfree documentation link : https://docs.cashfree.com/docs/checkout-migration-to-version-2022-09-01

Added the js sdk script in index.html in the public folder

<script src="https://sdk.cashfree.com/js/ui/2.0.0/cashfree.sandbox.js"></script>

But while doing

let cf = new Cashfree(session_id)
getting error "Cannot find name Cashfree"

How to import or use "new Cashfree()" in this case?

2

There are 2 answers

1
Harshith Kanigalpula S On BEST ANSWER

Once you add the javascript SDK url in the index.html which is in the public folder, try importing it by adding

let cf = new window.Cashfree(session_id)

wherever required

0
ankur mishra On

We can use NPM package of cashfree to get over this problem. For the sandbox environment we can use import { cashfreeSandbox } from "cashfree-pg-sdk-javascript";

Furthere details are provided in below link. Implementation of cashfree redirection through cashfree-pg-sdk-javascript