UNPKG

razorpay-react-sdk

Version:

A simple Razorpay integration package for React & Next.js with TypeScript support.

3 lines (2 loc) 1.2 kB
import{useMemo as o,useCallback as t}from"react";function n(o,t,n,r){return new(n||(n=Promise))((function(e,i){function c(o){try{d(r.next(o))}catch(o){i(o)}}function a(o){try{d(r.throw(o))}catch(o){i(o)}}function d(o){var t;o.done?e(o.value):(t=o.value,t instanceof n?t:new n((function(o){o(t)}))).then(c,a)}d((r=r.apply(o,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class r{static loadScript(){return n(this,void 0,void 0,(function*(){return new Promise(((o,t)=>{if(this.scriptLoaded)return o(!0);const n=document.createElement("script");n.src="https://checkout.razorpay.com/v1/checkout.js",n.async=!0,n.onload=()=>{this.scriptLoaded=!0,o(!0)},n.onerror=()=>t(new Error("Error while loading razorpay script")),document.body.appendChild(n)}))}))}static openPayment(o){return n(this,void 0,void 0,(function*(){if(!(yield this.loadScript()))throw new Error("Failed to load Razorpay SDK");new window.Razorpay(o).open()}))}}function e(e){const i=o((()=>"undefined"!=typeof window),[]);return t((()=>n(this,void 0,void 0,(function*(){i&&(yield r.openPayment(e))}))),[e])}r.scriptLoaded=!1;export{r as RazorpayClient,e as useRazorpay}; //# sourceMappingURL=index.esm.js.map