@lydianpay/sdk-web 3.15.4 → 3.15.5

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.
@@ -1,91 +1,91 @@
1
- const g = ["USD", "TRY", "PHP"];
2
- function S(t) {
3
- return typeof t == "string" && g.includes(t);
1
+ const T = ["USD", "TRY", "PHP"];
2
+ function U(e) {
3
+ return typeof e == "string" && T.includes(e);
4
4
  }
5
- function c(t) {
6
- return "sessionID" in t && typeof t.sessionID == "string" && t.sessionID.length > 0;
5
+ function l(e) {
6
+ return "sessionID" in e && typeof e.sessionID == "string" && e.sessionID.length > 0;
7
7
  }
8
- class y {
8
+ class p {
9
9
  // Optional: a caller-supplied session has no key and needs none (see Sessions).
10
10
  // The key is still required when the SDK creates the session, enforced in
11
11
  // index.ts where that is known.
12
- constructor(e, a) {
13
- if (this.baseUri = e, this.publishableKey = a, !this.baseUri)
12
+ constructor(t, a) {
13
+ if (this.baseUri = t, this.publishableKey = a, !this.baseUri)
14
14
  throw new Error("baseUri is required");
15
15
  }
16
16
  // Omitted rather than blank when there is no key: the gateway checks the pk_
17
17
  // prefix first, so an empty header is a 400 where an absent one is anonymous.
18
- headers(e) {
19
- const a = { ...e };
18
+ headers(t) {
19
+ const a = { ...t };
20
20
  return this.publishableKey && (a["X-Publishable-Key"] = this.publishableKey), a;
21
21
  }
22
- async request(e, a) {
23
- const n = `${this.baseUri}${e}`, o = this.headers({ "Content-Type": "application/json" }), r = Object.assign({}, a, { headers: o }), s = await fetch(n, r);
22
+ async request(t, a) {
23
+ const n = `${this.baseUri}${t}`, o = this.headers({ "Content-Type": "application/json" }), r = Object.assign({}, a, { headers: o }), s = await fetch(n, r);
24
24
  if (s.ok)
25
25
  return await s.json();
26
- throw new Error(s.statusText);
26
+ throw new Error(s.statusText, { cause: s });
27
27
  }
28
28
  // For endpoints that reply text/plain rather than JSON (e.g. PATCH
29
29
  // /customer/otp -> "OTP sent"). Sends the same JSON request headers but does
30
30
  // not call response.json(), which would throw on a non-JSON body.
31
- async requestText(e, a) {
32
- const n = `${this.baseUri}${e}`, o = this.headers({ "Content-Type": "application/json" }), r = Object.assign({}, a, { headers: o }), s = await fetch(n, r);
31
+ async requestText(t, a) {
32
+ const n = `${this.baseUri}${t}`, o = this.headers({ "Content-Type": "application/json" }), r = Object.assign({}, a, { headers: o }), s = await fetch(n, r);
33
33
  if (s.ok)
34
34
  return await s.text();
35
35
  throw new Error(s.statusText);
36
36
  }
37
- async requestWithFormData(e, a) {
38
- const n = `${this.baseUri}${e}`, o = this.headers(), r = Object.assign({}, a, { headers: o }), s = await fetch(n, r);
37
+ async requestWithFormData(t, a) {
38
+ const n = `${this.baseUri}${t}`, o = this.headers(), r = Object.assign({}, a, { headers: o }), s = await fetch(n, r);
39
39
  if (s.ok)
40
40
  return await s.json();
41
41
  throw new Error(s.statusText);
42
42
  }
43
43
  }
44
- const l = "transaction";
45
- class A extends y {
46
- async getCryptoTransaction(e) {
47
- return await this.request(`/${l}/${e}`);
44
+ const c = "transaction";
45
+ class R extends p {
46
+ async getCryptoTransaction(t) {
47
+ return await this.request(`/${c}/${t}`);
48
48
  }
49
- async createPaymentRequest(e, a) {
49
+ async createPaymentRequest(t, a) {
50
50
  return await this.request(
51
- `/${l}/${e}/payment`,
51
+ `/${c}/${t}/payment`,
52
52
  {
53
53
  method: "POST",
54
54
  body: JSON.stringify(a)
55
55
  }
56
56
  );
57
57
  }
58
- async buildTransfer(e, a, n) {
58
+ async buildTransfer(t, a, n) {
59
59
  return await this.request(
60
- `/${l}/${e}/payment/${a}/transfer`,
60
+ `/${c}/${t}/payment/${a}/transfer`,
61
61
  {
62
62
  method: "POST",
63
63
  body: JSON.stringify(n)
64
64
  }
65
65
  );
66
66
  }
67
- async broadcastTransfer(e, a, n) {
67
+ async broadcastTransfer(t, a, n) {
68
68
  return await this.request(
69
- `/${l}/${e}/payment/${a}/transfer/broadcast`,
69
+ `/${c}/${t}/payment/${a}/transfer/broadcast`,
70
70
  {
71
71
  method: "POST",
72
72
  body: JSON.stringify(n)
73
73
  }
74
74
  );
75
75
  }
76
- async cancelCryptoTransaction(e, a) {
76
+ async cancelCryptoTransaction(t, a) {
77
77
  return await this.request(
78
- `/${l}/${e}/cancel`,
78
+ `/${c}/${t}/cancel`,
79
79
  {
80
80
  method: "PATCH",
81
81
  body: JSON.stringify(a)
82
82
  }
83
83
  );
84
84
  }
85
- async kycVerification(e, a) {
85
+ async kycVerification(t, a) {
86
86
  const n = new FormData();
87
87
  return n.append("asset", a.asset), n.append("network", a.network), n.append("firstName", a.firstName), n.append("lastName", a.lastName), n.append("email", a.email), n.append("street", a.street), n.append("city", a.city), n.append("region", a.region), n.append("postalCode", a.postalCode), n.append("country", a.country), n.append("storeKYC", a.storeKYC ? "true" : "false"), a.customerUUID && n.append("customerUUID", a.customerUUID), a.walletAddress && n.append("walletAddress", a.walletAddress), a.documentType && n.append("documentType", a.documentType), a.documentFiles.forEach((o) => n.append("documentFiles", o)), await this.requestWithFormData(
88
- `/${l}/${e}/verification`,
88
+ `/${c}/${t}/verification`,
89
89
  {
90
90
  method: "POST",
91
91
  body: n
@@ -93,48 +93,48 @@ class A extends y {
93
93
  );
94
94
  }
95
95
  }
96
- function I(t, e) {
97
- e.forEach((a) => {
96
+ function O(e, t) {
97
+ t.forEach((a) => {
98
98
  Object.getOwnPropertyNames(a.prototype).forEach((n) => {
99
99
  const o = Object.getOwnPropertyDescriptor(a.prototype, n);
100
- o && Object.defineProperty(t.prototype, n, o);
100
+ o && Object.defineProperty(e.prototype, n, o);
101
101
  });
102
102
  });
103
103
  }
104
- const w = "customer/otp";
105
- class L extends y {
104
+ const b = "customer/otp";
105
+ class F extends p {
106
106
  // PATCH /customer/otp -> text/plain "OTP sent" (no JSON body).
107
- async sendCustomerOTP(e) {
108
- return await this.requestText(`/${w}`, {
107
+ async sendCustomerOTP(t) {
108
+ return await this.requestText(`/${b}`, {
109
109
  method: "PATCH",
110
- body: JSON.stringify(e)
110
+ body: JSON.stringify(t)
111
111
  });
112
112
  }
113
113
  // PUT /customer/otp -> { customerUUID, kycValidated }.
114
- async authenticateCustomerOTP(e) {
115
- return await this.request(`/${w}`, {
114
+ async authenticateCustomerOTP(t) {
115
+ return await this.request(`/${b}`, {
116
116
  method: "PUT",
117
- body: JSON.stringify(e)
117
+ body: JSON.stringify(t)
118
118
  });
119
119
  }
120
120
  }
121
121
  const d = "session";
122
- class U extends y {
123
- async createSession(e) {
122
+ class W extends p {
123
+ async createSession(t) {
124
124
  return await this.request(`/${d}`, {
125
125
  method: "POST",
126
- body: JSON.stringify(e)
126
+ body: JSON.stringify(t)
127
127
  });
128
128
  }
129
- async getSession(e) {
130
- return await this.request(`/${d}/${e}`);
129
+ async getSession(t) {
130
+ return await this.request(`/${d}/${t}`);
131
131
  }
132
132
  // Promotes the session into a transaction. Allowed once per session — except
133
133
  // that a KYC-pending (-3) response does not consume the promotion, which is
134
134
  // what lets the restore-details flow re-promote with a customerUUID.
135
- async createSessionTransaction(e, a) {
135
+ async createSessionTransaction(t, a) {
136
136
  return await this.request(
137
- `/${d}/${e}/transaction`,
137
+ `/${d}/${t}/transaction`,
138
138
  {
139
139
  method: "POST",
140
140
  body: JSON.stringify(a)
@@ -143,16 +143,16 @@ class U extends y {
143
143
  }
144
144
  // PATCH /session/{id}/cancel replies text/plain (the merchant's cancel URL),
145
145
  // not JSON. Cancelling cascades to the linked transaction, if any.
146
- async cancelSession(e) {
147
- return await this.requestText(`/${d}/${e}/cancel`, {
146
+ async cancelSession(t) {
147
+ return await this.requestText(`/${d}/${t}/cancel`, {
148
148
  method: "PATCH"
149
149
  });
150
150
  }
151
151
  }
152
- class b extends y {
152
+ class v extends p {
153
153
  }
154
- I(b, [A, L, U]);
155
- const R = b;
154
+ O(v, [R, F, W]);
155
+ const $ = v;
156
156
  var u = {
157
157
  COMPLIANCE_PENDING: -10,
158
158
  API_CANCELLED: -9,
@@ -170,153 +170,170 @@ var u = {
170
170
  FRAUD: -1,
171
171
  PENDING: 0,
172
172
  SUCCESS: 1
173
- }, V = {
173
+ }, ne = {
174
174
  PARTIALLY_PAID: 1,
175
175
  OVERPAID: 3
176
- }, O = {
176
+ }, x = {
177
177
  PENDING: 0,
178
178
  CONFIRMED: 1
179
- }, p = {
179
+ }, m = {
180
180
  dev: "https://api.lydian.dev",
181
181
  sandbox: "https://api.sandbox.lydian.com",
182
182
  prod: "https://api.lydian.com"
183
183
  };
184
- function F(t) {
185
- return t.gatewayUrl ? new URL(t.gatewayUrl).origin : t.dev ? p.dev : t.sandbox ? p.sandbox : p.prod;
184
+ function M(e) {
185
+ return e.gatewayUrl ? new URL(e.gatewayUrl).origin : e.dev ? m.dev : e.sandbox ? m.sandbox : m.prod;
186
186
  }
187
- function P({
188
- options: t,
189
- unsupportedKeys: e,
187
+ function E({
188
+ options: e,
189
+ unsupportedKeys: t,
190
190
  entryPoint: a
191
191
  }) {
192
- const n = e.filter((o) => t[o] !== void 0);
192
+ const n = t.filter((o) => e[o] !== void 0);
193
193
  return n.length === 0 ? null : `${n.join(" and ")} ${n.length > 1 ? "are" : "is"} not used by ${a}. Passing it has no effect, so this is almost always a mistake.`;
194
194
  }
195
- function C(t) {
196
- var e;
197
- return (e = t.flow) != null && e.walletConnect && !t.walletConnectProjectId ? "walletConnectProjectId is required when flow.walletConnect is on" : null;
195
+ function S(e) {
196
+ var t;
197
+ return (t = e.flow) != null && t.walletConnect && !e.walletConnectProjectId ? "walletConnectProjectId is required when flow.walletConnect is on" : null;
198
198
  }
199
- function k(t) {
200
- return t.gatewayUrl === void 0 || W(t.gatewayUrl) ? null : `gatewayUrl must be an http(s) origin such as http://localhost:8000, with no path, got ${JSON.stringify(t.gatewayUrl)}`;
199
+ function D(e) {
200
+ return e.gatewayUrl === void 0 || Y(e.gatewayUrl) ? null : `gatewayUrl must be an http(s) origin such as http://localhost:8000, with no path, got ${JSON.stringify(e.gatewayUrl)}`;
201
201
  }
202
- function W(t) {
203
- let e;
202
+ function Y(e) {
203
+ let t;
204
204
  try {
205
- e = new URL(t);
205
+ t = new URL(e);
206
206
  } catch {
207
207
  return !1;
208
208
  }
209
- return (e.protocol === "http:" || e.protocol === "https:") && e.pathname === "/" && e.search === "" && e.hash === "";
209
+ return (t.protocol === "http:" || t.protocol === "https:") && t.pathname === "/" && t.search === "" && t.hash === "";
210
210
  }
211
- function ee(t) {
212
- return t !== null && !c(t) && !!t.publishableKey;
211
+ function oe(e) {
212
+ return e !== null && !l(e) && !!e.publishableKey;
213
213
  }
214
- function te(t) {
215
- return t !== null && !c(t);
214
+ function re(e) {
215
+ return e !== null && !l(e);
216
216
  }
217
- function ae({
218
- options: t,
219
- session: e,
217
+ function se({
218
+ options: e,
219
+ session: t,
220
220
  settled: a
221
221
  }) {
222
- return !a && e !== null && t !== null && c(t);
222
+ return !a && t !== null && e !== null && l(e);
223
223
  }
224
- function T(t, e, a) {
224
+ function N(e, t, a) {
225
225
  try {
226
- t == null || t(e, a);
226
+ e == null || e(t, a);
227
227
  } catch (n) {
228
- console.error(`onEvent("${e}") threw:`, n);
228
+ console.error(`onEvent("${t}") threw:`, n);
229
229
  }
230
230
  }
231
- async function $({
232
- api: t,
233
- options: e,
231
+ function y(e) {
232
+ if (!e)
233
+ return;
234
+ let t;
235
+ try {
236
+ t = new URL(e);
237
+ } catch {
238
+ return;
239
+ }
240
+ return t.protocol === "https:" || t.protocol === "http:" ? e : void 0;
241
+ }
242
+ async function B({
243
+ api: e,
244
+ options: t,
234
245
  emit: a
235
246
  }) {
236
247
  try {
237
- const n = await x({ api: t, options: e }), { session: o, sessionPromoted: r } = await M({ api: t, sessionID: n });
238
- a("session.loaded", Y(o));
239
- const s = await B({
240
- api: t,
248
+ const n = await q({ api: e, options: t }), { session: o, sessionPromoted: r } = await G({ api: e, sessionID: n });
249
+ a("session.loaded", H(o));
250
+ const s = await K({
251
+ api: e,
241
252
  transactionID: o.transactionID
242
253
  });
243
254
  return { ok: !0, session: o, sessionPromoted: r, linkedTransaction: s };
255
+ } catch (n) {
256
+ return { ok: !1, ...await _(n) };
257
+ }
258
+ }
259
+ async function _(e) {
260
+ const t = e instanceof Error ? e.cause : void 0;
261
+ if (!(t instanceof Response && t.status === 404))
262
+ return {};
263
+ try {
264
+ const n = await t.json();
265
+ return {
266
+ failureURL: P(n == null ? void 0 : n.failureURL),
267
+ cancelURL: P(n == null ? void 0 : n.cancelURL)
268
+ };
244
269
  } catch {
245
- return { ok: !1 };
270
+ return {};
246
271
  }
247
272
  }
248
- async function x({
249
- api: t,
250
- options: e
273
+ function P(e) {
274
+ return typeof e == "string" ? y(e) : void 0;
275
+ }
276
+ async function q({
277
+ api: e,
278
+ options: t
251
279
  }) {
252
- return c(e) ? e.sessionID : (await t.createSession({
253
- amount: e.transaction.amount,
254
- amountCurrency: e.transaction.currency,
255
- descriptor: e.transaction.descriptor,
256
- referenceNumber: e.transaction.referenceNumber
280
+ return l(t) ? t.sessionID : (await e.createSession({
281
+ amount: t.transaction.amount,
282
+ amountCurrency: t.transaction.currency,
283
+ descriptor: t.transaction.descriptor,
284
+ referenceNumber: t.transaction.referenceNumber
257
285
  })).sessionID;
258
286
  }
259
- async function M({
260
- api: t,
261
- sessionID: e
287
+ async function G({
288
+ api: e,
289
+ sessionID: t
262
290
  }) {
263
- const a = await t.getSession(e);
264
- return { session: a, sessionPromoted: E(a) };
291
+ const a = await e.getSession(t);
292
+ return { session: a, sessionPromoted: A(a) };
265
293
  }
266
- function Y(t) {
294
+ function H(e) {
267
295
  return {
268
- sessionID: t.sessionID,
269
- merchantName: t.merchantName,
270
- alreadyPromoted: E(t)
296
+ sessionID: e.sessionID,
297
+ merchantName: e.merchantName,
298
+ alreadyPromoted: A(e)
271
299
  };
272
300
  }
273
- function E(t) {
274
- return !!t.transactionID;
301
+ function A(e) {
302
+ return !!e.transactionID;
275
303
  }
276
- async function B({
277
- api: t,
278
- transactionID: e
304
+ async function K({
305
+ api: e,
306
+ transactionID: t
279
307
  }) {
280
- if (!e)
308
+ if (!t)
281
309
  return null;
282
310
  try {
283
- return await t.getCryptoTransaction(e);
311
+ return await e.getCryptoTransaction(t);
284
312
  } catch (a) {
285
313
  return console.error("Failed to resolve the session transaction:", a), null;
286
314
  }
287
315
  }
288
- function h(t) {
289
- if (!t)
290
- return;
291
- let e;
292
- try {
293
- e = new URL(t);
294
- } catch {
295
- return;
296
- }
297
- return e.protocol === "https:" || e.protocol === "http:" ? t : void 0;
298
- }
299
- function _({
300
- message: t,
301
- reason: e,
316
+ function C({
317
+ message: e,
318
+ reason: t,
302
319
  shouldEndCheckout: a,
303
320
  transactionID: n,
304
321
  session: o
305
322
  }) {
306
323
  return {
307
- event: { reason: e, shouldEndCheckout: a, message: t },
324
+ event: { reason: t, shouldEndCheckout: a, message: e },
308
325
  failure: {
309
326
  shouldEndCheckout: a,
310
- reason: e,
327
+ reason: t,
311
328
  transactionID: n,
312
329
  // Only a failure that ends the checkout carries a redirect. A retryable one
313
330
  // leaves the customer mid-flow with something still to do, and a host that
314
331
  // navigated on it would eject them on a hiccup.
315
- redirectURL: a ? h(o == null ? void 0 : o.failureURL) : void 0
332
+ redirectURL: a ? y(o == null ? void 0 : o.failureURL) : void 0
316
333
  }
317
334
  };
318
335
  }
319
- const q = {
336
+ const j = {
320
337
  "common.cancelTransaction": "Cancel Transaction",
321
338
  "common.cancel": "Cancel",
322
339
  "common.back": "Back",
@@ -464,6 +481,9 @@ const q = {
464
481
  "success.totalAmountPaid": "Total amount paid",
465
482
  "success.cryptoMethod": "Crypto – {asset} on {network}",
466
483
  "success.cryptoMethodWallet": "Crypto – {wallet}",
484
+ "success.cryptoMethodInParts": "Crypto – paid in {count} parts",
485
+ "success.paymentPart": "Part {part}",
486
+ "success.paymentPartAmount": "{amount} on {network}",
467
487
  "success.getAppHeading": "GET THE APP",
468
488
  "success.getAppBody": "Want a simpler checkout experience? Try the <strong>Lydian Wallet</strong> next time.",
469
489
  "success.downloadFromAppStore": "Download from the App Store",
@@ -539,85 +559,85 @@ const q = {
539
559
  "validation.customerDetailsMissing": "Customer details are missing.",
540
560
  "validation.invalidOtp": "Please enter a valid 6-digit code.",
541
561
  "terms.notice": 'By continuing, you agree to Lydian <a href="https://lydian.com/privacy" target="_blank" rel="noopener noreferrer">Terms and Conditions</a> and understand your data will be processed according to the <a href="https://lydian.com/privacy" target="_blank" rel="noopener noreferrer">Privacy Notice</a>.'
542
- }, f = { en: q }, v = "en";
543
- let D = v;
544
- function ne() {
545
- return D;
562
+ }, k = { en: j }, I = "en";
563
+ let L = I;
564
+ function ie() {
565
+ return L;
546
566
  }
547
- function N(t, e) {
567
+ function h(e, t) {
548
568
  var n;
549
- const a = ((n = f[D]) == null ? void 0 : n[t]) ?? f[v][t] ?? t;
550
- return e ? a.replace(
569
+ const a = ((n = k[L]) == null ? void 0 : n[e]) ?? k[I][e] ?? e;
570
+ return t ? a.replace(
551
571
  /\{(\w+)\}/g,
552
- (o, r) => e[r] != null ? String(e[r]) : `{${r}}`
572
+ (o, r) => t[r] != null ? String(t[r]) : `{${r}}`
553
573
  ) : a;
554
574
  }
555
- function G(t) {
556
- return t === u.SUCCESS ? "succeeded" : t < u.PENDING && t !== u.KYC_VERIFICATION_PENDING && t !== u.COMPLIANCE_PENDING ? "failed" : "active";
575
+ function z(e) {
576
+ return e === u.SUCCESS ? "succeeded" : e < u.PENDING && e !== u.KYC_VERIFICATION_PENDING && e !== u.COMPLIANCE_PENDING ? "failed" : "active";
557
577
  }
558
- function H({
559
- transaction: t,
560
- session: e
578
+ function J({
579
+ transaction: e,
580
+ session: t
561
581
  }) {
562
582
  var o, r, s;
563
- const a = G(t.status);
583
+ const a = z(e.status);
564
584
  if (a === "active")
565
585
  return null;
566
586
  if (a === "failed")
567
587
  return {
568
588
  outcome: a,
569
- message: N("errors.paymentCouldNotComplete"),
589
+ message: h("errors.paymentCouldNotComplete"),
570
590
  failure: {
571
591
  shouldEndCheckout: !0,
572
592
  // Negative (non-KYC) status — cancelled / fraud / timeout.
573
593
  reason: "blocked",
574
- transactionID: t.transactionID,
575
- redirectURL: h(e == null ? void 0 : e.failureURL)
594
+ transactionID: e.transactionID,
595
+ redirectURL: y(t == null ? void 0 : t.failureURL)
576
596
  }
577
597
  };
578
- const n = (o = t.payments) == null ? void 0 : o.find(
579
- (i) => i.status === O.CONFIRMED
598
+ const n = (o = e.payments) == null ? void 0 : o.find(
599
+ (i) => i.status === x.CONFIRMED
580
600
  );
581
601
  return {
582
602
  outcome: a,
583
603
  event: {
584
- transactionID: t.transactionID,
604
+ transactionID: e.transactionID,
585
605
  asset: n == null ? void 0 : n.cryptoAsset,
586
606
  network: n == null ? void 0 : n.cryptoNetwork
587
607
  },
588
608
  result: {
589
- transactionID: t.transactionID,
590
- amount: (r = t.amounts) == null ? void 0 : r.totalLocal,
591
- currency: (s = t.amounts) == null ? void 0 : s.currency,
609
+ transactionID: e.transactionID,
610
+ amount: (r = e.amounts) == null ? void 0 : r.totalLocal,
611
+ currency: (s = e.amounts) == null ? void 0 : s.currency,
592
612
  asset: n == null ? void 0 : n.cryptoAsset,
593
613
  network: n == null ? void 0 : n.cryptoNetwork,
594
614
  completedAt: n == null ? void 0 : n.completedAt,
595
- redirectURL: h(e == null ? void 0 : e.successURL)
615
+ redirectURL: y(t == null ? void 0 : t.successURL)
596
616
  }
597
617
  };
598
618
  }
599
- function K() {
600
- let t = null;
619
+ function Q() {
620
+ let e = null;
601
621
  return {
602
- setOptions: (e) => {
603
- t = e;
622
+ setOptions: (t) => {
623
+ e = t;
604
624
  },
605
- emit: (e, a) => T(t == null ? void 0 : t.onEvent, e, a),
606
- paymentFailed: (e, a) => {
625
+ emit: (t, a) => N(e == null ? void 0 : e.onEvent, t, a),
626
+ paymentFailed: (t, a) => {
607
627
  var n;
608
- return (n = t == null ? void 0 : t.paymentFailedListener) == null ? void 0 : n.call(t, e, a);
628
+ return (n = e == null ? void 0 : e.paymentFailedListener) == null ? void 0 : n.call(e, t, a);
609
629
  },
610
- paymentSucceeded: (e) => {
630
+ paymentSucceeded: (t) => {
611
631
  var a;
612
- return (a = t == null ? void 0 : t.paymentSuccessListener) == null ? void 0 : a.call(t, e);
632
+ return (a = e == null ? void 0 : e.paymentSuccessListener) == null ? void 0 : a.call(e, t);
613
633
  },
614
- paymentCanceled: (e) => {
634
+ paymentCanceled: (t) => {
615
635
  var a;
616
- return (a = t == null ? void 0 : t.paymentCanceledListener) == null ? void 0 : a.call(t, e);
636
+ return (a = e == null ? void 0 : e.paymentCanceledListener) == null ? void 0 : a.call(e, t);
617
637
  }
618
638
  };
619
639
  }
620
- class j extends HTMLElement {
640
+ class Z extends HTMLElement {
621
641
  constructor() {
622
642
  super(), this.engine = null, this.engineLoadPromise = null, this.isTornDown = !1, this.shadow = this.attachShadow({ mode: "open" });
623
643
  }
@@ -626,26 +646,26 @@ class j extends HTMLElement {
626
646
  connectedCallback() {
627
647
  this.isTornDown = !1;
628
648
  }
629
- async initialize(e) {
630
- const a = z(e), n = J({ api: a, options: e }), o = await this.loadEngine(e, n);
631
- !o || this.isTornDown || (this.engine = o, await o.initialize(e, { api: a, sessionLoad: n }));
649
+ async initialize(t) {
650
+ const a = X(t), n = V({ api: a, options: t }), o = await this.loadEngine(t, n);
651
+ !o || this.isTornDown || (this.engine = o, await o.initialize(t, { api: a, sessionLoad: n }));
632
652
  }
633
- async loadEngine(e, a) {
653
+ async loadEngine(t, a) {
634
654
  const n = this.getOrLoadEngine();
635
655
  try {
636
656
  return await n;
637
657
  } catch {
638
658
  return await this.handleEngineLoadFailure({
639
659
  engineLoad: n,
640
- options: e,
660
+ options: t,
641
661
  sessionLoad: a
642
662
  }), null;
643
663
  }
644
664
  }
645
- async updateTransaction(e) {
665
+ async updateTransaction(t) {
646
666
  if (!this.engine)
647
667
  throw new Error("Tether Pay not initialized.");
648
- await this.engine.updateTransaction(e);
668
+ await this.engine.updateTransaction(t);
649
669
  }
650
670
  // A merchant SPA can unmount the element at any time; nothing else stops this
651
671
  // instance's timers.
@@ -655,8 +675,8 @@ class j extends HTMLElement {
655
675
  // Not started in the constructor: a page can carry the tag and never check out.
656
676
  // Overlapping initialize() calls share one download.
657
677
  getOrLoadEngine() {
658
- return this.engineLoadPromise ?? (this.engineLoadPromise = import("./mountEngine-B721ZzjQ.js").then((e) => e.m).then((e) => {
659
- const a = e.mountCheckoutEngine({
678
+ return this.engineLoadPromise ?? (this.engineLoadPromise = import("./mountEngine-Bk-qJ-ZC.js").then((t) => t.m).then((t) => {
679
+ const a = t.mountCheckoutEngine({
660
680
  host: this,
661
681
  shadowRoot: this.shadow
662
682
  });
@@ -664,11 +684,11 @@ class j extends HTMLElement {
664
684
  })), this.engineLoadPromise;
665
685
  }
666
686
  async handleEngineLoadFailure({
667
- engineLoad: e,
687
+ engineLoad: t,
668
688
  options: a,
669
689
  sessionLoad: n
670
690
  }) {
671
- this.engineLoadPromise === e && (this.engineLoadPromise = null, await this.reportEngineFailure({ options: a, sessionLoad: n }));
691
+ this.engineLoadPromise === t && (this.engineLoadPromise = null, await this.reportEngineFailure({ options: a, sessionLoad: n }));
672
692
  }
673
693
  // A host that removed the element has walked away; a failure report could send
674
694
  // it to a failureURL for a checkout it dismissed.
@@ -680,7 +700,7 @@ class j extends HTMLElement {
680
700
  // an outcome the gateway has already decided — a session resumed after the
681
701
  // payment settled must report that payment, not a dead checkout.
682
702
  async reportEngineFailure({
683
- options: e,
703
+ options: t,
684
704
  sessionLoad: a
685
705
  }) {
686
706
  if (this.isDismissedByHost)
@@ -688,9 +708,9 @@ class j extends HTMLElement {
688
708
  const n = await a;
689
709
  if (this.isDismissedByHost)
690
710
  return;
691
- const o = K();
692
- o.setOptions(e);
693
- const r = n.ok && n.linkedTransaction ? H({
711
+ const o = Q();
712
+ o.setOptions(t);
713
+ const r = n.ok && n.linkedTransaction ? J({
694
714
  transaction: n.linkedTransaction,
695
715
  session: n.session
696
716
  }) : null;
@@ -706,7 +726,21 @@ class j extends HTMLElement {
706
726
  }), o.paymentFailed(r.message, r.failure);
707
727
  return;
708
728
  }
709
- const s = N("errors.checkoutUnavailable"), i = _({
729
+ if (!n.ok && n.cancelURL) {
730
+ o.emit("payment.canceled"), o.paymentCanceled({ redirectURL: n.cancelURL });
731
+ return;
732
+ }
733
+ if (!n.ok && n.failureURL) {
734
+ const f = h("errors.unableToCreateSession"), g = C({
735
+ message: f,
736
+ reason: "sessionExpired",
737
+ shouldEndCheckout: !0,
738
+ session: { failureURL: n.failureURL }
739
+ });
740
+ o.emit("payment.failed", g.event), o.paymentFailed(f, g.failure);
741
+ return;
742
+ }
743
+ const s = h("errors.checkoutUnavailable"), i = C({
710
744
  message: s,
711
745
  reason: "error",
712
746
  shouldEndCheckout: !0,
@@ -716,92 +750,92 @@ class j extends HTMLElement {
716
750
  }
717
751
  // Always teardown and unmount together to avoid leaking the React engine.
718
752
  // Clear the cached load so a later initialize() creates a fresh engine.
719
- releaseEngine(e = this.engine) {
720
- e == null || e.teardown(), e == null || e.unmount(), this.engine = null, this.engineLoadPromise = null;
753
+ releaseEngine(t = this.engine) {
754
+ t == null || t.teardown(), t == null || t.unmount(), this.engine = null, this.engineLoadPromise = null;
721
755
  }
722
756
  }
723
- function z(t) {
724
- return new R(
725
- F(t),
726
- c(t) ? void 0 : t.publishableKey
757
+ function X(e) {
758
+ return new $(
759
+ M(e),
760
+ l(e) ? void 0 : e.publishableKey
727
761
  );
728
762
  }
729
- function J({
730
- api: t,
731
- options: e
763
+ function V({
764
+ api: e,
765
+ options: t
732
766
  }) {
733
- return $({
734
- api: t,
735
- options: e,
736
- emit: (a, n) => T(e.onEvent, a, n)
767
+ return B({
768
+ api: e,
769
+ options: t,
770
+ emit: (a, n) => N(t.onEvent, a, n)
737
771
  });
738
772
  }
739
- customElements.get("lydian-checkout") || customElements.define("lydian-checkout", j);
740
- function m() {
773
+ customElements.get("lydian-checkout") || customElements.define("lydian-checkout", Z);
774
+ function w() {
741
775
  return document.querySelector("lydian-checkout");
742
776
  }
743
- async function Q(t) {
744
- if (!t.publishableKey || !t.transaction.amount || !t.transaction.currency)
777
+ async function ee(e) {
778
+ if (!e.publishableKey || !e.transaction.amount || !e.transaction.currency)
745
779
  throw new Error("SDK initialization requires publishableKey and a transaction");
746
- const e = C(t);
747
- if (e)
748
- throw new Error(e);
749
- const a = k(t);
780
+ const t = S(e);
781
+ if (t)
782
+ throw new Error(t);
783
+ const a = D(e);
750
784
  if (a)
751
785
  throw new Error(a);
752
- if (!S(t.transaction.currency))
753
- throw new Error("Invalid value for currency, valid values are: " + g.join(", "));
754
- const n = P({
755
- options: t,
786
+ if (!U(e.transaction.currency))
787
+ throw new Error("Invalid value for currency, valid values are: " + T.join(", "));
788
+ const n = E({
789
+ options: e,
756
790
  unsupportedKeys: ["sessionID"],
757
791
  entryPoint: "init"
758
792
  });
759
793
  if (n)
760
794
  throw new Error(n);
761
- await m().initialize(t);
795
+ await w().initialize(e);
762
796
  }
763
- async function Z(t) {
764
- if (!t.sessionID)
797
+ async function te(e) {
798
+ if (!e.sessionID)
765
799
  throw new Error("initExistingSession requires a sessionID");
766
- const e = C(t);
767
- if (e)
768
- throw new Error(e);
769
- const a = k(t);
800
+ const t = S(e);
801
+ if (t)
802
+ throw new Error(t);
803
+ const a = D(e);
770
804
  if (a)
771
805
  throw new Error(a);
772
- const n = P({
773
- options: t,
806
+ const n = E({
807
+ options: e,
774
808
  unsupportedKeys: ["publishableKey", "transaction"],
775
809
  entryPoint: "initExistingSession"
776
810
  });
777
811
  if (n)
778
812
  throw new Error(n);
779
- await m().initialize(t);
813
+ await w().initialize(e);
780
814
  }
781
- async function X(t) {
782
- await m().updateTransaction(t);
815
+ async function ae(e) {
816
+ await w().updateTransaction(e);
783
817
  }
784
- window.Lydian = { init: Q, initExistingSession: Z, updateTransaction: X };
818
+ window.Lydian = { init: ee, initExistingSession: te, updateTransaction: ae };
785
819
  export {
786
- O as P,
820
+ ne as P,
787
821
  u as T,
788
- V as a,
789
- te as b,
790
- g as c,
791
- M as d,
792
- Y as e,
793
- B as f,
794
- ne as g,
795
- c as h,
796
- S as i,
797
- G as j,
798
- H as k,
799
- E as l,
800
- ae as m,
801
- _ as n,
802
- ee as o,
803
- K as p,
804
- x as r,
805
- h as s,
806
- N as t
822
+ x as a,
823
+ re as b,
824
+ T as c,
825
+ G as d,
826
+ H as e,
827
+ K as f,
828
+ ie as g,
829
+ l as h,
830
+ U as i,
831
+ z as j,
832
+ J as k,
833
+ A as l,
834
+ se as m,
835
+ C as n,
836
+ oe as o,
837
+ Q as p,
838
+ q as r,
839
+ y as s,
840
+ h as t
807
841
  };