@payfurl/react-plugin 1.5.0 → 1.6.0

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.
Files changed (27) hide show
  1. package/README.md +11 -0
  2. package/dist/DefaultThreeDsProvider-BS9pznAi-fDl8jKzq.js +248 -0
  3. package/dist/{MetricsGlobalThreeDsProvider-C93ttqbB-SRsVMed4.js → MetricsGlobalThreeDsProvider-C2mH6Z-m-BTiFsRgv.js} +27 -27
  4. package/dist/PayWayAppleButton-BcXMphiU-BwJKfUAJ.js +184 -0
  5. package/dist/{cxpay-DblHb5vN-C-l0lncv.js → cxpay-Bdz9DX5E-9-_yu7t4.js} +1 -1
  6. package/dist/{default-C7f86Fx--2njdEIN4.js → default-CmqRUII8-B6Im_IPh.js} +1 -1
  7. package/dist/{ecentric-B3UohyO_-XSxfe46h.js → ecentric-CZzDL4aQ-BRg09Y8f.js} +26 -23
  8. package/dist/{epna-DwUg2IlB-60mxqUE4.js → epna-A5WIS8Rv-DhjWr-Wx.js} +1 -1
  9. package/dist/{flashbanc-LXs8bahL-z2X9avF_.js → flashbanc-BnKR75SO-BStfAWAb.js} +1 -1
  10. package/dist/{forter-CLFaJUYa-0_gstIhb.js → forter-DtCvNxaz-D5SEPByD.js} +7 -7
  11. package/dist/{gpayments-DoZug3PV-r91JBiIn.js → gpayments-C98_oxi_-D02_MfHY.js} +20 -20
  12. package/dist/index-CqIxTjar.js +12169 -0
  13. package/dist/metrics_global-c4lRSySk-WxebdZ3j.js +7 -0
  14. package/dist/{nmi-BA3ZTdQa-DHWaU-52.js → nmi-CrPg94-y-Bco-VeX9.js} +1 -1
  15. package/dist/{nuvei-DIWsLlLz-Dnx1Hmez.js → nuvei-8V5Z1Bqi-7VHagYOe.js} +31 -32
  16. package/dist/{payabli-DgrTI1Et-aNWdpC9M.js → payabli-CAvI6xn--Nz5dJc0q.js} +1 -1
  17. package/dist/payfurl-react.es.js +1 -1
  18. package/dist/payfurl-react.umd.js +24 -22
  19. package/dist/payglocal-BcbX7wj--Dd68qYZO.js +114 -0
  20. package/dist/{payway_rest-D8-T-ULx-Dt-XGc-v.js → payway_rest-Det6oVYM-BzfFo5sS.js} +1 -1
  21. package/dist/{skybank-BgDLlFXX-BnauHbzw.js → skybank-CldRW65N-BFprFe0k.js} +1 -1
  22. package/package.json +2 -2
  23. package/dist/DefaultThreeDsProvider-bLoDSnkd-CuWxvLku.js +0 -220
  24. package/dist/PayWayAppleButton-BzAwlGS--DB5BVl1o.js +0 -163
  25. package/dist/index-DxOlzt-Z.js +0 -11576
  26. package/dist/metrics_global-BM-ooge--CapUrY7a.js +0 -7
  27. package/dist/payglocal-ezp0MsaZ-CA7TeuKm.js +0 -109
