htech-pay 1.0.4 → 1.0.6

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,37 +1,154 @@
1
1
  /*! HtechPay | MIT License */
2
- async function f(c, h = {}) {
2
+ async function W(i, C = {}) {
3
3
  const {
4
- environment: d = "qa",
5
- isPaymentWithToken: i = !1,
6
- onViewForm: n,
7
- onPaymentResult: a,
8
- theme: u = ""
9
- } = h, l = `${{
4
+ environment: o = "qa",
5
+ onViewForm: p,
6
+ onPaymentResult: f,
7
+ theme: _ = "",
8
+ on3dsChallengeOpen: v,
9
+ onProcessPayment: P,
10
+ onNeedCvv: w,
11
+ isPaymentToken: U = !1,
12
+ onClose: k
13
+ } = C;
14
+ let { type: r } = C;
15
+ const a = {
16
+ //qa: "http://localhost:5173",
10
17
  qa: "https://sp-checkout-qa.pagoshtechstage.com/index.html",
11
18
  stage: "https://sp-checkout-stage.pagoshtechstage.com/index.html",
12
- prod: ""
13
- }[d]}?orderId=${c}&theme=${u}${i ? "#/paymentToken" : ""}`, e = document.createElement("iframe");
14
- e.src = l, e.width = "100%", e.height = "635", e.frameBorder = "0", e.allowFullscreen = !0, e.title = "Payment form";
15
- const r = {
16
- onViewForm: () => n == null ? void 0 : n(!0),
17
- onPaymentResult: (t) => a == null ? void 0 : a(t.data.payload || {})
18
- }, s = (t) => {
19
- var m;
20
- const o = (m = t.data) == null ? void 0 : m.hook;
21
- !o || !r[o] || r[o](t.data);
19
+ prod: "https://sp-checkout.pagoshtech.com/index.html"
22
20
  };
23
- return window.addEventListener("message", s), {
24
- mount: (t) => {
25
- const o = typeof t == "string" ? document.querySelector(t) : t;
26
- if (!o)
21
+ let l = null;
22
+ const x = "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 = {
23
+ defaultUrl: {
24
+ url: `${a[o]}?orderId=${i}&theme=${_}`,
25
+ height: "670",
26
+ style: ""
27
+ },
28
+ widget: {
29
+ url: `${a[o]}?orderId=${i}#/widget`,
30
+ height: "88",
31
+ style: ""
32
+ },
33
+ paymentToken: {
34
+ url: `${a[o]}?orderId=${i}&theme=${_}#/paymentToken`,
35
+ height: "530",
36
+ style: x
37
+ },
38
+ paymentTokenWidget: {
39
+ url: `${a[o]}?orderId=${i}#/widgetPaymentToken`,
40
+ height: "88",
41
+ style: ""
42
+ }
43
+ };
44
+ m[r] || (r = "defaultUrl"), r === "widget" && U && (r = "paymentTokenWidget"), r === "defaultUrl" && U && (r = "paymentToken");
45
+ let d = null, u = null, c = null, h = null, g = null, y = !1, V = !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 T = () => {
49
+ window.removeEventListener("message", E), n.remove();
50
+ }, F = () => new Promise((e, t) => {
51
+ d = e, document.getElementById("iframe_htechPay").contentWindow.postMessage(
52
+ "htechPayment_onPayment",
53
+ new URL(a[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(a[o]).origin
64
+ ), setTimeout(() => {
65
+ V || e({
66
+ status: "validation_error",
67
+ message: "Unknown error"
68
+ });
69
+ }, 600);
70
+ }), b = () => new Promise((e) => {
71
+ const t = (s) => {
72
+ e({ needCvv: s });
73
+ };
74
+ if (l !== null) {
75
+ t(l);
76
+ return;
77
+ }
78
+ g = (s) => {
79
+ t(s.needCvv);
80
+ };
81
+ }), L = () => new Promise((e, t) => {
82
+ c = e, document.getElementById("iframe_htechPay").contentWindow.postMessage(
83
+ "htechPayment_onValidateForm",
84
+ new URL(a[o]).origin
85
+ ), setTimeout(() => {
86
+ y || e({
87
+ status: "validation_error",
88
+ message: "Unknown error"
89
+ });
90
+ }, 600);
91
+ }), M = () => new Promise((e, t) => {
92
+ h = e, document.getElementById("iframe_htechPay").contentWindow.postMessage(
93
+ "htechPayment_onValidateFormCvv",
94
+ new URL(a[o]).origin
95
+ ), setTimeout(() => {
96
+ y || e({
97
+ status: "validation_error",
98
+ message: "Unknown error"
99
+ });
100
+ }, 600);
101
+ }), $ = {
102
+ onViewForm: () => p == null ? void 0 : p(!0),
103
+ onPaymentResult: (e) => {
104
+ const t = e.data.payload || {};
105
+ return d && (d(t), d = null), u && (u(t), u = null), f == null ? void 0 : f(t);
106
+ },
107
+ on3dsChallengeOpen: (e) => (r !== "defaultUrl" && e.isOpen && (n.style.cssText = x), !e.isOpen && r !== "paymentToken" && (n.style = ""), v == null ? void 0 : v(e.isOpen)),
108
+ onProcessPayment: () => (V = !0, y = !0, P == null ? void 0 : P(!0)),
109
+ onValidForm: (e) => {
110
+ const t = {
111
+ isValid: e.formIsValid,
112
+ errors: e.errors
113
+ };
114
+ return c && (c(t), c = null), t;
115
+ },
116
+ onValidFormCvv: (e) => {
117
+ const t = {
118
+ isValid: e.formIsValid,
119
+ errors: e.errors
120
+ };
121
+ return h && (h(t), h = null), t;
122
+ },
123
+ onNeedCvv: (e) => (l = e.value, g && (g({
124
+ needCvv: l
125
+ }), g = null), w == null ? void 0 : w(e)),
126
+ onClose: () => (T(), k == null ? void 0 : k(!0)),
127
+ onConfigError: () => {
128
+ console.error("htech-pay: Configuration error"), T();
129
+ }
130
+ }, E = (e) => {
131
+ var s;
132
+ const t = (s = e.data) == null ? void 0 : s.hook;
133
+ !t || !$[t] || $[t](e.data);
134
+ };
135
+ return window.addEventListener("message", E), {
136
+ mount: (e) => {
137
+ const t = typeof e == "string" ? document.querySelector(e) : e;
138
+ if (!t)
27
139
  throw new Error("The container to mount the form could not be found");
28
- o.appendChild(e);
140
+ t.appendChild(n);
29
141
  },
30
142
  destroy: () => {
31
- window.removeEventListener("message", s), e.remove();
32
- }
143
+ T();
144
+ },
145
+ processPayment: F,
146
+ validateForm: L,
147
+ verifyNeedCvv: b,
148
+ processPaymentToken: I,
149
+ validateFormCvv: M
33
150
  };
34
151
  }
35
152
  export {
36
- f as htechPay
153
+ W as htechPay
37
154
  };
@@ -1 +1 @@
1
- (function(n,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(n=typeof globalThis<"u"?globalThis:n||self,s(n.HtechPay={}))})(this,function(n){"use strict";/*! HtechPay | MIT License */async function s(h,m={}){const{environment:u="qa",isPaymentWithToken:f=!1,onViewForm:a,onPaymentResult:r,theme:l=""}=m,p=`${{qa:"https://sp-checkout-qa.pagoshtechstage.com/index.html",stage:"https://sp-checkout-stage.pagoshtechstage.com/index.html",prod:""}[u]}?orderId=${h}&theme=${l}${f?"#/paymentToken":""}`,e=document.createElement("iframe");e.src=p,e.width="100%",e.height="635",e.frameBorder="0",e.allowFullscreen=!0,e.title="Payment form";const i={onViewForm:()=>a==null?void 0:a(!0),onPaymentResult:t=>r==null?void 0:r(t.data.payload||{})},d=t=>{var c;const o=(c=t.data)==null?void 0:c.hook;!o||!i[o]||i[o](t.data)};return window.addEventListener("message",d),{mount:t=>{const o=typeof t=="string"?document.querySelector(t):t;if(!o)throw new Error("The container to mount the form could not be found");o.appendChild(e)},destroy:()=>{window.removeEventListener("message",d),e.remove()}}}n.htechPay=s,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
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:U="",on3dsChallengeOpen:w,onProcessPayment:k,onNeedCvv:T,isPaymentToken:V=!1,onClose:C}=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 $="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=${U}`,height:"670",style:""},widget:{url:`${i[r]}?orderId=${m}#/widget`,height:"88",style:""},paymentToken:{url:`${i[r]}?orderId=${m}&theme=${U}#/paymentToken`,height:"530",style:$},paymentTokenWidget:{url:`${i[r]}?orderId=${m}#/widgetPaymentToken`,height:"88",style:""}};u[o]||(o="defaultUrl"),o==="widget"&&V&&(o="paymentTokenWidget"),o==="defaultUrl"&&V&&(o="paymentToken");let c=null,h=null,f=null,y=null,p=null,g=!1,b=!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 _=()=>{window.removeEventListener("message",F),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(()=>{b||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)}),E={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=$),!e.isOpen&&o!=="paymentToken"&&(n.style=""),w==null?void 0:w(e.isOpen)),onProcessPayment:()=>(b=!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:()=>(_(),C==null?void 0:C(!0)),onConfigError:()=>{console.error("htech-pay: Configuration error"),_()}},F=e=>{var a;const t=(a=e.data)==null?void 0:a.hook;!t||!E[t]||E[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(n)},destroy:()=>{_()},processPayment:I,validateForm:L,verifyNeedCvv:j,processPaymentToken:M,validateFormCvv:S}}s.htechPay=l,Object.defineProperty(s,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": "1.0.4",
4
+ "version": "1.0.6",
5
5
  "description": "Payment SDK for HtechPay",
6
6
  "main": "dist/htechPay.umd.js",
7
7
  "module": "dist/htechPay.mjs",
@@ -38,5 +38,8 @@
38
38
  "react": "^18.3.1",
39
39
  "react-dom": "^18.3.1",
40
40
  "vite": "^5.4.1"
41
+ },
42
+ "dependencies": {
43
+ "htech-pay": "^0.1.0-beta"
41
44
  }
42
45
  }