@lydianpay/sdk-web 3.13.1 → 3.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  const g = ["USD", "TRY", "PHP"];
2
- function N(e) {
2
+ function A(e) {
3
3
  return typeof e == "string" && g.includes(e);
4
4
  }
5
- function c(e) {
5
+ function l(e) {
6
6
  return "sessionID" in e && typeof e.sessionID == "string" && e.sessionID.length > 0;
7
7
  }
8
8
  class y {
@@ -41,14 +41,14 @@ class y {
41
41
  throw new Error(s.statusText);
42
42
  }
43
43
  }
44
- const l = "transaction";
45
- class A extends y {
44
+ const c = "transaction";
45
+ class S extends y {
46
46
  async getCryptoTransaction(t) {
47
- return await this.request(`/${l}/${t}`);
47
+ return await this.request(`/${c}/${t}`);
48
48
  }
49
49
  async createPaymentRequest(t, a) {
50
50
  return await this.request(
51
- `/${l}/${t}/payment`,
51
+ `/${c}/${t}/payment`,
52
52
  {
53
53
  method: "POST",
54
54
  body: JSON.stringify(a)
@@ -57,7 +57,7 @@ class A extends y {
57
57
  }
58
58
  async cancelCryptoTransaction(t, a) {
59
59
  return await this.request(
60
- `/${l}/${t}/cancel`,
60
+ `/${c}/${t}/cancel`,
61
61
  {
62
62
  method: "PATCH",
63
63
  body: JSON.stringify(a)
@@ -67,7 +67,7 @@ class A extends y {
67
67
  async kycVerification(t, a) {
68
68
  const n = new FormData();
69
69
  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(
70
- `/${l}/${t}/verification`,
70
+ `/${c}/${t}/verification`,
71
71
  {
72
72
  method: "POST",
73
73
  body: n
@@ -75,7 +75,7 @@ class A extends y {
75
75
  );
76
76
  }
77
77
  }
78
- function S(e, t) {
78
+ function I(e, t) {
79
79
  t.forEach((a) => {
80
80
  Object.getOwnPropertyNames(a.prototype).forEach((n) => {
81
81
  const o = Object.getOwnPropertyDescriptor(a.prototype, n);
@@ -84,7 +84,7 @@ function S(e, t) {
84
84
  });
85
85
  }
86
86
  const w = "customer/otp";
87
- class I extends y {
87
+ class L extends y {
88
88
  // PATCH /customer/otp -> text/plain "OTP sent" (no JSON body).
89
89
  async sendCustomerOTP(t) {
90
90
  return await this.requestText(`/${w}`, {
@@ -101,7 +101,7 @@ class I extends y {
101
101
  }
102
102
  }
103
103
  const d = "session";
104
- class L extends y {
104
+ class U extends y {
105
105
  async createSession(t) {
106
106
  return await this.request(`/${d}`, {
107
107
  method: "POST",
@@ -131,10 +131,10 @@ class L extends y {
131
131
  });
132
132
  }
133
133
  }
134
- class C extends y {
134
+ class b extends y {
135
135
  }
136
- S(C, [A, I, L]);
137
- const R = C;
136
+ I(b, [S, L, U]);
137
+ const R = b;
138
138
  var u = {
139
139
  COMPLIANCE_PENDING: -10,
140
140
  API_CANCELLED: -9,
@@ -152,7 +152,7 @@ var u = {
152
152
  FRAUD: -1,
153
153
  PENDING: 0,
154
154
  SUCCESS: 1
155
- }, Z = {
155
+ }, V = {
156
156
  PARTIALLY_PAID: 1,
157
157
  OVERPAID: 3
158
158
  }, O = {
@@ -164,9 +164,9 @@ var u = {
164
164
  prod: "https://api.lydian.com"
165
165
  };
166
166
  function F(e) {
167
- return e.dev ? p.dev : e.sandbox ? p.sandbox : p.prod;
167
+ return e.gatewayUrl ? new URL(e.gatewayUrl).origin : e.dev ? p.dev : e.sandbox ? p.sandbox : p.prod;
168
168
  }
169
- function b({
169
+ function C({
170
170
  options: e,
171
171
  unsupportedKeys: t,
172
172
  entryPoint: a
@@ -178,35 +178,47 @@ function P(e) {
178
178
  var t;
179
179
  return (t = e.flow) != null && t.walletConnect && !e.walletConnectProjectId ? "walletConnectProjectId is required when flow.walletConnect is on" : null;
180
180
  }
181
- function X(e) {
182
- return e !== null && !c(e) && !!e.publishableKey;
181
+ function k(e) {
182
+ return e.gatewayUrl === void 0 || W(e.gatewayUrl) ? null : `gatewayUrl must be an http(s) origin such as http://localhost:8000, with no path, got ${JSON.stringify(e.gatewayUrl)}`;
183
+ }
184
+ function W(e) {
185
+ let t;
186
+ try {
187
+ t = new URL(e);
188
+ } catch {
189
+ return !1;
190
+ }
191
+ return (t.protocol === "http:" || t.protocol === "https:") && t.pathname === "/" && t.search === "" && t.hash === "";
192
+ }
193
+ function ee(e) {
194
+ return e !== null && !l(e) && !!e.publishableKey;
183
195
  }
184
- function V(e) {
185
- return e !== null && !c(e);
196
+ function te(e) {
197
+ return e !== null && !l(e);
186
198
  }
187
- function ee({
199
+ function ae({
188
200
  options: e,
189
201
  session: t,
190
202
  settled: a
191
203
  }) {
192
- return !a && t !== null && e !== null && c(e);
204
+ return !a && t !== null && e !== null && l(e);
193
205
  }
194
- function k(e, t, a) {
206
+ function T(e, t, a) {
195
207
  try {
196
208
  e == null || e(t, a);
197
209
  } catch (n) {
198
210
  console.error(`onEvent("${t}") threw:`, n);
199
211
  }
200
212
  }
201
- async function U({
213
+ async function x({
202
214
  api: e,
203
215
  options: t,
204
216
  emit: a
205
217
  }) {
206
218
  try {
207
- const n = await W({ api: e, options: t }), { session: o, sessionPromoted: r } = await x({ api: e, sessionID: n });
208
- a("session.loaded", M(o));
209
- const s = await Y({
219
+ const n = await M({ api: e, options: t }), { session: o, sessionPromoted: r } = await Y({ api: e, sessionID: n });
220
+ a("session.loaded", $(o));
221
+ const s = await B({
210
222
  api: e,
211
223
  transactionID: o.transactionID
212
224
  });
@@ -215,35 +227,35 @@ async function U({
215
227
  return { ok: !1 };
216
228
  }
217
229
  }
218
- async function W({
230
+ async function M({
219
231
  api: e,
220
232
  options: t
221
233
  }) {
222
- return c(t) ? t.sessionID : (await e.createSession({
234
+ return l(t) ? t.sessionID : (await e.createSession({
223
235
  amount: t.transaction.amount,
224
236
  amountCurrency: t.transaction.currency,
225
237
  descriptor: t.transaction.descriptor,
226
238
  referenceNumber: t.transaction.referenceNumber
227
239
  })).sessionID;
228
240
  }
229
- async function x({
241
+ async function Y({
230
242
  api: e,
231
243
  sessionID: t
232
244
  }) {
233
245
  const a = await e.getSession(t);
234
- return { session: a, sessionPromoted: T(a) };
246
+ return { session: a, sessionPromoted: E(a) };
235
247
  }
236
- function M(e) {
248
+ function $(e) {
237
249
  return {
238
250
  sessionID: e.sessionID,
239
251
  merchantName: e.merchantName,
240
- alreadyPromoted: T(e)
252
+ alreadyPromoted: E(e)
241
253
  };
242
254
  }
243
- function T(e) {
255
+ function E(e) {
244
256
  return !!e.transactionID;
245
257
  }
246
- async function Y({
258
+ async function B({
247
259
  api: e,
248
260
  transactionID: t
249
261
  }) {
@@ -255,7 +267,7 @@ async function Y({
255
267
  return console.error("Failed to resolve the session transaction:", a), null;
256
268
  }
257
269
  }
258
- function m(e) {
270
+ function h(e) {
259
271
  if (!e)
260
272
  return;
261
273
  let t;
@@ -266,7 +278,7 @@ function m(e) {
266
278
  }
267
279
  return t.protocol === "https:" || t.protocol === "http:" ? e : void 0;
268
280
  }
269
- function $({
281
+ function _({
270
282
  message: e,
271
283
  reason: t,
272
284
  shouldEndCheckout: a,
@@ -282,11 +294,11 @@ function $({
282
294
  // Only a failure that ends the checkout carries a redirect. A retryable one
283
295
  // leaves the customer mid-flow with something still to do, and a host that
284
296
  // navigated on it would eject them on a hiccup.
285
- redirectURL: a ? m(o == null ? void 0 : o.failureURL) : void 0
297
+ redirectURL: a ? h(o == null ? void 0 : o.failureURL) : void 0
286
298
  }
287
299
  };
288
300
  }
289
- const B = {
301
+ const G = {
290
302
  "common.cancelTransaction": "Cancel Transaction",
291
303
  "common.cancel": "Cancel",
292
304
  "common.back": "Back",
@@ -329,6 +341,7 @@ const B = {
329
341
  "wallet.connectNamed": "Connect {wallet}",
330
342
  "wallet.scanToConnect": "Scan with your phone to connect with {wallet}.",
331
343
  "wallet.continueInApp": "Continue in {wallet}",
344
+ "wallet.paidInApp": "Paid {paid} of {total} in {wallet}",
332
345
  "wallet.backToWallets": "Back to wallets",
333
346
  "asset.chooseCoin": "Choose a coin",
334
347
  "asset.markupNotice": "Conversion includes a {percent}% markup fee",
@@ -507,40 +520,40 @@ const B = {
507
520
  "validation.customerDetailsMissing": "Customer details are missing.",
508
521
  "validation.invalidOtp": "Please enter a valid 6-digit code.",
509
522
  "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>.'
510
- }, f = { en: B }, E = "en";
511
- let D = E;
512
- function te() {
523
+ }, f = { en: G }, v = "en";
524
+ let D = v;
525
+ function ne() {
513
526
  return D;
514
527
  }
515
- function v(e, t) {
528
+ function N(e, t) {
516
529
  var n;
517
- const a = ((n = f[D]) == null ? void 0 : n[e]) ?? f[E][e] ?? e;
530
+ const a = ((n = f[D]) == null ? void 0 : n[e]) ?? f[v][e] ?? e;
518
531
  return t ? a.replace(
519
532
  /\{(\w+)\}/g,
520
533
  (o, r) => t[r] != null ? String(t[r]) : `{${r}}`
521
534
  ) : a;
522
535
  }
523
- function _(e) {
536
+ function q(e) {
524
537
  return e === u.SUCCESS ? "succeeded" : e < u.PENDING && e !== u.KYC_VERIFICATION_PENDING && e !== u.COMPLIANCE_PENDING ? "failed" : "active";
525
538
  }
526
- function q({
539
+ function H({
527
540
  transaction: e,
528
541
  session: t
529
542
  }) {
530
543
  var o, r, s;
531
- const a = _(e.status);
544
+ const a = q(e.status);
532
545
  if (a === "active")
533
546
  return null;
534
547
  if (a === "failed")
535
548
  return {
536
549
  outcome: a,
537
- message: v("errors.paymentCouldNotComplete"),
550
+ message: N("errors.paymentCouldNotComplete"),
538
551
  failure: {
539
552
  shouldEndCheckout: !0,
540
553
  // Negative (non-KYC) status — cancelled / fraud / timeout.
541
554
  reason: "blocked",
542
555
  transactionID: e.transactionID,
543
- redirectURL: m(t == null ? void 0 : t.failureURL)
556
+ redirectURL: h(t == null ? void 0 : t.failureURL)
544
557
  }
545
558
  };
546
559
  const n = (o = e.payments) == null ? void 0 : o.find(
@@ -560,7 +573,7 @@ function q({
560
573
  asset: n == null ? void 0 : n.cryptoAsset,
561
574
  network: n == null ? void 0 : n.cryptoNetwork,
562
575
  completedAt: n == null ? void 0 : n.completedAt,
563
- redirectURL: m(t == null ? void 0 : t.successURL)
576
+ redirectURL: h(t == null ? void 0 : t.successURL)
564
577
  }
565
578
  };
566
579
  }
@@ -570,7 +583,7 @@ function K() {
570
583
  setOptions: (t) => {
571
584
  e = t;
572
585
  },
573
- emit: (t, a) => k(e == null ? void 0 : e.onEvent, t, a),
586
+ emit: (t, a) => T(e == null ? void 0 : e.onEvent, t, a),
574
587
  paymentFailed: (t, a) => {
575
588
  var n;
576
589
  return (n = e == null ? void 0 : e.paymentFailedListener) == null ? void 0 : n.call(e, t, a);
@@ -585,7 +598,7 @@ function K() {
585
598
  }
586
599
  };
587
600
  }
588
- class G extends HTMLElement {
601
+ class j extends HTMLElement {
589
602
  constructor() {
590
603
  super(), this.engine = null, this.engineLoadPromise = null, this.isTornDown = !1, this.shadow = this.attachShadow({ mode: "open" });
591
604
  }
@@ -595,7 +608,7 @@ class G extends HTMLElement {
595
608
  this.isTornDown = !1;
596
609
  }
597
610
  async initialize(t) {
598
- const a = H(t), n = j({ api: a, options: t }), o = await this.loadEngine(t, n);
611
+ const a = z(t), n = J({ api: a, options: t }), o = await this.loadEngine(t, n);
599
612
  !o || this.isTornDown || (this.engine = o, await o.initialize(t, { api: a, sessionLoad: n }));
600
613
  }
601
614
  async loadEngine(t, a) {
@@ -623,7 +636,7 @@ class G extends HTMLElement {
623
636
  // Not started in the constructor: a page can carry the tag and never check out.
624
637
  // Overlapping initialize() calls share one download.
625
638
  getOrLoadEngine() {
626
- return this.engineLoadPromise ?? (this.engineLoadPromise = import("./mountEngine-BIIdZhCT.js").then((t) => t.m).then((t) => {
639
+ return this.engineLoadPromise ?? (this.engineLoadPromise = import("./mountEngine-0Lj7ZkFh.js").then((t) => t.m).then((t) => {
627
640
  const a = t.mountCheckoutEngine({
628
641
  host: this,
629
642
  shadowRoot: this.shadow
@@ -658,7 +671,7 @@ class G extends HTMLElement {
658
671
  return;
659
672
  const o = K();
660
673
  o.setOptions(t);
661
- const r = n.ok && n.linkedTransaction ? q({
674
+ const r = n.ok && n.linkedTransaction ? H({
662
675
  transaction: n.linkedTransaction,
663
676
  session: n.session
664
677
  }) : null;
@@ -674,7 +687,7 @@ class G extends HTMLElement {
674
687
  }), o.paymentFailed(r.message, r.failure);
675
688
  return;
676
689
  }
677
- const s = v("errors.checkoutUnavailable"), i = $({
690
+ const s = N("errors.checkoutUnavailable"), i = _({
678
691
  message: s,
679
692
  reason: "error",
680
693
  shouldEndCheckout: !0,
@@ -688,82 +701,88 @@ class G extends HTMLElement {
688
701
  t == null || t.teardown(), t == null || t.unmount(), this.engine = null, this.engineLoadPromise = null;
689
702
  }
690
703
  }
691
- function H(e) {
704
+ function z(e) {
692
705
  return new R(
693
706
  F(e),
694
- c(e) ? void 0 : e.publishableKey
707
+ l(e) ? void 0 : e.publishableKey
695
708
  );
696
709
  }
697
- function j({
710
+ function J({
698
711
  api: e,
699
712
  options: t
700
713
  }) {
701
- return U({
714
+ return x({
702
715
  api: e,
703
716
  options: t,
704
- emit: (a, n) => k(t.onEvent, a, n)
717
+ emit: (a, n) => T(t.onEvent, a, n)
705
718
  });
706
719
  }
707
- customElements.get("lydian-checkout") || customElements.define("lydian-checkout", G);
708
- function h() {
720
+ customElements.get("lydian-checkout") || customElements.define("lydian-checkout", j);
721
+ function m() {
709
722
  return document.querySelector("lydian-checkout");
710
723
  }
711
- async function z(e) {
724
+ async function Q(e) {
712
725
  if (!e.publishableKey || !e.transaction.amount || !e.transaction.currency)
713
726
  throw new Error("SDK initialization requires publishableKey and a transaction");
714
727
  const t = P(e);
715
728
  if (t)
716
729
  throw new Error(t);
717
- if (!N(e.transaction.currency))
730
+ const a = k(e);
731
+ if (a)
732
+ throw new Error(a);
733
+ if (!A(e.transaction.currency))
718
734
  throw new Error("Invalid value for currency, valid values are: " + g.join(", "));
719
- const a = b({
735
+ const n = C({
720
736
  options: e,
721
737
  unsupportedKeys: ["sessionID"],
722
738
  entryPoint: "init"
723
739
  });
724
- if (a)
725
- throw new Error(a);
726
- await h().initialize(e);
740
+ if (n)
741
+ throw new Error(n);
742
+ await m().initialize(e);
727
743
  }
728
- async function Q(e) {
744
+ async function Z(e) {
729
745
  if (!e.sessionID)
730
746
  throw new Error("initExistingSession requires a sessionID");
731
747
  const t = P(e);
732
748
  if (t)
733
749
  throw new Error(t);
734
- const a = b({
750
+ const a = k(e);
751
+ if (a)
752
+ throw new Error(a);
753
+ const n = C({
735
754
  options: e,
736
755
  unsupportedKeys: ["publishableKey", "transaction"],
737
756
  entryPoint: "initExistingSession"
738
757
  });
739
- if (a)
740
- throw new Error(a);
741
- await h().initialize(e);
758
+ if (n)
759
+ throw new Error(n);
760
+ await m().initialize(e);
742
761
  }
743
- async function J(e) {
744
- await h().updateTransaction(e);
762
+ async function X(e) {
763
+ await m().updateTransaction(e);
745
764
  }
746
- window.Lydian = { init: z, initExistingSession: Q, updateTransaction: J };
765
+ window.Lydian = { init: Q, initExistingSession: Z, updateTransaction: X };
747
766
  export {
748
767
  O as P,
749
768
  u as T,
750
- Z as a,
751
- V as b,
769
+ V as a,
770
+ te as b,
752
771
  g as c,
753
- x as d,
754
- M as e,
755
- Y as f,
756
- te as g,
757
- c as h,
758
- N as i,
759
- _ as j,
760
- q as k,
761
- T as l,
762
- ee as m,
763
- $ as n,
764
- X as o,
772
+ Y as d,
773
+ $ as e,
774
+ B as f,
775
+ ne as g,
776
+ l as h,
777
+ A as i,
778
+ q as j,
779
+ H as k,
780
+ E as l,
781
+ ae as m,
782
+ _ as n,
783
+ ee as o,
765
784
  K as p,
766
- W as r,
767
- m as s,
768
- v as t
785
+ M as r,
786
+ h as s,
787
+ N as t
769
788
  };