@lydianpay/sdk-web 3.18.6 → 3.18.7

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,11 +1,11 @@
1
1
  const E = ["USD", "TRY", "PHP"];
2
- function U(e) {
2
+ function O(e) {
3
3
  return typeof e == "string" && E.includes(e);
4
4
  }
5
5
  function u(e) {
6
6
  return "sessionID" in e && typeof e.sessionID == "string" && e.sessionID.length > 0;
7
7
  }
8
- class O extends Error {
8
+ class U extends Error {
9
9
  constructor({
10
10
  statusText: t,
11
11
  errorCode: a,
@@ -16,7 +16,7 @@ class O extends Error {
16
16
  }
17
17
  async function m(e) {
18
18
  const t = await e.clone().json().catch(() => null);
19
- return new O({
19
+ return new U({
20
20
  statusText: e.statusText,
21
21
  errorCode: F(t),
22
22
  response: e
@@ -62,7 +62,7 @@ class y {
62
62
  throw await m(s);
63
63
  }
64
64
  }
65
- const c = "transaction", W = [
65
+ const l = "transaction", W = [
66
66
  "firstName",
67
67
  "lastName",
68
68
  "email",
@@ -82,11 +82,11 @@ const c = "transaction", W = [
82
82
  ];
83
83
  class $ extends y {
84
84
  async getCryptoTransaction(t) {
85
- return await this.request(`/${c}/${t}`);
85
+ return await this.request(`/${l}/${t}`);
86
86
  }
87
87
  async createPaymentRequest(t, a) {
88
88
  return await this.request(
89
- `/${c}/${t}/payment`,
89
+ `/${l}/${t}/payment`,
90
90
  {
91
91
  method: "POST",
92
92
  body: JSON.stringify(a)
@@ -95,7 +95,7 @@ class $ extends y {
95
95
  }
96
96
  async buildTransfer(t, a, n) {
97
97
  return await this.request(
98
- `/${c}/${t}/payment/${a}/transfer`,
98
+ `/${l}/${t}/payment/${a}/transfer`,
99
99
  {
100
100
  method: "POST",
101
101
  body: JSON.stringify(n)
@@ -104,7 +104,7 @@ class $ extends y {
104
104
  }
105
105
  async broadcastTransfer(t, a, n) {
106
106
  return await this.request(
107
- `/${c}/${t}/payment/${a}/transfer/broadcast`,
107
+ `/${l}/${t}/payment/${a}/transfer/broadcast`,
108
108
  {
109
109
  method: "POST",
110
110
  body: JSON.stringify(n)
@@ -113,7 +113,7 @@ class $ extends y {
113
113
  }
114
114
  async cancelCryptoTransaction(t, a) {
115
115
  return await this.request(
116
- `/${c}/${t}/cancel`,
116
+ `/${l}/${t}/cancel`,
117
117
  {
118
118
  method: "PATCH",
119
119
  body: JSON.stringify(a)
@@ -128,7 +128,7 @@ class $ extends y {
128
128
  }), 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(
129
129
  (o, r) => n.append("documentFiles", o, `${r + 1}-${o.name}`)
130
130
  ), await this.requestWithFormData(
131
- `/${c}/${t}/verification`,
131
+ `/${l}/${t}/verification`,
132
132
  {
133
133
  method: "POST",
134
134
  body: n
@@ -136,7 +136,7 @@ class $ extends y {
136
136
  );
137
137
  }
138
138
  }
139
- function Y(e, t) {
139
+ function M(e, t) {
140
140
  t.forEach((a) => {
141
141
  Object.getOwnPropertyNames(a.prototype).forEach((n) => {
142
142
  const o = Object.getOwnPropertyDescriptor(a.prototype, n);
@@ -144,49 +144,57 @@ function Y(e, t) {
144
144
  });
145
145
  });
146
146
  }
147
- const k = "customer/otp";
148
- class x extends y {
147
+ const f = "customer";
148
+ class Y extends y {
149
149
  // PATCH /customer/otp -> text/plain "OTP sent" (no JSON body).
150
150
  async sendCustomerOTP(t) {
151
- return await this.requestText(`/${k}`, {
151
+ return await this.requestText(`/${f}/otp`, {
152
152
  method: "PATCH",
153
153
  body: JSON.stringify(t)
154
154
  });
155
155
  }
156
156
  // PUT /customer/otp -> { customerUUID, kycValidated }.
157
157
  async authenticateCustomerOTP(t) {
158
- return await this.request(`/${k}`, {
158
+ return await this.request(`/${f}/otp`, {
159
+ method: "PUT",
160
+ body: JSON.stringify(t)
161
+ });
162
+ }
163
+ // PUT /customer/pii -> the stored record, masked. Verifies the same code as
164
+ // PUT /customer/otp; a code serves both until it expires.
165
+ async getCustomerPII(t) {
166
+ return await this.request(`/${f}/pii`, {
159
167
  method: "PUT",
160
168
  body: JSON.stringify(t)
161
169
  });
162
170
  }
163
171
  }
164
- const B = "places", M = { "X-User": "lydian" };
172
+ const x = "places", B = { "X-User": "lydian" };
165
173
  class _ extends y {
166
174
  async getCountries(t) {
167
- return await this.request(`/${B}/countries`, {
168
- headers: M,
175
+ return await this.request(`/${x}/countries`, {
176
+ headers: B,
169
177
  signal: t
170
178
  });
171
179
  }
172
180
  }
173
- const l = "session";
181
+ const d = "session";
174
182
  class q extends y {
175
183
  async createSession(t) {
176
- return await this.request(`/${l}`, {
184
+ return await this.request(`/${d}`, {
177
185
  method: "POST",
178
186
  body: JSON.stringify(t)
179
187
  });
180
188
  }
181
189
  async getSession(t) {
182
- return await this.request(`/${l}/${t}`);
190
+ return await this.request(`/${d}/${t}`);
183
191
  }
184
192
  // Promotes the session into a transaction. Allowed once per session — except
185
193
  // that a KYC-pending (-3) response does not consume the promotion, which is
186
194
  // what lets the restore-details flow re-promote with a customerUUID.
187
195
  async createSessionTransaction(t, a) {
188
196
  return await this.request(
189
- `/${l}/${t}/transaction`,
197
+ `/${d}/${t}/transaction`,
190
198
  {
191
199
  method: "POST",
192
200
  body: JSON.stringify(a)
@@ -196,22 +204,22 @@ class q extends y {
196
204
  // PATCH /session/{id}/cancel replies text/plain (the merchant's cancel URL),
197
205
  // not JSON. Cancelling cascades to the linked transaction, if any.
198
206
  async cancelSession(t) {
199
- return await this.requestText(`/${l}/${t}/cancel`, {
207
+ return await this.requestText(`/${d}/${t}/cancel`, {
200
208
  method: "PATCH"
201
209
  });
202
210
  }
203
211
  async sendReceipt(t, a) {
204
- await this.request(`/${l}/${t}/receipt`, {
212
+ await this.request(`/${d}/${t}/receipt`, {
205
213
  method: "POST",
206
214
  body: JSON.stringify(a)
207
215
  });
208
216
  }
209
217
  }
210
- class v extends y {
218
+ class S extends y {
211
219
  }
212
- Y(v, [$, x, _, q]);
213
- const G = v;
214
- var d = {
220
+ M(S, [$, Y, _, q]);
221
+ const G = S;
222
+ var c = {
215
223
  COMPLIANCE_PENDING: -10,
216
224
  API_CANCELLED: -9,
217
225
  PAYMENT_TIMEOUT: -8,
@@ -228,10 +236,10 @@ var d = {
228
236
  FRAUD: -1,
229
237
  PENDING: 0,
230
238
  SUCCESS: 1
231
- }, j = {
239
+ }, H = {
232
240
  PARTIALLY_PAID: 1,
233
241
  OVERPAID: 3
234
- }, H = {
242
+ }, K = {
235
243
  PENDING: 0,
236
244
  CONFIRMED: 1
237
245
  }, w = {
@@ -239,10 +247,10 @@ var d = {
239
247
  sandbox: "https://api.sandbox.lydian.com",
240
248
  prod: "https://api.lydian.com"
241
249
  };
242
- function K(e) {
250
+ function j(e) {
243
251
  return e.gatewayUrl ? new URL(e.gatewayUrl).origin : e.dev ? w.dev : e.sandbox ? w.sandbox : w.prod;
244
252
  }
245
- function S({
253
+ function v({
246
254
  options: e,
247
255
  unsupportedKeys: t,
248
256
  entryPoint: a
@@ -266,20 +274,20 @@ function z(e) {
266
274
  }
267
275
  return (t.protocol === "http:" || t.protocol === "https:") && t.pathname === "/" && t.search === "" && t.hash === "";
268
276
  }
269
- function ue(e) {
277
+ function ye(e) {
270
278
  return e !== null && !u(e) && !!e.publishableKey;
271
279
  }
272
- function ye(e) {
280
+ function pe(e) {
273
281
  return e !== null && !u(e);
274
282
  }
275
- function pe({
283
+ function he({
276
284
  options: e,
277
285
  session: t,
278
286
  settled: a
279
287
  }) {
280
288
  return !a && t !== null && e !== null && u(e);
281
289
  }
282
- function N(e, t, a) {
290
+ function I(e, t, a) {
283
291
  try {
284
292
  e == null || e(t, a);
285
293
  } catch (n) {
@@ -297,24 +305,28 @@ function p(e) {
297
305
  }
298
306
  return t.protocol === "https:" || t.protocol === "http:" ? e : void 0;
299
307
  }
300
- async function J({
308
+ const J = [
309
+ c.KYC_VERIFICATION_PENDING,
310
+ c.COMPLIANCE_PENDING
311
+ ];
312
+ async function Q({
301
313
  api: e,
302
314
  options: t,
303
315
  emit: a
304
316
  }) {
305
317
  try {
306
- const n = await X({ api: e, options: t }), { session: o, sessionPromoted: r } = await V({ api: e, sessionID: n });
318
+ const n = await V({ api: e, options: t }), o = await e.getSession(n);
307
319
  a("session.loaded", Z(o));
308
- const s = await ee({
320
+ const r = await te({
309
321
  api: e,
310
322
  transactionID: o.transactionID
311
- });
312
- return { ok: !0, session: o, sessionPromoted: r, linkedTransaction: s };
323
+ }), s = ee({ session: o, linkedTransaction: r });
324
+ return { ok: !0, session: o, sessionPromoted: s, linkedTransaction: r };
313
325
  } catch (n) {
314
- return { ok: !1, ...await Q(n) };
326
+ return { ok: !1, ...await X(n) };
315
327
  }
316
328
  }
317
- async function Q(e) {
329
+ async function X(e) {
318
330
  const t = e instanceof Error ? e.cause : void 0;
319
331
  if (!(t instanceof Response && t.status === 404))
320
332
  return {};
@@ -331,7 +343,7 @@ async function Q(e) {
331
343
  function C(e) {
332
344
  return typeof e == "string" ? p(e) : void 0;
333
345
  }
334
- async function X({
346
+ async function V({
335
347
  api: e,
336
348
  options: t
337
349
  }) {
@@ -342,24 +354,23 @@ async function X({
342
354
  referenceNumber: t.transaction.referenceNumber
343
355
  })).sessionID;
344
356
  }
345
- async function V({
346
- api: e,
347
- sessionID: t
348
- }) {
349
- const a = await e.getSession(t);
350
- return { session: a, sessionPromoted: I(a) };
351
- }
352
357
  function Z(e) {
353
358
  return {
354
359
  sessionID: e.sessionID,
355
360
  merchantName: e.merchantName,
356
- alreadyPromoted: I(e)
361
+ alreadyPromoted: N(e)
357
362
  };
358
363
  }
359
- function I(e) {
364
+ function N(e) {
360
365
  return !!e.transactionID;
361
366
  }
362
- async function ee({
367
+ function ee({
368
+ session: e,
369
+ linkedTransaction: t
370
+ }) {
371
+ return N(e) ? t ? !J.includes(t.status) : !0 : !1;
372
+ }
373
+ async function te({
363
374
  api: e,
364
375
  transactionID: t
365
376
  }) {
@@ -391,7 +402,7 @@ function P({
391
402
  }
392
403
  };
393
404
  }
394
- const te = {
405
+ const ae = {
395
406
  "common.cancelTransaction": "Cancel Transaction",
396
407
  "common.cancel": "Cancel",
397
408
  "common.back": "Back",
@@ -500,6 +511,7 @@ const te = {
500
511
  "kyc.fileHint": "PNG, JPG or PDF, up to 10 MB",
501
512
  "kyc.saveInfo": "Securely save this info for next time",
502
513
  "kyc.saveInfoDescription": "Next time, skip this step by entering the one-time code sent to your email.",
514
+ "kyc.onFileHint": "Details we have on file are shown masked. Select a field to replace it.",
503
515
  "scan.exactAmountNotice": "Make sure you send the exact amount on the correct network to complete your payment smoothly.",
504
516
  "scan.scanWithWallet": "Scan the QR code with your preferred wallet",
505
517
  "scan.payOnWallet": "Pay on {wallet}",
@@ -639,32 +651,32 @@ const te = {
639
651
  "validation.customerDetailsMissing": "Customer details are missing.",
640
652
  "validation.invalidOtp": "Please enter a valid 6-digit code.",
641
653
  "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>.'
642
- }, T = { en: te }, L = "en";
643
- let R = L;
644
- function he() {
645
- return R;
654
+ }, T = { en: ae }, R = "en";
655
+ let L = R;
656
+ function me() {
657
+ return L;
646
658
  }
647
659
  function h(e, t) {
648
660
  var n;
649
- const a = ((n = T[R]) == null ? void 0 : n[e]) ?? T[L][e] ?? e;
661
+ const a = ((n = T[L]) == null ? void 0 : n[e]) ?? T[R][e] ?? e;
650
662
  return t ? a.replace(
651
663
  /\{(\w+)\}/g,
652
664
  (o, r) => t[r] != null ? String(t[r]) : `{${r}}`
653
665
  ) : a;
654
666
  }
655
- function ae(e) {
656
- return e === d.SUCCESS ? "succeeded" : e < d.PENDING && e !== d.KYC_VERIFICATION_PENDING && e !== d.COMPLIANCE_PENDING ? "failed" : "active";
667
+ function ne(e) {
668
+ return e === c.SUCCESS ? "succeeded" : e < c.PENDING && e !== c.KYC_VERIFICATION_PENDING && e !== c.COMPLIANCE_PENDING ? "failed" : "active";
657
669
  }
658
- function ne({
670
+ function oe({
659
671
  transaction: e,
660
672
  session: t
661
673
  }) {
662
674
  var o, r, s;
663
- const a = ae(e.status);
675
+ const a = ne(e.status);
664
676
  if (a === "active")
665
677
  return null;
666
678
  if (a === "failed") {
667
- const i = e.status === d.PAYMENT_TIMEOUT && e.paymentStatus === j.PARTIALLY_PAID;
679
+ const i = e.status === c.PAYMENT_TIMEOUT && e.paymentStatus === H.PARTIALLY_PAID;
668
680
  return {
669
681
  outcome: a,
670
682
  message: h(i ? "errors.paymentShortRefundRequested" : "errors.paymentCouldNotComplete"),
@@ -678,7 +690,7 @@ function ne({
678
690
  };
679
691
  }
680
692
  const n = (o = e.payments) == null ? void 0 : o.find(
681
- (i) => i.status === H.CONFIRMED
693
+ (i) => i.status === K.CONFIRMED
682
694
  );
683
695
  return {
684
696
  outcome: a,
@@ -698,13 +710,13 @@ function ne({
698
710
  }
699
711
  };
700
712
  }
701
- function oe() {
713
+ function re() {
702
714
  let e = null;
703
715
  return {
704
716
  setOptions: (t) => {
705
717
  e = t;
706
718
  },
707
- emit: (t, a) => N(e == null ? void 0 : e.onEvent, t, a),
719
+ emit: (t, a) => I(e == null ? void 0 : e.onEvent, t, a),
708
720
  paymentFailed: (t, a) => {
709
721
  var n;
710
722
  return (n = e == null ? void 0 : e.paymentFailedListener) == null ? void 0 : n.call(e, t, a);
@@ -719,7 +731,7 @@ function oe() {
719
731
  }
720
732
  };
721
733
  }
722
- class re extends HTMLElement {
734
+ class se extends HTMLElement {
723
735
  constructor() {
724
736
  super(), this.engine = null, this.engineLoadPromise = null, this.isTornDown = !1, this.shadow = this.attachShadow({ mode: "open" });
725
737
  }
@@ -729,7 +741,7 @@ class re extends HTMLElement {
729
741
  this.isTornDown = !1;
730
742
  }
731
743
  async initialize(t) {
732
- const a = se(t), n = ie({ api: a, options: t }), o = await this.loadEngine(t, n);
744
+ const a = ie(t), n = ce({ api: a, options: t }), o = await this.loadEngine(t, n);
733
745
  !o || this.isTornDown || (this.engine = o, await o.initialize(t, { api: a, sessionLoad: n }));
734
746
  }
735
747
  async loadEngine(t, a) {
@@ -757,7 +769,7 @@ class re extends HTMLElement {
757
769
  // Not started in the constructor: a page can carry the tag and never check out.
758
770
  // Overlapping initialize() calls share one download.
759
771
  getOrLoadEngine() {
760
- return this.engineLoadPromise ?? (this.engineLoadPromise = import("./mountEngine-CwbM3qVk.js").then((t) => t.m).then((t) => {
772
+ return this.engineLoadPromise ?? (this.engineLoadPromise = import("./mountEngine-CG_6rKvA.js").then((t) => t.m).then((t) => {
761
773
  const a = t.mountCheckoutEngine({
762
774
  host: this,
763
775
  shadowRoot: this.shadow
@@ -790,9 +802,9 @@ class re extends HTMLElement {
790
802
  const n = await a;
791
803
  if (this.isDismissedByHost)
792
804
  return;
793
- const o = oe();
805
+ const o = re();
794
806
  o.setOptions(t);
795
- const r = n.ok && n.linkedTransaction ? ne({
807
+ const r = n.ok && n.linkedTransaction ? oe({
796
808
  transaction: n.linkedTransaction,
797
809
  session: n.session
798
810
  }) : null;
@@ -813,13 +825,13 @@ class re extends HTMLElement {
813
825
  return;
814
826
  }
815
827
  if (!n.ok && n.failureURL) {
816
- const g = h("errors.unableToCreateSession"), b = P({
817
- message: g,
828
+ const b = h("errors.unableToCreateSession"), k = P({
829
+ message: b,
818
830
  reason: "sessionExpired",
819
831
  shouldEndCheckout: !0,
820
832
  session: { failureURL: n.failureURL }
821
833
  });
822
- o.emit("payment.failed", b.event), o.paymentFailed(g, b.failure);
834
+ o.emit("payment.failed", k.event), o.paymentFailed(b, k.failure);
823
835
  return;
824
836
  }
825
837
  const s = h("errors.checkoutUnavailable"), i = P({
@@ -836,27 +848,27 @@ class re extends HTMLElement {
836
848
  t == null || t.teardown(), t == null || t.unmount(), this.engine = null, this.engineLoadPromise = null;
837
849
  }
838
850
  }
839
- function se(e) {
851
+ function ie(e) {
840
852
  return new G(
841
- K(e),
853
+ j(e),
842
854
  u(e) ? void 0 : e.publishableKey
843
855
  );
844
856
  }
845
- function ie({
857
+ function ce({
846
858
  api: e,
847
859
  options: t
848
860
  }) {
849
- return J({
861
+ return Q({
850
862
  api: e,
851
863
  options: t,
852
- emit: (a, n) => N(t.onEvent, a, n)
864
+ emit: (a, n) => I(t.onEvent, a, n)
853
865
  });
854
866
  }
855
- customElements.get("lydian-checkout") || customElements.define("lydian-checkout", re);
856
- function f() {
867
+ customElements.get("lydian-checkout") || customElements.define("lydian-checkout", se);
868
+ function g() {
857
869
  return document.querySelector("lydian-checkout");
858
870
  }
859
- async function ce(e) {
871
+ async function le(e) {
860
872
  if (!e.publishableKey || !e.transaction.amount || !e.transaction.currency)
861
873
  throw new Error("SDK initialization requires publishableKey and a transaction");
862
874
  const t = D(e);
@@ -865,18 +877,18 @@ async function ce(e) {
865
877
  const a = A(e);
866
878
  if (a)
867
879
  throw new Error(a);
868
- if (!U(e.transaction.currency))
880
+ if (!O(e.transaction.currency))
869
881
  throw new Error("Invalid value for currency, valid values are: " + E.join(", "));
870
- const n = S({
882
+ const n = v({
871
883
  options: e,
872
884
  unsupportedKeys: ["sessionID"],
873
885
  entryPoint: "init"
874
886
  });
875
887
  if (n)
876
888
  throw new Error(n);
877
- await f().initialize(e);
889
+ await g().initialize(e);
878
890
  }
879
- async function le(e) {
891
+ async function de(e) {
880
892
  if (!e.sessionID)
881
893
  throw new Error("initExistingSession requires a sessionID");
882
894
  const t = D(e);
@@ -885,40 +897,40 @@ async function le(e) {
885
897
  const a = A(e);
886
898
  if (a)
887
899
  throw new Error(a);
888
- const n = S({
900
+ const n = v({
889
901
  options: e,
890
902
  unsupportedKeys: ["publishableKey", "transaction"],
891
903
  entryPoint: "initExistingSession"
892
904
  });
893
905
  if (n)
894
906
  throw new Error(n);
895
- await f().initialize(e);
907
+ await g().initialize(e);
896
908
  }
897
- async function de(e) {
898
- await f().updateTransaction(e);
909
+ async function ue(e) {
910
+ await g().updateTransaction(e);
899
911
  }
900
- window.Lydian = { init: ce, initExistingSession: le, updateTransaction: de };
912
+ window.Lydian = { init: le, initExistingSession: de, updateTransaction: ue };
901
913
  export {
902
- O as G,
903
- j as P,
904
- d as T,
905
- H as a,
906
- ye as b,
914
+ U as G,
915
+ H as P,
916
+ c as T,
917
+ K as a,
918
+ pe as b,
907
919
  E as c,
908
- V as d,
909
- Z as e,
910
- ee as f,
911
- he as g,
920
+ Z as d,
921
+ ee as e,
922
+ te as f,
923
+ me as g,
912
924
  u as h,
913
- U as i,
914
- ae as j,
915
- ne as k,
916
- I as l,
917
- pe as m,
925
+ O as i,
926
+ ne as j,
927
+ oe as k,
928
+ N as l,
929
+ he as m,
918
930
  P as n,
919
- ue as o,
920
- oe as p,
921
- X as r,
931
+ ye as o,
932
+ re as p,
933
+ V as r,
922
934
  p as s,
923
935
  h as t
924
936
  };