@paynext/sdk 1.0.21 → 1.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 PayNext
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -99,6 +99,13 @@ export declare interface CheckoutTranslate {
99
99
  button: string;
100
100
  };
101
101
  };
102
+ upi: {
103
+ description: string;
104
+ autopayDisclosure: string;
105
+ submit: {
106
+ button: string;
107
+ };
108
+ };
102
109
  savedPaymentMethod: {
103
110
  change: {
104
111
  button: string;
@@ -176,6 +183,13 @@ declare interface CheckoutTranslateOverrides {
176
183
  button?: string;
177
184
  };
178
185
  };
186
+ upi?: {
187
+ description?: string;
188
+ autopayDisclosure?: string;
189
+ submit?: {
190
+ button?: string;
191
+ };
192
+ };
179
193
  savedPaymentMethod?: {
180
194
  change?: {
181
195
  button?: string;
@@ -283,6 +297,8 @@ export declare interface LoadedResult {
283
297
 
284
298
  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';
285
299
 
300
+ declare const NON_UPDATABLE_CONFIG_KEYS: readonly ["clientToken", "environment", "apiVersion", "variant", "styles", "errorMessageText", "returnUrl", "applePayMpanEnabled", "applePayRecurringPaymentRequest", "onCheckoutLoaded", "onCheckoutAttempt", "beforeCheckoutAttempt", "onCheckoutComplete", "onCheckoutFail", "onCheckoutBlocked"];
301
+
286
302
  export declare enum PaymentMethod {
287
303
  PAYPAL = "PAYPAL",
288
304
  APPLE_PAY = "APPLEPAY",
@@ -291,7 +307,8 @@ export declare enum PaymentMethod {
291
307
  VENMO = "VENMO",
292
308
  CASHAPP = "CASHAPP",
293
309
  AMAZONPAY = "AMAZONPAY",
294
- PIX_AUTOMATICO = "PIX_AUTOMATICO"
310
+ PIX_AUTOMATICO = "PIX_AUTOMATICO",
311
+ UPI = "UPI"
295
312
  }
296
313
 
297
314
  export declare interface PaymentResult {
@@ -487,6 +504,7 @@ export declare class PayNextCheckout {
487
504
  private initialize;
488
505
  private assertReady;
489
506
  mount(containerId: string, config: PayNextConfig): Promise<void>;
507
+ update(config: PayNextConfigUpdate): void;
490
508
  setPaymentsEnabled(enabled: boolean): void;
491
509
  unmount(): Promise<void>;
492
510
  static preload(envType: TEnvironment): Promise<void>;
@@ -514,10 +532,21 @@ export declare interface PayNextConfig {
514
532
  onCheckoutBlocked?: (result: AttemptResult) => void;
515
533
  }
516
534
 
535
+ export declare type PayNextConfigUpdate = Partial<Omit<PayNextConfig, (typeof NON_UPDATABLE_CONFIG_KEYS)[number]>>;
536
+
517
537
  export declare const PayNextSDK: {
518
538
  preload: typeof PayNextCheckout.preload;
519
539
  };
520
540
 
541
+ export declare interface PixFormStyles {
542
+ colorPrimary?: string;
543
+ colorBackground?: string;
544
+ colorText?: string;
545
+ colorDanger?: string;
546
+ colorTextPlaceholder?: string;
547
+ borderRadius?: string;
548
+ }
549
+
521
550
  export declare interface StylesConfig {
522
551
  Input?: InputStyles;
523
552
  SubmitButton?: ISubmitButtonStyles;
@@ -529,6 +558,9 @@ export declare interface StylesConfig {
529
558
  CashAppButton?: HTMLStyles;
530
559
  AmazonPayButton?: HTMLStyles;
531
560
  PixButton?: HTMLStyles;
561
+ PixForm?: PixFormStyles;
562
+ UpiButton?: HTMLStyles;
563
+ UpiForm?: UpiFormStyles;
532
564
  BackButton?: HTMLStyles;
533
565
  cssVariables?: CSSVariablesConfig;
534
566
  }
@@ -537,4 +569,6 @@ export declare type TEnvironment = 'develop' | 'preview1' | 'preview2' | 'previe
537
569
 
538
570
  export declare type ThemeMode = 'light' | 'dark' | 'system';
539
571
 
572
+ export declare type UpiFormStyles = PixFormStyles;
573
+
540
574
  export { }
package/dist/index.es.js CHANGED
@@ -1,9 +1,9 @@
1
1
  var x = Object.defineProperty;
2
2
  var C = (n, e, t) => e in n ? x(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var d = (n, e, t) => C(n, typeof e != "symbol" ? e + "" : e, t);
4
- const T = "https://cdn-sdk-dev.paynext.com/index.cdn.js", k = "https://cdn-sdk.paynext.com/index.cdn.js";
3
+ var l = (n, e, t) => C(n, typeof e != "symbol" ? e + "" : e, t);
4
+ const k = "https://cdn-sdk-dev.paynext.com/index.cdn.js", K = "https://cdn-sdk.paynext.com/index.cdn.js";
5
5
  let y = null, w = null;
6
- function g() {
6
+ function T() {
7
7
  const n = navigator.connection || navigator.mozConnection || navigator.webkitConnection, e = {
8
8
  online: navigator.onLine,
9
9
  documentHidden: document.hidden,
@@ -12,61 +12,61 @@ function g() {
12
12
  };
13
13
  return n && (e.connectionType = n.type, e.effectiveType = n.effectiveType, e.downlink = n.downlink, e.rtt = n.rtt, e.saveData = n.saveData), navigator.onLine ? document.hidden ? e.likelyCause = "background_tab" : n?.effectiveType === "slow-2g" || n?.effectiveType === "2g" ? e.likelyCause = "slow_connection" : n?.downlink !== void 0 && n.downlink < 0.5 && (e.likelyCause = "poor_bandwidth") : e.likelyCause = "offline", e;
14
14
  }
15
- function K(n) {
15
+ function I(n) {
16
16
  const e = [];
17
17
  return n.likelyCause && e.push(`cause=${n.likelyCause}`), e.push(`online=${n.online}`), e.push(`hidden=${n.documentHidden}`), n.effectiveType && e.push(`net=${n.effectiveType}`), n.downlink !== void 0 && e.push(`downlink=${n.downlink}Mbps`), n.rtt !== void 0 && e.push(`rtt=${n.rtt}ms`), e.join(", ");
18
18
  }
19
- class r extends Error {
20
- constructor(t, o = !0, i = !1) {
21
- const s = i && typeof window < "u" ? g() : null, D = s ? `${t} [${K(s)}]` : t;
19
+ class o extends Error {
20
+ constructor(t, r = !0, i = !1) {
21
+ const s = i && typeof window < "u" ? T() : null, D = s ? `${t} [${I(s)}]` : t;
22
22
  super(D);
23
- d(this, "diagnostics");
24
- this.retryable = o, this.name = "SDKLoadError", this.diagnostics = s;
23
+ l(this, "diagnostics");
24
+ this.retryable = r, this.name = "SDKLoadError", this.diagnostics = s;
25
25
  }
26
26
  }
27
- const v = "PayNextSDK";
28
- function p() {
29
- return typeof window > "u" ? null : window[v];
27
+ const S = "PayNextSDK";
28
+ function E() {
29
+ return typeof window > "u" ? null : window[S];
30
30
  }
31
- function L(n) {
32
- typeof window > "u" || (window[v] = n);
31
+ function g(n) {
32
+ typeof window > "u" || (window[S] = n);
33
33
  }
34
- function S(n) {
34
+ function v(n) {
35
35
  return new Promise((e) => setTimeout(e, n));
36
36
  }
37
- async function _(n = 5e3) {
37
+ async function L(n = 5e3) {
38
38
  const t = Math.ceil(n / 50);
39
- for (let o = 0; o < t; o++) {
40
- const i = p();
39
+ for (let r = 0; r < t; r++) {
40
+ const i = E();
41
41
  if (i)
42
42
  return i;
43
- await S(50);
43
+ await v(50);
44
44
  }
45
- throw new r("PayNextSDK not found in window after waiting", !0, !0);
45
+ throw new o("PayNextSDK not found in window after waiting", !0, !0);
46
46
  }
47
47
  async function A(n, e = 1) {
48
- const t = n?.toLowerCase(), i = (t?.includes("develop") || t?.includes("staging") || t?.includes("preview") ? "develop" : "production") === "develop" ? T : k;
48
+ const t = n?.toLowerCase(), i = (t?.includes("develop") || t?.includes("staging") || t?.includes("preview") ? "develop" : "production") === "develop" ? k : K;
49
49
  try {
50
- const s = p();
50
+ const s = E();
51
51
  return s || (await new Promise((h, u) => {
52
52
  const c = document.querySelector(`script[src="${i}"]`);
53
53
  if (c) {
54
- if (p()) {
54
+ if (E()) {
55
55
  h();
56
56
  return;
57
57
  }
58
58
  const f = setTimeout(() => {
59
- c.removeEventListener("load", l), c.removeEventListener("error", E), u(new r("Existing SDK script loading timeout", !0, !0));
60
- }, 15e3), l = () => {
61
- clearTimeout(f), c.removeEventListener("load", l), c.removeEventListener("error", E), h();
62
- }, E = () => {
63
- clearTimeout(f), c.removeEventListener("load", l), c.removeEventListener("error", E), u(new r("Existing SDK script failed to load", !0, !0));
59
+ c.removeEventListener("load", d), c.removeEventListener("error", p), u(new o("Existing SDK script loading timeout", !0, !0));
60
+ }, 15e3), d = () => {
61
+ clearTimeout(f), c.removeEventListener("load", d), c.removeEventListener("error", p), h();
62
+ }, p = () => {
63
+ clearTimeout(f), c.removeEventListener("load", d), c.removeEventListener("error", p), u(new o("Existing SDK script failed to load", !0, !0));
64
64
  };
65
- c.addEventListener("load", l), c.addEventListener("error", E);
65
+ c.addEventListener("load", d), c.addEventListener("error", p);
66
66
  return;
67
67
  }
68
68
  const N = setTimeout(() => {
69
- m(), u(new r("SDK script loading timeout", !0, !0));
69
+ m(), u(new o("SDK script loading timeout", !0, !0));
70
70
  }, 15e3), a = document.createElement("script");
71
71
  a.src = i, a.crossOrigin = "anonymous", a.async = !0, a.setAttribute("data-paynext-sdk", "true");
72
72
  const m = () => {
@@ -78,20 +78,20 @@ async function A(n, e = 1) {
78
78
  console.error("[PayNext CDN] Script load error:", f), m();
79
79
  try {
80
80
  a.parentNode && a.parentNode.removeChild(a);
81
- } catch (l) {
82
- console.warn("[PayNext CDN] Failed to remove script:", l);
81
+ } catch (d) {
82
+ console.warn("[PayNext CDN] Failed to remove script:", d);
83
83
  }
84
- u(new r("Failed to load SDK script from CDN", !0, !0));
84
+ u(new o("Failed to load SDK script from CDN", !0, !0));
85
85
  };
86
86
  try {
87
87
  document.head.appendChild(a);
88
88
  } catch {
89
- m(), u(new r("Failed to append script to document", !1));
89
+ m(), u(new o("Failed to append script to document", !1));
90
90
  }
91
- }), await _(5e3));
91
+ }), await L(5e3));
92
92
  } catch (s) {
93
- if ((s instanceof r ? s.retryable : !0) && e < 5)
94
- return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`, s), await S(1500 * e), A(n, e + 1);
93
+ if ((s instanceof o ? s.retryable : !0) && e < 5)
94
+ return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`, s), await v(1500 * e), A(n, e + 1);
95
95
  throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`, s), s;
96
96
  }
97
97
  }
@@ -101,23 +101,23 @@ async function P(n) {
101
101
  if (y)
102
102
  return y;
103
103
  if (typeof window > "u")
104
- throw new r("PayNext SDK can only be loaded in browser environment", !1);
105
- const e = p();
104
+ throw new o("PayNext SDK can only be loaded in browser environment", !1);
105
+ const e = E();
106
106
  return e ? (w = e, w) : (y = (async () => {
107
107
  try {
108
108
  const t = await A(n);
109
- return w = t, L(t), t;
109
+ return w = t, g(t), t;
110
110
  } catch (t) {
111
111
  throw y = null, t;
112
112
  }
113
113
  })(), y);
114
114
  }
115
- class I {
115
+ class _ {
116
116
  constructor() {
117
- d(this, "cdnInstance", null);
118
- d(this, "initPromise", null);
119
- d(this, "isDestroyed", !1);
120
- d(this, "errorBoundary", null);
117
+ l(this, "cdnInstance", null);
118
+ l(this, "initPromise", null);
119
+ l(this, "isDestroyed", !1);
120
+ l(this, "errorBoundary", null);
121
121
  }
122
122
  // set error handler
123
123
  setErrorHandler(e) {
@@ -125,8 +125,8 @@ class I {
125
125
  }
126
126
  // handle error
127
127
  handleError(e, t) {
128
- const o = `[PayNext SDK Error - ${t}]: ${e.message}`;
129
- if (console.error(o, e), this.errorBoundary)
128
+ const r = `[PayNext SDK Error - ${t}]: ${e.message}`;
129
+ if (console.error(r, e), this.errorBoundary)
130
130
  try {
131
131
  this.errorBoundary(e);
132
132
  } catch (i) {
@@ -136,17 +136,17 @@ class I {
136
136
  // initialize
137
137
  async initialize(e) {
138
138
  if (this.isDestroyed)
139
- throw new r("Cannot initialize destroyed SDK instance", !1);
139
+ throw new o("Cannot initialize destroyed SDK instance", !1);
140
140
  return this.initPromise ? this.initPromise : (this.initPromise = (async () => {
141
141
  try {
142
142
  const t = await P(e);
143
143
  if (!t || !t.PayNextCheckout)
144
- throw new r("PayNextCheckout not found in loaded SDK module", !1);
144
+ throw new o("PayNextCheckout not found in loaded SDK module", !1);
145
145
  try {
146
146
  this.cdnInstance = new t.PayNextCheckout();
147
- } catch (o) {
148
- throw new r(
149
- `Failed to instantiate PayNextCheckout: ${o instanceof Error ? o.message : "Unknown error"}`,
147
+ } catch (r) {
148
+ throw new o(
149
+ `Failed to instantiate PayNextCheckout: ${r instanceof Error ? r.message : "Unknown error"}`,
150
150
  !1
151
151
  );
152
152
  }
@@ -158,30 +158,47 @@ class I {
158
158
  // assert ready
159
159
  assertReady() {
160
160
  if (this.isDestroyed)
161
- throw new r("SDK instance has been destroyed", !1);
161
+ throw new o("SDK instance has been destroyed", !1);
162
162
  if (!this.initPromise)
163
- throw new r("SDK initialization not started", !1);
163
+ throw new o("SDK initialization not started", !1);
164
164
  if (!this.cdnInstance)
165
- throw new r("SDK instance not created", !1);
165
+ throw new o("SDK instance not created", !1);
166
166
  }
167
167
  // mount
168
168
  async mount(e, t) {
169
169
  try {
170
170
  if (!e || typeof e != "string")
171
- throw new r("Invalid containerId provided", !1);
171
+ throw new o("Invalid containerId provided", !1);
172
172
  if (!t || !t.environment)
173
- throw new r("Invalid config provided", !1);
173
+ throw new o("Invalid config provided", !1);
174
174
  if (!document.getElementById(e))
175
- throw new r(`Container element with id "${e}" not found`, !1);
175
+ throw new o(`Container element with id "${e}" not found`, !1);
176
176
  await this.initialize(t.environment), this.assertReady(), await this.cdnInstance.mount(e, t);
177
- } catch (o) {
178
- const i = o instanceof r ? o : new r(
179
- o instanceof Error ? o.message : "Unknown mount error",
177
+ } catch (r) {
178
+ const i = r instanceof o ? r : new o(
179
+ r instanceof Error ? r.message : "Unknown mount error",
180
180
  !0
181
181
  );
182
182
  throw this.handleError(i, "mount"), i;
183
183
  }
184
184
  }
185
+ // update selected config fields at runtime (no re-mount required)
186
+ update(e) {
187
+ try {
188
+ if (this.isDestroyed) {
189
+ console.warn("[PayNext SDK] update called on destroyed instance");
190
+ return;
191
+ }
192
+ if (!this.cdnInstance) {
193
+ console.warn("[PayNext SDK] update called before mount");
194
+ return;
195
+ }
196
+ typeof this.cdnInstance.update == "function" ? this.cdnInstance.update(e) : console.warn("[PayNext SDK] update() is not supported by the loaded CDN bundle; a newer SDK version is required");
197
+ } catch (t) {
198
+ const r = t instanceof Error ? t : new Error(String(t));
199
+ this.handleError(r, "update");
200
+ }
201
+ }
185
202
  // enable/disable payments at runtime (no re-mount required)
186
203
  setPaymentsEnabled(e) {
187
204
  try {
@@ -195,8 +212,8 @@ class I {
195
212
  }
196
213
  typeof this.cdnInstance.setPaymentsEnabled == "function" && this.cdnInstance.setPaymentsEnabled(e);
197
214
  } catch (t) {
198
- const o = t instanceof Error ? t : new Error(String(t));
199
- this.handleError(o, "setPaymentsEnabled");
215
+ const r = t instanceof Error ? t : new Error(String(t));
216
+ this.handleError(r, "setPaymentsEnabled");
200
217
  }
201
218
  }
202
219
  // unmount
@@ -231,12 +248,12 @@ class I {
231
248
  }
232
249
  }
233
250
  }
234
- const b = {
235
- preload: I.preload
251
+ const R = {
252
+ preload: _.preload
236
253
  };
237
- var M = /* @__PURE__ */ ((n) => (n.PAYPAL = "PAYPAL", n.APPLE_PAY = "APPLEPAY", n.GOOGLE_PAY = "GPAY", n.CARD = "CARD", n.VENMO = "VENMO", n.CASHAPP = "CASHAPP", n.AMAZONPAY = "AMAZONPAY", n.PIX_AUTOMATICO = "PIX_AUTOMATICO", n))(M || {});
254
+ var b = /* @__PURE__ */ ((n) => (n.PAYPAL = "PAYPAL", n.APPLE_PAY = "APPLEPAY", n.GOOGLE_PAY = "GPAY", n.CARD = "CARD", n.VENMO = "VENMO", n.CASHAPP = "CASHAPP", n.AMAZONPAY = "AMAZONPAY", n.PIX_AUTOMATICO = "PIX_AUTOMATICO", n.UPI = "UPI", n))(b || {});
238
255
  export {
239
- I as PayNextCheckout,
240
- b as PayNextSDK,
241
- M as PaymentMethod
256
+ _ as PayNextCheckout,
257
+ R as PayNextSDK,
258
+ b as PaymentMethod
242
259
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(i,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(i=typeof globalThis<"u"?globalThis:i||self,s(i["PayNext SDK"]={}))})(this,(function(i){"use strict";var b=Object.defineProperty;var R=(i,s,u)=>s in i?b(i,s,{enumerable:!0,configurable:!0,writable:!0,value:u}):i[s]=u;var y=(i,s,u)=>R(i,typeof s!="symbol"?s+"":s,u);const s="https://cdn-sdk-dev.paynext.com/index.cdn.js",u="https://cdn-sdk.paynext.com/index.cdn.js";let h=null,w=null;function g(){const n=navigator.connection||navigator.mozConnection||navigator.webkitConnection,e={online:navigator.onLine,documentHidden:document.hidden,userAgent:navigator.userAgent,timestamp:new Date().toISOString()};return n&&(e.connectionType=n.type,e.effectiveType=n.effectiveType,e.downlink=n.downlink,e.rtt=n.rtt,e.saveData=n.saveData),navigator.onLine?document.hidden?e.likelyCause="background_tab":n?.effectiveType==="slow-2g"||n?.effectiveType==="2g"?e.likelyCause="slow_connection":n?.downlink!==void 0&&n.downlink<.5&&(e.likelyCause="poor_bandwidth"):e.likelyCause="offline",e}function K(n){const e=[];return n.likelyCause&&e.push(`cause=${n.likelyCause}`),e.push(`online=${n.online}`),e.push(`hidden=${n.documentHidden}`),n.effectiveType&&e.push(`net=${n.effectiveType}`),n.downlink!==void 0&&e.push(`downlink=${n.downlink}Mbps`),n.rtt!==void 0&&e.push(`rtt=${n.rtt}ms`),e.join(", ")}class r extends Error{constructor(t,o=!0,a=!1){const c=a&&typeof window<"u"?g():null,v=c?`${t} [${K(c)}]`:t;super(v);y(this,"diagnostics");this.retryable=o,this.name="SDKLoadError",this.diagnostics=c}}const A="PayNextSDK";function E(){return typeof window>"u"?null:window[A]}function L(n){typeof window>"u"||(window[A]=n)}function N(n){return new Promise(e=>setTimeout(e,n))}async function _(n=5e3){const t=Math.ceil(n/50);for(let o=0;o<t;o++){const a=E();if(a)return a;await N(50)}throw new r("PayNextSDK not found in window after waiting",!0,!0)}async function T(n,e=1){const t=n?.toLowerCase(),a=(t?.includes("develop")||t?.includes("staging")||t?.includes("preview")?"develop":"production")==="develop"?s:u;try{const c=E();return c||(await new Promise((P,m)=>{const l=document.querySelector(`script[src="${a}"]`);if(l){if(E()){P();return}const p=setTimeout(()=>{l.removeEventListener("load",f),l.removeEventListener("error",S),m(new r("Existing SDK script loading timeout",!0,!0))},15e3),f=()=>{clearTimeout(p),l.removeEventListener("load",f),l.removeEventListener("error",S),P()},S=()=>{clearTimeout(p),l.removeEventListener("load",f),l.removeEventListener("error",S),m(new r("Existing SDK script failed to load",!0,!0))};l.addEventListener("load",f),l.addEventListener("error",S);return}const M=setTimeout(()=>{D(),m(new r("SDK script loading timeout",!0,!0))},15e3),d=document.createElement("script");d.src=a,d.crossOrigin="anonymous",d.async=!0,d.setAttribute("data-paynext-sdk","true");const D=()=>{clearTimeout(M),d.onload=null,d.onerror=null};d.onload=()=>{D(),P()},d.onerror=p=>{console.error("[PayNext CDN] Script load error:",p),D();try{d.parentNode&&d.parentNode.removeChild(d)}catch(f){console.warn("[PayNext CDN] Failed to remove script:",f)}m(new r("Failed to load SDK script from CDN",!0,!0))};try{document.head.appendChild(d)}catch{D(),m(new r("Failed to append script to document",!1))}}),await _(5e3))}catch(c){if((c instanceof r?c.retryable:!0)&&e<5)return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`,c),await N(1500*e),T(n,e+1);throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`,c),c}}async function x(n){if(w)return w;if(h)return h;if(typeof window>"u")throw new r("PayNext SDK can only be loaded in browser environment",!1);const e=E();return e?(w=e,w):(h=(async()=>{try{const t=await T(n);return w=t,L(t),t}catch(t){throw h=null,t}})(),h)}class C{constructor(){y(this,"cdnInstance",null);y(this,"initPromise",null);y(this,"isDestroyed",!1);y(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(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 x(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 a=o instanceof r?o:new r(o instanceof Error?o.message:"Unknown mount error",!0);throw this.handleError(a,"mount"),a}}setPaymentsEnabled(e){try{if(this.isDestroyed){console.warn("[PayNext SDK] setPaymentsEnabled called on destroyed instance");return}if(!this.cdnInstance){console.warn("[PayNext SDK] setPaymentsEnabled called before mount");return}typeof this.cdnInstance.setPaymentsEnabled=="function"&&this.cdnInstance.setPaymentsEnabled(e)}catch(t){const o=t instanceof Error?t:new Error(String(t));this.handleError(o,"setPaymentsEnabled")}}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 x(e)}catch(t){throw console.error("[PayNext SDK] Preload failed:",t),t}}}const I={preload:C.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.AMAZONPAY="AMAZONPAY",n.PIX_AUTOMATICO="PIX_AUTOMATICO",n))(k||{});i.PayNextCheckout=C,i.PayNextSDK=I,i.PaymentMethod=k,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(i,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(i=typeof globalThis<"u"?globalThis:i||self,s(i["PayNext SDK"]={}))})(this,(function(i){"use strict";var M=Object.defineProperty;var R=(i,s,u)=>s in i?M(i,s,{enumerable:!0,configurable:!0,writable:!0,value:u}):i[s]=u;var y=(i,s,u)=>R(i,typeof s!="symbol"?s+"":s,u);const s="https://cdn-sdk-dev.paynext.com/index.cdn.js",u="https://cdn-sdk.paynext.com/index.cdn.js";let h=null,w=null;function k(){const n=navigator.connection||navigator.mozConnection||navigator.webkitConnection,e={online:navigator.onLine,documentHidden:document.hidden,userAgent:navigator.userAgent,timestamp:new Date().toISOString()};return n&&(e.connectionType=n.type,e.effectiveType=n.effectiveType,e.downlink=n.downlink,e.rtt=n.rtt,e.saveData=n.saveData),navigator.onLine?document.hidden?e.likelyCause="background_tab":n?.effectiveType==="slow-2g"||n?.effectiveType==="2g"?e.likelyCause="slow_connection":n?.downlink!==void 0&&n.downlink<.5&&(e.likelyCause="poor_bandwidth"):e.likelyCause="offline",e}function g(n){const e=[];return n.likelyCause&&e.push(`cause=${n.likelyCause}`),e.push(`online=${n.online}`),e.push(`hidden=${n.documentHidden}`),n.effectiveType&&e.push(`net=${n.effectiveType}`),n.downlink!==void 0&&e.push(`downlink=${n.downlink}Mbps`),n.rtt!==void 0&&e.push(`rtt=${n.rtt}ms`),e.join(", ")}class o extends Error{constructor(t,r=!0,a=!1){const c=a&&typeof window<"u"?k():null,v=c?`${t} [${g(c)}]`:t;super(v);y(this,"diagnostics");this.retryable=r,this.name="SDKLoadError",this.diagnostics=c}}const N="PayNextSDK";function E(){return typeof window>"u"?null:window[N]}function I(n){typeof window>"u"||(window[N]=n)}function A(n){return new Promise(e=>setTimeout(e,n))}async function L(n=5e3){const t=Math.ceil(n/50);for(let r=0;r<t;r++){const a=E();if(a)return a;await A(50)}throw new o("PayNextSDK not found in window after waiting",!0,!0)}async function x(n,e=1){const t=n?.toLowerCase(),a=(t?.includes("develop")||t?.includes("staging")||t?.includes("preview")?"develop":"production")==="develop"?s:u;try{const c=E();return c||(await new Promise((D,m)=>{const l=document.querySelector(`script[src="${a}"]`);if(l){if(E()){D();return}const p=setTimeout(()=>{l.removeEventListener("load",f),l.removeEventListener("error",S),m(new o("Existing SDK script loading timeout",!0,!0))},15e3),f=()=>{clearTimeout(p),l.removeEventListener("load",f),l.removeEventListener("error",S),D()},S=()=>{clearTimeout(p),l.removeEventListener("load",f),l.removeEventListener("error",S),m(new o("Existing SDK script failed to load",!0,!0))};l.addEventListener("load",f),l.addEventListener("error",S);return}const b=setTimeout(()=>{P(),m(new o("SDK script loading timeout",!0,!0))},15e3),d=document.createElement("script");d.src=a,d.crossOrigin="anonymous",d.async=!0,d.setAttribute("data-paynext-sdk","true");const P=()=>{clearTimeout(b),d.onload=null,d.onerror=null};d.onload=()=>{P(),D()},d.onerror=p=>{console.error("[PayNext CDN] Script load error:",p),P();try{d.parentNode&&d.parentNode.removeChild(d)}catch(f){console.warn("[PayNext CDN] Failed to remove script:",f)}m(new o("Failed to load SDK script from CDN",!0,!0))};try{document.head.appendChild(d)}catch{P(),m(new o("Failed to append script to document",!1))}}),await L(5e3))}catch(c){if((c instanceof o?c.retryable:!0)&&e<5)return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`,c),await A(1500*e),x(n,e+1);throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`,c),c}}async function T(n){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 t=await x(n);return w=t,I(t),t}catch(t){throw h=null,t}})(),h)}class C{constructor(){y(this,"cdnInstance",null);y(this,"initPromise",null);y(this,"isDestroyed",!1);y(this,"errorBoundary",null)}setErrorHandler(e){this.errorBoundary=e}handleError(e,t){const r=`[PayNext SDK Error - ${t}]: ${e.message}`;if(console.error(r,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 o("Cannot initialize destroyed SDK instance",!1);return this.initPromise?this.initPromise:(this.initPromise=(async()=>{try{const t=await T(e);if(!t||!t.PayNextCheckout)throw new o("PayNextCheckout not found in loaded SDK module",!1);try{this.cdnInstance=new t.PayNextCheckout}catch(r){throw new o(`Failed to instantiate PayNextCheckout: ${r instanceof Error?r.message:"Unknown error"}`,!1)}}catch(t){throw this.initPromise=null,t}})(),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,t){try{if(!e||typeof e!="string")throw new o("Invalid containerId provided",!1);if(!t||!t.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(t.environment),this.assertReady(),await this.cdnInstance.mount(e,t)}catch(r){const a=r instanceof o?r:new o(r instanceof Error?r.message:"Unknown mount error",!0);throw this.handleError(a,"mount"),a}}update(e){try{if(this.isDestroyed){console.warn("[PayNext SDK] update called on destroyed instance");return}if(!this.cdnInstance){console.warn("[PayNext SDK] update called before mount");return}typeof this.cdnInstance.update=="function"?this.cdnInstance.update(e):console.warn("[PayNext SDK] update() is not supported by the loaded CDN bundle; a newer SDK version is required")}catch(t){const r=t instanceof Error?t:new Error(String(t));this.handleError(r,"update")}}setPaymentsEnabled(e){try{if(this.isDestroyed){console.warn("[PayNext SDK] setPaymentsEnabled called on destroyed instance");return}if(!this.cdnInstance){console.warn("[PayNext SDK] setPaymentsEnabled called before mount");return}typeof this.cdnInstance.setPaymentsEnabled=="function"&&this.cdnInstance.setPaymentsEnabled(e)}catch(t){const r=t instanceof Error?t:new Error(String(t));this.handleError(r,"setPaymentsEnabled")}}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 T(e)}catch(t){throw console.error("[PayNext SDK] Preload failed:",t),t}}}const _={preload:C.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.AMAZONPAY="AMAZONPAY",n.PIX_AUTOMATICO="PIX_AUTOMATICO",n.UPI="UPI",n))(K||{});i.PayNextCheckout=C,i.PayNextSDK=_,i.PaymentMethod=K,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paynext/sdk",
3
- "version": "1.0.21",
3
+ "version": "1.1.0",
4
4
  "description": "PayNext SDK - Payment processing with automatic CDN loading",
5
5
  "type": "module",
6
6
  "main": "dist/index.es.js",
@@ -8,6 +8,9 @@
8
8
  "types": "dist/index.d.ts",
9
9
  "browser": "dist/index.es.js",
10
10
  "license": "MIT",
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
11
14
  "exports": {
12
15
  ".": {
13
16
  "types": "./dist/index.d.ts",
@@ -45,8 +48,8 @@
45
48
  "analyze": "ANALYZE=true yarn build",
46
49
  "pub": "yarn build && npm publish --scope=@paynext",
47
50
  "pub-ts": "npm run build && npm version patch --no-git-tag-version && npm publish --access restricted",
48
- "deploy:dev": "yarn build:cdn && yarn wrangler deploy --env='development'",
49
- "deploy:prod": "yarn build:cdn && yarn wrangler deploy --env=''",
51
+ "deploy:dev": "yarn test && yarn build:cdn && yarn wrangler deploy --env='development'",
52
+ "deploy:prod": "yarn test && yarn build:cdn && yarn wrangler deploy --env=''",
50
53
  "test": "vitest run",
51
54
  "test:watch": "vitest"
52
55
  },
@@ -79,6 +82,7 @@
79
82
  "@vitejs/plugin-legacy": "^7.2.1",
80
83
  "@vitejs/plugin-react": "^5.1.0",
81
84
  "autoprefixer": "^10.4.22",
85
+ "baseline-browser-mapping": "^2.10.38",
82
86
  "braintree-web": "3.140.0",
83
87
  "credit-card-type": "^10.1.0",
84
88
  "eslint": "^9.39.1",
@@ -114,5 +118,8 @@
114
118
  "> 0.2%",
115
119
  "defaults"
116
120
  ],
121
+ "resolutions": {
122
+ "baseline-browser-mapping": "^2.10.38"
123
+ },
117
124
  "packageManager": "yarn@1.22.22"
118
125
  }
@@ -1 +0,0 @@
1
- 7b2276657273696f6e223a312c227073704964223a2230373434434444394536373533423346413835354439313837374235424543354538373137353142383032364444454638434644443639453337453234443142222c22637265617465644f6e223a313737393436353530393931357d