@paynext/sdk 1.0.20 → 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,8 +1,8 @@
1
- var N = Object.defineProperty;
2
- var C = (n, e, t) => e in n ? N(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 x = "https://cdn-sdk-dev.paynext.com/index.cdn.js", k = "https://cdn-sdk.paynext.com/index.cdn.js";
5
- let w = null, h = null;
1
+ var x = Object.defineProperty;
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 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
+ let y = null, w = null;
6
6
  function T() {
7
7
  const n = navigator.connection || navigator.mozConnection || navigator.webkitConnection, e = {
8
8
  online: navigator.onLine,
@@ -12,112 +12,112 @@ function T() {
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 g(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
19
  class o extends Error {
20
20
  constructor(t, r = !0, i = !1) {
21
- const u = i && typeof window < "u" ? T() : null, c = u ? `${t} [${g(u)}]` : t;
22
- super(c);
23
- d(this, "diagnostics");
24
- this.retryable = r, this.name = "SDKLoadError", this.diagnostics = u;
21
+ const s = i && typeof window < "u" ? T() : null, D = s ? `${t} [${I(s)}]` : t;
22
+ super(D);
23
+ l(this, "diagnostics");
24
+ this.retryable = r, this.name = "SDKLoadError", this.diagnostics = s;
25
25
  }
26
26
  }
27
- const P = "PayNextSDK";
28
- function p() {
29
- return typeof window > "u" ? null : window[P];
27
+ const S = "PayNextSDK";
28
+ function E() {
29
+ return typeof window > "u" ? null : window[S];
30
30
  }
31
- function K(n) {
32
- typeof window > "u" || (window[P] = 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
37
  async function L(n = 5e3) {
38
38
  const t = Math.ceil(n / 50);
39
39
  for (let r = 0; r < t; r++) {
40
- const i = p();
40
+ const i = E();
41
41
  if (i)
42
42
  return i;
43
- await S(50);
43
+ await v(50);
44
44
  }
45
45
  throw new o("PayNextSDK not found in window after waiting", !0, !0);
46
46
  }
47
- async function v(n, e = 1) {
48
- const r = (n?.toLowerCase()?.includes("develop") || n?.toLowerCase()?.includes("staging") ? "develop" : "production") === "develop" ? x : k;
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" ? k : K;
49
49
  try {
50
- const i = p();
51
- return i || (await new Promise((c, f) => {
52
- const a = document.querySelector(`script[src="${r}"]`);
53
- if (a) {
54
- if (p()) {
55
- c();
50
+ const s = E();
51
+ return s || (await new Promise((h, u) => {
52
+ const c = document.querySelector(`script[src="${i}"]`);
53
+ if (c) {
54
+ if (E()) {
55
+ h();
56
56
  return;
57
57
  }
58
- const y = setTimeout(() => {
59
- a.removeEventListener("load", l), a.removeEventListener("error", E), f(new o("Existing SDK script loading timeout", !0, !0));
60
- }, 15e3), l = () => {
61
- clearTimeout(y), a.removeEventListener("load", l), a.removeEventListener("error", E), c();
62
- }, E = () => {
63
- clearTimeout(y), a.removeEventListener("load", l), a.removeEventListener("error", E), f(new o("Existing SDK script failed to load", !0, !0));
58
+ const f = setTimeout(() => {
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
- a.addEventListener("load", l), a.addEventListener("error", E);
65
+ c.addEventListener("load", d), c.addEventListener("error", p);
66
66
  return;
67
67
  }
68
- const A = setTimeout(() => {
69
- m(), f(new o("SDK script loading timeout", !0, !0));
70
- }, 15e3), s = document.createElement("script");
71
- s.src = r, s.crossOrigin = "anonymous", s.async = !0, s.setAttribute("data-paynext-sdk", "true");
68
+ const N = setTimeout(() => {
69
+ m(), u(new o("SDK script loading timeout", !0, !0));
70
+ }, 15e3), a = document.createElement("script");
71
+ a.src = i, a.crossOrigin = "anonymous", a.async = !0, a.setAttribute("data-paynext-sdk", "true");
72
72
  const m = () => {
73
- clearTimeout(A), s.onload = null, s.onerror = null;
73
+ clearTimeout(N), a.onload = null, a.onerror = null;
74
74
  };
75
- s.onload = () => {
76
- m(), c();
77
- }, s.onerror = (y) => {
78
- console.error("[PayNext CDN] Script load error:", y), m();
75
+ a.onload = () => {
76
+ m(), h();
77
+ }, a.onerror = (f) => {
78
+ console.error("[PayNext CDN] Script load error:", f), m();
79
79
  try {
80
- s.parentNode && s.parentNode.removeChild(s);
81
- } catch (l) {
82
- console.warn("[PayNext CDN] Failed to remove script:", l);
80
+ a.parentNode && a.parentNode.removeChild(a);
81
+ } catch (d) {
82
+ console.warn("[PayNext CDN] Failed to remove script:", d);
83
83
  }
84
- f(new o("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
- document.head.appendChild(s);
87
+ document.head.appendChild(a);
88
88
  } catch {
89
- m(), f(new o("Failed to append script to document", !1));
89
+ m(), u(new o("Failed to append script to document", !1));
90
90
  }
91
91
  }), await L(5e3));
92
- } catch (i) {
93
- if ((i instanceof o ? i.retryable : !0) && e < 5)
94
- return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`, i), await S(1500 * e), v(n, e + 1);
95
- throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`, i), i;
92
+ } catch (s) {
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
+ throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`, s), s;
96
96
  }
97
97
  }
98
- async function D(n) {
99
- if (h)
100
- return h;
98
+ async function P(n) {
101
99
  if (w)
102
100
  return w;
101
+ if (y)
102
+ return y;
103
103
  if (typeof window > "u")
104
104
  throw new o("PayNext SDK can only be loaded in browser environment", !1);
105
- const e = p();
106
- return e ? (h = e, h) : (w = (async () => {
105
+ const e = E();
106
+ return e ? (w = e, w) : (y = (async () => {
107
107
  try {
108
- const t = await v(n);
109
- return h = t, K(t), t;
108
+ const t = await A(n);
109
+ return w = t, g(t), t;
110
110
  } catch (t) {
111
- throw w = null, t;
111
+ throw y = null, t;
112
112
  }
113
- })(), w);
113
+ })(), y);
114
114
  }
115
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) {
@@ -139,7 +139,7 @@ class _ {
139
139
  throw new o("Cannot initialize destroyed SDK instance", !1);
140
140
  return this.initPromise ? this.initPromise : (this.initPromise = (async () => {
141
141
  try {
142
- const t = await D(e);
142
+ const t = await P(e);
143
143
  if (!t || !t.PayNextCheckout)
144
144
  throw new o("PayNextCheckout not found in loaded SDK module", !1);
145
145
  try {
@@ -182,6 +182,23 @@ class _ {
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 {
@@ -225,7 +242,7 @@ class _ {
225
242
  // preload SDK
226
243
  static async preload(e) {
227
244
  try {
228
- await D(e);
245
+ await P(e);
229
246
  } catch (t) {
230
247
  throw console.error("[PayNext SDK] Preload failed:", t), t;
231
248
  }
@@ -234,9 +251,9 @@ class _ {
234
251
  const R = {
235
252
  preload: _.preload
236
253
  };
237
- var I = /* @__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))(I || {});
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
256
  _ as PayNextCheckout,
240
257
  R as PayNextSDK,
241
- I as PaymentMethod
258
+ b as PaymentMethod
242
259
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
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 M=Object.defineProperty;var b=(s,a,l)=>a in s?M(s,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):s[a]=l;var y=(s,a,l)=>b(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 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,i=!1){const m=i&&typeof window<"u"?k():null,u=m?`${t} [${g(m)}]`:t;super(u);y(this,"diagnostics");this.retryable=r,this.name="SDKLoadError",this.diagnostics=m}}const v="PayNextSDK";function P(){return typeof window>"u"?null:window[v]}function K(n){typeof window>"u"||(window[v]=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 i=P();if(i)return i;await A(50)}throw new o("PayNextSDK not found in window after waiting",!0,!0)}async function N(n,e=1){const r=(n?.toLowerCase()?.includes("develop")||n?.toLowerCase()?.includes("staging")?"develop":"production")==="develop"?a:l;try{const i=P();return i||(await new Promise((u,E)=>{const d=document.querySelector(`script[src="${r}"]`);if(d){if(P()){u();return}const p=setTimeout(()=>{d.removeEventListener("load",f),d.removeEventListener("error",S),E(new o("Existing SDK script loading timeout",!0,!0))},15e3),f=()=>{clearTimeout(p),d.removeEventListener("load",f),d.removeEventListener("error",S),u()},S=()=>{clearTimeout(p),d.removeEventListener("load",f),d.removeEventListener("error",S),E(new o("Existing SDK script failed to load",!0,!0))};d.addEventListener("load",f),d.addEventListener("error",S);return}const I=setTimeout(()=>{D(),E(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 D=()=>{clearTimeout(I),c.onload=null,c.onerror=null};c.onload=()=>{D(),u()},c.onerror=p=>{console.error("[PayNext CDN] Script load error:",p),D();try{c.parentNode&&c.parentNode.removeChild(c)}catch(f){console.warn("[PayNext CDN] Failed to remove script:",f)}E(new o("Failed to load SDK script from CDN",!0,!0))};try{document.head.appendChild(c)}catch{D(),E(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 A(1500*e),N(n,e+1);throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`,i),i}}async function x(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=P();return e?(w=e,w):(h=(async()=>{try{const t=await N(n);return w=t,K(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(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 t=await x(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 i=r instanceof o?r:new o(r instanceof Error?r.message:"Unknown mount error",!0);throw this.handleError(i,"mount"),i}}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 x(e)}catch(t){throw console.error("[PayNext SDK] Preload failed:",t),t}}}const _={preload:C.preload};var T=(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))(T||{});s.PayNextCheckout=C,s.PayNextSDK=_,s.PaymentMethod=T,Object.defineProperty(s,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.20",
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",
@@ -86,8 +90,10 @@
86
90
  "eslint-plugin-react-hooks": "^7.0.1",
87
91
  "eslint-plugin-react-refresh": "^0.4.24",
88
92
  "globals": "^16.5.0",
93
+ "happy-dom": "^20.10.6",
89
94
  "json5": "^2.2.3",
90
95
  "motion": "^12.23.24",
96
+ "msw": "^2.14.6",
91
97
  "prettier": "^3.6.2",
92
98
  "prettier-plugin-tailwindcss": "^0.6.9",
93
99
  "react": "^19.2.0",
@@ -112,5 +118,8 @@
112
118
  "> 0.2%",
113
119
  "defaults"
114
120
  ],
121
+ "resolutions": {
122
+ "baseline-browser-mapping": "^2.10.38"
123
+ },
115
124
  "packageManager": "yarn@1.22.22"
116
125
  }
@@ -1 +0,0 @@
1
- 7b2276657273696f6e223a312c227073704964223a2230373434434444394536373533423346413835354439313837374235424543354538373137353142383032364444454638434644443639453337453234443142222c22637265617465644f6e223a313737393436353530393931357d