@@ -0,0 +1,114 @@
1
+ import { O as C } from "./DefaultThreeDsProvider-BS9pznAi-fDl8jKzq.js";
2
+ import { j as u, q as f, i as E, u as S, e as L, b as D, U as R, a as v, y, t as b, X as d, z as k, k as m, c as I, l as U } from "./index-CqIxTjar.js";
3
+ var h = D(!1);
4
+ function A(e, ...t) {
5
+ h.value && console.log(m(e), m(t));
6
+ }
7
+ function p(e) {
8
+ var t, s;
9
+ (t = e == null ? void 0 : e.data) != null && t.status && e.data.status === "init-card-form" && (h.value = !!((s = e == null ? void 0 : e.data) != null && s.debug));
10
+ }
11
+ function _() {
12
+ return v(() => {
13
+ window.addEventListener("message", p);
14
+ }), y(() => {
15
+ window.removeEventListener("message", p);
16
+ }), {
17
+ debug: h,
18
+ logMessage: A
19
+ };
20
+ }
21
+ var x = { class: "modal-mask" }, M = { class: "modal-wrapper" }, G = ["src"], O = /* @__PURE__ */ S(/* @__PURE__ */ L({
22
+ __name: "PayGLocalThreeDsChallenge",
23
+ props: { url: {} },
24
+ emits: ["close"],
25
+ setup(e, { emit: t }) {
26
+ let { logMessage: s } = _(), r = e, n = t, o = D(r.url), i = k(() => U(o.value) ? o.value : "");
27
+ R(() => r.url, (a) => {
28
+ o.value = a;
29
+ }), v(() => {
30
+ window.addEventListener("message", c);
31
+ }), y(() => {
32
+ window.removeEventListener("message", c);
33
+ });
34
+ function c(a) {
35
+ var g;
36
+ if (s("PayGLocalThreeDsChallenge: Message received", a.data), !((g = a == null ? void 0 : a.data) != null && g["payglocal-token"])) return;
37
+ let l = a.data["payglocal-token"];
38
+ s("Token received", l);
39
+ let T = l.split(".")[1], w = window.atob(T), P = JSON.parse(w);
40
+ n("close", P);
41
+ }
42
+ return (a, l) => (I(), b("div", x, [d("div", M, [d("iframe", {
43
+ src: i.value,
44
+ sandbox: "allow-same-origin allow-scripts allow-popups allow-forms"
45
+ }, null, 8, G)])]));
46
+ }
47
+ }), [["__scopeId", "data-v-9fa1282d"]]), $ = class extends C {
48
+ getType() {
49
+ return "PayGLocal";
50
+ }
51
+ onPreAuth() {
52
+ var e, t;
53
+ this.log(`[${this.getType()}]: onPreAuth`), (e = this.threeDsProcessor) != null && e.getTokenId() ? this.threeDsProcessor.getGatewayData(this.threeDsProcessor.getProviderId(), this.threeDsProcessor.getTokenId(), (s) => {
54
+ var r;
55
+ return this.initChallenge(((r = s.gatewayMetadata) == null ? void 0 : r.RedirectUrl) || "");
56
+ }, () => {
57
+ var s;
58
+ return (s = this.threeDsProcessor) == null ? void 0 : s.onError({ error: "Unable to get card information" });
59
+ }) : (t = this.threeDsProcessor) == null || t.tokeniseCard(this.threeDsProcessor.getProviderId(), (s) => {
60
+ this.log(`[${this.getType()}]: tokeniseCard`, s), this.initChallenge(s.gatewayTokenData.RedirectUrl);
61
+ }, (s) => {
62
+ var r;
63
+ u(this.container, s), (r = this.threeDsProcessor) == null || r.onError({ error: s });
64
+ });
65
+ }
66
+ onAuth(e, t) {
67
+ }
68
+ onPostAuth() {
69
+ }
70
+ initChallenge(e) {
71
+ var s;
72
+ if (this.log(`[${this.getType()}]: initChallenge`, e), !e) {
73
+ u(this.container, "3D Secure URL is missing"), (s = this.threeDsProcessor) == null || s.onError({ error: "3D Secure URL is missing" });
74
+ return;
75
+ }
76
+ this.setChallengeFrameVisible(!0);
77
+ let { destroy: t } = f({
78
+ el: document.body,
79
+ component: O,
80
+ props: { url: e },
81
+ on: { close: (r) => {
82
+ var n, o, i;
83
+ this.closeChallenge(), this.log(`[${this.getType()}]: Challenge Results`, r), r.status === "AUTHORIZED" ? (n = this.threeDsProcessor) == null || n.onSuccess({
84
+ acsRenderingType: {},
85
+ acsTransID: "",
86
+ authenticationType: "",
87
+ authenticationValue: "",
88
+ challengeCancel: "",
89
+ dsTransID: "",
90
+ eci: "",
91
+ interactionCounter: "",
92
+ messageCategory: "",
93
+ messageExtension: [],
94
+ messageType: "",
95
+ messageVersion: "",
96
+ threeDSRequestorTransID: "",
97
+ threeDSServerTransID: "",
98
+ transStatusReason: "",
99
+ transStatus: "Y"
100
+ }) : r.status === "CUSTOMER_CANCELLED" ? (o = this.threeDsProcessor) == null || o.onError({
101
+ error: "Challenge cancelled",
102
+ cancelReason: "abandoned"
103
+ }) : (i = this.threeDsProcessor) == null || i.onError({ error: E });
104
+ } }
105
+ });
106
+ this.threeDSDestroy = t;
107
+ }
108
+ };
109
+ function z(e, t, s) {
110
+ return new $(e, t, s);
111
+ }
112
+ export {
113
+ z as default
114
+ };
@@ -1,4 +1,4 @@
1
- import { PayWayAppleButton as p } from "./PayWayAppleButton-BzAwlGS--DB5BVl1o.js";
1
+ import { PayWayAppleButton as p } from "./PayWayAppleButton-BcXMphiU-BwJKfUAJ.js";
2
2
  function f(t, a, e, n, o, r) {
3
3
  return new p(t, a, e, n, o, r);
4
4
  }
