@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 +35 -0
- package/dist/index.d.ts +25 -1
- package/dist/index.es.js +87 -70
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
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
|
|
2
|
-
var
|
|
3
|
-
var d = (n, e, t) =>
|
|
4
|
-
const
|
|
5
|
-
let
|
|
6
|
-
function
|
|
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
|
|
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
|
|
20
|
-
constructor(t,
|
|
21
|
-
const u = i && typeof window < "u" ?
|
|
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 =
|
|
24
|
+
this.retryable = r, this.name = "SDKLoadError", this.diagnostics = u;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
const P = "PayNextSDK";
|
|
28
|
-
function
|
|
28
|
+
function p() {
|
|
29
29
|
return typeof window > "u" ? null : window[P];
|
|
30
30
|
}
|
|
31
|
-
function
|
|
31
|
+
function K(n) {
|
|
32
32
|
typeof window > "u" || (window[P] = n);
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function S(n) {
|
|
35
35
|
return new Promise((e) => setTimeout(e, n));
|
|
36
36
|
}
|
|
37
|
-
async function
|
|
37
|
+
async function L(n = 5e3) {
|
|
38
38
|
const t = Math.ceil(n / 50);
|
|
39
|
-
for (let
|
|
40
|
-
const i =
|
|
39
|
+
for (let r = 0; r < t; r++) {
|
|
40
|
+
const i = p();
|
|
41
41
|
if (i)
|
|
42
42
|
return i;
|
|
43
|
-
await
|
|
43
|
+
await S(50);
|
|
44
44
|
}
|
|
45
|
-
throw new
|
|
45
|
+
throw new o("PayNextSDK not found in window after waiting", !0, !0);
|
|
46
46
|
}
|
|
47
|
-
async function
|
|
48
|
-
const
|
|
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 =
|
|
50
|
+
const i = p();
|
|
51
51
|
return i || (await new Promise((c, f) => {
|
|
52
|
-
const a = document.querySelector(`script[src="${
|
|
52
|
+
const a = document.querySelector(`script[src="${r}"]`);
|
|
53
53
|
if (a) {
|
|
54
|
-
if (
|
|
54
|
+
if (p()) {
|
|
55
55
|
c();
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
|
-
const
|
|
59
|
-
a.removeEventListener("load", l), a.removeEventListener("error",
|
|
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(
|
|
62
|
-
},
|
|
63
|
-
clearTimeout(
|
|
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",
|
|
65
|
+
a.addEventListener("load", l), a.addEventListener("error", E);
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
68
|
const A = setTimeout(() => {
|
|
69
|
-
m(), f(new
|
|
69
|
+
m(), f(new o("SDK script loading timeout", !0, !0));
|
|
70
70
|
}, 15e3), s = document.createElement("script");
|
|
71
|
-
s.src =
|
|
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 = (
|
|
78
|
-
console.error("[PayNext CDN] Script load error:",
|
|
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
|
|
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
|
|
89
|
+
m(), f(new o("Failed to append script to document", !1));
|
|
90
90
|
}
|
|
91
|
-
}), await
|
|
91
|
+
}), await L(5e3));
|
|
92
92
|
} catch (i) {
|
|
93
|
-
if ((i instanceof
|
|
94
|
-
return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1500ms...`, i), await
|
|
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
|
|
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
|
|
105
|
-
const e =
|
|
106
|
-
return e ? (
|
|
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
|
|
109
|
-
return
|
|
108
|
+
const t = await v(n);
|
|
109
|
+
return h = t, K(t), t;
|
|
110
110
|
} catch (t) {
|
|
111
|
-
throw
|
|
111
|
+
throw w = null, t;
|
|
112
112
|
}
|
|
113
|
-
})(),
|
|
113
|
+
})(), w);
|
|
114
114
|
}
|
|
115
|
-
class
|
|
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
|
|
129
|
-
if (console.error(
|
|
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
|
|
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
|
|
142
|
+
const t = await D(e);
|
|
143
143
|
if (!t || !t.PayNextCheckout)
|
|
144
|
-
throw new
|
|
144
|
+
throw new o("PayNextCheckout not found in loaded SDK module", !1);
|
|
145
145
|
try {
|
|
146
146
|
this.cdnInstance = new t.PayNextCheckout();
|
|
147
|
-
} catch (
|
|
148
|
-
throw new
|
|
149
|
-
`Failed to instantiate PayNextCheckout: ${
|
|
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
|
|
161
|
+
throw new o("SDK instance has been destroyed", !1);
|
|
162
162
|
if (!this.initPromise)
|
|
163
|
-
throw new
|
|
163
|
+
throw new o("SDK initialization not started", !1);
|
|
164
164
|
if (!this.cdnInstance)
|
|
165
|
-
throw new
|
|
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
|
|
171
|
+
throw new o("Invalid containerId provided", !1);
|
|
172
172
|
if (!t || !t.environment)
|
|
173
|
-
throw new
|
|
173
|
+
throw new o("Invalid config provided", !1);
|
|
174
174
|
if (!document.getElementById(e))
|
|
175
|
-
throw new
|
|
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 (
|
|
178
|
-
const i =
|
|
179
|
-
|
|
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
|
|
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:
|
|
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
|
-
|
|
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
|
|
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"})}));
|