@paynext/sdk 1.0.14 → 1.0.16

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.
@@ -1 +1 @@
1
- 7b2276657273696f6e223a312c227073704964223a2236394232464131343345334542383933313031394339463845343130414243323131413845303444324433433131314445373144313932334231394345383644222c22637265617465644f6e223a313733303931303136363636387d
1
+ 7b2276657273696f6e223a312c227073704964223a2230373434434444394536373533423346413835354439313837374235424543354538373137353142383032364444454638434644443639453337453234443142222c22637265617465644f6e223a313737393436353530393931357d
package/dist/index.d.ts CHANGED
@@ -57,6 +57,26 @@ export declare interface CheckoutTranslate {
57
57
  compact: {
58
58
  button: string;
59
59
  };
60
+ taxId: {
61
+ label: string;
62
+ error: {
63
+ required: string;
64
+ invalid: string;
65
+ };
66
+ };
67
+ };
68
+ pix: {
69
+ description: string;
70
+ taxId: {
71
+ label: string;
72
+ error: {
73
+ required: string;
74
+ invalid: string;
75
+ };
76
+ };
77
+ submit: {
78
+ button: string;
79
+ };
60
80
  };
61
81
  savedPaymentMethod: {
62
82
  change: {
@@ -114,6 +134,26 @@ declare interface CheckoutTranslateOverrides {
114
134
  compact?: {
115
135
  button?: string;
116
136
  };
137
+ taxId?: {
138
+ label?: string;
139
+ error?: {
140
+ required?: string;
141
+ invalid?: string;
142
+ };
143
+ };
144
+ };
145
+ pix?: {
146
+ description?: string;
147
+ taxId?: {
148
+ label?: string;
149
+ error?: {
150
+ required?: string;
151
+ invalid?: string;
152
+ };
153
+ };
154
+ submit?: {
155
+ button?: string;
156
+ };
117
157
  };
118
158
  savedPaymentMethod?: {
119
159
  change?: {
@@ -228,7 +268,9 @@ export declare enum PaymentMethod {
228
268
  GOOGLE_PAY = "GPAY",
229
269
  CARD = "CARD",
230
270
  VENMO = "VENMO",
231
- CASHAPP = "CASHAPP"
271
+ CASHAPP = "CASHAPP",
272
+ AMAZONPAY = "AMAZONPAY",
273
+ PIX_AUTOMATICO = "PIX_AUTOMATICO"
232
274
  }
233
275
 
234
276
  export declare interface PaymentResult {
@@ -337,6 +379,20 @@ export declare interface PaymentResult {
337
379
  };
338
380
  refunded_amount: number;
339
381
  status_reason: CheckoutError;
382
+ tax?: {
383
+ provider?: {
384
+ id?: string;
385
+ type?: string;
386
+ };
387
+ calculation_id?: string;
388
+ transaction_id?: string;
389
+ amount_subtotal?: number;
390
+ amount_subtotal_usd?: number;
391
+ amount_tax?: number;
392
+ amount_tax_usd?: number;
393
+ behavior?: string;
394
+ status?: string;
395
+ };
340
396
  subscription?: {
341
397
  id: string;
342
398
  created_at: string;
@@ -394,6 +450,7 @@ declare enum PaymentStatus {
394
450
  SETTLED = "SETTLED",
395
451
  DECLINED = "DECLINED",
396
452
  CANCELLED = "CANCELLED",
453
+ REFUNDED = "REFUNDED",
397
454
  BLOCKED = "BLOCKED",
398
455
  INCOMPLETE = "INCOMPLETE"
399
456
  }
@@ -410,7 +467,7 @@ export declare class PayNextCheckout {
410
467
  private assertReady;
411
468
  mount(containerId: string, config: PayNextConfig): Promise<void>;
412
469
  unmount(): Promise<void>;
413
- static preload(envType: 'develop' | 'staging' | 'sandbox' | 'production'): Promise<void>;
470
+ static preload(envType: TEnvironment): Promise<void>;
414
471
  }
415
472
 
416
473
  export declare interface PayNextConfig {
@@ -443,11 +500,13 @@ export declare interface StylesConfig {
443
500
  WalletButton?: HTMLStyles;
444
501
  BraintreeButton?: HTMLStyles;
445
502
  CashAppButton?: HTMLStyles;
503
+ AmazonPayButton?: HTMLStyles;
504
+ PixButton?: HTMLStyles;
446
505
  BackButton?: HTMLStyles;
447
506
  cssVariables?: CSSVariablesConfig;
448
507
  }
449
508
 
450
- export declare type TEnvironment = 'develop' | 'staging' | 'sandbox' | 'production';
509
+ export declare type TEnvironment = 'develop' | 'preview1' | 'preview2' | 'staging' | 'sandbox' | 'production';
451
510
 
452
511
  export declare type ThemeMode = 'light' | 'dark' | 'system';
453
512
 
package/dist/index.es.js CHANGED
@@ -1,51 +1,51 @@
1
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";
2
+ var N = (n, e, t) => e in n ? C(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var d = (n, e, t) => N(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";
5
5
  let h = null, y = null;
6
- function L() {
7
- const t = navigator.connection || navigator.mozConnection || navigator.webkitConnection, e = {
6
+ function x() {
7
+ const n = navigator.connection || navigator.mozConnection || navigator.webkitConnection, e = {
8
8
  online: navigator.onLine,
9
9
  documentHidden: document.hidden,
10
10
  userAgent: navigator.userAgent,
11
11
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
12
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;
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(t) {
15
+ function L(n) {
16
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(", ");
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 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;
20
+ constructor(t, o = !0, i = !1) {
21
+ const u = i && typeof window < "u" ? x() : null, c = u ? `${t} [${L(u)}]` : t;
22
22
  super(c);
23
23
  d(this, "diagnostics");
24
24
  this.retryable = o, this.name = "SDKLoadError", this.diagnostics = u;
25
25
  }
26
26
  }
27
- const v = "PayNextSDK";
27
+ const P = "PayNextSDK";
28
28
  function D() {
29
- return typeof window > "u" ? null : window[v];
29
+ return typeof window > "u" ? null : window[P];
30
30
  }
31
- function T(t) {
32
- typeof window > "u" || (window[v] = t);
31
+ function g(n) {
32
+ typeof window > "u" || (window[P] = n);
33
33
  }
34
- function P(t) {
35
- return new Promise((e) => setTimeout(e, t));
34
+ function v(n) {
35
+ return new Promise((e) => setTimeout(e, n));
36
36
  }
37
- async function K(t = 5e3) {
38
- const n = Math.ceil(t / 50);
39
- for (let o = 0; o < n; o++) {
37
+ async function _(n = 5e3) {
38
+ const t = Math.ceil(n / 50);
39
+ for (let o = 0; o < t; o++) {
40
40
  const i = D();
41
41
  if (i)
42
42
  return i;
43
- await P(50);
43
+ await v(50);
44
44
  }
45
45
  throw new r("PayNextSDK not found in window after waiting", !0, !0);
46
46
  }
47
- async function S(t, e = 1) {
48
- const o = (t?.toLowerCase()?.includes("develop") || t?.toLowerCase()?.includes("staging") ? "develop" : "production") === "develop" ? k : x;
47
+ async function S(n, e = 1) {
48
+ const o = (n?.toLowerCase()?.includes("develop") || n?.toLowerCase()?.includes("staging") ? "develop" : "production") === "develop" ? T : k;
49
49
  try {
50
50
  const i = D();
51
51
  return i || (await new Promise((c, f) => {
@@ -88,14 +88,14 @@ async function S(t, e = 1) {
88
88
  } catch {
89
89
  m(), f(new r("Failed to append script to document", !1));
90
90
  }
91
- }), await K(5e3));
91
+ }), await _(5e3));
92
92
  } catch (i) {
93
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);
94
+ return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`, i), await v(1500 * e), S(n, e + 1);
95
95
  throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`, i), i;
96
96
  }
97
97
  }
98
- async function E(t) {
98
+ async function E(n) {
99
99
  if (y)
100
100
  return y;
101
101
  if (h)
@@ -105,14 +105,14 @@ async function E(t) {
105
105
  const e = D();
106
106
  return e ? (y = e, y) : (h = (async () => {
107
107
  try {
108
- const n = await S(t);
109
- return y = n, T(n), n;
110
- } catch (n) {
111
- throw h = null, n;
108
+ const t = await S(n);
109
+ return y = t, g(t), t;
110
+ } catch (t) {
111
+ throw h = null, t;
112
112
  }
113
113
  })(), h);
114
114
  }
115
- class _ {
115
+ class K {
116
116
  constructor() {
117
117
  d(this, "cdnInstance", null);
118
118
  d(this, "initPromise", null);
@@ -124,8 +124,8 @@ class _ {
124
124
  this.errorBoundary = e;
125
125
  }
126
126
  // handle error
127
- handleError(e, n) {
128
- const o = `[PayNext SDK Error - ${n}]: ${e.message}`;
127
+ handleError(e, t) {
128
+ const o = `[PayNext SDK Error - ${t}]: ${e.message}`;
129
129
  if (console.error(o, e), this.errorBoundary)
130
130
  try {
131
131
  this.errorBoundary(e);
@@ -139,19 +139,19 @@ class _ {
139
139
  throw new r("Cannot initialize destroyed SDK instance", !1);
140
140
  return this.initPromise ? this.initPromise : (this.initPromise = (async () => {
141
141
  try {
142
- const n = await E(e);
143
- if (!n || !n.PayNextCheckout)
142
+ const t = await E(e);
143
+ if (!t || !t.PayNextCheckout)
144
144
  throw new r("PayNextCheckout not found in loaded SDK module", !1);
145
145
  try {
146
- this.cdnInstance = new n.PayNextCheckout();
146
+ this.cdnInstance = new t.PayNextCheckout();
147
147
  } catch (o) {
148
148
  throw new r(
149
149
  `Failed to instantiate PayNextCheckout: ${o instanceof Error ? o.message : "Unknown error"}`,
150
150
  !1
151
151
  );
152
152
  }
153
- } catch (n) {
154
- throw this.initPromise = null, n;
153
+ } catch (t) {
154
+ throw this.initPromise = null, t;
155
155
  }
156
156
  })(), this.initPromise);
157
157
  }
@@ -165,15 +165,15 @@ class _ {
165
165
  throw new r("SDK instance not created", !1);
166
166
  }
167
167
  // mount
168
- async mount(e, n) {
168
+ async mount(e, t) {
169
169
  try {
170
170
  if (!e || typeof e != "string")
171
171
  throw new r("Invalid containerId provided", !1);
172
- if (!n || !n.environment)
172
+ if (!t || !t.environment)
173
173
  throw new r("Invalid config provided", !1);
174
174
  if (!document.getElementById(e))
175
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);
176
+ await this.initialize(t.environment), this.assertReady(), await this.cdnInstance.mount(e, t);
177
177
  } catch (o) {
178
178
  const i = o instanceof r ? o : new r(
179
179
  o instanceof Error ? o.message : "Unknown mount error",
@@ -196,30 +196,30 @@ class _ {
196
196
  try {
197
197
  typeof this.cdnInstance.unmount == "function" && await this.cdnInstance.unmount();
198
198
  } catch (e) {
199
- const n = e instanceof Error ? e : new Error(String(e));
200
- this.handleError(n, "unmount");
199
+ const t = e instanceof Error ? e : new Error(String(e));
200
+ this.handleError(t, "unmount");
201
201
  }
202
202
  this.cdnInstance = null, this.initPromise = null;
203
203
  } catch (e) {
204
- const n = e instanceof Error ? e : new Error(String(e));
205
- this.handleError(n, "unmount");
204
+ const t = e instanceof Error ? e : new Error(String(e));
205
+ this.handleError(t, "unmount");
206
206
  }
207
207
  }
208
208
  // preload SDK
209
209
  static async preload(e) {
210
210
  try {
211
211
  await E(e);
212
- } catch (n) {
213
- throw console.error("[PayNext SDK] Preload failed:", n), n;
212
+ } catch (t) {
213
+ throw console.error("[PayNext SDK] Preload failed:", t), t;
214
214
  }
215
215
  }
216
216
  }
217
- const I = {
218
- preload: _.preload
217
+ const R = {
218
+ preload: K.preload
219
219
  };
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 || {});
220
+ 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 || {});
221
221
  export {
222
- _ as PayNextCheckout,
223
- I as PayNextSDK,
224
- R as PaymentMethod
222
+ K as PayNextCheckout,
223
+ R as PayNextSDK,
224
+ I as PaymentMethod
225
225
  };
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 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"})}));
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 I=Object.defineProperty;var R=(s,a,l)=>a in s?I(s,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):s[a]=l;var y=(s,a,l)=>R(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 w=null,h=null;function k(){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"?k():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 A(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 A(50)}throw new o("PayNextSDK not found in window after waiting",!0,!0)}async function N(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 A(1500*e),N(t,e+1);throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`,i),i}}async function C(t){if(h)return h;if(w)return w;if(typeof window>"u")throw new o("PayNext SDK can only be loaded in browser environment",!1);const e=E();return e?(h=e,h):(w=(async()=>{try{const n=await N(t);return h=n,K(n),n}catch(n){throw w=null,n}})(),w)}class T{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:T.preload};var x=(t=>(t.PAYPAL="PAYPAL",t.APPLE_PAY="APPLEPAY",t.GOOGLE_PAY="GPAY",t.CARD="CARD",t.VENMO="VENMO",t.CASHAPP="CASHAPP",t.AMAZONPAY="AMAZONPAY",t.PIX_AUTOMATICO="PIX_AUTOMATICO",t))(x||{});s.PayNextCheckout=T,s.PayNextSDK=_,s.PaymentMethod=x,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.14",
3
+ "version": "1.0.16",
4
4
  "description": "PayNext SDK - Payment processing with automatic CDN loading",
5
5
  "type": "module",
6
6
  "main": "dist/index.es.js",
@@ -33,19 +33,22 @@
33
33
  ],
34
34
  "scripts": {
35
35
  "type-check": "tsc --noEmit",
36
+ "types:worker": "wrangler types",
36
37
  "format": "yarn type-check && yarn lint && yarn prettier",
37
38
  "preview": "PREVIEW=true NODE_ENV=development vite --host",
38
39
  "preview-host": "PREVIEW=true yarn build-preview && vite preview --host",
39
40
  "preview:cdn": "yarn wrangler dev",
40
41
  "build-preview": "PREVIEW=true yarn build",
41
42
  "build": "tsc -b && vite build",
42
- "build:cdn": "CDN=true tsc -b && CDN=true vite build",
43
+ "build:cdn": "yarn types:worker && node scripts/build-cdn.mjs",
43
44
  "lint": "eslint .",
44
45
  "analyze": "ANALYZE=true yarn build",
45
46
  "pub": "yarn build && npm publish --scope=@paynext",
46
47
  "pub-ts": "npm run build && npm version patch --no-git-tag-version && npm publish --access restricted",
47
48
  "deploy:dev": "yarn build:cdn && yarn wrangler deploy --env='development'",
48
- "deploy:prod": "yarn build:cdn && yarn wrangler deploy --env=''"
49
+ "deploy:prod": "yarn build:cdn && yarn wrangler deploy --env=''",
50
+ "test": "vitest run",
51
+ "test:watch": "vitest"
49
52
  },
50
53
  "peerDependencies": {
51
54
  "react": "^19.0.0",
@@ -60,13 +63,15 @@
60
63
  }
61
64
  },
62
65
  "devDependencies": {
66
+ "@cloudflare/workers-types": "^4.20260426.1",
63
67
  "@eslint/js": "^9.39.1",
64
68
  "@evervault/js": "^2.9.0",
69
+ "@google-pay/button-element": "^3.2.1",
65
70
  "@heroui/react": "^2.8.5",
66
71
  "@paypal/paypal-js": "^8.4.2",
67
72
  "@paypal/react-paypal-js": "^8.9.2",
68
73
  "@sentry/browser": "^10.24.0",
69
- "@stripe/stripe-js": "^8.3.0",
74
+ "@stripe/stripe-js": "^8.7.0",
70
75
  "@types/braintree-web": "^3.96.17",
71
76
  "@types/node": "^22",
72
77
  "@types/react": "^19.2.2",
@@ -74,13 +79,14 @@
74
79
  "@vitejs/plugin-legacy": "^7.2.1",
75
80
  "@vitejs/plugin-react": "^5.1.0",
76
81
  "autoprefixer": "^10.4.22",
77
- "braintree-web": "^3.132.0",
82
+ "braintree-web": "3.140.0",
78
83
  "credit-card-type": "^10.1.0",
79
84
  "eslint": "^9.39.1",
80
85
  "eslint-plugin-prettier": "^5.5.4",
81
86
  "eslint-plugin-react-hooks": "^7.0.1",
82
87
  "eslint-plugin-react-refresh": "^0.4.24",
83
88
  "globals": "^16.5.0",
89
+ "json5": "^2.2.3",
84
90
  "motion": "^12.23.24",
85
91
  "prettier": "^3.6.2",
86
92
  "prettier-plugin-tailwindcss": "^0.6.9",
@@ -97,6 +103,7 @@
97
103
  "vite-plugin-dts": "^4.5.4",
98
104
  "vite-plugin-static-copy": "^3.1.4",
99
105
  "vite-plugin-svgr": "^4.5.0",
106
+ "vitest": "2.1.9",
100
107
  "wrangler": "^4.46.0"
101
108
  },
102
109
  "browserslist": [