@@ -1,4 +1,4 @@
1
- import { w as r } from "./MetricsGlobalThreeDsProvider-C93ttqbB-SRsVMed4.js";
1
+ import { w as r } from "./MetricsGlobalThreeDsProvider-C2mH6Z-m-BTiFsRgv.js";
2
2
  var a = class extends r {
3
3
  getType() {
4
4
  return "SkyBank";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@payfurl/react-plugin",
3
3
  "private": false,
4
- "version": "1.5.0",
4
+ "version": "1.6.0",
5
5
  "description": "PayFURL React Plugin",
6
6
  "type": "module",
7
7
  "files": [
@@ -26,7 +26,7 @@
26
26
  "lint": "eslint . --max-warnings 0"
27
27
  },
28
28
  "dependencies": {
29
- "@payfurl/client": "^4.11.0"
29
+ "@payfurl/client": "^4.12.0"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "react": "^18.3.1",
@@ -1,220 +0,0 @@
1
- var S = Object.defineProperty;
2
- var g = (t, s, e) => s in t ? S(t, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[s] = e;
3
- var r = (t, s, e) => g(t, typeof s != "symbol" ? s + "" : s, e);
4
- import { t as p, A as m, W as T, i as u, h as I, s as v, Z as f, a as y, Q as A, X as l, b as C, g as R, e as P, I as U, c as b, q as w, o as E } from "./index-DxOlzt-Z.js";
5
- var $ = { class: "mask" }, M = { class: "wrapper" }, L = { class: "container" }, k = ["action"], q = ["value"], V = /* @__PURE__ */ v(/* @__PURE__ */ f({
6
- __name: "ThreeDsChallenge",
7
- props: {
8
- threeDSServerTransID: {},
9
- acsTransID: {},
10
- formAction: {}
11
- },
12
- emits: ["close", "submit"],
13
- setup(t, { emit: s }) {
14
- let e = t, a = s, o = U(() => E(e.formAction) ? e.formAction : ""), n = b(null), c = JSON.stringify({
15
- threeDSServerTransID: e.threeDSServerTransID,
16
- acsTransID: e.acsTransID,
17
- messageVersion: "2.2.0",
18
- messageType: "CReq",
19
- challengeWindowSize: "01"
20
- }), D = encodeURI(window.btoa(c).replace(/=*$/, ""));
21
- return y(() => {
22
- var i;
23
- o.value && ((i = n.value) == null || i.submit());
24
- }), (i, h) => (w(), A("div", $, [l("div", M, [l("div", L, [
25
- C(R, {
26
- onClick: h[0] || (h[0] = (N) => a("close")),
27
- id: "3ds-challenge-close"
28
- }),
29
- h[1] || (h[1] = l("iframe", { name: "ThreeDsChallengeIFrame" }, null, -1)),
30
- l("form", {
31
- action: o.value,
32
- target: "ThreeDsChallengeIFrame",
33
- method: "post",
34
- ref_key: "form",
35
- ref: n
36
- }, [l("input", {
37
- type: "hidden",
38
- name: "creq",
39
- value: P(D)
40
- }, null, 8, q)], 8, k)
41
- ])])]));
42
- }
43
- }), [["__scopeId", "data-v-07081e85"]]), _ = class {
44
- constructor() {
45
- r(this, "iframeId", "threeDsIframeMethod");
46
- r(this, "containerId", "payfurlContainerFormInvoker");
47
- r(this, "iframe", null);
48
- r(this, "container", null);
49
- }
50
- createIFrame() {
51
- this.iframe || (this.container = document.createElement("div"), this.container.id = this.containerId, document.body.appendChild(this.container), this.iframe = document.createElement("iframe"), this.iframe.name = this.iframeId, this.iframe.style.display = "none", this.container.appendChild(this.iframe));
52
- }
53
- invoke(t, s, e, a, o) {
54
- var c;
55
- this.createIFrame();
56
- let n = document.createElement("form");
57
- n.action = t, n.target = this.iframeId, n.method = "post", (c = this.container) == null || c.appendChild(n);
58
- for (let D in e) {
59
- let i = document.createElement("input");
60
- i.type = "hidden", i.name = D, i.value = e[D], n.appendChild(i);
61
- }
62
- n.submit();
63
- }
64
- }, { hideSpinner: d, showSpinner: F } = I(), H = class {
65
- constructor(t, s, e) {
66
- r(this, "log");
67
- r(this, "container");
68
- r(this, "options");
69
- r(this, "threeDsProcessor", null);
70
- r(this, "threeDSDestroy", () => {
71
- });
72
- r(this, "threeDSServerTransID", "");
73
- r(this, "threeDSAuthURL", "");
74
- r(this, "threeDSRequestorTransID", "");
75
- r(this, "threeDSMonitorURL", "");
76
- r(this, "internalMessageHandler", this.messageHandler.bind(this));
77
- r(this, "onError", (t, s) => {
78
- var e, a;
79
- this.closeChallenge(), d(), t === 404 ? (e = this.threeDsProcessor) == null || e.onError({ error: "This feature is only supported by ActiveServer v1.1.2+" }) : (a = this.threeDsProcessor) == null || a.onError({
80
- error: u,
81
- body: s
82
- });
83
- });
84
- r(this, "onSuccess", (t, s) => {
85
- var a, o;
86
- this.closeChallenge(), d();
87
- let e = JSON.parse(s);
88
- ["Y", "A"].includes(e.transStatus) ? (a = this.threeDsProcessor) == null || a.onSuccess(e) : (this.log(`[${this.getType()}]: ${u}`, e), (o = this.threeDsProcessor) == null || o.onError({ error: u }));
89
- });
90
- r(this, "onInitAuthSuccess", (t, s) => {
91
- let e = JSON.parse(s);
92
- this.log(`[${this.getType()}][onInitAuthSuccess]`, e), this.threeDSRequestorTransID = e.threeDSRequestorTransID, this.threeDSServerTransID = e.threeDSServerTransID, this.threeDSMonitorURL = e.threeDSMonitorURL, this.threeDSAuthURL = e.threeDSAuthURL, e.threeDSMethodURL ? this.threeDsMethodInvoke(e.threeDSServerTransID, e.threeDSMethodURL) : this.onAuth(!1, "");
93
- });
94
- r(this, "onDoAuthSuccess", (t, s) => {
95
- var a;
96
- let e = JSON.parse(s);
97
- if (this.log(`[${this.getType()}][onDoAuthSuccess]`, e), !e.transStatus) this.onError(t, "No transStatus specified");
98
- else switch (e.transStatus) {
99
- case "C":
100
- if (!e.acsURL) {
101
- this.onError(t, "Invalid Challenge Url");
102
- return;
103
- }
104
- this.doChallenge(e.acsURL, e.acsTransID, e.authenticationValue);
105
- break;
106
- case "N":
107
- this.log(`[${this.getType()}][threeDsAuth], 3DS Verification failed, transaction denied`), this.onError(400, "3DS Verification failed, transaction denied");
108
- break;
109
- case "U":
110
- this.log(`[${this.getType()}][threeDsAuth], Unable to perform 3DS verification`), this.onError(400, "Unable to perform 3DS verification");
111
- break;
112
- case "R":
113
- this.log(`[${this.getType()}][threeDsAuth], Unable to perform 3DS verification, rejected at issuer`), this.onError(400, "Unable to perform 3DS verification, rejected at issuer");
114
- break;
115
- default:
116
- this.log(`[${this.getType()}][threeDsAuth], 3DS challenge not required, tranStatus: ${e.transStatus}`), (a = this.threeDsProcessor) == null || a.onSuccess({
117
- threeDSServerTransID: e.threeDSServerTransID,
118
- threeDSRequestorTransID: "",
119
- acsRenderingType: e.acsRenderingType,
120
- acsTransID: e.acsTransID,
121
- authenticationType: e.authenticationType,
122
- authenticationValue: e.authenticationValue,
123
- challengeCancel: "",
124
- dsTransID: e.dsTransID,
125
- eci: e.eci,
126
- interactionCounter: "",
127
- messageCategory: "",
128
- messageExtension: e.messageExtension,
129
- messageType: e.messageType,
130
- messageVersion: e.messageVersion,
131
- transStatus: e.transStatus,
132
- transStatusReason: e.transStatusReason
133
- });
134
- }
135
- });
136
- this.log = t, this.container = s, this.options = e;
137
- }
138
- getType() {
139
- return "Default";
140
- }
141
- getDomain() {
142
- return "";
143
- }
144
- onPreAuth() {
145
- this.log(`[${this.getType()}][onPreAuth]`), this.threeDsProcessor && (F(), this.threeDsProcessor.onPreAuth(this.onInitAuthSuccess, this.onError), window.addEventListener("message", this.internalMessageHandler));
146
- }
147
- onAuth(t, s) {
148
- var e;
149
- this.log(`[${this.getType()}][onAuth]`, {
150
- threeDSAuthURL: this.threeDSAuthURL,
151
- threeDSRequestorTransID: this.threeDSRequestorTransID,
152
- threeDSServerTransID: this.threeDSServerTransID,
153
- isMethodPerformed: t
154
- }), (e = this.threeDsProcessor) == null || e.onAuth(this.threeDSAuthURL, this.threeDSRequestorTransID, this.threeDSServerTransID, t, s, this.onDoAuthSuccess, this.onError);
155
- }
156
- onPostAuth() {
157
- var t;
158
- this.log(`[${this.getType()}][onPostAuth]`, { threeDSServerTransID: this.threeDSServerTransID }), (t = this.threeDsProcessor) == null || t.onPostAuth({ threeDSServerTransID: this.threeDSServerTransID }, this.onSuccess, this.onError);
159
- }
160
- setThreeDsProcessor(t) {
161
- this.log(`[${this.getType()}][setThreeDsProcessor]`), this.threeDsProcessor = t;
162
- }
163
- messageHandler(t) {
164
- var s, e;
165
- (s = t == null ? void 0 : t.data) != null && s.status && ((e = t == null ? void 0 : t.data) == null ? void 0 : e.status) !== "tokenise-card-failure" && (t.data.status === "3ds_method_invocation_complete" ? (t.stopPropagation(), this.invocationComplete(t)) : t.data.status === "3ds_challenge_complete" && (t.stopPropagation(), this.challengeComplete(t)));
166
- }
167
- invocationComplete(t) {
168
- this.log(`[${this.getType()}]: 3Ds Method invocation complete`), this.onAuth(!0, "");
169
- }
170
- challengeComplete(t) {
171
- this.log(`[${this.getType()}]: 3Ds Challenge complete`, t.data), this.closeChallenge();
172
- let s = JSON.parse(window.atob(t.data.cres));
173
- this.log(`[${this.getType()}]: cresData`, s), ["Y", "A"].includes(s.transStatus) ? this.onPostAuth() : [
174
- "N",
175
- "U",
176
- "R"
177
- ].includes(s.transStatus) && (this.log(`[${this.getType()}]: Failed 3DS Challenge`, t.data), this.onError(400, "Failed 3DS Challenge"));
178
- }
179
- setChallengeFrameVisible(t) {
180
- var s;
181
- t && ((s = this.threeDsProcessor) == null || s.challengeShown()), window.self !== window.top && window.parent.postMessage({ status: t ? p : m }, "*");
182
- }
183
- doChallenge(t, s, e) {
184
- this.log(`[${this.getType()}][doChallenge]`), d(), this.setChallengeFrameVisible(!0);
185
- let { destroy: a } = T({
186
- el: document.body,
187
- component: V,
188
- props: {
189
- threeDSServerTransID: this.threeDSServerTransID,
190
- acsTransID: s,
191
- formAction: t,
192
- authenticationValue: e
193
- },
194
- on: { close: () => {
195
- var o;
196
- a(), this.threeDSDestroy = () => {
197
- }, (o = this.threeDsProcessor) == null || o.onError({ error: "Challenge cancelled" });
198
- } }
199
- });
200
- this.threeDSDestroy = a;
201
- }
202
- closeChallenge() {
203
- var t;
204
- (t = this.threeDSDestroy) == null || t.call(this), this.setChallengeFrameVisible(!1), window.removeEventListener("message", this.internalMessageHandler);
205
- }
206
- threeDsMethodInvoke(t, s) {
207
- this.log(`[${this.getType()}][threeDsMethodInvoke]`, {
208
- threeDSServerTransID: t,
209
- threeDSMethodURL: s
210
- });
211
- let e = {
212
- threeDSServerTransID: t,
213
- threeDSMethodNotificationURL: this.options.apiUrl + "/3ds/method_invocation"
214
- }, a = encodeURI(window.btoa(JSON.stringify(e)).replace(/=*$/, ""));
215
- new _().invoke(s, "POST", { threeDSMethodData: a });
216
- }
217
- };
218
- export {
219
- H as O
220
- };
@@ -1,163 +0,0 @@
1
- var m = Object.defineProperty;
2
- var g = (t, e, r) => e in t ? m(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
- var i = (t, e, r) => g(t, typeof e != "symbol" ? e + "" : e, r);
4
- import { f as b, m as A, l as v } from "./index-DxOlzt-Z.js";
5
- var l = {
6
- CHECKOUT: "CHECKOUT",
7
- CHARGE: "CHARGE"
8
- }, p = (t) => ({
9
- [l.CHECKOUT]: {
10
- url: t + "/payment_method/checkout",
11
- method: "POST"
12
- },
13
- [l.CHARGE]: {
14
- url: t + "/charge/checkout",
15
- method: "POST"
16
- }
17
- }), k = class {
18
- constructor(t, e, r, a, o, s) {
19
- i(this, "log");
20
- i(this, "container");
21
- i(this, "button", null);
22
- i(this, "validator", null);
23
- i(this, "validationError", null);
24
- i(this, "providerId");
25
- i(this, "apiUrl");
26
- i(this, "amount");
27
- i(this, "currency");
28
- i(this, "clientParameters");
29
- i(this, "billingAddress", null);
30
- i(this, "customer", null);
31
- i(this, "order", null);
32
- i(this, "buttonId", "apple-pay-payway-button");
33
- i(this, "validatorId", "apple-pay-payway-button-validator");
34
- i(this, "onLoad", () => {
35
- });
36
- i(this, "onSuccess");
37
- i(this, "onFailure");
38
- i(this, "userOnValidate");
39
- i(this, "httpInvoker", null);
40
- this.log = t, this.apiUrl = s.apiUrl, this.container = e || document.body, this.clientParameters = s.clientParameters, this.providerId = s.providerId, this.amount = Number(a), this.currency = o, this.providerId = r, this.onSuccess = s.onSuccess || null, this.onFailure = s.onFailure || null, this.userOnValidate = s.onValidate;
41
- let c = new b(s.environment, A(s.publicKey));
42
- this.httpInvoker = new v(s.publicKey, s.version, c), this.init(), setInterval(() => {
43
- var d;
44
- this.validator && (((d = this.userOnValidate) == null ? void 0 : d.call(this)) === !1 ? this.validator.style.display = "block" : (this.validator.style.display = "none", this.validationError && (this.validationError.style.display = "none")));
45
- }, 1e3);
46
- }
47
- draw() {
48
- let t = () => {
49
- this.onLoad = () => {
50
- };
51
- let e = {
52
- container: this.buttonId,
53
- publishableApiKey: this.clientParameters.PublishableApiKey,
54
- principalAmount: this.amount,
55
- currency: String(this.currency).toLowerCase(),
56
- buttonMode: "callback"
57
- };
58
- this.log("[createPaymentRequestButton]", e), window.payway.createPaymentRequestButton(e, (r, a) => {
59
- var o;
60
- this.log("[createPaymentRequestButton]", r, a), r ? (o = this.onFailure) == null || o.call(this, r) : this.checkout(a.singleUseTokenId);
61
- }), this.addValidator();
62
- };
63
- window.payway ? t() : this.onLoad = t;
64
- }
65
- show() {
66
- this.button && (this.button.style.display = "block");
67
- }
68
- hide() {
69
- this.button && (this.button.style.display = "none");
70
- }
71
- init() {
72
- let t = document.createElement("div");
73
- t.id = this.buttonId, t.style.position = "relative", this.container.appendChild(t), this.button = t, this.initScript();
74
- }
75
- addValidator() {
76
- var e;
77
- if (document.getElementById(this.validatorId)) return;
78
- let t = document.createElement("div");
79
- t.id = this.validatorId, t.style.width = "100%", t.style.height = "100%", t.style.position = "absolute", t.style.top = "0", t.style.left = "0", t.style.display = "none", (e = this.button) == null || e.appendChild(t), this.validator = t;
80
- }
81
- initScript() {
82
- let t = document.createElement("script");
83
- t.src = "https://api.payway.com.au/rest/v1/payway.js", t.onload = () => {
84
- this.onLoad && this.onLoad();
85
- }, document.head.appendChild(t);
86
- }
87
- checkout(t) {
88
- var r, a, o, s, c, d;
89
- let e = {
90
- providerId: this.providerId,
91
- amount: this.amount,
92
- currency: this.currency,
93
- reference: (r = this.order) == null ? void 0 : r.orderNumber,
94
- options: { ProviderToken: t },
95
- customer: {
96
- firstName: (a = this.customer) == null ? void 0 : a.firstName,
97
- lastName: (o = this.customer) == null ? void 0 : o.lastName,
98
- email: (s = this.customer) == null ? void 0 : s.email,
99
- phone: (c = this.customer) == null ? void 0 : c.phoneNumber,
100
- billingAddress: this.billingAddress && {
101
- name: `${this.billingAddress.firstName} ${this.billingAddress.lastName}`,
102
- addressLine1: this.billingAddress.streetAddress,
103
- addressLine2: this.billingAddress.streetAddress2,
104
- suburb: this.billingAddress.city,
105
- countryCode: this.billingAddress.country,
106
- postcode: this.billingAddress.postalCode,
107
- state: this.billingAddress.state
108
- } || void 0
109
- },
110
- items: this.order && this.order.orderItems.map((n) => ({
111
- name: n.name,
112
- reference: n.sku,
113
- quantity: Number(n.quantity),
114
- amount: Number(n.unitPrice)
115
- })) || []
116
- };
117
- this.log("[PayWayAppleButton][checkout]", e), (d = this.httpInvoker) == null || d.invoke(p(this.apiUrl)[l.CHECKOUT].url, p(this.apiUrl)[l.CHECKOUT].method, JSON.stringify(e), (n, h) => {
118
- this.log("[PayWayAppleButton][checkout]: successCheckoutHandler", n, h);
119
- let y = JSON.parse(h), u = JSON.parse(window.atob(y.checkoutData));
120
- this.log("[PayWayAppleButton][checkout]: decodedData", u), this.charge(u.checkoutId);
121
- }, (n, h) => {
122
- var u;
123
- this.log("[PayWayAppleButton][checkout]: failureCheckoutHandler", n, h);
124
- let y = JSON.parse(h);
125
- (u = this.onFailure) == null || u.call(this, { error: y.message });
126
- });
127
- }
128
- charge(t) {
129
- var e;
130
- this.log("[PayWayAppleButton][charge]", { checkoutId: t }), (e = this.httpInvoker) == null || e.invoke(p(this.apiUrl)[l.CHARGE].url, p(this.apiUrl)[l.CHARGE].method, JSON.stringify({ checkoutId: t }), (r, a) => {
131
- var s;
132
- this.log("[PayWayAppleButton][charge]: successChargeHandler", r, a);
133
- let o = JSON.parse(a);
134
- (s = this.onSuccess) == null || s.call(this, { transactionId: o == null ? void 0 : o.chargeId });
135
- }, (r, a) => {
136
- var s;
137
- this.log("[PayWayAppleButton][charge]: failureChargeHandler", r, a);
138
- let o = JSON.parse(a);
139
- (s = this.onFailure) == null || s.call(this, { error: o.message });
140
- });
141
- }
142
- redraw() {
143
- this.button && (this.button.innerHTML = "", this.draw());
144
- }
145
- setAmount(t) {
146
- this.log("[PayWayAppleButton][setAmount]", t), this.amount = t, this.redraw();
147
- }
148
- setCurrency(t) {
149
- this.log("[PayWayAppleButton][setCurrency]", t), this.currency = t, this.redraw();
150
- }
151
- setCustomerInfo(t) {
152
- this.log("[PayWayAppleButton][setCustomerInfo]", t), this.customer = { ...t };
153
- }
154
- setBillingAddress(t) {
155
- this.log("[PayWayAppleButton][setBillingAddress]", t), this.billingAddress = { ...t };
156
- }
157
- setOrderInfo(t) {
158
- this.log("[PayWayAppleButton][setOrderInfo]", t), this.order = { ...t };
159
- }
160
- };
161
- export {
162
- k as PayWayAppleButton
163
- };