@paynext/sdk 1.0.11 → 1.0.13

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 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",
@@ -394,7 +394,8 @@ declare enum PaymentStatus {
394
394
  SETTLED = "SETTLED",
395
395
  DECLINED = "DECLINED",
396
396
  CANCELLED = "CANCELLED",
397
- BLOCKED = "BLOCKED"
397
+ BLOCKED = "BLOCKED",
398
+ INCOMPLETE = "INCOMPLETE"
398
399
  }
399
400
 
400
401
  export declare class PayNextCheckout {
package/dist/index.es.js CHANGED
@@ -1,99 +1,131 @@
1
- var p = Object.defineProperty;
2
- var N = (r, e, t) => e in r ? p(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var a = (r, e, t) => N(r, typeof e != "symbol" ? e + "" : e, t);
4
- const x = "https://cdn-sdk-dev.paynext.com/index.cdn.js", A = "https://cdn-sdk.paynext.com/index.cdn.js";
5
- let c = null, d = null;
6
- class n extends Error {
7
- constructor(e, t = !0) {
8
- super(e), this.retryable = t, this.name = "SDKLoadError";
1
+ var C = Object.defineProperty;
2
+ var N = (t, e, n) => e in t ? C(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
+ var d = (t, e, n) => N(t, typeof e != "symbol" ? e + "" : e, n);
4
+ const k = "https://cdn-sdk-dev.paynext.com/index.cdn.js", x = "https://cdn-sdk.paynext.com/index.cdn.js";
5
+ let h = null, y = null;
6
+ function L() {
7
+ const t = navigator.connection || navigator.mozConnection || navigator.webkitConnection, e = {
8
+ online: navigator.onLine,
9
+ documentHidden: document.hidden,
10
+ userAgent: navigator.userAgent,
11
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
12
+ };
13
+ return t && (e.connectionType = t.type, e.effectiveType = t.effectiveType, e.downlink = t.downlink, e.rtt = t.rtt, e.saveData = t.saveData), navigator.onLine ? document.hidden ? e.likelyCause = "background_tab" : t?.effectiveType === "slow-2g" || t?.effectiveType === "2g" ? e.likelyCause = "slow_connection" : t?.downlink !== void 0 && t.downlink < 0.5 && (e.likelyCause = "poor_bandwidth") : e.likelyCause = "offline", e;
14
+ }
15
+ function g(t) {
16
+ const e = [];
17
+ return t.likelyCause && e.push(`cause=${t.likelyCause}`), e.push(`online=${t.online}`), e.push(`hidden=${t.documentHidden}`), t.effectiveType && e.push(`net=${t.effectiveType}`), t.downlink !== void 0 && e.push(`downlink=${t.downlink}Mbps`), t.rtt !== void 0 && e.push(`rtt=${t.rtt}ms`), e.join(", ");
18
+ }
19
+ class r extends Error {
20
+ constructor(n, o = !0, i = !1) {
21
+ const u = i && typeof window < "u" ? L() : null, c = u ? `${n} [${g(u)}]` : n;
22
+ super(c);
23
+ d(this, "diagnostics");
24
+ this.retryable = o, this.name = "SDKLoadError", this.diagnostics = u;
9
25
  }
10
26
  }
11
- const D = "PayNextSDK";
12
- function y() {
13
- return typeof window > "u" ? null : window[D];
27
+ const v = "PayNextSDK";
28
+ function D() {
29
+ return typeof window > "u" ? null : window[v];
14
30
  }
15
- function C(r) {
16
- typeof window > "u" || (window[D] = r);
31
+ function T(t) {
32
+ typeof window > "u" || (window[v] = t);
17
33
  }
18
- function K(r) {
19
- return new Promise((e) => setTimeout(e, r));
34
+ function P(t) {
35
+ return new Promise((e) => setTimeout(e, t));
20
36
  }
21
- async function P(r, e = 1) {
22
- const o = (r?.toLowerCase()?.includes("develop") || r?.toLowerCase()?.includes("staging") ? "develop" : "production") === "develop" ? x : A;
23
- try {
24
- const i = y();
37
+ async function K(t = 5e3) {
38
+ const n = Math.ceil(t / 50);
39
+ for (let o = 0; o < n; o++) {
40
+ const i = D();
25
41
  if (i)
26
42
  return i;
27
- await new Promise((h, w) => {
28
- if (document.querySelector(`script[src="${o}"]`)) {
29
- h();
43
+ await P(50);
44
+ }
45
+ throw new r("PayNextSDK not found in window after waiting", !0, !0);
46
+ }
47
+ async function S(t, e = 1) {
48
+ const o = (t?.toLowerCase()?.includes("develop") || t?.toLowerCase()?.includes("staging") ? "develop" : "production") === "develop" ? k : x;
49
+ try {
50
+ const i = D();
51
+ return i || (await new Promise((c, f) => {
52
+ const a = document.querySelector(`script[src="${o}"]`);
53
+ if (a) {
54
+ if (D()) {
55
+ c();
56
+ return;
57
+ }
58
+ const w = setTimeout(() => {
59
+ a.removeEventListener("load", l), a.removeEventListener("error", p), f(new r("Existing SDK script loading timeout", !0, !0));
60
+ }, 15e3), l = () => {
61
+ clearTimeout(w), a.removeEventListener("load", l), a.removeEventListener("error", p), c();
62
+ }, p = () => {
63
+ clearTimeout(w), a.removeEventListener("load", l), a.removeEventListener("error", p), f(new r("Existing SDK script failed to load", !0, !0));
64
+ };
65
+ a.addEventListener("load", l), a.addEventListener("error", p);
30
66
  return;
31
67
  }
32
- const E = setTimeout(() => {
33
- l(), w(new n("SDK script loading timeout", !0));
68
+ const A = setTimeout(() => {
69
+ m(), f(new r("SDK script loading timeout", !0, !0));
34
70
  }, 15e3), s = document.createElement("script");
35
71
  s.src = o, s.crossOrigin = "anonymous", s.async = !0, s.setAttribute("data-paynext-sdk", "true");
36
- const l = () => {
37
- clearTimeout(E), s.onload = null, s.onerror = null;
72
+ const m = () => {
73
+ clearTimeout(A), s.onload = null, s.onerror = null;
38
74
  };
39
75
  s.onload = () => {
40
- l(), h();
41
- }, s.onerror = (f) => {
42
- console.error("[PayNext CDN] Script load error:", f), l();
76
+ m(), c();
77
+ }, s.onerror = (w) => {
78
+ console.error("[PayNext CDN] Script load error:", w), m();
43
79
  try {
44
80
  s.parentNode && s.parentNode.removeChild(s);
45
- } catch (S) {
46
- console.warn("[PayNext CDN] Failed to remove script:", S);
81
+ } catch (l) {
82
+ console.warn("[PayNext CDN] Failed to remove script:", l);
47
83
  }
48
- w(new n("Failed to load SDK script from CDN", !0));
84
+ f(new r("Failed to load SDK script from CDN", !0, !0));
49
85
  };
50
86
  try {
51
87
  document.head.appendChild(s);
52
88
  } catch {
53
- l(), w(new n("Failed to append script to document", !1));
89
+ m(), f(new r("Failed to append script to document", !1));
54
90
  }
55
- });
56
- const u = y();
57
- if (!u)
58
- throw new n("PayNextSDK not found in window after load", !0);
59
- return u;
91
+ }), await K(5e3));
60
92
  } catch (i) {
61
- if ((i instanceof n ? i.retryable : !0) && e < 5)
62
- return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`, i), await K(1500 * e), P(r, e + 1);
93
+ if ((i instanceof r ? i.retryable : !0) && e < 5)
94
+ return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`, i), await P(1500 * e), S(t, e + 1);
63
95
  throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`, i), i;
64
96
  }
65
97
  }
66
- async function m(r) {
67
- if (d)
68
- return d;
69
- if (c)
70
- return c;
98
+ async function E(t) {
99
+ if (y)
100
+ return y;
101
+ if (h)
102
+ return h;
71
103
  if (typeof window > "u")
72
- throw new n("PayNext SDK can only be loaded in browser environment", !1);
73
- const e = y();
74
- return e ? (d = e, d) : (c = (async () => {
104
+ throw new r("PayNext SDK can only be loaded in browser environment", !1);
105
+ const e = D();
106
+ return e ? (y = e, y) : (h = (async () => {
75
107
  try {
76
- const t = await P(r);
77
- return d = t, C(t), t;
78
- } catch (t) {
79
- throw c = null, t;
108
+ const n = await S(t);
109
+ return y = n, T(n), n;
110
+ } catch (n) {
111
+ throw h = null, n;
80
112
  }
81
- })(), c);
113
+ })(), h);
82
114
  }
83
- class R {
115
+ class _ {
84
116
  constructor() {
85
- a(this, "cdnInstance", null);
86
- a(this, "initPromise", null);
87
- a(this, "isDestroyed", !1);
88
- a(this, "errorBoundary", null);
117
+ d(this, "cdnInstance", null);
118
+ d(this, "initPromise", null);
119
+ d(this, "isDestroyed", !1);
120
+ d(this, "errorBoundary", null);
89
121
  }
90
122
  // set error handler
91
123
  setErrorHandler(e) {
92
124
  this.errorBoundary = e;
93
125
  }
94
126
  // handle error
95
- handleError(e, t) {
96
- const o = `[PayNext SDK Error - ${t}]: ${e.message}`;
127
+ handleError(e, n) {
128
+ const o = `[PayNext SDK Error - ${n}]: ${e.message}`;
97
129
  if (console.error(o, e), this.errorBoundary)
98
130
  try {
99
131
  this.errorBoundary(e);
@@ -104,46 +136,46 @@ class R {
104
136
  // initialize
105
137
  async initialize(e) {
106
138
  if (this.isDestroyed)
107
- throw new n("Cannot initialize destroyed SDK instance", !1);
139
+ throw new r("Cannot initialize destroyed SDK instance", !1);
108
140
  return this.initPromise ? this.initPromise : (this.initPromise = (async () => {
109
141
  try {
110
- const t = await m(e);
111
- if (!t || !t.PayNextCheckout)
112
- throw new n("PayNextCheckout not found in loaded SDK module", !1);
142
+ const n = await E(e);
143
+ if (!n || !n.PayNextCheckout)
144
+ throw new r("PayNextCheckout not found in loaded SDK module", !1);
113
145
  try {
114
- this.cdnInstance = new t.PayNextCheckout();
146
+ this.cdnInstance = new n.PayNextCheckout();
115
147
  } catch (o) {
116
- throw new n(
148
+ throw new r(
117
149
  `Failed to instantiate PayNextCheckout: ${o instanceof Error ? o.message : "Unknown error"}`,
118
150
  !1
119
151
  );
120
152
  }
121
- } catch (t) {
122
- throw this.initPromise = null, t;
153
+ } catch (n) {
154
+ throw this.initPromise = null, n;
123
155
  }
124
156
  })(), this.initPromise);
125
157
  }
126
158
  // assert ready
127
159
  assertReady() {
128
160
  if (this.isDestroyed)
129
- throw new n("SDK instance has been destroyed", !1);
161
+ throw new r("SDK instance has been destroyed", !1);
130
162
  if (!this.initPromise)
131
- throw new n("SDK initialization not started", !1);
163
+ throw new r("SDK initialization not started", !1);
132
164
  if (!this.cdnInstance)
133
- throw new n("SDK instance not created", !1);
165
+ throw new r("SDK instance not created", !1);
134
166
  }
135
167
  // mount
136
- async mount(e, t) {
168
+ async mount(e, n) {
137
169
  try {
138
170
  if (!e || typeof e != "string")
139
- throw new n("Invalid containerId provided", !1);
140
- if (!t || !t.environment)
141
- throw new n("Invalid config provided", !1);
171
+ throw new r("Invalid containerId provided", !1);
172
+ if (!n || !n.environment)
173
+ throw new r("Invalid config provided", !1);
142
174
  if (!document.getElementById(e))
143
- throw new n(`Container element with id "${e}" not found`, !1);
144
- await this.initialize(t.environment), this.assertReady(), await this.cdnInstance.mount(e, t);
175
+ throw new r(`Container element with id "${e}" not found`, !1);
176
+ await this.initialize(n.environment), this.assertReady(), await this.cdnInstance.mount(e, n);
145
177
  } catch (o) {
146
- const i = o instanceof n ? o : new n(
178
+ const i = o instanceof r ? o : new r(
147
179
  o instanceof Error ? o.message : "Unknown mount error",
148
180
  !0
149
181
  );
@@ -164,30 +196,30 @@ class R {
164
196
  try {
165
197
  typeof this.cdnInstance.unmount == "function" && await this.cdnInstance.unmount();
166
198
  } catch (e) {
167
- const t = e instanceof Error ? e : new Error(String(e));
168
- this.handleError(t, "unmount");
199
+ const n = e instanceof Error ? e : new Error(String(e));
200
+ this.handleError(n, "unmount");
169
201
  }
170
202
  this.cdnInstance = null, this.initPromise = null;
171
203
  } catch (e) {
172
- const t = e instanceof Error ? e : new Error(String(e));
173
- this.handleError(t, "unmount");
204
+ const n = e instanceof Error ? e : new Error(String(e));
205
+ this.handleError(n, "unmount");
174
206
  }
175
207
  }
176
208
  // preload SDK
177
209
  static async preload(e) {
178
210
  try {
179
- await m(e);
180
- } catch (t) {
181
- throw console.error("[PayNext SDK] Preload failed:", t), t;
211
+ await E(e);
212
+ } catch (n) {
213
+ throw console.error("[PayNext SDK] Preload failed:", n), n;
182
214
  }
183
215
  }
184
216
  }
185
- const T = {
186
- preload: R.preload
217
+ const I = {
218
+ preload: _.preload
187
219
  };
188
- var _ = /* @__PURE__ */ ((r) => (r.PAYPAL = "PAYPAL", r.APPLE_PAY = "APPLEPAY", r.GOOGLE_PAY = "GPAY", r.CARD = "CARD", r.VENMO = "VENMO", r.CASHAPP = "CASHAPP", r))(_ || {});
220
+ var R = /* @__PURE__ */ ((t) => (t.PAYPAL = "PAYPAL", t.APPLE_PAY = "APPLEPAY", t.GOOGLE_PAY = "GPAY", t.CARD = "CARD", t.VENMO = "VENMO", t.CASHAPP = "CASHAPP", t))(R || {});
189
221
  export {
190
- R as PayNextCheckout,
191
- T as PayNextSDK,
192
- _ as PaymentMethod
222
+ _ as PayNextCheckout,
223
+ I as PayNextSDK,
224
+ R as PaymentMethod
193
225
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(o,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(o=typeof globalThis<"u"?globalThis:o||self,i(o["PayNext SDK"]={}))})(this,(function(o){"use strict";var T=Object.defineProperty;var g=(o,i,d)=>i in o?T(o,i,{enumerable:!0,configurable:!0,writable:!0,value:d}):o[i]=d;var h=(o,i,d)=>g(o,typeof i!="symbol"?i+"":i,d);const i="https://cdn-sdk-dev.paynext.com/index.cdn.js",d="https://cdn-sdk.paynext.com/index.cdn.js";let l=null,u=null;class r extends Error{constructor(e,t=!0){super(e),this.retryable=t,this.name="SDKLoadError"}}const D="PayNextSDK";function y(){return typeof window>"u"?null:window[D]}function A(n){typeof window>"u"||(window[D]=n)}function K(n){return new Promise(e=>setTimeout(e,n))}async function S(n,e=1){const s=(n?.toLowerCase()?.includes("develop")||n?.toLowerCase()?.includes("staging")?"develop":"production")==="develop"?i:d;try{const a=y();if(a)return a;await new Promise((m,P)=>{if(document.querySelector(`script[src="${s}"]`)){m();return}const R=setTimeout(()=>{f(),P(new r("SDK script loading timeout",!0))},15e3),c=document.createElement("script");c.src=s,c.crossOrigin="anonymous",c.async=!0,c.setAttribute("data-paynext-sdk","true");const f=()=>{clearTimeout(R),c.onload=null,c.onerror=null};c.onload=()=>{f(),m()},c.onerror=x=>{console.error("[PayNext CDN] Script load error:",x),f();try{c.parentNode&&c.parentNode.removeChild(c)}catch(_){console.warn("[PayNext CDN] Failed to remove script:",_)}P(new r("Failed to load SDK script from CDN",!0))};try{document.head.appendChild(c)}catch{f(),P(new r("Failed to append script to document",!1))}});const w=y();if(!w)throw new r("PayNextSDK not found in window after load",!0);return w}catch(a){if((a instanceof r?a.retryable:!0)&&e<5)return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`,a),await K(1500*e),S(n,e+1);throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`,a),a}}async function E(n){if(u)return u;if(l)return l;if(typeof window>"u")throw new r("PayNext SDK can only be loaded in browser environment",!1);const e=y();return e?(u=e,u):(l=(async()=>{try{const t=await S(n);return u=t,A(t),t}catch(t){throw l=null,t}})(),l)}class p{constructor(){h(this,"cdnInstance",null);h(this,"initPromise",null);h(this,"isDestroyed",!1);h(this,"errorBoundary",null)}setErrorHandler(e){this.errorBoundary=e}handleError(e,t){const s=`[PayNext SDK Error - ${t}]: ${e.message}`;if(console.error(s,e),this.errorBoundary)try{this.errorBoundary(e)}catch(a){console.error("[PayNext SDK] Error in custom error handler:",a)}}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 E(e);if(!t||!t.PayNextCheckout)throw new r("PayNextCheckout not found in loaded SDK module",!1);try{this.cdnInstance=new t.PayNextCheckout}catch(s){throw new r(`Failed to instantiate PayNextCheckout: ${s instanceof Error?s.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(s){const a=s instanceof r?s:new r(s instanceof Error?s.message:"Unknown mount error",!0);throw this.handleError(a,"mount"),a}}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 E(e)}catch(t){throw console.error("[PayNext SDK] Preload failed:",t),t}}}const C={preload:p.preload};var N=(n=>(n.PAYPAL="PAYPAL",n.APPLE_PAY="APPLEPAY",n.GOOGLE_PAY="GPAY",n.CARD="CARD",n.VENMO="VENMO",n.CASHAPP="CASHAPP",n))(N||{});o.PayNextCheckout=p,o.PayNextSDK=C,o.PaymentMethod=N,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
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 R=Object.defineProperty;var I=(s,a,l)=>a in s?R(s,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):s[a]=l;var y=(s,a,l)=>I(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 h=null,w=null;function T(){const t=navigator.connection||navigator.mozConnection||navigator.webkitConnection,e={online:navigator.onLine,documentHidden:document.hidden,userAgent:navigator.userAgent,timestamp:new Date().toISOString()};return t&&(e.connectionType=t.type,e.effectiveType=t.effectiveType,e.downlink=t.downlink,e.rtt=t.rtt,e.saveData=t.saveData),navigator.onLine?document.hidden?e.likelyCause="background_tab":t?.effectiveType==="slow-2g"||t?.effectiveType==="2g"?e.likelyCause="slow_connection":t?.downlink!==void 0&&t.downlink<.5&&(e.likelyCause="poor_bandwidth"):e.likelyCause="offline",e}function g(t){const e=[];return t.likelyCause&&e.push(`cause=${t.likelyCause}`),e.push(`online=${t.online}`),e.push(`hidden=${t.documentHidden}`),t.effectiveType&&e.push(`net=${t.effectiveType}`),t.downlink!==void 0&&e.push(`downlink=${t.downlink}Mbps`),t.rtt!==void 0&&e.push(`rtt=${t.rtt}ms`),e.join(", ")}class o extends Error{constructor(n,r=!0,i=!1){const m=i&&typeof window<"u"?T():null,u=m?`${n} [${g(m)}]`:n;super(u);y(this,"diagnostics");this.retryable=r,this.name="SDKLoadError",this.diagnostics=m}}const v="PayNextSDK";function E(){return typeof window>"u"?null:window[v]}function K(t){typeof window>"u"||(window[v]=t)}function N(t){return new Promise(e=>setTimeout(e,t))}async function L(t=5e3){const n=Math.ceil(t/50);for(let r=0;r<n;r++){const i=E();if(i)return i;await N(50)}throw new o("PayNextSDK not found in window after waiting",!0,!0)}async function x(t,e=1){const r=(t?.toLowerCase()?.includes("develop")||t?.toLowerCase()?.includes("staging")?"develop":"production")==="develop"?a:l;try{const i=E();return i||(await new Promise((u,p)=>{const d=document.querySelector(`script[src="${r}"]`);if(d){if(E()){u();return}const D=setTimeout(()=>{d.removeEventListener("load",f),d.removeEventListener("error",S),p(new o("Existing SDK script loading timeout",!0,!0))},15e3),f=()=>{clearTimeout(D),d.removeEventListener("load",f),d.removeEventListener("error",S),u()},S=()=>{clearTimeout(D),d.removeEventListener("load",f),d.removeEventListener("error",S),p(new o("Existing SDK script failed to load",!0,!0))};d.addEventListener("load",f),d.addEventListener("error",S);return}const M=setTimeout(()=>{P(),p(new o("SDK script loading timeout",!0,!0))},15e3),c=document.createElement("script");c.src=r,c.crossOrigin="anonymous",c.async=!0,c.setAttribute("data-paynext-sdk","true");const P=()=>{clearTimeout(M),c.onload=null,c.onerror=null};c.onload=()=>{P(),u()},c.onerror=D=>{console.error("[PayNext CDN] Script load error:",D),P();try{c.parentNode&&c.parentNode.removeChild(c)}catch(f){console.warn("[PayNext CDN] Failed to remove script:",f)}p(new o("Failed to load SDK script from CDN",!0,!0))};try{document.head.appendChild(c)}catch{P(),p(new o("Failed to append script to document",!1))}}),await L(5e3))}catch(i){if((i instanceof o?i.retryable:!0)&&e<5)return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`,i),await N(1500*e),x(t,e+1);throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`,i),i}}async function C(t){if(w)return w;if(h)return h;if(typeof window>"u")throw new o("PayNext SDK can only be loaded in browser environment",!1);const e=E();return e?(w=e,w):(h=(async()=>{try{const n=await x(t);return w=n,K(n),n}catch(n){throw h=null,n}})(),h)}class k{constructor(){y(this,"cdnInstance",null);y(this,"initPromise",null);y(this,"isDestroyed",!1);y(this,"errorBoundary",null)}setErrorHandler(e){this.errorBoundary=e}handleError(e,n){const r=`[PayNext SDK Error - ${n}]: ${e.message}`;if(console.error(r,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 o("Cannot initialize destroyed SDK instance",!1);return this.initPromise?this.initPromise:(this.initPromise=(async()=>{try{const n=await C(e);if(!n||!n.PayNextCheckout)throw new o("PayNextCheckout not found in loaded SDK module",!1);try{this.cdnInstance=new n.PayNextCheckout}catch(r){throw new o(`Failed to instantiate PayNextCheckout: ${r instanceof Error?r.message:"Unknown error"}`,!1)}}catch(n){throw this.initPromise=null,n}})(),this.initPromise)}assertReady(){if(this.isDestroyed)throw new o("SDK instance has been destroyed",!1);if(!this.initPromise)throw new o("SDK initialization not started",!1);if(!this.cdnInstance)throw new o("SDK instance not created",!1)}async mount(e,n){try{if(!e||typeof e!="string")throw new o("Invalid containerId provided",!1);if(!n||!n.environment)throw new o("Invalid config provided",!1);if(!document.getElementById(e))throw new o(`Container element with id "${e}" not found`,!1);await this.initialize(n.environment),this.assertReady(),await this.cdnInstance.mount(e,n)}catch(r){const i=r instanceof o?r:new o(r instanceof Error?r.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 n=e instanceof Error?e:new Error(String(e));this.handleError(n,"unmount")}this.cdnInstance=null,this.initPromise=null}catch(e){const n=e instanceof Error?e:new Error(String(e));this.handleError(n,"unmount")}}static async preload(e){try{await C(e)}catch(n){throw console.error("[PayNext SDK] Preload failed:",n),n}}}const _={preload:k.preload};var A=(t=>(t.PAYPAL="PAYPAL",t.APPLE_PAY="APPLEPAY",t.GOOGLE_PAY="GPAY",t.CARD="CARD",t.VENMO="VENMO",t.CASHAPP="CASHAPP",t))(A||{});s.PayNextCheckout=k,s.PayNextSDK=_,s.PaymentMethod=A,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.11",
3
+ "version": "1.0.13",
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.6.0",
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",