@montonio/montonio-js 1.0.19
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/LICENSE +21 -0
- package/README.md +90 -0
- package/dist/montonio.es.js +467 -0
- package/dist/montonio.es.js.map +1 -0
- package/dist/montonio.umd.js +2 -0
- package/dist/montonio.umd.js.map +1 -0
- package/dist/types/common/exceptions/exceptions.d.ts +11 -0
- package/dist/types/common/index.d.ts +1 -0
- package/dist/types/components/BaseComponent.d.ts +15 -0
- package/dist/types/components/Iframe/Iframe.d.ts +48 -0
- package/dist/types/components/Iframe/types.d.ts +24 -0
- package/dist/types/components/MontonioCheckout/MontonioCheckout.d.ts +26 -0
- package/dist/types/components/MontonioCheckout/types.d.ts +47 -0
- package/dist/types/components/PaymentAuth/PaymentAuth.d.ts +14 -0
- package/dist/types/components/PaymentAuth/types.d.ts +5 -0
- package/dist/types/components/index.d.ts +5 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/services/Config/Config.d.ts +13 -0
- package/dist/types/services/Config/types.d.ts +17 -0
- package/dist/types/services/HTTP/HTTP.d.ts +23 -0
- package/dist/types/services/Messaging/Messaging.d.ts +52 -0
- package/dist/types/services/Messaging/index.d.ts +2 -0
- package/dist/types/services/Messaging/types.d.ts +92 -0
- package/dist/types/services/index.d.ts +3 -0
- package/dist/types/utils/DOM/DOM.d.ts +10 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/package.json +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Montonio
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Montonio JS SDK
|
|
2
|
+
|
|
3
|
+
This package allows you to integrate the Montonio checkout experience into the front-end of your store, enabling your customers to pay with Montonio payment methods.
|
|
4
|
+
|
|
5
|
+
This is a front-end library. Server-side code and configuration is required to complete the integration. Please visit the [Montonio Documentation](https://docs.montonio.com/) for full integration guides.
|
|
6
|
+
|
|
7
|
+
# Installation
|
|
8
|
+
|
|
9
|
+
We support installation both as a JavaScript module (ESM) and as an embedded script tag (UMD).
|
|
10
|
+
|
|
11
|
+
## ES Module
|
|
12
|
+
|
|
13
|
+
1. Install the package using npm or yarn:
|
|
14
|
+
```bash
|
|
15
|
+
npm install @montonio/montonio-js
|
|
16
|
+
```
|
|
17
|
+
2. Import the library in your JavaScript code:
|
|
18
|
+
```javascript
|
|
19
|
+
import { MontonioCheckout } from '@montonio/montonio-js';
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Embedded script tag
|
|
23
|
+
|
|
24
|
+
To embed the classic UMD version of the library, you can include the following script tag in your HTML file:
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
<script src="https://js.montonio.com/1.x.x/montonio.umd.js"></script>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
In this case, the library and its components will be available in the global object `window.Montonio`:
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
const { MontonioCheckout } = window.Montonio;
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
# Usage
|
|
37
|
+
|
|
38
|
+
To integrate Montonio's embeddable payment methods into your checkout, you first need to create a Montonio Session on your server. Follow the [Montonio Documentation](https://docs.montonio.com/) to create a session. Once you have the session UUID, you can use it to initialize the `MontonioCheckout` component on your front-end.
|
|
39
|
+
|
|
40
|
+
### 1. Initialize MontonioCheckout
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
import { MontonioCheckout } from '@montonio/montonio-js'; // ES Module usage. See above for UMD imports
|
|
44
|
+
|
|
45
|
+
const checkoutOptions = {
|
|
46
|
+
sessionUuid: 'session-uuid', // The UUID of the session created on your server
|
|
47
|
+
environment: 'sandbox', // Defaults to 'production'
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const montonioCheckout = new MontonioCheckout(checkoutOptions);
|
|
51
|
+
await montonioCheckout.initialize('#montonio-checkout-container'); // The CSS selector string or HTMLElement of the container to mount the Montonio Checkout component
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The `MontonioCheckout.initialize()` method will render the Montonio Checkout iframe in the specified container. You can then interact with the checkout by calling methods on the `MontonioCheckout` instance.
|
|
55
|
+
|
|
56
|
+
### 2. Validate the payment form
|
|
57
|
+
|
|
58
|
+
Most embedded payment methods require user input (e.g. card details). As such, you must check the validity of the form before submitting it. Simply call the `validateOrReject` method on the `MontonioCheckout` instance. By default, validation errors are displayed to the user already in the payment form. Optionally, you can also catch the validation errors and display them to the user yourself.
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
// User clicks the "Pay" button in your checkout form
|
|
62
|
+
// Make sure to now lock your checkout and prevent the user from making any further changes.
|
|
63
|
+
try {
|
|
64
|
+
await montonioCheckout.validateOrReject();
|
|
65
|
+
// Proceed with the payment
|
|
66
|
+
} catch (error) {
|
|
67
|
+
// Handle validation errors
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 3. Create the order and submit the payment
|
|
72
|
+
|
|
73
|
+
Once the user has clicked the "Pay" button in your checkout and you have validated the form, you can create the order and submit the payment. First, you need to create a Montonio Order on your server. Follow the [Montonio Documentation](https://docs.montonio.com/) to create an order. Make sure you include the session UUID in the order request.
|
|
74
|
+
|
|
75
|
+
Once the order is created, you can call the `submitPayment` method on the `MontonioCheckout` instance.
|
|
76
|
+
|
|
77
|
+
Immediately after the user clicks "Pay" and even before you create the Montonio order, lock your checkout and prevent the user from making any further changes. Show a loading indicator to the user while the order is being created and while the payment is being submitted.
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
try {
|
|
81
|
+
const result = await montonioCheckout.submitPayment();
|
|
82
|
+
window.location.href = result.returnUrl; // Redirect the user to the thank you page
|
|
83
|
+
} catch (error) {
|
|
84
|
+
// Handle errors
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The `MontonioCheckout.submitPayment()` method will attempt to submit the payment form and complete the payment. In case a payment method requires additional user authentication (such as 3DS for card payments), a modal will pop up to handle the authentication. The original `submitPayment` promise will be resolved when the authentication is complete, and the final result of the payment process will be returned.
|
|
89
|
+
|
|
90
|
+
The final result will contain the `paymentStatus`, `orderToken`, and `returnUrl` fields. The `returnUrl` is the URL you provided in the backend request to create the order. As per the API documentation, this URL will contain the `order-token` query parameter, which you can use to validate the payment. In most cases, you should just redirect the user to the `returnUrl` and handle the token validation on that page.
|
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
var c;
|
|
2
|
+
(function(i) {
|
|
3
|
+
i.CHECKOUT_PAYMENT_COMPONENT_READY = "montonio:checkout.paymentComponentReady", i.CHECKOUT_CHANGE_LOCALE = "montonio:checkout.changeLocale", i.CHECKOUT_SUBMIT_PAYMENT = "montonio:checkout.submitPayment", i.CHECKOUT_START_PAYMENT_AUTH = "montonio:checkout.startPaymentAuth", i.CHECKOUT_SEND_PAYMENT_AUTH_DATA = "montonio:checkout.sendPaymentAuthData", i.CHECKOUT_PAYMENT_AUTH_COMPONENT_READY = "montonio:checkout.paymentAuthComponentReady", i.CHECKOUT_PAYMENT_AUTH_COMPLETED = "montonio:checkout.paymentAuthCompleted", i.CHECKOUT_PAYMENT_COMPLETED = "montonio:checkout.paymentCompleted", i.CHECKOUT_PAYMENT_FAILED = "montonio:checkout.paymentFailed", i.CHECKOUT_SEND_PAYMENT_FAILED_DATA = "montonio:checkout.sendPaymentFailedData", i.CHECKOUT_HEIGHT_CHANGED = "montonio:checkout.heightChanged";
|
|
4
|
+
})(c || (c = {}));
|
|
5
|
+
class m {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.environmentVariables = {
|
|
8
|
+
stargateUrl: {
|
|
9
|
+
sandbox: "https://stargate-sandbox.montonio.com",
|
|
10
|
+
production: "https://stargate.montonio.com",
|
|
11
|
+
"prelive-sandbox": "https://stargate-prelive-sandbox.montonio.com",
|
|
12
|
+
"prelive-production": "https://stargate-prelive.montonio.com",
|
|
13
|
+
development: "https://stargate-dev.montonio.com"
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
static getInstance() {
|
|
18
|
+
return m.instance || (m.instance = new m()), m.instance;
|
|
19
|
+
}
|
|
20
|
+
getConfig(t, e) {
|
|
21
|
+
return this.environmentVariables[t][e];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
class l {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.timeout = 1e4;
|
|
27
|
+
}
|
|
28
|
+
static getInstance() {
|
|
29
|
+
return l.instance || (l.instance = new l()), l.instance;
|
|
30
|
+
}
|
|
31
|
+
async get(t) {
|
|
32
|
+
return this.request(t, "GET");
|
|
33
|
+
}
|
|
34
|
+
async post(t, e) {
|
|
35
|
+
return this.request(t, "POST", e);
|
|
36
|
+
}
|
|
37
|
+
async patch(t, e) {
|
|
38
|
+
return this.request(t, "PATCH", e);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Core request method that handles all HTTP requests
|
|
42
|
+
* @param url The URL to make the request to
|
|
43
|
+
* @param method The HTTP method to use
|
|
44
|
+
* @param data Optional data to send in the request body
|
|
45
|
+
* @returns Promise that resolves with the JSON response
|
|
46
|
+
*/
|
|
47
|
+
async request(t, e, s) {
|
|
48
|
+
const n = new AbortController(), o = setTimeout(() => n.abort(), this.timeout);
|
|
49
|
+
try {
|
|
50
|
+
const a = {
|
|
51
|
+
Accept: "application/json",
|
|
52
|
+
"X-Montonio-Js-Version": "1.0.19"
|
|
53
|
+
};
|
|
54
|
+
s && (a["Content-Type"] = "application/json");
|
|
55
|
+
const r = {
|
|
56
|
+
method: e,
|
|
57
|
+
headers: a,
|
|
58
|
+
credentials: "include",
|
|
59
|
+
mode: "cors",
|
|
60
|
+
signal: n.signal
|
|
61
|
+
};
|
|
62
|
+
s && (r.body = JSON.stringify(s));
|
|
63
|
+
const u = await fetch(t, r);
|
|
64
|
+
if (!u.ok)
|
|
65
|
+
throw new Error(`HTTP error ${u.status}: ${u.statusText}`);
|
|
66
|
+
return await u.json();
|
|
67
|
+
} catch (a) {
|
|
68
|
+
throw a instanceof DOMException && a.name === "AbortError" ? new Error(`Request timeout after ${this.timeout}ms`) : a;
|
|
69
|
+
} finally {
|
|
70
|
+
clearTimeout(o);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
class h {
|
|
75
|
+
constructor() {
|
|
76
|
+
this.subscriptions = /* @__PURE__ */ new Map(), this.globalListenerAttached = !1, this.subscriptionCounter = 0, this.setupGlobalMessageListener();
|
|
77
|
+
}
|
|
78
|
+
static getInstance() {
|
|
79
|
+
return h.instance || (h.instance = new h()), h.instance;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Subscribe to messages of a specific type from specific sources
|
|
83
|
+
* @param messageType The message type to listen for
|
|
84
|
+
* @param handler Handler function to call when the message is received
|
|
85
|
+
* @param sources Array of specific iframe windows or Iframe objects to listen to
|
|
86
|
+
* @returns Subscription ID that can be used to unsubscribe
|
|
87
|
+
*/
|
|
88
|
+
subscribe(t, e, s) {
|
|
89
|
+
const n = `sub_${++this.subscriptionCounter}`, o = this.extractWindowSources(s);
|
|
90
|
+
return this.subscriptions.set(n, {
|
|
91
|
+
id: n,
|
|
92
|
+
messageType: t,
|
|
93
|
+
handler: e,
|
|
94
|
+
sources: o
|
|
95
|
+
}), n;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Add a source to an existing subscription
|
|
99
|
+
*/
|
|
100
|
+
addSourceToSubscription(t, e) {
|
|
101
|
+
const s = this.subscriptions.get(t);
|
|
102
|
+
if (!s)
|
|
103
|
+
throw new Error(`Subscription with ID '${t}' not found`);
|
|
104
|
+
return s.sources.includes(e) ? !1 : (s.sources.push(e), !0);
|
|
105
|
+
}
|
|
106
|
+
unsubscribe(t) {
|
|
107
|
+
this.subscriptions.delete(t);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Wait for a specific message type from specific sources
|
|
111
|
+
* @param messageType The message type to wait for
|
|
112
|
+
* @param sources Array of specific iframe windows or Iframe objects to listen to
|
|
113
|
+
* @param timeout Timeout in milliseconds
|
|
114
|
+
* @returns Promise that resolves when the message is received or rejects on timeout
|
|
115
|
+
*/
|
|
116
|
+
waitForMessage(t, e, s = 1e4) {
|
|
117
|
+
return new Promise((n, o) => {
|
|
118
|
+
const a = setTimeout(() => {
|
|
119
|
+
this.unsubscribe(r), o(new Error(`Message ${t} timeout after ${s}ms`));
|
|
120
|
+
}, s), r = this.subscribe(t, (u) => {
|
|
121
|
+
clearTimeout(a), this.unsubscribe(r), n(u);
|
|
122
|
+
}, e);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Post a message to a specific iframe window
|
|
127
|
+
*/
|
|
128
|
+
postMessage(t, e, s = "*") {
|
|
129
|
+
if (!t)
|
|
130
|
+
throw new Error("Target window is not available.");
|
|
131
|
+
t.postMessage(e, s);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Clear all subscriptions for a specific source (useful when unmounting an iframe)
|
|
135
|
+
*/
|
|
136
|
+
clearSubscriptionsForSource(t) {
|
|
137
|
+
const e = [];
|
|
138
|
+
this.subscriptions.forEach((s) => {
|
|
139
|
+
s.sources.includes(t) && (s.sources = s.sources.filter((n) => n !== t), s.sources.length === 0 && e.push(s.id));
|
|
140
|
+
}), e.forEach((s) => {
|
|
141
|
+
this.subscriptions.delete(s);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Clear all subscriptions
|
|
146
|
+
*/
|
|
147
|
+
clearAllSubscriptions() {
|
|
148
|
+
this.subscriptions.clear();
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Set up the global message listener (called only once)
|
|
152
|
+
*/
|
|
153
|
+
setupGlobalMessageListener() {
|
|
154
|
+
this.globalListenerAttached || (window.addEventListener("message", (t) => {
|
|
155
|
+
try {
|
|
156
|
+
if (!t.data || typeof t.data != "object" || !t.data.name)
|
|
157
|
+
return;
|
|
158
|
+
const e = t.data;
|
|
159
|
+
this.subscriptions.forEach((s) => {
|
|
160
|
+
if (!(s.messageType !== e.name || !s.sources.some((o) => o === t.source)))
|
|
161
|
+
try {
|
|
162
|
+
s.handler(e);
|
|
163
|
+
} catch (o) {
|
|
164
|
+
console.error("Error in message handler:", o);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
} catch (e) {
|
|
168
|
+
console.error("Error processing iframe message:", e);
|
|
169
|
+
}
|
|
170
|
+
}), this.globalListenerAttached = !0);
|
|
171
|
+
}
|
|
172
|
+
extractWindowSources(t) {
|
|
173
|
+
return t.map((e) => {
|
|
174
|
+
if (e instanceof p) {
|
|
175
|
+
const s = e.getContentWindow();
|
|
176
|
+
if (!s)
|
|
177
|
+
throw new Error("Iframe contentWindow is not available. Make sure the iframe is mounted and loaded.");
|
|
178
|
+
return s;
|
|
179
|
+
}
|
|
180
|
+
return e;
|
|
181
|
+
}).filter((e) => e !== null);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
class p {
|
|
185
|
+
constructor(t) {
|
|
186
|
+
var e;
|
|
187
|
+
this.defaultStyles = {
|
|
188
|
+
width: "100%",
|
|
189
|
+
height: "100%"
|
|
190
|
+
}, this.subscriptionIds = /* @__PURE__ */ new Set(), this.options = t, this.resizeOnHeightChange = (e = t.resizeOnHeightChange) !== null && e !== void 0 ? e : !0, this.element = document.createElement("iframe"), this.messagingService = h.getInstance(), this.setupIframe();
|
|
191
|
+
}
|
|
192
|
+
setupIframe() {
|
|
193
|
+
const { src: t, allow: e = "payment", styles: s = {} } = this.options;
|
|
194
|
+
this.element.src = t, this.element.allow = e;
|
|
195
|
+
const n = { ...this.defaultStyles, ...s };
|
|
196
|
+
Object.assign(this.element.style, n);
|
|
197
|
+
}
|
|
198
|
+
mount() {
|
|
199
|
+
return this.options.mountElement.appendChild(this.element), this.resizeOnHeightChange && this.startResizing(this.element), this.element;
|
|
200
|
+
}
|
|
201
|
+
unmount() {
|
|
202
|
+
this.clearSubscriptions(), this.element.contentWindow && this.messagingService.clearSubscriptionsForSource(this.element.contentWindow), this.element.parentNode && this.element.parentNode.removeChild(this.element);
|
|
203
|
+
}
|
|
204
|
+
clearSubscriptions() {
|
|
205
|
+
this.subscriptionIds.forEach((t) => {
|
|
206
|
+
this.messagingService.unsubscribe(t);
|
|
207
|
+
}), this.subscriptionIds.clear();
|
|
208
|
+
}
|
|
209
|
+
getElement() {
|
|
210
|
+
return this.element;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Get the Window object of the iframe
|
|
214
|
+
*/
|
|
215
|
+
getContentWindow() {
|
|
216
|
+
if (!this.element.contentWindow)
|
|
217
|
+
throw new Error("Iframe contentWindow is not available. Make sure the iframe is mounted and loaded.");
|
|
218
|
+
return this.element.contentWindow;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Wait for the iframe to load
|
|
222
|
+
* @param timeout Timeout in milliseconds
|
|
223
|
+
* @returns Promise that resolves when the iframe is loaded or rejects on timeout
|
|
224
|
+
*/
|
|
225
|
+
waitForLoad(t = 1e4) {
|
|
226
|
+
return new Promise((e, s) => {
|
|
227
|
+
const n = setTimeout(() => {
|
|
228
|
+
s(new Error(`Iframe load timeout after ${t}ms`));
|
|
229
|
+
}, t);
|
|
230
|
+
this.element.onload = () => {
|
|
231
|
+
clearTimeout(n), e();
|
|
232
|
+
};
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Wait for a specific message from the iframe
|
|
237
|
+
* @param messageType The message type to wait for
|
|
238
|
+
* @param timeout Timeout in milliseconds
|
|
239
|
+
* @returns Promise that resolves when the message is received or rejects on timeout
|
|
240
|
+
*/
|
|
241
|
+
waitForMessage(t, e = 1e4) {
|
|
242
|
+
const s = this.element.contentWindow;
|
|
243
|
+
if (!s)
|
|
244
|
+
throw new Error("Iframe contentWindow is not available. Make sure the iframe is mounted and loaded.");
|
|
245
|
+
return this.messagingService.waitForMessage(t, [s], e);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Subscribe to messages from the iframe with automatic cleanup
|
|
249
|
+
* Subscriptions are automatically cleaned up when the iframe is unmounted
|
|
250
|
+
* @param messageType The message type to listen for
|
|
251
|
+
* @param handler Handler function to call when the message is received
|
|
252
|
+
*/
|
|
253
|
+
subscribe(t, e) {
|
|
254
|
+
const s = this.element.contentWindow;
|
|
255
|
+
if (!s)
|
|
256
|
+
throw new Error("Iframe contentWindow is not available. Make sure the iframe is mounted and loaded.");
|
|
257
|
+
const n = this.messagingService.subscribe(t, e, [s]);
|
|
258
|
+
this.subscriptionIds.add(n);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Post a message to the child iframe
|
|
262
|
+
*/
|
|
263
|
+
postMessage(t, e = "*") {
|
|
264
|
+
if (!this.element.contentWindow)
|
|
265
|
+
throw new Error("Iframe is not available. Make sure the iframe is mounted and loaded.");
|
|
266
|
+
this.messagingService.postMessage(this.element.contentWindow, t, e);
|
|
267
|
+
}
|
|
268
|
+
startResizing(t) {
|
|
269
|
+
this.subscribe(c.CHECKOUT_HEIGHT_CHANGED, (e) => {
|
|
270
|
+
t.style.height = e.payload.height + "px";
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
class E {
|
|
275
|
+
constructor() {
|
|
276
|
+
this.iframe = null, this.mountElement = null, this.loaded = !1, this.http = l.getInstance(), this.config = m.getInstance(), this.messaging = h.getInstance();
|
|
277
|
+
}
|
|
278
|
+
destroy() {
|
|
279
|
+
this.cleanup();
|
|
280
|
+
}
|
|
281
|
+
getIframe() {
|
|
282
|
+
if (!this.iframe)
|
|
283
|
+
throw new Error("Iframe not initialized");
|
|
284
|
+
return this.iframe;
|
|
285
|
+
}
|
|
286
|
+
cleanup() {
|
|
287
|
+
this.iframe && (this.iframe.unmount(), this.iframe = null);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
class b extends E {
|
|
291
|
+
constructor(t) {
|
|
292
|
+
super(), this.options = t, this.mountElement = t.mountElement || document.body;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Initialize and mount the payment auth iframe
|
|
296
|
+
*/
|
|
297
|
+
async initialize() {
|
|
298
|
+
if (this.options.paymentAuthData.type === "redirect") {
|
|
299
|
+
await this.redirectViaPost(this.options.paymentAuthData);
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (!this.options.paymentAuthData.embeddedUrl)
|
|
303
|
+
throw new Error("Embedded URL is not set in paymentAuthData");
|
|
304
|
+
this.iframe = new p({
|
|
305
|
+
src: this.options.paymentAuthData.embeddedUrl,
|
|
306
|
+
mountElement: this.mountElement,
|
|
307
|
+
styles: {
|
|
308
|
+
width: "100vw",
|
|
309
|
+
height: "100vh",
|
|
310
|
+
position: "fixed",
|
|
311
|
+
top: "0",
|
|
312
|
+
left: "0",
|
|
313
|
+
zIndex: "16777271"
|
|
314
|
+
},
|
|
315
|
+
resizeOnHeightChange: !1
|
|
316
|
+
}), this.iframe.mount(), await this.iframe.waitForMessage(c.CHECKOUT_PAYMENT_AUTH_COMPONENT_READY), this.iframe.postMessage({
|
|
317
|
+
name: c.CHECKOUT_SEND_PAYMENT_AUTH_DATA,
|
|
318
|
+
payload: {
|
|
319
|
+
paymentAuthData: this.options.paymentAuthData
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Handle redirect-based payment auth
|
|
325
|
+
*/
|
|
326
|
+
async redirectViaPost(t) {
|
|
327
|
+
if (!t.redirectUrl)
|
|
328
|
+
throw new Error("Redirect URL is not set in paymentAuthData");
|
|
329
|
+
const e = document.createElement("form");
|
|
330
|
+
if (e.method = t.redirectMethod || "get", e.action = t.redirectUrl, e.style.display = "none", t.formData)
|
|
331
|
+
for (const [s, n] of Object.entries(t.formData)) {
|
|
332
|
+
const o = document.createElement("input");
|
|
333
|
+
o.type = "hidden", o.name = s, o.value = n, e.appendChild(o);
|
|
334
|
+
}
|
|
335
|
+
throw document.body.appendChild(e), e.submit(), await new Promise((s) => setTimeout(s, 1e4)), new Error("Redirect timeout: Expected redirect to occur within 10 seconds");
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
function g(i) {
|
|
339
|
+
if (typeof i == "string") {
|
|
340
|
+
const t = document.querySelector(i);
|
|
341
|
+
if (!t || !(t instanceof HTMLElement))
|
|
342
|
+
throw new Error(`Element not found: ${i}`);
|
|
343
|
+
return t;
|
|
344
|
+
}
|
|
345
|
+
return i;
|
|
346
|
+
}
|
|
347
|
+
var d;
|
|
348
|
+
(function(i) {
|
|
349
|
+
i.DEVELOPMENT = "development", i.PRODUCTION = "production", i.SANDBOX = "sandbox", i.PRELIVE_SANDBOX = "prelive-sandbox", i.PRELIVE_PRODUCTION = "prelive-production";
|
|
350
|
+
})(d || (d = {}));
|
|
351
|
+
class f extends Error {
|
|
352
|
+
constructor(t = "MontonioCheckout not initialized. Please call the .initialize() method of the MontonioCheckout class first.") {
|
|
353
|
+
super(t), this.name = "MontonioCheckoutNotInitializedError";
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
class w extends Error {
|
|
357
|
+
constructor(t) {
|
|
358
|
+
super(`Payment failed: ${t.errorCode}`), this.name = "PaymentFailedError", this.paymentFailedMessageData = t;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
class C extends E {
|
|
362
|
+
constructor(t) {
|
|
363
|
+
super(), this.paymentAuth = null, this.submitPaymentSubscriptions = {
|
|
364
|
+
completedId: "",
|
|
365
|
+
failedId: "",
|
|
366
|
+
authId: ""
|
|
367
|
+
}, this.options = t, this.environment = t.environment || d.PRODUCTION;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Mount the checkout to the DOM
|
|
371
|
+
* @param mountTo - The element to mount the checkout to. Can be a CSS selector or an HTMLElement.
|
|
372
|
+
*/
|
|
373
|
+
async initialize(t) {
|
|
374
|
+
try {
|
|
375
|
+
this.mountElement = g(t);
|
|
376
|
+
const e = await this.fetchSession();
|
|
377
|
+
return console.log("SDK: sessionData from Stargate", e), this.iframe = new p({
|
|
378
|
+
src: e.url,
|
|
379
|
+
mountElement: this.mountElement,
|
|
380
|
+
styles: {
|
|
381
|
+
minHeight: "230px"
|
|
382
|
+
}
|
|
383
|
+
}), this.iframe.mount(), await this.iframe.waitForMessage(c.CHECKOUT_PAYMENT_COMPONENT_READY), this.loaded = !0, !0;
|
|
384
|
+
} catch (e) {
|
|
385
|
+
throw this.cleanup(), e;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
updateOptions(t) {
|
|
389
|
+
if (!this.loaded)
|
|
390
|
+
throw new f();
|
|
391
|
+
t.locale !== void 0 && (this.options.locale = t.locale, this.getIframe().postMessage({
|
|
392
|
+
name: c.CHECKOUT_CHANGE_LOCALE,
|
|
393
|
+
payload: { locale: t.locale }
|
|
394
|
+
}));
|
|
395
|
+
}
|
|
396
|
+
async validateOrReject() {
|
|
397
|
+
return await console.log("Payment form validation not implemented yet");
|
|
398
|
+
}
|
|
399
|
+
async submitPayment() {
|
|
400
|
+
if (!this.loaded)
|
|
401
|
+
throw new f();
|
|
402
|
+
return new Promise((t, e) => {
|
|
403
|
+
this.submitPaymentSubscriptions.completedId = this.messaging.subscribe(c.CHECKOUT_PAYMENT_COMPLETED, async (s) => {
|
|
404
|
+
console.log("CHECKOUT_PAYMENT_COMPLETED (from main iframe)", s);
|
|
405
|
+
const n = await this.handlePaymentCompletedMessage(s);
|
|
406
|
+
t(n), this.cleanupAfterPaymentSubmission();
|
|
407
|
+
}, [this.getIframe()]), this.submitPaymentSubscriptions.failedId = this.messaging.subscribe(c.CHECKOUT_PAYMENT_FAILED, (s) => {
|
|
408
|
+
console.error("CHECKOUT_PAYMENT_FAILED (from main iframe)", s), this.getIframe().postMessage({
|
|
409
|
+
name: c.CHECKOUT_SEND_PAYMENT_FAILED_DATA,
|
|
410
|
+
payload: s.payload
|
|
411
|
+
}), e(new w(s.payload)), this.cleanupAfterPaymentSubmission();
|
|
412
|
+
}, [this.getIframe()]), this.submitPaymentSubscriptions.authId = this.messaging.subscribe(c.CHECKOUT_START_PAYMENT_AUTH, async (s) => {
|
|
413
|
+
try {
|
|
414
|
+
console.log("PAYMENT AUTH STARTED", s), this.paymentAuth = new b({
|
|
415
|
+
paymentAuthData: s.payload.paymentAuthData
|
|
416
|
+
}), await this.paymentAuth.initialize();
|
|
417
|
+
const n = this.paymentAuth.getIframe();
|
|
418
|
+
this.messaging.addSourceToSubscription(this.submitPaymentSubscriptions.completedId, n.getContentWindow()), this.messaging.addSourceToSubscription(this.submitPaymentSubscriptions.failedId, n.getContentWindow());
|
|
419
|
+
} catch (n) {
|
|
420
|
+
e(n);
|
|
421
|
+
}
|
|
422
|
+
}, [this.getIframe()]), this.getIframe().postMessage({
|
|
423
|
+
name: c.CHECKOUT_SUBMIT_PAYMENT
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
async fetchSession() {
|
|
428
|
+
const e = `${this.config.getConfig("stargateUrl", this.environment)}/api/sessions/${this.options.sessionUuid}/gateway-url${this.options.locale ? `?preferredLocale=${this.options.locale}` : ""}`;
|
|
429
|
+
return await this.http.get(e);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* After a payment has completed, fetch the return URL. Keep fetching until we
|
|
433
|
+
* exhaust all the attempts
|
|
434
|
+
*/
|
|
435
|
+
async handlePaymentCompletedMessage(t) {
|
|
436
|
+
const s = `${this.config.getConfig("stargateUrl", this.environment)}/api/payment-intents/${t.payload.paymentIntentUuid}/return-url`, n = 10, o = 1e3;
|
|
437
|
+
let a = 0;
|
|
438
|
+
for (; a < n; ) {
|
|
439
|
+
try {
|
|
440
|
+
const r = await this.http.get(s);
|
|
441
|
+
if (a++, r != null && r.merchantReturnUrl)
|
|
442
|
+
return {
|
|
443
|
+
returnUrl: r.merchantReturnUrl
|
|
444
|
+
};
|
|
445
|
+
} catch (r) {
|
|
446
|
+
console.error("Error fetching return URL:", r);
|
|
447
|
+
}
|
|
448
|
+
a < n && await new Promise((r) => setTimeout(r, o));
|
|
449
|
+
}
|
|
450
|
+
throw new Error(`Failed to fetch the return url after ${a} attempts`);
|
|
451
|
+
}
|
|
452
|
+
cleanupAfterPaymentSubmission() {
|
|
453
|
+
this.messaging.unsubscribe(this.submitPaymentSubscriptions.completedId), this.messaging.unsubscribe(this.submitPaymentSubscriptions.failedId), this.messaging.unsubscribe(this.submitPaymentSubscriptions.authId), this.cleanupPaymentAuth();
|
|
454
|
+
}
|
|
455
|
+
cleanup() {
|
|
456
|
+
this.cleanupPaymentAuth(), super.cleanup();
|
|
457
|
+
}
|
|
458
|
+
cleanupPaymentAuth() {
|
|
459
|
+
this.paymentAuth && (this.paymentAuth.destroy(), this.paymentAuth = null);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
export {
|
|
463
|
+
d as Environment,
|
|
464
|
+
c as MessageTypeEnum,
|
|
465
|
+
C as MontonioCheckout
|
|
466
|
+
};
|
|
467
|
+
//# sourceMappingURL=montonio.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"montonio.es.js","sources":["../src/services/Messaging/types.ts","../src/services/Config/Config.ts","../src/services/HTTP/HTTP.ts","../src/services/Messaging/Messaging.ts","../src/components/Iframe/Iframe.ts","../src/components/BaseComponent.ts","../src/components/PaymentAuth/PaymentAuth.ts","../src/utils/DOM/DOM.ts","../src/services/Config/types.ts","../src/common/exceptions/exceptions.ts","../src/components/MontonioCheckout/MontonioCheckout.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null],"names":["MessageTypeEnum","ConfigService","name","environment","HTTPService","url","data","method","controller","timeoutId","headers","options","response","error","MessagingService","messageType","handler","sources","subscriptionId","windowSources","source","subscription","timeout","resolve","reject","message","target","messageData","targetOrigin","subscriptionsToRemove","s","id","event","Iframe","contentWindow","window","_a","src","allow","styles","combinedStyles","element","BaseComponent","PaymentAuth","paymentAuthData","form","key","value","input","getElement","selector","Environment","MontonioCheckoutNotInitializedError","PaymentFailedError","paymentFailedMessageData","MontonioCheckout","mountTo","sessionData","completedMessage","result","failedMessage","paymentAuthIframe","paymentCompletedMessage","MAX_ATTEMPTS","DELAY_BETWEEN_ATTEMPTS_IN_MS","attempts"],"mappings":"AAaY,IAAAA;AAAA,CAAZ,SAAYA,GAAe;AACvBA,EAAAA,EAAA,mCAAA,2CACAA,EAAA,yBAAA,kCACAA,EAAA,0BAAA,mCACAA,EAAA,8BAAA,sCACAA,EAAA,kCAAA,yCACAA,EAAA,wCAAA,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AAQ,iBAAiB,eACzFC,IAAe,IACfC,IAA+B;AACrC,QAAIC,IAAW;AAEf,WAAOA,IAAWF,KAAc;AACxB,UAAA;AACA,cAAMJ,IAAS,MAAM,KAAK,KAAK,IAAuBtD,CAAG;AAEzD,YADA4D,KACIN,aAAAA,EAAQ;AACD,iBAAA;AAAA,YACH,WAAWA,EAAO;AAAA;eAGrB9C,GAAO;AACJ,gBAAA,MAAM,8BAA8BA,CAAK;AAAA,MAAA;AAIrD,MAAIoD,IAAWF,KACX,MAAM,IAAI,QAAQ,CAACxC,MAAY,WAAWA,GAASyC,CAA4B,CAAC;AAAA,IACpF;AAGJ,UAAM,IAAI,MAAM,wCAAwCC,CAAQ,WAAW;AAAA,EAAA;AAAA,EAGvE,gCAA6B;AACjC,SAAK,UAAU,YAAY,KAAK,2BAA2B,WAAW,GACtE,KAAK,UAAU,YAAY,KAAK,2BAA2B,QAAQ,GACnE,KAAK,UAAU,YAAY,KAAK,2BAA2B,MAAM,GAEjE,KAAK,mBAAkB;AAAA,EAAA;AAAA,EAGjB,UAAO;AACb,SAAK,mBAAkB,GACvB,MAAM,QAAO;AAAA,EAAA;AAAA,EAGT,qBAAkB;AACtB,IAAI,KAAK,gBACL,KAAK,YAAY,WACjB,KAAK,cAAc;AAAA,EACvB;AAEP;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
(function(o,u){typeof exports=="object"&&typeof module!="undefined"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(o=typeof globalThis!="undefined"?globalThis:o||self,u(o.Montonio={}))})(this,function(o){"use strict";o.MessageTypeEnum=void 0,function(i){i.CHECKOUT_PAYMENT_COMPONENT_READY="montonio:checkout.paymentComponentReady",i.CHECKOUT_CHANGE_LOCALE="montonio:checkout.changeLocale",i.CHECKOUT_SUBMIT_PAYMENT="montonio:checkout.submitPayment",i.CHECKOUT_START_PAYMENT_AUTH="montonio:checkout.startPaymentAuth",i.CHECKOUT_SEND_PAYMENT_AUTH_DATA="montonio:checkout.sendPaymentAuthData",i.CHECKOUT_PAYMENT_AUTH_COMPONENT_READY="montonio:checkout.paymentAuthComponentReady",i.CHECKOUT_PAYMENT_AUTH_COMPLETED="montonio:checkout.paymentAuthCompleted",i.CHECKOUT_PAYMENT_COMPLETED="montonio:checkout.paymentCompleted",i.CHECKOUT_PAYMENT_FAILED="montonio:checkout.paymentFailed",i.CHECKOUT_SEND_PAYMENT_FAILED_DATA="montonio:checkout.sendPaymentFailedData",i.CHECKOUT_HEIGHT_CHANGED="montonio:checkout.heightChanged"}(o.MessageTypeEnum||(o.MessageTypeEnum={}));class u{constructor(){this.environmentVariables={stargateUrl:{sandbox:"https://stargate-sandbox.montonio.com",production:"https://stargate.montonio.com","prelive-sandbox":"https://stargate-prelive-sandbox.montonio.com","prelive-production":"https://stargate-prelive.montonio.com",development:"https://stargate-dev.montonio.com"}}}static getInstance(){return u.instance||(u.instance=new u),u.instance}getConfig(t,e){return this.environmentVariables[t][e]}}class m{constructor(){this.timeout=1e4}static getInstance(){return m.instance||(m.instance=new m),m.instance}async get(t){return this.request(t,"GET")}async post(t,e){return this.request(t,"POST",e)}async patch(t,e){return this.request(t,"PATCH",e)}async request(t,e,n){const s=new AbortController,r=setTimeout(()=>s.abort(),this.timeout);try{const c={Accept:"application/json","X-Montonio-Js-Version":"1.0.19"};n&&(c["Content-Type"]="application/json");const a={method:e,headers:c,credentials:"include",mode:"cors",signal:s.signal};n&&(a.body=JSON.stringify(n));const l=await fetch(t,a);if(!l.ok)throw new Error(`HTTP error ${l.status}: ${l.statusText}`);return await l.json()}catch(c){throw c instanceof DOMException&&c.name==="AbortError"?new Error(`Request timeout after ${this.timeout}ms`):c}finally{clearTimeout(r)}}}class h{constructor(){this.subscriptions=new Map,this.globalListenerAttached=!1,this.subscriptionCounter=0,this.setupGlobalMessageListener()}static getInstance(){return h.instance||(h.instance=new h),h.instance}subscribe(t,e,n){const s=`sub_${++this.subscriptionCounter}`,r=this.extractWindowSources(n);return this.subscriptions.set(s,{id:s,messageType:t,handler:e,sources:r}),s}addSourceToSubscription(t,e){const n=this.subscriptions.get(t);if(!n)throw new Error(`Subscription with ID '${t}' not found`);return n.sources.includes(e)?!1:(n.sources.push(e),!0)}unsubscribe(t){this.subscriptions.delete(t)}waitForMessage(t,e,n=1e4){return new Promise((s,r)=>{const c=setTimeout(()=>{this.unsubscribe(a),r(new Error(`Message ${t} timeout after ${n}ms`))},n),a=this.subscribe(t,l=>{clearTimeout(c),this.unsubscribe(a),s(l)},e)})}postMessage(t,e,n="*"){if(!t)throw new Error("Target window is not available.");t.postMessage(e,n)}clearSubscriptionsForSource(t){const e=[];this.subscriptions.forEach(n=>{n.sources.includes(t)&&(n.sources=n.sources.filter(s=>s!==t),n.sources.length===0&&e.push(n.id))}),e.forEach(n=>{this.subscriptions.delete(n)})}clearAllSubscriptions(){this.subscriptions.clear()}setupGlobalMessageListener(){this.globalListenerAttached||(window.addEventListener("message",t=>{try{if(!t.data||typeof t.data!="object"||!t.data.name)return;const e=t.data;this.subscriptions.forEach(n=>{if(!(n.messageType!==e.name||!n.sources.some(r=>r===t.source)))try{n.handler(e)}catch(r){console.error("Error in message handler:",r)}})}catch(e){console.error("Error processing iframe message:",e)}}),this.globalListenerAttached=!0)}extractWindowSources(t){return t.map(e=>{if(e instanceof d){const n=e.getContentWindow();if(!n)throw new Error("Iframe contentWindow is not available. Make sure the iframe is mounted and loaded.");return n}return e}).filter(e=>e!==null)}}class d{constructor(t){var e;this.defaultStyles={width:"100%",height:"100%"},this.subscriptionIds=new Set,this.options=t,this.resizeOnHeightChange=(e=t.resizeOnHeightChange)!==null&&e!==void 0?e:!0,this.element=document.createElement("iframe"),this.messagingService=h.getInstance(),this.setupIframe()}setupIframe(){const{src:t,allow:e="payment",styles:n={}}=this.options;this.element.src=t,this.element.allow=e;const s={...this.defaultStyles,...n};Object.assign(this.element.style,s)}mount(){return this.options.mountElement.appendChild(this.element),this.resizeOnHeightChange&&this.startResizing(this.element),this.element}unmount(){this.clearSubscriptions(),this.element.contentWindow&&this.messagingService.clearSubscriptionsForSource(this.element.contentWindow),this.element.parentNode&&this.element.parentNode.removeChild(this.element)}clearSubscriptions(){this.subscriptionIds.forEach(t=>{this.messagingService.unsubscribe(t)}),this.subscriptionIds.clear()}getElement(){return this.element}getContentWindow(){if(!this.element.contentWindow)throw new Error("Iframe contentWindow is not available. Make sure the iframe is mounted and loaded.");return this.element.contentWindow}waitForLoad(t=1e4){return new Promise((e,n)=>{const s=setTimeout(()=>{n(new Error(`Iframe load timeout after ${t}ms`))},t);this.element.onload=()=>{clearTimeout(s),e()}})}waitForMessage(t,e=1e4){const n=this.element.contentWindow;if(!n)throw new Error("Iframe contentWindow is not available. Make sure the iframe is mounted and loaded.");return this.messagingService.waitForMessage(t,[n],e)}subscribe(t,e){const n=this.element.contentWindow;if(!n)throw new Error("Iframe contentWindow is not available. Make sure the iframe is mounted and loaded.");const s=this.messagingService.subscribe(t,e,[n]);this.subscriptionIds.add(s)}postMessage(t,e="*"){if(!this.element.contentWindow)throw new Error("Iframe is not available. Make sure the iframe is mounted and loaded.");this.messagingService.postMessage(this.element.contentWindow,t,e)}startResizing(t){this.subscribe(o.MessageTypeEnum.CHECKOUT_HEIGHT_CHANGED,e=>{t.style.height=e.payload.height+"px"})}}class p{constructor(){this.iframe=null,this.mountElement=null,this.loaded=!1,this.http=m.getInstance(),this.config=u.getInstance(),this.messaging=h.getInstance()}destroy(){this.cleanup()}getIframe(){if(!this.iframe)throw new Error("Iframe not initialized");return this.iframe}cleanup(){this.iframe&&(this.iframe.unmount(),this.iframe=null)}}class E extends p{constructor(t){super(),this.options=t,this.mountElement=t.mountElement||document.body}async initialize(){if(this.options.paymentAuthData.type==="redirect"){await this.redirectViaPost(this.options.paymentAuthData);return}if(!this.options.paymentAuthData.embeddedUrl)throw new Error("Embedded URL is not set in paymentAuthData");this.iframe=new d({src:this.options.paymentAuthData.embeddedUrl,mountElement:this.mountElement,styles:{width:"100vw",height:"100vh",position:"fixed",top:"0",left:"0",zIndex:"16777271"},resizeOnHeightChange:!1}),this.iframe.mount(),await this.iframe.waitForMessage(o.MessageTypeEnum.CHECKOUT_PAYMENT_AUTH_COMPONENT_READY),this.iframe.postMessage({name:o.MessageTypeEnum.CHECKOUT_SEND_PAYMENT_AUTH_DATA,payload:{paymentAuthData:this.options.paymentAuthData}})}async redirectViaPost(t){if(!t.redirectUrl)throw new Error("Redirect URL is not set in paymentAuthData");const e=document.createElement("form");if(e.method=t.redirectMethod||"get",e.action=t.redirectUrl,e.style.display="none",t.formData)for(const[n,s]of Object.entries(t.formData)){const r=document.createElement("input");r.type="hidden",r.name=n,r.value=s,e.appendChild(r)}throw document.body.appendChild(e),e.submit(),await new Promise(n=>setTimeout(n,1e4)),new Error("Redirect timeout: Expected redirect to occur within 10 seconds")}}function g(i){if(typeof i=="string"){const t=document.querySelector(i);if(!t||!(t instanceof HTMLElement))throw new Error(`Element not found: ${i}`);return t}return i}o.Environment=void 0,function(i){i.DEVELOPMENT="development",i.PRODUCTION="production",i.SANDBOX="sandbox",i.PRELIVE_SANDBOX="prelive-sandbox",i.PRELIVE_PRODUCTION="prelive-production"}(o.Environment||(o.Environment={}));class f extends Error{constructor(t="MontonioCheckout not initialized. Please call the .initialize() method of the MontonioCheckout class first."){super(t),this.name="MontonioCheckoutNotInitializedError"}}class b extends Error{constructor(t){super(`Payment failed: ${t.errorCode}`),this.name="PaymentFailedError",this.paymentFailedMessageData=t}}class y extends p{constructor(t){super(),this.paymentAuth=null,this.submitPaymentSubscriptions={completedId:"",failedId:"",authId:""},this.options=t,this.environment=t.environment||o.Environment.PRODUCTION}async initialize(t){try{this.mountElement=g(t);const e=await this.fetchSession();return console.log("SDK: sessionData from Stargate",e),this.iframe=new d({src:e.url,mountElement:this.mountElement,styles:{minHeight:"230px"}}),this.iframe.mount(),await this.iframe.waitForMessage(o.MessageTypeEnum.CHECKOUT_PAYMENT_COMPONENT_READY),this.loaded=!0,!0}catch(e){throw this.cleanup(),e}}updateOptions(t){if(!this.loaded)throw new f;t.locale!==void 0&&(this.options.locale=t.locale,this.getIframe().postMessage({name:o.MessageTypeEnum.CHECKOUT_CHANGE_LOCALE,payload:{locale:t.locale}}))}async validateOrReject(){return await console.log("Payment form validation not implemented yet")}async submitPayment(){if(!this.loaded)throw new f;return new Promise((t,e)=>{this.submitPaymentSubscriptions.completedId=this.messaging.subscribe(o.MessageTypeEnum.CHECKOUT_PAYMENT_COMPLETED,async n=>{console.log("CHECKOUT_PAYMENT_COMPLETED (from main iframe)",n);const s=await this.handlePaymentCompletedMessage(n);t(s),this.cleanupAfterPaymentSubmission()},[this.getIframe()]),this.submitPaymentSubscriptions.failedId=this.messaging.subscribe(o.MessageTypeEnum.CHECKOUT_PAYMENT_FAILED,n=>{console.error("CHECKOUT_PAYMENT_FAILED (from main iframe)",n),this.getIframe().postMessage({name:o.MessageTypeEnum.CHECKOUT_SEND_PAYMENT_FAILED_DATA,payload:n.payload}),e(new b(n.payload)),this.cleanupAfterPaymentSubmission()},[this.getIframe()]),this.submitPaymentSubscriptions.authId=this.messaging.subscribe(o.MessageTypeEnum.CHECKOUT_START_PAYMENT_AUTH,async n=>{try{console.log("PAYMENT AUTH STARTED",n),this.paymentAuth=new E({paymentAuthData:n.payload.paymentAuthData}),await this.paymentAuth.initialize();const s=this.paymentAuth.getIframe();this.messaging.addSourceToSubscription(this.submitPaymentSubscriptions.completedId,s.getContentWindow()),this.messaging.addSourceToSubscription(this.submitPaymentSubscriptions.failedId,s.getContentWindow())}catch(s){e(s)}},[this.getIframe()]),this.getIframe().postMessage({name:o.MessageTypeEnum.CHECKOUT_SUBMIT_PAYMENT})})}async fetchSession(){const e=`${this.config.getConfig("stargateUrl",this.environment)}/api/sessions/${this.options.sessionUuid}/gateway-url${this.options.locale?`?preferredLocale=${this.options.locale}`:""}`;return await this.http.get(e)}async handlePaymentCompletedMessage(t){const n=`${this.config.getConfig("stargateUrl",this.environment)}/api/payment-intents/${t.payload.paymentIntentUuid}/return-url`,s=10,r=1e3;let c=0;for(;c<s;){try{const a=await this.http.get(n);if(c++,a!=null&&a.merchantReturnUrl)return{returnUrl:a.merchantReturnUrl}}catch(a){console.error("Error fetching return URL:",a)}c<s&&await new Promise(a=>setTimeout(a,r))}throw new Error(`Failed to fetch the return url after ${c} attempts`)}cleanupAfterPaymentSubmission(){this.messaging.unsubscribe(this.submitPaymentSubscriptions.completedId),this.messaging.unsubscribe(this.submitPaymentSubscriptions.failedId),this.messaging.unsubscribe(this.submitPaymentSubscriptions.authId),this.cleanupPaymentAuth()}cleanup(){this.cleanupPaymentAuth(),super.cleanup()}cleanupPaymentAuth(){this.paymentAuth&&(this.paymentAuth.destroy(),this.paymentAuth=null)}}o.MontonioCheckout=y,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
|
2
|
+
//# sourceMappingURL=montonio.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"montonio.umd.js","sources":["../src/services/Messaging/types.ts","../src/services/Config/Config.ts","../src/services/HTTP/HTTP.ts","../src/services/Messaging/Messaging.ts","../src/components/Iframe/Iframe.ts","../src/components/BaseComponent.ts","../src/components/PaymentAuth/PaymentAuth.ts","../src/utils/DOM/DOM.ts","../src/services/Config/types.ts","../src/common/exceptions/exceptions.ts","../src/components/MontonioCheckout/MontonioCheckout.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null],"names":["MessageTypeEnum","ConfigService","name","environment","HTTPService","url","data","method","controller","timeoutId","headers","options","response","error","MessagingService","messageType","handler","sources","subscriptionId","windowSources","source","subscription","timeout","resolve","reject","message","target","messageData","targetOrigin","subscriptionsToRemove","id","event","Iframe","contentWindow","window","_a","src","allow","styles","combinedStyles","element","BaseComponent","PaymentAuth","paymentAuthData","form","key","value","input","getElement","selector","Environment","MontonioCheckoutNotInitializedError","PaymentFailedError","paymentFailedMessageData","MontonioCheckout","mountTo","sessionData","completedMessage","result","failedMessage","paymentAuthIframe","paymentCompletedMessage","MAX_ATTEMPTS","DEL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,SAAAA,EAAQ,kBACD,MAAA,CACH,UAAWA,EAAO,yBAGrB7C,EAAO,CACJ,QAAA,MAAM,6BAA8BA,CAAK,CAAA,CAIjDmD,EAAWF,GACX,MAAM,IAAI,QAASvC,GAAY,WAAWA,EAASwC,CAA4B,CAAC,CACpF,CAGJ,MAAM,IAAI,MAAM,wCAAwCC,CAAQ,WAAW,CAAA,CAGvE,+BAA6B,CACjC,KAAK,UAAU,YAAY,KAAK,2BAA2B,WAAW,EACtE,KAAK,UAAU,YAAY,KAAK,2BAA2B,QAAQ,EACnE,KAAK,UAAU,YAAY,KAAK,2BAA2B,MAAM,EAEjE,KAAK,mBAAkB,CAAA,CAGjB,SAAO,CACb,KAAK,mBAAkB,EACvB,MAAM,QAAO,CAAA,CAGT,oBAAkB,CAClB,KAAK,cACL,KAAK,YAAY,UACjB,KAAK,YAAc,KACvB,CAEP"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PaymentFailedMessageData } from '../../services/Messaging/types';
|
|
2
|
+
export declare class MontonioCheckoutNotInitializedError extends Error {
|
|
3
|
+
constructor(message?: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class PaymentAuthNotInitializedError extends Error {
|
|
6
|
+
constructor(message?: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class PaymentFailedError extends Error {
|
|
9
|
+
paymentFailedMessageData: PaymentFailedMessageData;
|
|
10
|
+
constructor(paymentFailedMessageData: PaymentFailedMessageData);
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './exceptions/exceptions';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Iframe } from './Iframe/Iframe';
|
|
2
|
+
import { ConfigService, HTTPService, MessagingService } from '../services';
|
|
3
|
+
export declare abstract class BaseComponent {
|
|
4
|
+
protected http: HTTPService;
|
|
5
|
+
protected config: ConfigService;
|
|
6
|
+
protected messaging: MessagingService;
|
|
7
|
+
protected iframe: Iframe | null;
|
|
8
|
+
protected mountElement: HTMLElement | null;
|
|
9
|
+
loaded: boolean;
|
|
10
|
+
constructor();
|
|
11
|
+
abstract initialize(...args: unknown[]): Promise<unknown>;
|
|
12
|
+
destroy(): void;
|
|
13
|
+
getIframe(): Iframe;
|
|
14
|
+
protected cleanup(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { IframeOptions } from './types';
|
|
2
|
+
import { MessageData } from '../../services/Messaging/types';
|
|
3
|
+
/**
|
|
4
|
+
* Iframe component for rendering and communicating with iframes
|
|
5
|
+
*/
|
|
6
|
+
export declare class Iframe {
|
|
7
|
+
private element;
|
|
8
|
+
private options;
|
|
9
|
+
private readonly defaultStyles;
|
|
10
|
+
private resizeOnHeightChange;
|
|
11
|
+
private messagingService;
|
|
12
|
+
private subscriptionIds;
|
|
13
|
+
constructor(options: IframeOptions);
|
|
14
|
+
private setupIframe;
|
|
15
|
+
mount(): HTMLIFrameElement;
|
|
16
|
+
unmount(): void;
|
|
17
|
+
clearSubscriptions(): void;
|
|
18
|
+
getElement(): HTMLIFrameElement;
|
|
19
|
+
/**
|
|
20
|
+
* Get the Window object of the iframe
|
|
21
|
+
*/
|
|
22
|
+
getContentWindow(): Window;
|
|
23
|
+
/**
|
|
24
|
+
* Wait for the iframe to load
|
|
25
|
+
* @param timeout Timeout in milliseconds
|
|
26
|
+
* @returns Promise that resolves when the iframe is loaded or rejects on timeout
|
|
27
|
+
*/
|
|
28
|
+
waitForLoad(timeout?: number): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Wait for a specific message from the iframe
|
|
31
|
+
* @param messageType The message type to wait for
|
|
32
|
+
* @param timeout Timeout in milliseconds
|
|
33
|
+
* @returns Promise that resolves when the message is received or rejects on timeout
|
|
34
|
+
*/
|
|
35
|
+
waitForMessage<T extends MessageData = MessageData>(messageType: T['name'], timeout?: number): Promise<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Subscribe to messages from the iframe with automatic cleanup
|
|
38
|
+
* Subscriptions are automatically cleaned up when the iframe is unmounted
|
|
39
|
+
* @param messageType The message type to listen for
|
|
40
|
+
* @param handler Handler function to call when the message is received
|
|
41
|
+
*/
|
|
42
|
+
subscribe<T extends MessageData = MessageData>(messageType: T['name'], handler: (message: T) => void): void;
|
|
43
|
+
/**
|
|
44
|
+
* Post a message to the child iframe
|
|
45
|
+
*/
|
|
46
|
+
postMessage<T extends MessageData>(messageData: T, targetOrigin?: string): void;
|
|
47
|
+
startResizing(element: HTMLIFrameElement): void;
|
|
48
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface IframeOptions {
|
|
2
|
+
/**
|
|
3
|
+
* URL to load in the iframe
|
|
4
|
+
*/
|
|
5
|
+
src: string;
|
|
6
|
+
/**
|
|
7
|
+
* Element to mount the iframe to
|
|
8
|
+
*/
|
|
9
|
+
mountElement: HTMLElement;
|
|
10
|
+
/**
|
|
11
|
+
* Optional allow attribute for iframe permissions
|
|
12
|
+
* @default 'payment'
|
|
13
|
+
*/
|
|
14
|
+
allow?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Optional iframe styles as CSS properties
|
|
17
|
+
*/
|
|
18
|
+
styles?: Partial<CSSStyleDeclaration>;
|
|
19
|
+
/**
|
|
20
|
+
* Whether to resize based on height messages from iframe
|
|
21
|
+
* @default true
|
|
22
|
+
*/
|
|
23
|
+
resizeOnHeightChange?: boolean;
|
|
24
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CheckoutOptions, PaymentResult, UpdatableCheckoutOptions } from './types';
|
|
2
|
+
import { BaseComponent } from '../BaseComponent';
|
|
3
|
+
export declare class MontonioCheckout extends BaseComponent {
|
|
4
|
+
private options;
|
|
5
|
+
private environment;
|
|
6
|
+
private paymentAuth;
|
|
7
|
+
private submitPaymentSubscriptions;
|
|
8
|
+
constructor(options: CheckoutOptions);
|
|
9
|
+
/**
|
|
10
|
+
* Mount the checkout to the DOM
|
|
11
|
+
* @param mountTo - The element to mount the checkout to. Can be a CSS selector or an HTMLElement.
|
|
12
|
+
*/
|
|
13
|
+
initialize(mountTo: string | HTMLElement): Promise<boolean>;
|
|
14
|
+
updateOptions(options: UpdatableCheckoutOptions): void;
|
|
15
|
+
validateOrReject(): Promise<void>;
|
|
16
|
+
submitPayment(): Promise<PaymentResult>;
|
|
17
|
+
private fetchSession;
|
|
18
|
+
/**
|
|
19
|
+
* After a payment has completed, fetch the return URL. Keep fetching until we
|
|
20
|
+
* exhaust all the attempts
|
|
21
|
+
*/
|
|
22
|
+
private handlePaymentCompletedMessage;
|
|
23
|
+
private cleanupAfterPaymentSubmission;
|
|
24
|
+
protected cleanup(): void;
|
|
25
|
+
private cleanupPaymentAuth;
|
|
26
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { EnvironmentOptions } from '../../services/Config/types';
|
|
2
|
+
/**
|
|
3
|
+
* Montonio Checkout options
|
|
4
|
+
*/
|
|
5
|
+
export interface CheckoutOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The UUID of the checkout session
|
|
8
|
+
*/
|
|
9
|
+
sessionUuid: string;
|
|
10
|
+
/**
|
|
11
|
+
* Defaults to 'en_US' on the backend
|
|
12
|
+
*/
|
|
13
|
+
locale?: LocaleEnum;
|
|
14
|
+
/**
|
|
15
|
+
* Environment to use
|
|
16
|
+
* Defaults to 'production'
|
|
17
|
+
*/
|
|
18
|
+
environment?: EnvironmentOptions;
|
|
19
|
+
}
|
|
20
|
+
export type UpdatableCheckoutOptions = Pick<Partial<CheckoutOptions>, 'locale'>;
|
|
21
|
+
/**
|
|
22
|
+
* Checkout session data returned from Stargate
|
|
23
|
+
*/
|
|
24
|
+
export interface GatewayUrlResponse {
|
|
25
|
+
uuid: string;
|
|
26
|
+
url: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Payment result returned to the store after submitting a payment
|
|
30
|
+
*/
|
|
31
|
+
export interface PaymentResult {
|
|
32
|
+
returnUrl: string;
|
|
33
|
+
orderToken?: string;
|
|
34
|
+
paymentStatus?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface ReturnUrlResponse {
|
|
37
|
+
merchantReturnUrl: string;
|
|
38
|
+
}
|
|
39
|
+
export declare enum LocaleEnum {
|
|
40
|
+
EN_US = "en_US",
|
|
41
|
+
ET = "et",
|
|
42
|
+
LV = "lv",
|
|
43
|
+
LT = "lt",
|
|
44
|
+
PL = "pl",
|
|
45
|
+
FI = "fi",
|
|
46
|
+
RU = "ru"
|
|
47
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PaymentAuthOptions } from './types';
|
|
2
|
+
import { BaseComponent } from '../BaseComponent';
|
|
3
|
+
export declare class PaymentAuth extends BaseComponent {
|
|
4
|
+
private options;
|
|
5
|
+
constructor(options: PaymentAuthOptions);
|
|
6
|
+
/**
|
|
7
|
+
* Initialize and mount the payment auth iframe
|
|
8
|
+
*/
|
|
9
|
+
initialize(): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Handle redirect-based payment auth
|
|
12
|
+
*/
|
|
13
|
+
private redirectViaPost;
|
|
14
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CheckoutOptions } from './MontonioCheckout/types';
|
|
2
|
+
import { MontonioCheckout } from './MontonioCheckout/MontonioCheckout';
|
|
3
|
+
import { PaymentAuth } from './PaymentAuth/PaymentAuth';
|
|
4
|
+
import { PaymentAuthOptions } from './PaymentAuth/types';
|
|
5
|
+
export { CheckoutOptions, MontonioCheckout, PaymentAuth, PaymentAuthOptions };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { MontonioCheckout } from './components/MontonioCheckout/MontonioCheckout';
|
|
2
|
+
import type { CheckoutOptions } from './components/MontonioCheckout/types';
|
|
3
|
+
import { Environment } from './services/Config/types';
|
|
4
|
+
import { MessageTypeEnum } from './services/Messaging/types';
|
|
5
|
+
export { CheckoutOptions, MontonioCheckout, Environment, MessageTypeEnum };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EnvironmentOptions, EnvironmentVariables } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Returns environment variables from the .env file
|
|
4
|
+
* Implemented as a singleton
|
|
5
|
+
*/
|
|
6
|
+
export declare class ConfigService {
|
|
7
|
+
private static instance;
|
|
8
|
+
private environmentVariables;
|
|
9
|
+
private constructor();
|
|
10
|
+
static getInstance(): ConfigService;
|
|
11
|
+
getConfig(name: keyof EnvironmentVariables, environment: EnvironmentOptions): string;
|
|
12
|
+
}
|
|
13
|
+
export default ConfigService;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface EnvironmentVariables {
|
|
2
|
+
stargateUrl: {
|
|
3
|
+
sandbox: string;
|
|
4
|
+
production: string;
|
|
5
|
+
'prelive-sandbox': string;
|
|
6
|
+
'prelive-production': string;
|
|
7
|
+
development: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export declare enum Environment {
|
|
11
|
+
DEVELOPMENT = "development",
|
|
12
|
+
PRODUCTION = "production",
|
|
13
|
+
SANDBOX = "sandbox",
|
|
14
|
+
PRELIVE_SANDBOX = "prelive-sandbox",
|
|
15
|
+
PRELIVE_PRODUCTION = "prelive-production"
|
|
16
|
+
}
|
|
17
|
+
export type EnvironmentOptions = Environment | `${Environment}`;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Service for making API requests
|
|
3
|
+
* Handles GET, POST, and PATCH requests with JSON data
|
|
4
|
+
* Implemented as a singleton
|
|
5
|
+
*/
|
|
6
|
+
export declare class HTTPService {
|
|
7
|
+
private static instance;
|
|
8
|
+
private readonly timeout;
|
|
9
|
+
private constructor();
|
|
10
|
+
static getInstance(): HTTPService;
|
|
11
|
+
get<T>(url: string): Promise<T>;
|
|
12
|
+
post<T, D = unknown>(url: string, data: D): Promise<T>;
|
|
13
|
+
patch<T, D = unknown>(url: string, data: D): Promise<T>;
|
|
14
|
+
/**
|
|
15
|
+
* Core request method that handles all HTTP requests
|
|
16
|
+
* @param url The URL to make the request to
|
|
17
|
+
* @param method The HTTP method to use
|
|
18
|
+
* @param data Optional data to send in the request body
|
|
19
|
+
* @returns Promise that resolves with the JSON response
|
|
20
|
+
*/
|
|
21
|
+
private request;
|
|
22
|
+
}
|
|
23
|
+
export default HTTPService;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { MessageData, MessageTypeEnum } from './types';
|
|
2
|
+
import { Iframe } from '../../components/Iframe/Iframe';
|
|
3
|
+
/**
|
|
4
|
+
* Service for sending and receiving messages between iframes
|
|
5
|
+
* Implemented as a singleton
|
|
6
|
+
*/
|
|
7
|
+
export declare class MessagingService {
|
|
8
|
+
private static instance;
|
|
9
|
+
private subscriptions;
|
|
10
|
+
private globalListenerAttached;
|
|
11
|
+
private subscriptionCounter;
|
|
12
|
+
private constructor();
|
|
13
|
+
static getInstance(): MessagingService;
|
|
14
|
+
/**
|
|
15
|
+
* Subscribe to messages of a specific type from specific sources
|
|
16
|
+
* @param messageType The message type to listen for
|
|
17
|
+
* @param handler Handler function to call when the message is received
|
|
18
|
+
* @param sources Array of specific iframe windows or Iframe objects to listen to
|
|
19
|
+
* @returns Subscription ID that can be used to unsubscribe
|
|
20
|
+
*/
|
|
21
|
+
subscribe<T extends MessageData = MessageData>(messageType: MessageTypeEnum, handler: (message: T) => void, sources: Window[] | Iframe[]): string;
|
|
22
|
+
/**
|
|
23
|
+
* Add a source to an existing subscription
|
|
24
|
+
*/
|
|
25
|
+
addSourceToSubscription(subscriptionId: string, source: Window): boolean;
|
|
26
|
+
unsubscribe(subscriptionId: string): void;
|
|
27
|
+
/**
|
|
28
|
+
* Wait for a specific message type from specific sources
|
|
29
|
+
* @param messageType The message type to wait for
|
|
30
|
+
* @param sources Array of specific iframe windows or Iframe objects to listen to
|
|
31
|
+
* @param timeout Timeout in milliseconds
|
|
32
|
+
* @returns Promise that resolves when the message is received or rejects on timeout
|
|
33
|
+
*/
|
|
34
|
+
waitForMessage<T extends MessageData = MessageData>(messageType: MessageTypeEnum, sources: Window[] | Iframe[], timeout?: number): Promise<T>;
|
|
35
|
+
/**
|
|
36
|
+
* Post a message to a specific iframe window
|
|
37
|
+
*/
|
|
38
|
+
postMessage(target: Window, messageData: MessageData, targetOrigin?: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* Clear all subscriptions for a specific source (useful when unmounting an iframe)
|
|
41
|
+
*/
|
|
42
|
+
clearSubscriptionsForSource(source: Window): void;
|
|
43
|
+
/**
|
|
44
|
+
* Clear all subscriptions
|
|
45
|
+
*/
|
|
46
|
+
clearAllSubscriptions(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Set up the global message listener (called only once)
|
|
49
|
+
*/
|
|
50
|
+
private setupGlobalMessageListener;
|
|
51
|
+
private extractWindowSources;
|
|
52
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { MessageTypeEnum } from './types';
|
|
2
|
+
export type { MessageOptions, MessageData, CheckoutHeightChangedMessage, CheckoutPaymentComponentReadyMessage, CheckoutChangeLocaleMessage, CheckoutSubmitPaymentMessage, PaymentAuthMessageData, CheckoutStartPaymentAuthMessage, CheckoutSendPaymentAuthDataMessage, CheckoutPaymentAuthComponentReadyMessage, CheckoutPaymentAuthCompletedMessage, CheckoutPaymentCompletedMessage, PaymentFailedMessageData, CheckoutPaymentFailedMessage, CheckoutSendPaymentFailedDataMessage, } from './types';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { LocaleEnum } from '../../components/MontonioCheckout/types';
|
|
2
|
+
export interface MessageSubscription {
|
|
3
|
+
id: string;
|
|
4
|
+
messageType: MessageTypeEnum;
|
|
5
|
+
handler: (message: MessageData) => void;
|
|
6
|
+
sources: Window[];
|
|
7
|
+
}
|
|
8
|
+
export interface MessageOptions {
|
|
9
|
+
targetOrigin?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare enum MessageTypeEnum {
|
|
12
|
+
CHECKOUT_PAYMENT_COMPONENT_READY = "montonio:checkout.paymentComponentReady",
|
|
13
|
+
CHECKOUT_CHANGE_LOCALE = "montonio:checkout.changeLocale",
|
|
14
|
+
CHECKOUT_SUBMIT_PAYMENT = "montonio:checkout.submitPayment",
|
|
15
|
+
CHECKOUT_START_PAYMENT_AUTH = "montonio:checkout.startPaymentAuth",
|
|
16
|
+
CHECKOUT_SEND_PAYMENT_AUTH_DATA = "montonio:checkout.sendPaymentAuthData",
|
|
17
|
+
CHECKOUT_PAYMENT_AUTH_COMPONENT_READY = "montonio:checkout.paymentAuthComponentReady",
|
|
18
|
+
CHECKOUT_PAYMENT_AUTH_COMPLETED = "montonio:checkout.paymentAuthCompleted",
|
|
19
|
+
CHECKOUT_PAYMENT_COMPLETED = "montonio:checkout.paymentCompleted",
|
|
20
|
+
CHECKOUT_PAYMENT_FAILED = "montonio:checkout.paymentFailed",
|
|
21
|
+
CHECKOUT_SEND_PAYMENT_FAILED_DATA = "montonio:checkout.sendPaymentFailedData",
|
|
22
|
+
CHECKOUT_HEIGHT_CHANGED = "montonio:checkout.heightChanged"
|
|
23
|
+
}
|
|
24
|
+
export interface MessageData {
|
|
25
|
+
name: MessageTypeEnum;
|
|
26
|
+
payload?: unknown;
|
|
27
|
+
}
|
|
28
|
+
export interface CheckoutHeightChangedMessage extends MessageData {
|
|
29
|
+
name: MessageTypeEnum.CHECKOUT_HEIGHT_CHANGED;
|
|
30
|
+
payload: {
|
|
31
|
+
height: number;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export interface CheckoutPaymentComponentReadyMessage extends MessageData {
|
|
35
|
+
name: MessageTypeEnum.CHECKOUT_PAYMENT_COMPONENT_READY;
|
|
36
|
+
}
|
|
37
|
+
export interface CheckoutChangeLocaleMessage extends MessageData {
|
|
38
|
+
name: MessageTypeEnum.CHECKOUT_CHANGE_LOCALE;
|
|
39
|
+
payload: {
|
|
40
|
+
locale: LocaleEnum;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export interface CheckoutSubmitPaymentMessage extends MessageData {
|
|
44
|
+
name: MessageTypeEnum.CHECKOUT_SUBMIT_PAYMENT;
|
|
45
|
+
}
|
|
46
|
+
export interface PaymentAuthMessageData {
|
|
47
|
+
type: 'redirect' | 'embedded';
|
|
48
|
+
embeddedUrl?: string;
|
|
49
|
+
redirectUrl?: string;
|
|
50
|
+
redirectMethod?: string;
|
|
51
|
+
formData?: Record<string, string>;
|
|
52
|
+
originalPaymentMethodData?: unknown;
|
|
53
|
+
}
|
|
54
|
+
export interface CheckoutStartPaymentAuthMessage extends MessageData {
|
|
55
|
+
name: MessageTypeEnum.CHECKOUT_START_PAYMENT_AUTH;
|
|
56
|
+
payload: {
|
|
57
|
+
paymentAuthData: PaymentAuthMessageData;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export interface CheckoutSendPaymentAuthDataMessage extends MessageData {
|
|
61
|
+
name: MessageTypeEnum.CHECKOUT_SEND_PAYMENT_AUTH_DATA;
|
|
62
|
+
payload: {
|
|
63
|
+
paymentAuthData: PaymentAuthMessageData;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export interface CheckoutPaymentAuthComponentReadyMessage extends MessageData {
|
|
67
|
+
name: MessageTypeEnum.CHECKOUT_PAYMENT_AUTH_COMPONENT_READY;
|
|
68
|
+
}
|
|
69
|
+
export interface CheckoutPaymentAuthCompletedMessage extends MessageData {
|
|
70
|
+
name: MessageTypeEnum.CHECKOUT_PAYMENT_AUTH_COMPLETED;
|
|
71
|
+
}
|
|
72
|
+
export interface CheckoutPaymentCompletedMessage extends MessageData {
|
|
73
|
+
name: MessageTypeEnum.CHECKOUT_PAYMENT_COMPLETED;
|
|
74
|
+
payload: {
|
|
75
|
+
paymentIntentUuid: string;
|
|
76
|
+
resultCode: string;
|
|
77
|
+
returnUrl?: string;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export interface PaymentFailedMessageData {
|
|
81
|
+
errorCode: string;
|
|
82
|
+
paymentIntentUuid?: string;
|
|
83
|
+
originalPaymentMethodResult?: unknown;
|
|
84
|
+
}
|
|
85
|
+
export interface CheckoutPaymentFailedMessage extends MessageData {
|
|
86
|
+
name: MessageTypeEnum.CHECKOUT_PAYMENT_FAILED;
|
|
87
|
+
payload: PaymentFailedMessageData;
|
|
88
|
+
}
|
|
89
|
+
export interface CheckoutSendPaymentFailedDataMessage extends MessageData {
|
|
90
|
+
name: MessageTypeEnum.CHECKOUT_SEND_PAYMENT_FAILED_DATA;
|
|
91
|
+
payload: PaymentFailedMessageData;
|
|
92
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM utils for selecting elements and manipulating the DOM
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Get an element from a CSS selector or HTMLElement
|
|
6
|
+
* @param selector CSS selector string or HTMLElement
|
|
7
|
+
* @returns HTMLElement
|
|
8
|
+
* @throws Error if element is not found
|
|
9
|
+
*/
|
|
10
|
+
export declare function getElement(selector: string | HTMLElement): HTMLElement;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getElement } from './DOM/DOM';
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@montonio/montonio-js",
|
|
3
|
+
"version": "1.0.19",
|
|
4
|
+
"description": "Montonio JS SDK for front-end web applications",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"registry": "https://registry.npmjs.org/",
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"main": "dist/montonio.es.js",
|
|
11
|
+
"types": "dist/types/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/types/index.d.ts",
|
|
16
|
+
"default": "./dist/montonio.es.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"./services/Messaging": {
|
|
20
|
+
"types": "./dist/types/services/Messaging/index.d.ts",
|
|
21
|
+
"import": "./dist/montonio.es.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"start": "vite build --watch --mode development",
|
|
29
|
+
"dev": "vite --mode development",
|
|
30
|
+
"build": "vite build --mode live",
|
|
31
|
+
"build:prelive": "vite build --mode prelive",
|
|
32
|
+
"build:live": "vite build --mode live",
|
|
33
|
+
"build:watch": "vite build --watch --mode development",
|
|
34
|
+
"preview": "vite preview",
|
|
35
|
+
"test": "vitest run",
|
|
36
|
+
"lint": "eslint src",
|
|
37
|
+
"prepublishOnly": "npm run build:live"
|
|
38
|
+
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/montonio/montonio-js.git"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"montonio",
|
|
45
|
+
"payments",
|
|
46
|
+
"checkout",
|
|
47
|
+
"sdk",
|
|
48
|
+
"frontend",
|
|
49
|
+
"javascript",
|
|
50
|
+
"typescript"
|
|
51
|
+
],
|
|
52
|
+
"author": "Montonio",
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/montonio/montonio-js/issues"
|
|
56
|
+
},
|
|
57
|
+
"homepage": "https://github.com/montonio/montonio-js#readme",
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@eslint/js": "^9.26.0",
|
|
60
|
+
"@rollup/plugin-replace": "^6.0.2",
|
|
61
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
62
|
+
"@types/node": "^22.15.17",
|
|
63
|
+
"@typescript-eslint/eslint-plugin": "^8.32.1",
|
|
64
|
+
"@typescript-eslint/parser": "^8.32.1",
|
|
65
|
+
"eslint": "^9.26.0",
|
|
66
|
+
"eslint-config-prettier": "^10.1.5",
|
|
67
|
+
"eslint-plugin-prettier": "^5.4.0",
|
|
68
|
+
"globals": "^16.1.0",
|
|
69
|
+
"prettier": "^3.5.3",
|
|
70
|
+
"typescript": "5.8.3",
|
|
71
|
+
"typescript-eslint": "^8.32.1",
|
|
72
|
+
"vite": "6.3.5",
|
|
73
|
+
"vitest": "3.1.3"
|
|
74
|
+
}
|
|
75
|
+
}
|