@paynext/sdk 1.0.11 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +71 -55
- package/dist/index.umd.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -220,7 +220,7 @@ export declare interface LoadedResult {
|
|
|
220
220
|
error?: CheckoutError;
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
-
export declare type Locale = 'ar' | 'en' | 'bg' | 'cs' | 'da' | 'de' | 'el' | 'es' | 'et' | 'fi' | 'fil' | 'fr' | 'hr' | 'hu' | 'id' | 'it' | 'ja' | 'ko' | 'lt' | 'lv' | 'ms' | 'ru' | 'mt' | 'no' | 'nl' | 'pl' | 'pt' | 'ro' | 'uk' | 'sk' | 'sl' | 'sv' | 'th' | 'tr' | 'vi' | 'zh';
|
|
223
|
+
export declare type Locale = 'ar' | 'en' | 'bg' | 'cs' | 'da' | 'de' | 'el' | 'es' | 'et' | 'fi' | 'fil' | 'fr' | 'hr' | 'hu' | 'id' | 'it' | 'ja' | 'ko' | 'lt' | 'lv' | 'ms' | 'ru' | 'mt' | 'no' | 'nl' | 'pl' | 'pt' | 'ro' | 'uk' | 'sk' | 'sl' | 'sv' | 'th' | 'tr' | 'vi' | 'zh' | 'sr' | 'is' | 'nl-BE';
|
|
224
224
|
|
|
225
225
|
export declare enum PaymentMethod {
|
|
226
226
|
PAYPAL = "PAYPAL",
|
package/dist/index.es.js
CHANGED
|
@@ -1,91 +1,107 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
const
|
|
5
|
-
let
|
|
1
|
+
var A = Object.defineProperty;
|
|
2
|
+
var v = (r, e, t) => e in r ? A(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var u = (r, e, t) => v(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
const K = "https://cdn-sdk-dev.paynext.com/index.cdn.js", L = "https://cdn-sdk.paynext.com/index.cdn.js";
|
|
5
|
+
let w = null, h = null;
|
|
6
6
|
class n extends Error {
|
|
7
7
|
constructor(e, t = !0) {
|
|
8
8
|
super(e), this.retryable = t, this.name = "SDKLoadError";
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
const
|
|
12
|
-
function
|
|
13
|
-
return typeof window > "u" ? null : window[
|
|
11
|
+
const P = "PayNextSDK";
|
|
12
|
+
function E() {
|
|
13
|
+
return typeof window > "u" ? null : window[P];
|
|
14
14
|
}
|
|
15
15
|
function C(r) {
|
|
16
|
-
typeof window > "u" || (window[
|
|
16
|
+
typeof window > "u" || (window[P] = r);
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function S(r) {
|
|
19
19
|
return new Promise((e) => setTimeout(e, r));
|
|
20
20
|
}
|
|
21
|
-
async function
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const i =
|
|
21
|
+
async function _(r = 5e3) {
|
|
22
|
+
const t = Math.ceil(r / 50);
|
|
23
|
+
for (let o = 0; o < t; o++) {
|
|
24
|
+
const i = E();
|
|
25
25
|
if (i)
|
|
26
26
|
return i;
|
|
27
|
-
await
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
await S(50);
|
|
28
|
+
}
|
|
29
|
+
throw new n("PayNextSDK not found in window after waiting", !0);
|
|
30
|
+
}
|
|
31
|
+
async function p(r, e = 1) {
|
|
32
|
+
const o = (r?.toLowerCase()?.includes("develop") || r?.toLowerCase()?.includes("staging") ? "develop" : "production") === "develop" ? K : L;
|
|
33
|
+
try {
|
|
34
|
+
const i = E();
|
|
35
|
+
return i || (await new Promise((y, d) => {
|
|
36
|
+
const a = document.querySelector(`script[src="${o}"]`);
|
|
37
|
+
if (a) {
|
|
38
|
+
if (E()) {
|
|
39
|
+
y();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const l = setTimeout(() => {
|
|
43
|
+
a.removeEventListener("load", c), a.removeEventListener("error", m), d(new n("Existing SDK script loading timeout", !0));
|
|
44
|
+
}, 15e3), c = () => {
|
|
45
|
+
clearTimeout(l), a.removeEventListener("load", c), a.removeEventListener("error", m), y();
|
|
46
|
+
}, m = () => {
|
|
47
|
+
clearTimeout(l), a.removeEventListener("load", c), a.removeEventListener("error", m), d(new n("Existing SDK script failed to load", !0));
|
|
48
|
+
};
|
|
49
|
+
a.addEventListener("load", c), a.addEventListener("error", m);
|
|
30
50
|
return;
|
|
31
51
|
}
|
|
32
|
-
const
|
|
33
|
-
|
|
52
|
+
const x = setTimeout(() => {
|
|
53
|
+
f(), d(new n("SDK script loading timeout", !0));
|
|
34
54
|
}, 15e3), s = document.createElement("script");
|
|
35
55
|
s.src = o, s.crossOrigin = "anonymous", s.async = !0, s.setAttribute("data-paynext-sdk", "true");
|
|
36
|
-
const
|
|
37
|
-
clearTimeout(
|
|
56
|
+
const f = () => {
|
|
57
|
+
clearTimeout(x), s.onload = null, s.onerror = null;
|
|
38
58
|
};
|
|
39
59
|
s.onload = () => {
|
|
40
|
-
|
|
41
|
-
}, s.onerror = (
|
|
42
|
-
console.error("[PayNext CDN] Script load error:",
|
|
60
|
+
f(), y();
|
|
61
|
+
}, s.onerror = (l) => {
|
|
62
|
+
console.error("[PayNext CDN] Script load error:", l), f();
|
|
43
63
|
try {
|
|
44
64
|
s.parentNode && s.parentNode.removeChild(s);
|
|
45
|
-
} catch (
|
|
46
|
-
console.warn("[PayNext CDN] Failed to remove script:",
|
|
65
|
+
} catch (c) {
|
|
66
|
+
console.warn("[PayNext CDN] Failed to remove script:", c);
|
|
47
67
|
}
|
|
48
|
-
|
|
68
|
+
d(new n("Failed to load SDK script from CDN", !0));
|
|
49
69
|
};
|
|
50
70
|
try {
|
|
51
71
|
document.head.appendChild(s);
|
|
52
72
|
} catch {
|
|
53
|
-
|
|
73
|
+
f(), d(new n("Failed to append script to document", !1));
|
|
54
74
|
}
|
|
55
|
-
});
|
|
56
|
-
const u = y();
|
|
57
|
-
if (!u)
|
|
58
|
-
throw new n("PayNextSDK not found in window after load", !0);
|
|
59
|
-
return u;
|
|
75
|
+
}), await _(5e3));
|
|
60
76
|
} catch (i) {
|
|
61
77
|
if ((i instanceof n ? i.retryable : !0) && e < 5)
|
|
62
|
-
return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`, i), await
|
|
78
|
+
return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`, i), await S(1500 * e), p(r, e + 1);
|
|
63
79
|
throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`, i), i;
|
|
64
80
|
}
|
|
65
81
|
}
|
|
66
|
-
async function
|
|
67
|
-
if (
|
|
68
|
-
return
|
|
69
|
-
if (
|
|
70
|
-
return
|
|
82
|
+
async function D(r) {
|
|
83
|
+
if (h)
|
|
84
|
+
return h;
|
|
85
|
+
if (w)
|
|
86
|
+
return w;
|
|
71
87
|
if (typeof window > "u")
|
|
72
88
|
throw new n("PayNext SDK can only be loaded in browser environment", !1);
|
|
73
|
-
const e =
|
|
74
|
-
return e ? (
|
|
89
|
+
const e = E();
|
|
90
|
+
return e ? (h = e, h) : (w = (async () => {
|
|
75
91
|
try {
|
|
76
|
-
const t = await
|
|
77
|
-
return
|
|
92
|
+
const t = await p(r);
|
|
93
|
+
return h = t, C(t), t;
|
|
78
94
|
} catch (t) {
|
|
79
|
-
throw
|
|
95
|
+
throw w = null, t;
|
|
80
96
|
}
|
|
81
|
-
})(),
|
|
97
|
+
})(), w);
|
|
82
98
|
}
|
|
83
99
|
class R {
|
|
84
100
|
constructor() {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
101
|
+
u(this, "cdnInstance", null);
|
|
102
|
+
u(this, "initPromise", null);
|
|
103
|
+
u(this, "isDestroyed", !1);
|
|
104
|
+
u(this, "errorBoundary", null);
|
|
89
105
|
}
|
|
90
106
|
// set error handler
|
|
91
107
|
setErrorHandler(e) {
|
|
@@ -107,7 +123,7 @@ class R {
|
|
|
107
123
|
throw new n("Cannot initialize destroyed SDK instance", !1);
|
|
108
124
|
return this.initPromise ? this.initPromise : (this.initPromise = (async () => {
|
|
109
125
|
try {
|
|
110
|
-
const t = await
|
|
126
|
+
const t = await D(e);
|
|
111
127
|
if (!t || !t.PayNextCheckout)
|
|
112
128
|
throw new n("PayNextCheckout not found in loaded SDK module", !1);
|
|
113
129
|
try {
|
|
@@ -176,18 +192,18 @@ class R {
|
|
|
176
192
|
// preload SDK
|
|
177
193
|
static async preload(e) {
|
|
178
194
|
try {
|
|
179
|
-
await
|
|
195
|
+
await D(e);
|
|
180
196
|
} catch (t) {
|
|
181
197
|
throw console.error("[PayNext SDK] Preload failed:", t), t;
|
|
182
198
|
}
|
|
183
199
|
}
|
|
184
200
|
}
|
|
185
|
-
const
|
|
201
|
+
const I = {
|
|
186
202
|
preload: R.preload
|
|
187
203
|
};
|
|
188
|
-
var
|
|
204
|
+
var T = /* @__PURE__ */ ((r) => (r.PAYPAL = "PAYPAL", r.APPLE_PAY = "APPLEPAY", r.GOOGLE_PAY = "GPAY", r.CARD = "CARD", r.VENMO = "VENMO", r.CASHAPP = "CASHAPP", r))(T || {});
|
|
189
205
|
export {
|
|
190
206
|
R as PayNextCheckout,
|
|
191
|
-
|
|
192
|
-
|
|
207
|
+
I as PayNextSDK,
|
|
208
|
+
T as PaymentMethod
|
|
193
209
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(s,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(s=typeof globalThis<"u"?globalThis:s||self,a(s["PayNext SDK"]={}))})(this,(function(s){"use strict";var g=Object.defineProperty;var M=(s,a,l)=>a in s?g(s,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):s[a]=l;var m=(s,a,l)=>M(s,typeof a!="symbol"?a+"":a,l);const a="https://cdn-sdk-dev.paynext.com/index.cdn.js",l="https://cdn-sdk.paynext.com/index.cdn.js";let f=null,h=null;class r extends Error{constructor(e,t=!0){super(e),this.retryable=t,this.name="SDKLoadError"}}const p="PayNextSDK";function E(){return typeof window>"u"?null:window[p]}function L(n){typeof window>"u"||(window[p]=n)}function N(n){return new Promise(e=>setTimeout(e,n))}async function C(n=5e3){const t=Math.ceil(n/50);for(let o=0;o<t;o++){const i=E();if(i)return i;await N(50)}throw new r("PayNextSDK not found in window after waiting",!0)}async function x(n,e=1){const o=(n?.toLowerCase()?.includes("develop")||n?.toLowerCase()?.includes("staging")?"develop":"production")==="develop"?a:l;try{const i=E();return i||(await new Promise((D,y)=>{const c=document.querySelector(`script[src="${o}"]`);if(c){if(E()){D();return}const w=setTimeout(()=>{c.removeEventListener("load",u),c.removeEventListener("error",S),y(new r("Existing SDK script loading timeout",!0))},15e3),u=()=>{clearTimeout(w),c.removeEventListener("load",u),c.removeEventListener("error",S),D()},S=()=>{clearTimeout(w),c.removeEventListener("load",u),c.removeEventListener("error",S),y(new r("Existing SDK script failed to load",!0))};c.addEventListener("load",u),c.addEventListener("error",S);return}const R=setTimeout(()=>{P(),y(new r("SDK script loading timeout",!0))},15e3),d=document.createElement("script");d.src=o,d.crossOrigin="anonymous",d.async=!0,d.setAttribute("data-paynext-sdk","true");const P=()=>{clearTimeout(R),d.onload=null,d.onerror=null};d.onload=()=>{P(),D()},d.onerror=w=>{console.error("[PayNext CDN] Script load error:",w),P();try{d.parentNode&&d.parentNode.removeChild(d)}catch(u){console.warn("[PayNext CDN] Failed to remove script:",u)}y(new r("Failed to load SDK script from CDN",!0))};try{document.head.appendChild(d)}catch{P(),y(new r("Failed to append script to document",!1))}}),await C(5e3))}catch(i){if((i instanceof r?i.retryable:!0)&&e<5)return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`,i),await N(1500*e),x(n,e+1);throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`,i),i}}async function v(n){if(h)return h;if(f)return f;if(typeof window>"u")throw new r("PayNext SDK can only be loaded in browser environment",!1);const e=E();return e?(h=e,h):(f=(async()=>{try{const t=await x(n);return h=t,L(t),t}catch(t){throw f=null,t}})(),f)}class A{constructor(){m(this,"cdnInstance",null);m(this,"initPromise",null);m(this,"isDestroyed",!1);m(this,"errorBoundary",null)}setErrorHandler(e){this.errorBoundary=e}handleError(e,t){const o=`[PayNext SDK Error - ${t}]: ${e.message}`;if(console.error(o,e),this.errorBoundary)try{this.errorBoundary(e)}catch(i){console.error("[PayNext SDK] Error in custom error handler:",i)}}async initialize(e){if(this.isDestroyed)throw new r("Cannot initialize destroyed SDK instance",!1);return this.initPromise?this.initPromise:(this.initPromise=(async()=>{try{const t=await v(e);if(!t||!t.PayNextCheckout)throw new r("PayNextCheckout not found in loaded SDK module",!1);try{this.cdnInstance=new t.PayNextCheckout}catch(o){throw new r(`Failed to instantiate PayNextCheckout: ${o instanceof Error?o.message:"Unknown error"}`,!1)}}catch(t){throw this.initPromise=null,t}})(),this.initPromise)}assertReady(){if(this.isDestroyed)throw new r("SDK instance has been destroyed",!1);if(!this.initPromise)throw new r("SDK initialization not started",!1);if(!this.cdnInstance)throw new r("SDK instance not created",!1)}async mount(e,t){try{if(!e||typeof e!="string")throw new r("Invalid containerId provided",!1);if(!t||!t.environment)throw new r("Invalid config provided",!1);if(!document.getElementById(e))throw new r(`Container element with id "${e}" not found`,!1);await this.initialize(t.environment),this.assertReady(),await this.cdnInstance.mount(e,t)}catch(o){const i=o instanceof r?o:new r(o instanceof Error?o.message:"Unknown mount error",!0);throw this.handleError(i,"mount"),i}}async unmount(){try{if(this.isDestroyed){console.warn("[PayNext SDK] Instance already destroyed");return}if(!this.cdnInstance){console.warn("[PayNext SDK] No instance to unmount");return}try{typeof this.cdnInstance.unmount=="function"&&await this.cdnInstance.unmount()}catch(e){const t=e instanceof Error?e:new Error(String(e));this.handleError(t,"unmount")}this.cdnInstance=null,this.initPromise=null}catch(e){const t=e instanceof Error?e:new Error(String(e));this.handleError(t,"unmount")}}static async preload(e){try{await v(e)}catch(t){throw console.error("[PayNext SDK] Preload failed:",t),t}}}const T={preload:A.preload};var K=(n=>(n.PAYPAL="PAYPAL",n.APPLE_PAY="APPLEPAY",n.GOOGLE_PAY="GPAY",n.CARD="CARD",n.VENMO="VENMO",n.CASHAPP="CASHAPP",n))(K||{});s.PayNextCheckout=A,s.PayNextSDK=T,s.PaymentMethod=K,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paynext/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "PayNext SDK - Payment processing with automatic CDN loading",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.es.js",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@eslint/js": "^9.39.1",
|
|
64
|
-
"@evervault/js": "^2.
|
|
64
|
+
"@evervault/js": "^2.9.0",
|
|
65
65
|
"@heroui/react": "^2.8.5",
|
|
66
66
|
"@paypal/paypal-js": "^8.4.2",
|
|
67
67
|
"@paypal/react-paypal-js": "^8.9.2",
|