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 CHANGED
@@ -1,151 +1,143 @@
1
1
  /*! HtechPay | MIT License */
2
- async function W(i, T = {}) {
2
+ async function _(k = {}) {
3
3
  const {
4
- environment: o = "qa",
5
- onViewForm: p,
6
- onPaymentResult: f,
7
- theme: _ = "",
8
- on3dsChallengeOpen: v,
9
- onProcessPayment: P,
10
- onNeedCvv: w,
11
- isPaymentToken: C = !1,
12
- onClose: k
13
- } = T;
14
- let { type: r } = T;
15
- const s = {
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 l = null;
22
- const U = "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 = {
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: `${s[o]}?orderId=${i}&theme=${_}`,
25
+ url: `${d}?orderId=${r}&theme=${i}`,
25
26
  height: "670",
26
27
  style: ""
27
28
  },
28
29
  widget: {
29
- url: `${s[o]}?orderId=${i}#/widget`,
30
+ url: `${d}${r ? `?orderId=${r}` : ""}#/widget`,
30
31
  height: "88",
31
32
  style: ""
32
33
  },
33
34
  paymentToken: {
34
- url: `${s[o]}?orderId=${i}&theme=${_}#/paymentToken`,
35
+ url: `${d}?orderId=${r}&theme=${i}#/paymentToken`,
35
36
  height: "530",
36
- style: U
37
+ style: T
37
38
  },
38
39
  paymentTokenWidget: {
39
- url: `${s[o]}?orderId=${i}#/widgetPaymentToken`,
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
- m[r] || (r = "defaultUrl"), r === "widget" && C && (r = "paymentTokenWidget"), r === "defaultUrl" && C && (r = "paymentToken");
45
- let d = null, u = null, c = null, h = null, g = null, y = !1, x = !1;
46
- const n = document.createElement("iframe");
47
- n.id = "iframe_htechPay", n.src = m[r].url, n.width = "100%", n.height = m[r].height, n.frameBorder = "0", n.allowFullscreen = !0, n.title = "Payment form", n.style = m[r].style;
48
- const V = () => {
49
- window.removeEventListener("message", F), n.remove();
50
- }, E = () => new Promise((e, t) => {
51
- d = e, document.getElementById("iframe_htechPay").contentWindow.postMessage(
52
- "htechPayment_onPayment",
53
- new URL(s[o]).origin
54
- ), setTimeout(() => {
55
- y || e({
56
- status: "validation_error",
57
- message: "Unknown error"
58
- });
59
- }, 600);
60
- }), I = () => new Promise((e, t) => {
61
- u = e, document.getElementById("iframe_htechPay").contentWindow.postMessage(
62
- "htechPayment_onPaymentToken",
63
- new URL(s[o]).origin
64
- ), setTimeout(() => {
65
- x || e({
66
- status: "validation_error",
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
- const t = (a) => {
72
- e({ needCvv: a });
73
- };
74
- if (l !== null) {
75
- t(l);
79
+ if (m !== null) {
80
+ e({ needCvv: m });
76
81
  return;
77
82
  }
78
- g = (a) => {
79
- t(a.needCvv);
80
- };
81
- }), L = () => new Promise((e, t) => {
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
- }), M = () => new Promise((e, t) => {
92
- h = e, document.getElementById("iframe_htechPay").contentWindow.postMessage(
93
- "htechPayment_onValidateFormCvv",
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: () => p == null ? void 0 : p(!0),
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 d && (d(t), d = null), u && (u(t), u = null), f == null ? void 0 : f(t);
97
+ return (a = o.onPaymentResult) == null || a.call(o, t), delete o.onPaymentResult, l == null ? void 0 : l(t);
106
98
  },
107
- on3dsChallengeOpen: (e) => (r !== "defaultUrl" && e.isOpen && (n.style.cssText = U), !e.isOpen && r !== "paymentToken" && (n.style = ""), v == null ? void 0 : v(e.isOpen)),
108
- onProcessPayment: () => (x = !0, y = !0, P == null ? void 0 : P(!0)),
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
- const t = {
111
- isValid: e.formIsValid,
112
- errors: e.errors
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
- const t = {
118
- isValid: e.formIsValid,
119
- errors: e.errors
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) => (l = e.value, g && (g({
124
- needCvv: l
125
- }), g = null), w == null ? void 0 : w(e)),
126
- onClose: () => (V(), k == null ? void 0 : k(!0))
127
- }, F = (e) => {
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 || !$[t] || $[t](e.data);
122
+ !t || !C[t] || C[t](e.data);
131
123
  };
132
- return window.addEventListener("message", F), {
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(n);
129
+ t.appendChild(s);
138
130
  },
139
131
  destroy: () => {
140
- V();
132
+ P();
141
133
  },
142
- processPayment: E,
143
- validateForm: L,
134
+ processPayment: F,
135
+ validateForm: q,
144
136
  verifyNeedCvv: b,
145
- processPaymentToken: I,
146
- validateFormCvv: M
137
+ processPaymentToken: x,
138
+ validateFormCvv: U
147
139
  };
148
140
  }
149
141
  export {
150
- W as htechPay
142
+ _ as htechPay
151
143
  };
@@ -1 +1 @@
1
- (function(s,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(s=typeof globalThis<"u"?globalThis:s||self,l(s.HtechPay={}))})(this,function(s){"use strict";/*! HtechPay | MIT License */async function l(m,x={}){const{environment:r="qa",onViewForm:v,onPaymentResult:P,theme:C="",on3dsChallengeOpen:w,onProcessPayment:k,onNeedCvv:T,isPaymentToken:U=!1,onClose:_}=x;let{type:o}=x;const i={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 d=null;const V="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",u={defaultUrl:{url:`${i[r]}?orderId=${m}&theme=${C}`,height:"670",style:""},widget:{url:`${i[r]}?orderId=${m}#/widget`,height:"88",style:""},paymentToken:{url:`${i[r]}?orderId=${m}&theme=${C}#/paymentToken`,height:"530",style:V},paymentTokenWidget:{url:`${i[r]}?orderId=${m}#/widgetPaymentToken`,height:"88",style:""}};u[o]||(o="defaultUrl"),o==="widget"&&U&&(o="paymentTokenWidget"),o==="defaultUrl"&&U&&(o="paymentToken");let c=null,h=null,f=null,y=null,p=null,g=!1,$=!1;const n=document.createElement("iframe");n.id="iframe_htechPay",n.src=u[o].url,n.width="100%",n.height=u[o].height,n.frameBorder="0",n.allowFullscreen=!0,n.title="Payment form",n.style=u[o].style;const b=()=>{window.removeEventListener("message",E),n.remove()},I=()=>new Promise((e,t)=>{c=e,document.getElementById("iframe_htechPay").contentWindow.postMessage("htechPayment_onPayment",new URL(i[r]).origin),setTimeout(()=>{g||e({status:"validation_error",message:"Unknown error"})},600)}),M=()=>new Promise((e,t)=>{h=e,document.getElementById("iframe_htechPay").contentWindow.postMessage("htechPayment_onPaymentToken",new URL(i[r]).origin),setTimeout(()=>{$||e({status:"validation_error",message:"Unknown error"})},600)}),j=()=>new Promise(e=>{const t=a=>{e({needCvv:a})};if(d!==null){t(d);return}p=a=>{t(a.needCvv)}}),L=()=>new Promise((e,t)=>{f=e,document.getElementById("iframe_htechPay").contentWindow.postMessage("htechPayment_onValidateForm",new URL(i[r]).origin),setTimeout(()=>{g||e({status:"validation_error",message:"Unknown error"})},600)}),S=()=>new Promise((e,t)=>{y=e,document.getElementById("iframe_htechPay").contentWindow.postMessage("htechPayment_onValidateFormCvv",new URL(i[r]).origin),setTimeout(()=>{g||e({status:"validation_error",message:"Unknown error"})},600)}),F={onViewForm:()=>v==null?void 0:v(!0),onPaymentResult:e=>{const t=e.data.payload||{};return c&&(c(t),c=null),h&&(h(t),h=null),P==null?void 0:P(t)},on3dsChallengeOpen:e=>(o!=="defaultUrl"&&e.isOpen&&(n.style.cssText=V),!e.isOpen&&o!=="paymentToken"&&(n.style=""),w==null?void 0:w(e.isOpen)),onProcessPayment:()=>($=!0,g=!0,k==null?void 0:k(!0)),onValidForm:e=>{const t={isValid:e.formIsValid,errors:e.errors};return f&&(f(t),f=null),t},onValidFormCvv:e=>{const t={isValid:e.formIsValid,errors:e.errors};return y&&(y(t),y=null),t},onNeedCvv:e=>(d=e.value,p&&(p({needCvv:d}),p=null),T==null?void 0:T(e)),onClose:()=>(b(),_==null?void 0:_(!0))},E=e=>{var a;const t=(a=e.data)==null?void 0:a.hook;!t||!F[t]||F[t](e.data)};return window.addEventListener("message",E),{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(n)},destroy:()=>{b()},processPayment:I,validateForm:L,verifyNeedCvv:j,processPaymentToken:M,validateFormCvv:S}}s.htechPay=l,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
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.1-beta",
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"