@paynext/sdk 1.0.18 → 1.0.20

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/README.md CHANGED
@@ -112,11 +112,13 @@ interface PayNextConfig {
112
112
  errorMessageText?: string
113
113
  returnUrl?: string
114
114
  styles?: StylesConfig
115
+ paymentsEnabled?: boolean
115
116
  onCheckoutLoaded?: (result: LoadedResult) => void
116
117
  beforeCheckoutAttempt?: (result: AttemptResult) => boolean | Promise<boolean>
117
118
  onCheckoutAttempt?: (result: AttemptResult) => void
118
119
  onCheckoutComplete?: (result: PaymentResult) => void
119
120
  onCheckoutFail?: (error: CheckoutError) => void
121
+ onCheckoutBlocked?: (result: AttemptResult) => void // fires on a tap while payments are disabled
120
122
  }
121
123
 
122
124
  interface LoadedResult {
@@ -193,6 +195,39 @@ await checkout.mount('checkout-container', {
193
195
  })
194
196
  ```
195
197
 
198
+ ### Gate Payments Behind Your Own Consent Checkbox
199
+
200
+ Use `paymentsEnabled` when payment must be blocked until an external condition is met — for example, the customer ticking your own terms/consent checkbox that lives outside the SDK.
201
+
202
+ When `paymentsEnabled` is `false`:
203
+
204
+ - Tapping any payment button (Google Pay, PayPal, Apple Pay, etc.) does **not** start a payment and does **not** open any provider sheet/popup.
205
+ - The card and Pix forms can still **expand**, but submitting them is blocked.
206
+ - Each blocked interaction fires `onCheckoutBlocked` with the same `{ paymentMethod, cardType }` payload as `onCheckoutAttempt`, so you can highlight your checkbox.
207
+ - Button appearance is **unchanged** — there is no visual disabled state.
208
+
209
+ `paymentsEnabled` defaults to `true`, so existing integrations are unaffected. Toggle the state at runtime — without re-mounting — with `checkout.setPaymentsEnabled(enabled)`.
210
+
211
+ ```ts
212
+ const checkout = new PayNextCheckout()
213
+
214
+ await checkout.mount('checkout-container', {
215
+ ...config,
216
+ // Start blocked until the customer accepts your terms.
217
+ paymentsEnabled: termsAccepted,
218
+ onCheckoutBlocked: ({ paymentMethod }) => {
219
+ // The user tried to pay before accepting — draw attention to your checkbox.
220
+ highlightTermsCheckbox()
221
+ console.info('Payment blocked, terms not accepted:', paymentMethod)
222
+ },
223
+ })
224
+
225
+ // Later, when the customer toggles your checkbox — no re-mount required:
226
+ termsCheckbox.addEventListener('change', (e) => {
227
+ checkout.setPaymentsEnabled((e.target as HTMLInputElement).checked)
228
+ })
229
+ ```
230
+
196
231
  ## Supported Languages
197
232
 
198
233
  English, German, French, Spanish, Italian, Portuguese, Dutch, Polish, Czech, Slovak, Hungarian, Romanian, Bulgarian, Croatian, Slovenian, Estonian, Latvian, Lithuanian, Finnish, Swedish, Danish, Norwegian, Russian, Ukrainian, Arabic, Chinese, Japanese, Korean, Thai, Vietnamese, Indonesian, Malay, Filipino, Hindi, Turkish, Greek, Maltese.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,24 @@
1
1
  import { PayPalButtonStyle } from '@paypal/paypal-js';
2
2
 
3
+ export declare interface ApplePayRecurringPaymentLineItem {
4
+ label: string;
5
+ amount: string;
6
+ paymentTiming: 'immediate' | 'recurring';
7
+ recurringPaymentStartDate?: Date;
8
+ recurringPaymentEndDate?: Date;
9
+ recurringPaymentIntervalUnit?: 'year' | 'month' | 'day' | 'hour' | 'minute';
10
+ recurringPaymentIntervalCount?: number;
11
+ }
12
+
13
+ export declare interface ApplePayRecurringPaymentRequest {
14
+ paymentDescription: string;
15
+ regularBilling: ApplePayRecurringPaymentLineItem;
16
+ trialBilling?: ApplePayRecurringPaymentLineItem;
17
+ billingAgreement?: string;
18
+ managementURL: string;
19
+ tokenNotificationURL?: string;
20
+ }
21
+
3
22
  export declare interface AttemptResult {
4
23
  paymentMethod: PaymentMethod;
5
24
  cardType: string;
@@ -468,6 +487,7 @@ export declare class PayNextCheckout {
468
487
  private initialize;
469
488
  private assertReady;
470
489
  mount(containerId: string, config: PayNextConfig): Promise<void>;
490
+ setPaymentsEnabled(enabled: boolean): void;
471
491
  unmount(): Promise<void>;
472
492
  static preload(envType: TEnvironment): Promise<void>;
473
493
  }
@@ -483,11 +503,15 @@ export declare interface PayNextConfig {
483
503
  locale?: Locale;
484
504
  errorMessageText?: string;
485
505
  returnUrl?: string;
506
+ paymentsEnabled?: boolean;
507
+ applePayMpanEnabled?: boolean;
508
+ applePayRecurringPaymentRequest?: ApplePayRecurringPaymentRequest;
486
509
  onCheckoutLoaded?: (result: LoadedResult) => void;
487
510
  onCheckoutAttempt?: (result: AttemptResult) => void;
488
511
  beforeCheckoutAttempt?: (result: AttemptResult) => boolean | Promise<boolean>;
489
512
  onCheckoutComplete?: (result: PaymentResult) => void;
490
513
  onCheckoutFail?: (error: CheckoutError) => void;
514
+ onCheckoutBlocked?: (result: AttemptResult) => void;
491
515
  }
492
516
 
493
517
  export declare const PayNextSDK: {
@@ -509,7 +533,7 @@ export declare interface StylesConfig {
509
533
  cssVariables?: CSSVariablesConfig;
510
534
  }
511
535
 
512
- export declare type TEnvironment = 'develop' | 'preview1' | 'preview2' | 'preview3' | 'staging' | 'sandbox' | 'production';
536
+ export declare type TEnvironment = 'develop' | 'preview1' | 'preview2' | 'preview3' | 'preview4' | 'staging' | 'staging_preview1' | 'sandbox' | 'production';
513
537
 
514
538
  export declare type ThemeMode = 'light' | 'dark' | 'system';
515
539
 
package/dist/index.es.js CHANGED
@@ -1,9 +1,9 @@
1
- var C = Object.defineProperty;
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
- let h = null, y = null;
6
- function x() {
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;
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,107 +12,107 @@ function x() {
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 L(n) {
15
+ function g(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 u = i && typeof window < "u" ? x() : null, c = u ? `${t} [${L(u)}]` : t;
19
+ class o extends Error {
20
+ constructor(t, r = !0, i = !1) {
21
+ const u = i && typeof window < "u" ? T() : null, c = u ? `${t} [${g(u)}]` : t;
22
22
  super(c);
23
23
  d(this, "diagnostics");
24
- this.retryable = o, this.name = "SDKLoadError", this.diagnostics = u;
24
+ this.retryable = r, this.name = "SDKLoadError", this.diagnostics = u;
25
25
  }
26
26
  }
27
27
  const P = "PayNextSDK";
28
- function D() {
28
+ function p() {
29
29
  return typeof window > "u" ? null : window[P];
30
30
  }
31
- function g(n) {
31
+ function K(n) {
32
32
  typeof window > "u" || (window[P] = n);
33
33
  }
34
- function v(n) {
34
+ function S(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 = D();
39
+ for (let r = 0; r < t; r++) {
40
+ const i = p();
41
41
  if (i)
42
42
  return i;
43
- await v(50);
43
+ await S(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
- async function S(n, e = 1) {
48
- const o = (n?.toLowerCase()?.includes("develop") || n?.toLowerCase()?.includes("staging") ? "develop" : "production") === "develop" ? T : k;
47
+ async function v(n, e = 1) {
48
+ const r = (n?.toLowerCase()?.includes("develop") || n?.toLowerCase()?.includes("staging") ? "develop" : "production") === "develop" ? x : k;
49
49
  try {
50
- const i = D();
50
+ const i = p();
51
51
  return i || (await new Promise((c, f) => {
52
- const a = document.querySelector(`script[src="${o}"]`);
52
+ const a = document.querySelector(`script[src="${r}"]`);
53
53
  if (a) {
54
- if (D()) {
54
+ if (p()) {
55
55
  c();
56
56
  return;
57
57
  }
58
- const w = setTimeout(() => {
59
- a.removeEventListener("load", l), a.removeEventListener("error", p), f(new r("Existing SDK script loading timeout", !0, !0));
58
+ const y = setTimeout(() => {
59
+ a.removeEventListener("load", l), a.removeEventListener("error", E), f(new o("Existing SDK script loading timeout", !0, !0));
60
60
  }, 15e3), l = () => {
61
- clearTimeout(w), a.removeEventListener("load", l), a.removeEventListener("error", p), c();
62
- }, p = () => {
63
- clearTimeout(w), a.removeEventListener("load", l), a.removeEventListener("error", p), f(new r("Existing SDK script failed to load", !0, !0));
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));
64
64
  };
65
- a.addEventListener("load", l), a.addEventListener("error", p);
65
+ a.addEventListener("load", l), a.addEventListener("error", E);
66
66
  return;
67
67
  }
68
68
  const A = setTimeout(() => {
69
- m(), f(new r("SDK script loading timeout", !0, !0));
69
+ m(), f(new o("SDK script loading timeout", !0, !0));
70
70
  }, 15e3), s = document.createElement("script");
71
- s.src = o, s.crossOrigin = "anonymous", s.async = !0, s.setAttribute("data-paynext-sdk", "true");
71
+ s.src = r, s.crossOrigin = "anonymous", s.async = !0, s.setAttribute("data-paynext-sdk", "true");
72
72
  const m = () => {
73
73
  clearTimeout(A), s.onload = null, s.onerror = null;
74
74
  };
75
75
  s.onload = () => {
76
76
  m(), c();
77
- }, s.onerror = (w) => {
78
- console.error("[PayNext CDN] Script load error:", w), m();
77
+ }, s.onerror = (y) => {
78
+ console.error("[PayNext CDN] Script load error:", y), m();
79
79
  try {
80
80
  s.parentNode && s.parentNode.removeChild(s);
81
81
  } catch (l) {
82
82
  console.warn("[PayNext CDN] Failed to remove script:", l);
83
83
  }
84
- f(new r("Failed to load SDK script from CDN", !0, !0));
84
+ f(new o("Failed to load SDK script from CDN", !0, !0));
85
85
  };
86
86
  try {
87
87
  document.head.appendChild(s);
88
88
  } catch {
89
- m(), f(new r("Failed to append script to document", !1));
89
+ m(), f(new o("Failed to append script to document", !1));
90
90
  }
91
- }), await _(5e3));
91
+ }), await L(5e3));
92
92
  } catch (i) {
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 v(1500 * e), S(n, e + 1);
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
95
  throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`, i), i;
