htech-pay 0.1.1-beta → 0.1.5-beta
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/htechPay.mjs +93 -101
- package/dist/htechPay.umd.js +1 -1
- package/package.json +11 -3
package/dist/htechPay.mjs
CHANGED
|
@@ -1,151 +1,143 @@
|
|
|
1
1
|
/*! HtechPay | MIT License */
|
|
2
|
-
async function
|
|
2
|
+
async function _(k = {}) {
|
|
3
3
|
const {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
orderId: r,
|
|
5
|
+
environment: $ = "qa",
|
|
6
|
+
onViewForm: u,
|
|
7
|
+
onPaymentResult: l,
|
|
8
|
+
theme: i = "",
|
|
9
|
+
on3dsChallengeOpen: p,
|
|
10
|
+
onProcessPayment: y,
|
|
11
|
+
onNeedCvv: f,
|
|
12
|
+
isPaymentToken: g = !1,
|
|
13
|
+
onClose: v
|
|
14
|
+
} = k;
|
|
15
|
+
let { type: n } = k;
|
|
16
|
+
const w = {
|
|
16
17
|
//qa: "http://localhost:5173",
|
|
17
18
|
qa: "https://sp-checkout-qa.pagoshtechstage.com/index.html",
|
|
18
19
|
stage: "https://sp-checkout-stage.pagoshtechstage.com/index.html",
|
|
19
20
|
prod: "https://sp-checkout.pagoshtech.com/index.html"
|
|
20
21
|
};
|
|
21
|
-
let
|
|
22
|
-
const
|
|
22
|
+
let m = null;
|
|
23
|
+
const T = "position: fixed !important; z-index: 2147483647 !important; background: rgba(40, 40, 40, 0.75) !important; transition: background 400ms !important; will-change: background !important; inset: 0px !important; margin: 0px !important; padding: 0px !important; border-radius: 0px; height:100vh", d = w[$], c = {
|
|
23
24
|
defaultUrl: {
|
|
24
|
-
url: `${
|
|
25
|
+
url: `${d}?orderId=${r}&theme=${i}`,
|
|
25
26
|
height: "670",
|
|
26
27
|
style: ""
|
|
27
28
|
},
|
|
28
29
|
widget: {
|
|
29
|
-
url: `${
|
|
30
|
+
url: `${d}${r ? `?orderId=${r}` : ""}#/widget`,
|
|
30
31
|
height: "88",
|
|
31
32
|
style: ""
|
|
32
33
|
},
|
|
33
34
|
paymentToken: {
|
|
34
|
-
url: `${
|
|
35
|
+
url: `${d}?orderId=${r}&theme=${i}#/paymentToken`,
|
|
35
36
|
height: "530",
|
|
36
|
-
style:
|
|
37
|
+
style: T
|
|
37
38
|
},
|
|
38
39
|
paymentTokenWidget: {
|
|
39
|
-
url: `${
|
|
40
|
+
url: `${d}${r ? `?orderId=${r}` : ""}#/widgetPaymentToken`,
|
|
40
41
|
height: "88",
|
|
41
42
|
style: ""
|
|
43
|
+
},
|
|
44
|
+
checkout: {
|
|
45
|
+
url: `${d}${r ? `?orderId=${r}&theme=${i}` : `?theme=${i}`}#/checkout`,
|
|
46
|
+
height: "500",
|
|
47
|
+
style: ""
|
|
48
|
+
},
|
|
49
|
+
checkoutPaymentToken: {
|
|
50
|
+
url: `${d}${r ? `?orderId=${r}&theme=${i}` : `?theme=${i}`}#/checkoutPaymentToken`,
|
|
51
|
+
height: "330",
|
|
52
|
+
style: ""
|
|
42
53
|
}
|
|
43
54
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
message: "Unknown error"
|
|
68
|
-
});
|
|
69
|
-
}, 600);
|
|
55
|
+
c[n] || (n = "defaultUrl"), n === "widget" && g && (n = "paymentTokenWidget"), n === "defaultUrl" && g && (n = "paymentToken"), n === "checkout" && g && (n = "checkoutPaymentToken");
|
|
56
|
+
const o = {}, s = document.createElement("iframe");
|
|
57
|
+
s.id = "iframe_htechPay", s.src = c[n].url, s.width = "100%", s.height = c[n].height, s.frameBorder = "0", s.allowFullscreen = !0, s.title = "Payment form", s.style = c[n].style;
|
|
58
|
+
const V = new URL(w[$]).origin, P = () => {
|
|
59
|
+
window.removeEventListener("message", I), s.remove();
|
|
60
|
+
}, h = (e) => {
|
|
61
|
+
s.contentWindow.postMessage(e, V);
|
|
62
|
+
}, F = (e) => new Promise((t) => {
|
|
63
|
+
if (!e)
|
|
64
|
+
return console.error("htech-pay: orderId is required in processPayment to process the transaction."), t({ status: "error", message: "orderId is required in processPayment" });
|
|
65
|
+
if (r && r !== e)
|
|
66
|
+
return console.error(
|
|
67
|
+
`htech-pay: orderId mismatch. Setup orderId: "${r}", processPayment orderId: "${e}". Transaction stopped.`
|
|
68
|
+
), t({ status: "error", message: "orderId mismatch between setup and processPayment" });
|
|
69
|
+
o.onPaymentResult = t, h({ type: "htechPayment_onPayment", orderId: e });
|
|
70
|
+
}), x = (e) => new Promise((t) => {
|
|
71
|
+
if (!e)
|
|
72
|
+
return console.error("htech-pay: orderId is required in processPaymentToken to process the transaction."), t({ status: "error", message: "orderId is required in processPaymentToken" });
|
|
73
|
+
if (r && r !== e)
|
|
74
|
+
return console.error(
|
|
75
|
+
`htech-pay: orderId mismatch. Setup orderId: "${r}", processPaymentToken orderId: "${e}". Transaction stopped.`
|
|
76
|
+
), t({ status: "error", message: "orderId mismatch between setup and processPaymentToken" });
|
|
77
|
+
o.onPaymentResult = t, h({ type: "htechPayment_onPaymentToken", orderId: e });
|
|
70
78
|
}), b = () => new Promise((e) => {
|
|
71
|
-
|
|
72
|
-
e({ needCvv:
|
|
73
|
-
};
|
|
74
|
-
if (l !== null) {
|
|
75
|
-
t(l);
|
|
79
|
+
if (m !== null) {
|
|
80
|
+
e({ needCvv: m });
|
|
76
81
|
return;
|
|
77
82
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
c = e, document.getElementById("iframe_htechPay").contentWindow.postMessage(
|
|
83
|
-
"htechPayment_onValidateForm",
|
|
84
|
-
new URL(s[o]).origin
|
|
85
|
-
), setTimeout(() => {
|
|
86
|
-
y || e({
|
|
87
|
-
status: "validation_error",
|
|
88
|
-
message: "Unknown error"
|
|
89
|
-
});
|
|
83
|
+
o.onNeedCvv = (t) => e({ needCvv: t });
|
|
84
|
+
}), q = () => new Promise((e) => {
|
|
85
|
+
o.onValidForm = e, h("htechPayment_onValidateForm"), setTimeout(() => {
|
|
86
|
+
o.onValidForm && (delete o.onValidForm, e({ status: "validation_error", message: "Unknown error" }));
|
|
90
87
|
}, 600);
|
|
91
|
-
}),
|
|
92
|
-
|
|
93
|
-
"
|
|
94
|
-
new URL(s[o]).origin
|
|
95
|
-
), setTimeout(() => {
|
|
96
|
-
y || e({
|
|
97
|
-
status: "validation_error",
|
|
98
|
-
message: "Unknown error"
|
|
99
|
-
});
|
|
88
|
+
}), U = () => new Promise((e) => {
|
|
89
|
+
o.onValidFormCvv = e, h("htechPayment_onValidateFormCvv"), setTimeout(() => {
|
|
90
|
+
o.onValidFormCvv && (delete o.onValidFormCvv, e({ status: "validation_error", message: "Unknown error" }));
|
|
100
91
|
}, 600);
|
|
101
|
-
}),
|
|
102
|
-
onViewForm: () =>
|
|
92
|
+
}), C = {
|
|
93
|
+
onViewForm: () => u == null ? void 0 : u(!0),
|
|
103
94
|
onPaymentResult: (e) => {
|
|
95
|
+
var a;
|
|
104
96
|
const t = e.data.payload || {};
|
|
105
|
-
return
|
|
97
|
+
return (a = o.onPaymentResult) == null || a.call(o, t), delete o.onPaymentResult, l == null ? void 0 : l(t);
|
|
106
98
|
},
|
|
107
|
-
on3dsChallengeOpen: (e) => (
|
|
108
|
-
onProcessPayment: () =>
|
|
99
|
+
on3dsChallengeOpen: (e) => (n !== "defaultUrl" && e.isOpen && (s.style.cssText = T), !e.isOpen && n !== "paymentToken" && (s.style = ""), p == null ? void 0 : p(e.isOpen)),
|
|
100
|
+
onProcessPayment: () => y == null ? void 0 : y(!0),
|
|
109
101
|
onValidForm: (e) => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
};
|
|
114
|
-
return c && (c(t), c = null), t;
|
|
102
|
+
var a;
|
|
103
|
+
const t = { isValid: e.formIsValid, errors: e.errors };
|
|
104
|
+
return (a = o.onValidForm) == null || a.call(o, t), delete o.onValidForm, t;
|
|
115
105
|
},
|
|
116
106
|
onValidFormCvv: (e) => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
};
|
|
121
|
-
return h && (h(t), h = null), t;
|
|
107
|
+
var a;
|
|
108
|
+
const t = { isValid: e.formIsValid, errors: e.errors };
|
|
109
|
+
return (a = o.onValidFormCvv) == null || a.call(o, t), delete o.onValidFormCvv, t;
|
|
122
110
|
},
|
|
123
|
-
onNeedCvv: (e) =>
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
111
|
+
onNeedCvv: (e) => {
|
|
112
|
+
var t;
|
|
113
|
+
return m = e.value, (t = o.onNeedCvv) == null || t.call(o, m), delete o.onNeedCvv, f == null ? void 0 : f(e);
|
|
114
|
+
},
|
|
115
|
+
onClose: () => (P(), v == null ? void 0 : v(!0)),
|
|
116
|
+
onConfigError: () => {
|
|
117
|
+
console.error("htech-pay: Configuration error"), P();
|
|
118
|
+
}
|
|
119
|
+
}, I = (e) => {
|
|
128
120
|
var a;
|
|
129
121
|
const t = (a = e.data) == null ? void 0 : a.hook;
|
|
130
|
-
!t ||
|
|
122
|
+
!t || !C[t] || C[t](e.data);
|
|
131
123
|
};
|
|
132
|
-
return window.addEventListener("message",
|
|
124
|
+
return window.addEventListener("message", I), {
|
|
133
125
|
mount: (e) => {
|
|
134
126
|
const t = typeof e == "string" ? document.querySelector(e) : e;
|
|
135
127
|
if (!t)
|
|
136
128
|
throw new Error("The container to mount the form could not be found");
|
|
137
|
-
t.appendChild(
|
|
129
|
+
t.appendChild(s);
|
|
138
130
|
},
|
|
139
131
|
destroy: () => {
|
|
140
|
-
|
|
132
|
+
P();
|
|
141
133
|
},
|
|
142
|
-
processPayment:
|
|
143
|
-
validateForm:
|
|
134
|
+
processPayment: F,
|
|
135
|
+
validateForm: q,
|
|
144
136
|
verifyNeedCvv: b,
|
|
145
|
-
processPaymentToken:
|
|
146
|
-
validateFormCvv:
|
|
137
|
+
processPaymentToken: x,
|
|
138
|
+
validateFormCvv: U
|
|
147
139
|
};
|
|
148
140
|
}
|
|
149
141
|
export {
|
|
150
|
-
|
|
142
|
+
_ as htechPay
|
|
151
143
|
};
|
package/dist/htechPay.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(i,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(i=typeof globalThis<"u"?globalThis:i||self,c(i.HtechPay={}))})(this,function(i){"use strict";/*! HtechPay | MIT License */async function c($={}){const{orderId:r,environment:w="qa",onViewForm:p,onPaymentResult:y,theme:d="",on3dsChallengeOpen:f,onProcessPayment:g,onNeedCvv:v,isPaymentToken:P=!1,onClose:k}=$;let{type:n}=$;const C={qa:"https://sp-checkout-qa.pagoshtechstage.com/index.html",stage:"https://sp-checkout-stage.pagoshtechstage.com/index.html",prod:"https://sp-checkout.pagoshtech.com/index.html"};let u=null;const I="position: fixed !important; z-index: 2147483647 !important; background: rgba(40, 40, 40, 0.75) !important; transition: background 400ms !important; will-change: background !important; inset: 0px !important; margin: 0px !important; padding: 0px !important; border-radius: 0px; height:100vh",m=C[w],h={defaultUrl:{url:`${m}?orderId=${r}&theme=${d}`,height:"670",style:""},widget:{url:`${m}${r?`?orderId=${r}`:""}#/widget`,height:"88",style:""},paymentToken:{url:`${m}?orderId=${r}&theme=${d}#/paymentToken`,height:"530",style:I},paymentTokenWidget:{url:`${m}${r?`?orderId=${r}`:""}#/widgetPaymentToken`,height:"88",style:""},checkout:{url:`${m}${r?`?orderId=${r}&theme=${d}`:`?theme=${d}`}#/checkout`,height:"500",style:""},checkoutPaymentToken:{url:`${m}${r?`?orderId=${r}&theme=${d}`:`?theme=${d}`}#/checkoutPaymentToken`,height:"330",style:""}};h[n]||(n="defaultUrl"),n==="widget"&&P&&(n="paymentTokenWidget"),n==="defaultUrl"&&P&&(n="paymentToken"),n==="checkout"&&P&&(n="checkoutPaymentToken");const o={},s=document.createElement("iframe");s.id="iframe_htechPay",s.src=h[n].url,s.width="100%",s.height=h[n].height,s.frameBorder="0",s.allowFullscreen=!0,s.title="Payment form",s.style=h[n].style;const b=new URL(C[w]).origin,T=()=>{window.removeEventListener("message",F),s.remove()},l=e=>{s.contentWindow.postMessage(e,b)},x=e=>new Promise(t=>{if(!e)return console.error("htech-pay: orderId is required in processPayment to process the transaction."),t({status:"error",message:"orderId is required in processPayment"});if(r&&r!==e)return console.error(`htech-pay: orderId mismatch. Setup orderId: "${r}", processPayment orderId: "${e}". Transaction stopped.`),t({status:"error",message:"orderId mismatch between setup and processPayment"});o.onPaymentResult=t,l({type:"htechPayment_onPayment",orderId:e})}),q=e=>new Promise(t=>{if(!e)return console.error("htech-pay: orderId is required in processPaymentToken to process the transaction."),t({status:"error",message:"orderId is required in processPaymentToken"});if(r&&r!==e)return console.error(`htech-pay: orderId mismatch. Setup orderId: "${r}", processPaymentToken orderId: "${e}". Transaction stopped.`),t({status:"error",message:"orderId mismatch between setup and processPaymentToken"});o.onPaymentResult=t,l({type:"htechPayment_onPaymentToken",orderId:e})}),U=()=>new Promise(e=>{if(u!==null){e({needCvv:u});return}o.onNeedCvv=t=>e({needCvv:t})}),_=()=>new Promise(e=>{o.onValidForm=e,l("htechPayment_onValidateForm"),setTimeout(()=>{o.onValidForm&&(delete o.onValidForm,e({status:"validation_error",message:"Unknown error"}))},600)}),S=()=>new Promise(e=>{o.onValidFormCvv=e,l("htechPayment_onValidateFormCvv"),setTimeout(()=>{o.onValidFormCvv&&(delete o.onValidFormCvv,e({status:"validation_error",message:"Unknown error"}))},600)}),V={onViewForm:()=>p==null?void 0:p(!0),onPaymentResult:e=>{var a;const t=e.data.payload||{};return(a=o.onPaymentResult)==null||a.call(o,t),delete o.onPaymentResult,y==null?void 0:y(t)},on3dsChallengeOpen:e=>(n!=="defaultUrl"&&e.isOpen&&(s.style.cssText=I),!e.isOpen&&n!=="paymentToken"&&(s.style=""),f==null?void 0:f(e.isOpen)),onProcessPayment:()=>g==null?void 0:g(!0),onValidForm:e=>{var a;const t={isValid:e.formIsValid,errors:e.errors};return(a=o.onValidForm)==null||a.call(o,t),delete o.onValidForm,t},onValidFormCvv:e=>{var a;const t={isValid:e.formIsValid,errors:e.errors};return(a=o.onValidFormCvv)==null||a.call(o,t),delete o.onValidFormCvv,t},onNeedCvv:e=>{var t;return u=e.value,(t=o.onNeedCvv)==null||t.call(o,u),delete o.onNeedCvv,v==null?void 0:v(e)},onClose:()=>(T(),k==null?void 0:k(!0)),onConfigError:()=>{console.error("htech-pay: Configuration error"),T()}},F=e=>{var a;const t=(a=e.data)==null?void 0:a.hook;!t||!V[t]||V[t](e.data)};return window.addEventListener("message",F),{mount:e=>{const t=typeof e=="string"?document.querySelector(e):e;if(!t)throw new Error("The container to mount the form could not be found");t.appendChild(s)},destroy:()=>{T()},processPayment:x,validateForm:_,verifyNeedCvv:U,processPaymentToken:q,validateFormCvv:S}}i.htechPay=c,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "htech-pay",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.5-beta",
|
|
5
5
|
"description": "Payment SDK for HtechPay",
|
|
6
6
|
"main": "dist/htechPay.umd.js",
|
|
7
7
|
"module": "dist/htechPay.mjs",
|
|
@@ -31,13 +31,21 @@
|
|
|
31
31
|
"dev": "vite",
|
|
32
32
|
"build": "vite build",
|
|
33
33
|
"preview": "vite preview",
|
|
34
|
-
"publish:npm": "npm run build && npm publish --access public --tag alpha"
|
|
34
|
+
"publish:npm": "npm run build && npm publish --access public --tag alpha",
|
|
35
|
+
"test": "vitest run",
|
|
36
|
+
"test:watch": "vitest",
|
|
37
|
+
"test:coverage": "vitest run --coverage"
|
|
35
38
|
},
|
|
36
39
|
"devDependencies": {
|
|
40
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
41
|
+
"@testing-library/react": "^16.3.2",
|
|
37
42
|
"@vitejs/plugin-react": "^4.3.1",
|
|
43
|
+
"@vitest/coverage-v8": "^4.1.5",
|
|
44
|
+
"jsdom": "^29.1.1",
|
|
38
45
|
"react": "^18.3.1",
|
|
39
46
|
"react-dom": "^18.3.1",
|
|
40
|
-
"vite": "^5.4.1"
|
|
47
|
+
"vite": "^5.4.1",
|
|
48
|
+
"vitest": "^4.1.5"
|
|
41
49
|
},
|
|
42
50
|
"dependencies": {
|
|
43
51
|
"htech-pay": "^0.1.0-beta"
|