@paynext/sdk 1.0.6 → 1.0.8
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/dist/index.d.ts +46 -1
- package/dist/index.es.js +74 -76
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -58,10 +58,21 @@ export declare interface CheckoutTranslate {
|
|
|
58
58
|
button: string;
|
|
59
59
|
};
|
|
60
60
|
};
|
|
61
|
+
savedPaymentMethod: {
|
|
62
|
+
change: {
|
|
63
|
+
button: string;
|
|
64
|
+
select: string;
|
|
65
|
+
};
|
|
66
|
+
pay: {
|
|
67
|
+
button: string;
|
|
68
|
+
};
|
|
69
|
+
separator: string;
|
|
70
|
+
};
|
|
61
71
|
status: {
|
|
62
72
|
error: string;
|
|
63
73
|
invalidSession: string;
|
|
64
74
|
authenticationFailed: string;
|
|
75
|
+
errorSavedPaymentMethod: string;
|
|
65
76
|
};
|
|
66
77
|
}
|
|
67
78
|
|
|
@@ -104,15 +115,48 @@ declare interface CheckoutTranslateOverrides {
|
|
|
104
115
|
button?: string;
|
|
105
116
|
};
|
|
106
117
|
};
|
|
118
|
+
savedPaymentMethod?: {
|
|
119
|
+
change?: {
|
|
120
|
+
button?: string;
|
|
121
|
+
select?: string;
|
|
122
|
+
};
|
|
123
|
+
pay?: {
|
|
124
|
+
button?: string;
|
|
125
|
+
};
|
|
126
|
+
separator?: string;
|
|
127
|
+
};
|
|
107
128
|
status?: {
|
|
108
129
|
error?: string;
|
|
109
130
|
invalidSession?: string;
|
|
110
131
|
authenticationFailed?: string;
|
|
132
|
+
errorSavedPaymentMethod?: string;
|
|
111
133
|
};
|
|
112
134
|
}
|
|
113
135
|
|
|
114
136
|
declare type CSSProperties = Record<string, string>;
|
|
115
137
|
|
|
138
|
+
export declare interface CSSVariablesConfig {
|
|
139
|
+
'--paynext-sdk-bg'?: string;
|
|
140
|
+
'--paynext-sdk-text'?: string;
|
|
141
|
+
'--paynext-sdk-border'?: string;
|
|
142
|
+
'--paynext-sdk-border-focus'?: string;
|
|
143
|
+
'--paynext-sdk-border-radius'?: string;
|
|
144
|
+
'--paynext-sdk-input-bg'?: string;
|
|
145
|
+
'--paynext-sdk-input-text'?: string;
|
|
146
|
+
'--paynext-sdk-input-focus-shadow'?: string;
|
|
147
|
+
'--paynext-sdk-placeholder'?: string;
|
|
148
|
+
'--paynext-sdk-error'?: string;
|
|
149
|
+
'--paynext-sdk-error-border'?: string;
|
|
150
|
+
'--paynext-sdk-disabled-bg'?: string;
|
|
151
|
+
'--paynext-sdk-disabled-text'?: string;
|
|
152
|
+
'--paynext-sdk-button-bg'?: string;
|
|
153
|
+
'--paynext-sdk-button-text'?: string;
|
|
154
|
+
'--paynext-sdk-button-hover-bg'?: string;
|
|
155
|
+
'--paynext-sdk-button-hover-opacity'?: string;
|
|
156
|
+
'--paynext-sdk-card-bg'?: string;
|
|
157
|
+
'--paynext-sdk-card-icon'?: string;
|
|
158
|
+
}
|
|
159
|
+
|
|
116
160
|
declare enum DeclineCode {
|
|
117
161
|
INSUFFICIENT_FUNDS = "insufficient_funds",
|
|
118
162
|
AUTHENTICATION_REQUIRED = "authentication_required",
|
|
@@ -377,11 +421,11 @@ export declare interface PayNextConfig {
|
|
|
377
421
|
translate?: CheckoutTranslateOverrides;
|
|
378
422
|
locale?: Locale;
|
|
379
423
|
errorMessageText?: string;
|
|
424
|
+
returnUrl?: string;
|
|
380
425
|
onCheckoutLoaded?: (result: LoadedResult) => void;
|
|
381
426
|
onCheckoutAttempt?: (result: AttemptResult) => void;
|
|
382
427
|
onCheckoutComplete?: (result: PaymentResult) => void;
|
|
383
428
|
onCheckoutFail?: (error: CheckoutError) => void;
|
|
384
|
-
_themeExplicit?: boolean;
|
|
385
429
|
}
|
|
386
430
|
|
|
387
431
|
export declare const PayNextSDK: {
|
|
@@ -398,6 +442,7 @@ export declare interface StylesConfig {
|
|
|
398
442
|
BraintreeButton?: HTMLStyles;
|
|
399
443
|
CashAppButton?: HTMLStyles;
|
|
400
444
|
BackButton?: HTMLStyles;
|
|
445
|
+
cssVariables?: CSSVariablesConfig;
|
|
401
446
|
}
|
|
402
447
|
|
|
403
448
|
export declare type TEnvironment = 'develop' | 'staging' | 'sandbox' | 'production';
|
package/dist/index.es.js
CHANGED
|
@@ -1,87 +1,86 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var a = (
|
|
4
|
-
const
|
|
5
|
-
let c = null,
|
|
6
|
-
class
|
|
1
|
+
var p = Object.defineProperty;
|
|
2
|
+
var N = (r, e, t) => e in r ? p(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var a = (r, e, t) => N(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
const x = "https://cdn-sdk-dev.paynext.com/index.cdn.js", A = "https://cdn-sdk.paynext.com/index.cdn.js";
|
|
5
|
+
let c = null, d = null;
|
|
6
|
+
class n extends Error {
|
|
7
7
|
constructor(e, t = !0) {
|
|
8
8
|
super(e), this.retryable = t, this.name = "SDKLoadError";
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
const
|
|
12
|
-
function
|
|
13
|
-
return typeof window > "u" ? null : window[
|
|
11
|
+
const D = "PayNextSDK";
|
|
12
|
+
function y() {
|
|
13
|
+
return typeof window > "u" ? null : window[D];
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
typeof window > "u" || (window[
|
|
15
|
+
function C(r) {
|
|
16
|
+
typeof window > "u" || (window[D] = r);
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
return new Promise((e) => setTimeout(e,
|
|
18
|
+
function K(r) {
|
|
19
|
+
return new Promise((e) => setTimeout(e, r));
|
|
20
20
|
}
|
|
21
|
-
async function
|
|
22
|
-
const o = (
|
|
21
|
+
async function P(r, e = 1) {
|
|
22
|
+
const o = (r?.toLowerCase()?.includes("develop") || r?.toLowerCase()?.includes("staging") ? "develop" : "production") === "develop" ? x : A;
|
|
23
23
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
await new Promise((y, h) => {
|
|
24
|
+
const i = y();
|
|
25
|
+
if (i)
|
|
26
|
+
return i;
|
|
27
|
+
await new Promise((h, w) => {
|
|
29
28
|
if (document.querySelector(`script[src="${o}"]`)) {
|
|
30
|
-
|
|
29
|
+
h();
|
|
31
30
|
return;
|
|
32
31
|
}
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
}, 1e4),
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
clearTimeout(
|
|
32
|
+
const E = setTimeout(() => {
|
|
33
|
+
l(), w(new n("SDK script loading timeout", !0));
|
|
34
|
+
}, 1e4), s = document.createElement("script");
|
|
35
|
+
s.src = o, s.crossOrigin = "anonymous", s.async = !0, s.setAttribute("data-paynext-sdk", "true");
|
|
36
|
+
const l = () => {
|
|
37
|
+
clearTimeout(E), s.onload = null, s.onerror = null;
|
|
39
38
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
},
|
|
43
|
-
console.error("[PayNext CDN] Script load error:", f),
|
|
39
|
+
s.onload = () => {
|
|
40
|
+
l(), h();
|
|
41
|
+
}, s.onerror = (f) => {
|
|
42
|
+
console.error("[PayNext CDN] Script load error:", f), l();
|
|
44
43
|
try {
|
|
45
|
-
|
|
46
|
-
} catch (
|
|
47
|
-
console.warn("[PayNext CDN] Failed to remove script:",
|
|
44
|
+
s.parentNode && s.parentNode.removeChild(s);
|
|
45
|
+
} catch (S) {
|
|
46
|
+
console.warn("[PayNext CDN] Failed to remove script:", S);
|
|
48
47
|
}
|
|
49
|
-
|
|
48
|
+
w(new n("Failed to load SDK script from CDN", !0));
|
|
50
49
|
};
|
|
51
50
|
try {
|
|
52
|
-
document.head.appendChild(
|
|
51
|
+
document.head.appendChild(s);
|
|
53
52
|
} catch {
|
|
54
|
-
|
|
53
|
+
l(), w(new n("Failed to append script to document", !1));
|
|
55
54
|
}
|
|
56
55
|
});
|
|
57
|
-
const u =
|
|
56
|
+
const u = y();
|
|
58
57
|
if (!u)
|
|
59
|
-
throw new
|
|
60
|
-
return
|
|
61
|
-
} catch (
|
|
62
|
-
if ((
|
|
63
|
-
return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1000ms...`,
|
|
64
|
-
throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`,
|
|
58
|
+
throw new n("PayNextSDK not found in window after load", !0);
|
|
59
|
+
return u;
|
|
60
|
+
} catch (i) {
|
|
61
|
+
if ((i instanceof n ? i.retryable : !0) && e < 3)
|
|
62
|
+
return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1000ms...`, i), await K(1e3 * e), P(r, e + 1);
|
|
63
|
+
throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`, i), i;
|
|
65
64
|
}
|
|
66
65
|
}
|
|
67
|
-
async function
|
|
68
|
-
if (
|
|
69
|
-
return
|
|
66
|
+
async function m(r) {
|
|
67
|
+
if (d)
|
|
68
|
+
return d;
|
|
70
69
|
if (c)
|
|
71
|
-
return
|
|
70
|
+
return c;
|
|
72
71
|
if (typeof window > "u")
|
|
73
|
-
throw new
|
|
74
|
-
const e =
|
|
75
|
-
return e ? (
|
|
72
|
+
throw new n("PayNext SDK can only be loaded in browser environment", !1);
|
|
73
|
+
const e = y();
|
|
74
|
+
return e ? (d = e, d) : (c = (async () => {
|
|
76
75
|
try {
|
|
77
|
-
const t = await
|
|
78
|
-
return
|
|
76
|
+
const t = await P(r);
|
|
77
|
+
return d = t, C(t), t;
|
|
79
78
|
} catch (t) {
|
|
80
79
|
throw c = null, t;
|
|
81
80
|
}
|
|
82
81
|
})(), c);
|
|
83
82
|
}
|
|
84
|
-
class
|
|
83
|
+
class R {
|
|
85
84
|
constructor() {
|
|
86
85
|
a(this, "cdnInstance", null);
|
|
87
86
|
a(this, "initPromise", null);
|
|
@@ -98,28 +97,27 @@ class A {
|
|
|
98
97
|
if (console.error(o, e), this.errorBoundary)
|
|
99
98
|
try {
|
|
100
99
|
this.errorBoundary(e);
|
|
101
|
-
} catch (
|
|
102
|
-
console.error("[PayNext SDK] Error in custom error handler:",
|
|
100
|
+
} catch (i) {
|
|
101
|
+
console.error("[PayNext SDK] Error in custom error handler:", i);
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
104
|
// initialize
|
|
106
105
|
async initialize(e) {
|
|
107
106
|
if (this.isDestroyed)
|
|
108
|
-
throw new
|
|
107
|
+
throw new n("Cannot initialize destroyed SDK instance", !1);
|
|
109
108
|
return this.initPromise ? this.initPromise : (this.initPromise = (async () => {
|
|
110
109
|
try {
|
|
111
|
-
const t = await
|
|
110
|
+
const t = await m(e);
|
|
112
111
|
if (!t || !t.PayNextCheckout)
|
|
113
|
-
throw new
|
|
112
|
+
throw new n("PayNextCheckout not found in loaded SDK module", !1);
|
|
114
113
|
try {
|
|
115
114
|
this.cdnInstance = new t.PayNextCheckout();
|
|
116
115
|
} catch (o) {
|
|
117
|
-
throw new
|
|
116
|
+
throw new n(
|
|
118
117
|
`Failed to instantiate PayNextCheckout: ${o instanceof Error ? o.message : "Unknown error"}`,
|
|
119
118
|
!1
|
|
120
119
|
);
|
|
121
120
|
}
|
|
122
|
-
console.log("[PayNext SDK] Initialized successfully");
|
|
123
121
|
} catch (t) {
|
|
124
122
|
throw this.initPromise = null, t;
|
|
125
123
|
}
|
|
@@ -128,28 +126,28 @@ class A {
|
|
|
128
126
|
// assert ready
|
|
129
127
|
assertReady() {
|
|
130
128
|
if (this.isDestroyed)
|
|
131
|
-
throw new
|
|
129
|
+
throw new n("SDK instance has been destroyed", !1);
|
|
132
130
|
if (!this.initPromise)
|
|
133
|
-
throw new
|
|
131
|
+
throw new n("SDK initialization not started", !1);
|
|
134
132
|
if (!this.cdnInstance)
|
|
135
|
-
throw new
|
|
133
|
+
throw new n("SDK instance not created", !1);
|
|
136
134
|
}
|
|
137
135
|
// mount
|
|
138
136
|
async mount(e, t) {
|
|
139
137
|
try {
|
|
140
138
|
if (!e || typeof e != "string")
|
|
141
|
-
throw new
|
|
139
|
+
throw new n("Invalid containerId provided", !1);
|
|
142
140
|
if (!t || !t.environment)
|
|
143
|
-
throw new
|
|
141
|
+
throw new n("Invalid config provided", !1);
|
|
144
142
|
if (!document.getElementById(e))
|
|
145
|
-
throw new
|
|
143
|
+
throw new n(`Container element with id "${e}" not found`, !1);
|
|
146
144
|
await this.initialize(t.environment), this.assertReady(), await this.cdnInstance.mount(e, t);
|
|
147
145
|
} catch (o) {
|
|
148
|
-
const
|
|
146
|
+
const i = o instanceof n ? o : new n(
|
|
149
147
|
o instanceof Error ? o.message : "Unknown mount error",
|
|
150
148
|
!0
|
|
151
149
|
);
|
|
152
|
-
throw this.handleError(
|
|
150
|
+
throw this.handleError(i, "mount"), i;
|
|
153
151
|
}
|
|
154
152
|
}
|
|
155
153
|
// unmount
|
|
@@ -178,18 +176,18 @@ class A {
|
|
|
178
176
|
// preload SDK
|
|
179
177
|
static async preload(e) {
|
|
180
178
|
try {
|
|
181
|
-
await
|
|
179
|
+
await m(e);
|
|
182
180
|
} catch (t) {
|
|
183
181
|
throw console.error("[PayNext SDK] Preload failed:", t), t;
|
|
184
182
|
}
|
|
185
183
|
}
|
|
186
184
|
}
|
|
187
|
-
const
|
|
188
|
-
preload:
|
|
185
|
+
const T = {
|
|
186
|
+
preload: R.preload
|
|
189
187
|
};
|
|
190
|
-
var
|
|
188
|
+
var _ = /* @__PURE__ */ ((r) => (r.PAYPAL = "PAYPAL", r.APPLE_PAY = "APPLEPAY", r.GOOGLE_PAY = "GPAY", r.CARD = "CARD", r.VENMO = "VENMO", r.CASHAPP = "CASHAPP", r))(_ || {});
|
|
191
189
|
export {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
190
|
+
R as PayNextCheckout,
|
|
191
|
+
T as PayNextSDK,
|
|
192
|
+
_ as PaymentMethod
|
|
195
193
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(o,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(o=typeof globalThis<"u"?globalThis:o||self,i(o["PayNext SDK"]={}))})(this,(function(o){"use strict";var T=Object.defineProperty;var g=(o,i,d)=>i in o?T(o,i,{enumerable:!0,configurable:!0,writable:!0,value:d}):o[i]=d;var h=(o,i,d)=>g(o,typeof i!="symbol"?i+"":i,d);const i="https://cdn-sdk-dev.paynext.com/index.cdn.js",d="https://cdn-sdk.paynext.com/index.cdn.js";let l=null,u=null;class r extends Error{constructor(e,t=!0){super(e),this.retryable=t,this.name="SDKLoadError"}}const D="PayNextSDK";function y(){return typeof window>"u"?null:window[D]}function A(n){typeof window>"u"||(window[D]=n)}function K(n){return new Promise(e=>setTimeout(e,n))}async function S(n,e=1){const s=(n?.toLowerCase()?.includes("develop")||n?.toLowerCase()?.includes("staging")?"develop":"production")==="develop"?i:d;try{const a=y();if(a)return a;await new Promise((m,P)=>{if(document.querySelector(`script[src="${s}"]`)){m();return}const R=setTimeout(()=>{f(),P(new r("SDK script loading timeout",!0))},1e4),c=document.createElement("script");c.src=s,c.crossOrigin="anonymous",c.async=!0,c.setAttribute("data-paynext-sdk","true");const f=()=>{clearTimeout(R),c.onload=null,c.onerror=null};c.onload=()=>{f(),m()},c.onerror=x=>{console.error("[PayNext CDN] Script load error:",x),f();try{c.parentNode&&c.parentNode.removeChild(c)}catch(_){console.warn("[PayNext CDN] Failed to remove script:",_)}P(new r("Failed to load SDK script from CDN",!0))};try{document.head.appendChild(c)}catch{f(),P(new r("Failed to append script to document",!1))}});const w=y();if(!w)throw new r("PayNextSDK not found in window after load",!0);return w}catch(a){if((a instanceof r?a.retryable:!0)&&e<3)return console.warn(`[PayNext CDN] Load attempt ${e} failed, retrying in 1000ms...`,a),await K(1e3*e),S(n,e+1);throw console.error(`[PayNext CDN] Failed to load SDK after ${e} attempts:`,a),a}}async function E(n){if(u)return u;if(l)return l;if(typeof window>"u")throw new r("PayNext SDK can only be loaded in browser environment",!1);const e=y();return e?(u=e,u):(l=(async()=>{try{const t=await S(n);return u=t,A(t),t}catch(t){throw l=null,t}})(),l)}class p{constructor(){h(this,"cdnInstance",null);h(this,"initPromise",null);h(this,"isDestroyed",!1);h(this,"errorBoundary",null)}setErrorHandler(e){this.errorBoundary=e}handleError(e,t){const s=`[PayNext SDK Error - ${t}]: ${e.message}`;if(console.error(s,e),this.errorBoundary)try{this.errorBoundary(e)}catch(a){console.error("[PayNext SDK] Error in custom error handler:",a)}}async initialize(e){if(this.isDestroyed)throw new r("Cannot initialize destroyed SDK instance",!1);return this.initPromise?this.initPromise:(this.initPromise=(async()=>{try{const t=await E(e);if(!t||!t.PayNextCheckout)throw new r("PayNextCheckout not found in loaded SDK module",!1);try{this.cdnInstance=new t.PayNextCheckout}catch(s){throw new r(`Failed to instantiate PayNextCheckout: ${s instanceof Error?s.message:"Unknown error"}`,!1)}}catch(t){throw this.initPromise=null,t}})(),this.initPromise)}assertReady(){if(this.isDestroyed)throw new r("SDK instance has been destroyed",!1);if(!this.initPromise)throw new r("SDK initialization not started",!1);if(!this.cdnInstance)throw new r("SDK instance not created",!1)}async mount(e,t){try{if(!e||typeof e!="string")throw new r("Invalid containerId provided",!1);if(!t||!t.environment)throw new r("Invalid config provided",!1);if(!document.getElementById(e))throw new r(`Container element with id "${e}" not found`,!1);await this.initialize(t.environment),this.assertReady(),await this.cdnInstance.mount(e,t)}catch(s){const a=s instanceof r?s:new r(s instanceof Error?s.message:"Unknown mount error",!0);throw this.handleError(a,"mount"),a}}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 E(e)}catch(t){throw console.error("[PayNext SDK] Preload failed:",t),t}}}const C={preload:p.preload};var N=(n=>(n.PAYPAL="PAYPAL",n.APPLE_PAY="APPLEPAY",n.GOOGLE_PAY="GPAY",n.CARD="CARD",n.VENMO="VENMO",n.CASHAPP="CASHAPP",n))(N||{});o.PayNextCheckout=p,o.PayNextSDK=C,o.PaymentMethod=N,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
|