96
96
  }
97
97
  }
98
- async function E(n) {
99
- if (y)
100
- return y;
98
+ async function D(n) {
101
99
  if (h)
102
100
  return h;
101
+ if (w)
102
+ return w;
103
103
  if (typeof window > "u")
104
- throw new r("PayNext SDK can only be loaded in browser environment", !1);
105
- const e = D();
106
- return e ? (y = e, y) : (h = (async () => {
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 () => {
107
107
  try {
108
- const t = await S(n);
109
- return y = t, g(t), t;
108
+ const t = await v(n);
109
+ return h = t, K(t), t;
110
110
  } catch (t) {
111
- throw h = null, t;
111
+ throw w = null, t;
112
112
  }
113
- })(), h);
113
+ })(), w);
114
114
  }
115
- class K {
115
+ class _ {
116
116
  constructor() {
117
117
  d(this, "cdnInstance", null);
118
118
  d(this, "initPromise", null);
@@ -125,8 +125,8 @@ class K {
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 K {
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
- const t = await E(e);
142
+ const t = await D(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 K {
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
+ // enable/disable payments at runtime (no re-mount required)
186
+ setPaymentsEnabled(e) {
187
+ try {
188
+ if (this.isDestroyed) {
189
+ console.warn("[PayNext SDK] setPaymentsEnabled called on destroyed instance");
190
+ return;
191
+ }
192
+ if (!this.cdnInstance) {
193
+ console.warn("[PayNext SDK] setPaymentsEnabled called before mount");
194
+ return;
195
+ }
196
+ typeof this.cdnInstance.setPaymentsEnabled == "function" && this.cdnInstance.setPaymentsEnabled(e);
197
+ } catch (t) {
198
+ const r = t instanceof Error ? t : new Error(String(t));
199
+ this.handleError(r, "setPaymentsEnabled");
200
+ }
201
+ }
185
202
  // unmount
186
203
  async unmount() {
187
204
  try {
@@ -208,18 +225,18 @@ class K {
208
225
  // preload SDK
209
226
  static async preload(e) {
210
227
  try {
211
- await E(e);
228
+ await D(e);
212
229
  } catch (t) {
213
230
  throw console.error("[PayNext SDK] Preload failed:", t), t;
214
231
  }
215
232
  }
216
233
  }
217
234
  const R = {
218
- preload: K.preload
235
+ preload: _.preload
219
236
  };
220
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 || {});
221
238
  export {
222
- K as PayNextCheckout,
239
+ _ as PayNextCheckout,
223
240
  R as PayNextSDK,
224
241
  I as PaymentMethod
225
242
  };
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 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"})}));
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"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paynext/sdk",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "PayNext SDK - Payment processing with automatic CDN loading",
5
5
  "type": "module",
6
6
  "main": "dist/index.es.js",