@bcc-code/payment-client 1.1.0 → 1.1.2

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,14 +1,14 @@
1
- import { defineComponent as R, ref as h, computed as w, onMounted as B, onUnmounted as N, watch as E, createElementBlock as P, openBlock as C, createElementVNode as y, createCommentVNode as A, toDisplayString as F } from "vue";
2
- const x = { class: "stripe-elements" }, M = {
1
+ import { defineComponent as R, ref as D, computed as S, onMounted as A, onUnmounted as I, watch as E, createElementBlock as v, openBlock as b, createElementVNode as o, createCommentVNode as C, toDisplayString as _ } from "vue";
2
+ const $ = { class: "stripe-elements" }, x = {
3
3
  key: 0,
4
4
  class: "elements-loading"
5
- }, I = {
5
+ }, B = {
6
6
  key: 1,
7
7
  class: "elements-error"
8
- }, z = {
8
+ }, O = {
9
9
  key: 2,
10
10
  class: "payment-button-container"
11
- }, H = ["disabled"], O = /* @__PURE__ */ R({
11
+ }, M = ["disabled"], H = /* @__PURE__ */ R({
12
12
  __name: "StripePayment",
13
13
  props: {
14
14
  paymentId: {},
@@ -24,10 +24,10 @@ const x = { class: "stripe-elements" }, M = {
24
24
  returnUrl: { default: void 0 }
25
25
  },
26
26
  emits: ["submit", "success", "error", "ready"],
27
- setup(d, { expose: g, emit: i }) {
28
- const t = d, o = i, b = h(), u = h(!0), r = h(!1), s = h("");
29
- let l = null, m = null, c = null;
30
- const D = w(() => ({
27
+ setup(h, { expose: P, emit: m }) {
28
+ const e = h, a = m, p = D(), u = D(!0), n = D(!1), c = D("");
29
+ let d = null, f = null, y = null;
30
+ const U = S(() => ({
31
31
  EUR: "€",
32
32
  USD: "$",
33
33
  GBP: "£",
@@ -38,34 +38,34 @@ const x = { class: "stripe-elements" }, M = {
38
38
  PLN: "zł",
39
39
  CZK: "Kč",
40
40
  HUF: "Ft"
41
- })[t.currency] || t.currency), _ = w(() => t.amount.toFixed(2)), k = w(() => {
42
- if (t.clientData)
41
+ })[e.currency] || e.currency), K = S(() => e.amount.toFixed(2)), s = S(() => {
42
+ if (e.clientData)
43
43
  try {
44
- const n = JSON.parse(t.clientData);
45
- return n.clientSecret || n.client_secret;
44
+ const r = JSON.parse(e.clientData);
45
+ return r.clientSecret || r.client_secret;
46
46
  } catch {
47
47
  return;
48
48
  }
49
- }), p = async () => {
50
- if (!b.value) return;
51
- let n = t.publishableKey;
52
- if (!n && t.clientData)
49
+ }), i = async () => {
50
+ if (!p.value) return;
51
+ let r = e.publishableKey;
52
+ if (!r && e.clientData)
53
53
  try {
54
- const a = JSON.parse(t.clientData);
55
- n = a.publishableKey || a.publishable_key;
54
+ const l = JSON.parse(e.clientData);
55
+ r = l.publishableKey || l.publishable_key;
56
56
  } catch {
57
57
  }
58
- if (!n) {
59
- s.value = "Publishable key is required", u.value = !1;
58
+ if (!r) {
59
+ c.value = "Publishable key is required", u.value = !1;
60
60
  return;
61
61
  }
62
62
  try {
63
- u.value = !0, s.value = "";
64
- const { loadStripe: a } = await import("@stripe/stripe-js");
65
- if (l = await a(n), !l)
63
+ u.value = !0, c.value = "";
64
+ const { loadStripe: l } = await import("@stripe/stripe-js");
65
+ if (d = await l(r), !d)
66
66
  throw new Error("Failed to load Stripe");
67
- const e = k.value, v = {
68
- appearance: t.appearance || {
67
+ const t = s.value, w = {
68
+ appearance: e.appearance || {
69
69
  theme: "stripe",
70
70
  variables: {
71
71
  colorPrimary: "#0570de",
@@ -77,10 +77,10 @@ const x = { class: "stripe-elements" }, M = {
77
77
  borderRadius: "4px"
78
78
  }
79
79
  },
80
- loader: t.loader,
81
- locale: t.locale
80
+ loader: e.loader,
81
+ locale: e.locale
82
82
  };
83
- e && (v.clientSecret = e), m = l.elements(v), c = m.create("payment", {
83
+ t && (w.clientSecret = t), f = d.elements(w), y = f.create("payment", {
84
84
  layout: "tabs",
85
85
  defaultValues: {
86
86
  billingDetails: {
@@ -89,86 +89,86 @@ const x = { class: "stripe-elements" }, M = {
89
89
  phone: ""
90
90
  }
91
91
  }
92
- }), c.mount(b.value), c.on("ready", () => {
93
- u.value = !1, o("ready");
94
- }), c.on("change", (K) => {
95
- K.error ? (s.value = K.error.message, o("error", K.error)) : s.value = "";
92
+ }), y.mount(p.value), y.on("ready", () => {
93
+ u.value = !1, a("ready");
94
+ }), y.on("change", (N) => {
95
+ N.error ? (c.value = N.error.message, a("error", N.error)) : c.value = "";
96
96
  });
97
- } catch (a) {
98
- s.value = a instanceof Error ? a.message : "Failed to initialize payment form", u.value = !1, o("error", a);
97
+ } catch (l) {
98
+ c.value = l instanceof Error ? l.message : "Failed to initialize payment form", u.value = !1, a("error", l);
99
99
  }
100
- }, S = async () => {
101
- if (!(!l || !c)) {
102
- r.value = !0, s.value = "";
100
+ }, k = async () => {
101
+ if (!(!d || !y)) {
102
+ n.value = !0, c.value = "";
103
103
  try {
104
- const n = t.returnUrl || `${window.location.origin}/payment/return`, { error: a, paymentIntent: e } = await l.confirmPayment({
105
- elements: m,
104
+ const r = e.returnUrl || `${window.location.origin}/payment/return`, { error: l, paymentIntent: t } = await d.confirmPayment({
105
+ elements: f,
106
106
  confirmParams: {
107
- return_url: n
107
+ return_url: r
108
108
  },
109
109
  redirect: "if_required"
110
110
  });
111
- a ? (s.value = a.message || "Payment failed", o("error", a)) : e ? e.status === "succeeded" ? o("success", {
112
- paymentIntent: e,
111
+ l ? (c.value = l.message || "Payment failed", a("error", l)) : t ? t.status === "succeeded" ? a("success", {
112
+ paymentIntent: t,
113
113
  status: "succeeded",
114
114
  message: "Payment completed successfully!"
115
- }) : e.status === "processing" ? o("success", {
116
- paymentIntent: e,
115
+ }) : t.status === "processing" ? a("success", {
116
+ paymentIntent: t,
117
117
  status: "processing",
118
118
  message: "Payment is being processed..."
119
- }) : o("submit", { paymentIntent: e, status: e.status }) : o("submit", c);
120
- } catch (n) {
121
- s.value = n instanceof Error ? n.message : "Payment failed", o("error", n);
119
+ }) : a("submit", { paymentIntent: t, status: t.status }) : a("submit", y);
120
+ } catch (r) {
121
+ c.value = r instanceof Error ? r.message : "Payment failed", a("error", r);
122
122
  } finally {
123
- r.value = !1;
123
+ n.value = !1;
124
124
  }
125
125
  }
126
- }, f = () => {
127
- c && (c.destroy(), c = null), m && (m = null), l && (l = null);
126
+ }, g = () => {
127
+ y && (y.destroy(), y = null), f && (f = null), d && (d = null);
128
128
  };
129
- return B(() => {
130
- p();
131
- }), N(() => {
132
- f();
133
- }), E(() => t.currency, () => {
134
- f(), p();
135
- }), E([() => t.publishableKey, () => t.clientData], () => {
136
- (t.publishableKey || t.clientData) && (f(), p());
137
- }), g({
138
- destroyElements: f
139
- }), (n, a) => (C(), P("div", x, [
140
- y("div", {
129
+ return A(() => {
130
+ i();
131
+ }), I(() => {
132
+ g();
133
+ }), E(() => e.currency, () => {
134
+ g(), i();
135
+ }), E([() => e.publishableKey, () => e.clientData], () => {
136
+ (e.publishableKey || e.clientData) && (g(), i());
137
+ }), P({
138
+ destroyElements: g
139
+ }), (r, l) => (b(), v("div", $, [
140
+ o("div", {
141
141
  ref_key: "elementsContainer",
142
- ref: b,
142
+ ref: p,
143
143
  class: "elements-container"
144
144
  }, null, 512),
145
- u.value ? (C(), P("div", M, [...a[0] || (a[0] = [
146
- y("div", { class: "loading-spinner" }, null, -1),
147
- y("p", null, "Loading payment form...", -1)
148
- ])])) : A("", !0),
149
- s.value ? (C(), P("div", I, [
150
- a[1] || (a[1] = y("div", { class: "error-icon" }, " ⚠️ ", -1)),
151
- y("p", null, F(s.value), 1),
152
- y("button", {
145
+ u.value ? (b(), v("div", x, [...l[0] || (l[0] = [
146
+ o("div", { class: "loading-spinner" }, null, -1),
147
+ o("p", null, "Loading payment form...", -1)
148
+ ])])) : C("", !0),
149
+ c.value ? (b(), v("div", B, [
150
+ l[1] || (l[1] = o("div", { class: "error-icon" }, " ⚠️ ", -1)),
151
+ o("p", null, _(c.value), 1),
152
+ o("button", {
153
153
  class: "retry-btn",
154
- onClick: p
154
+ onClick: i
155
155
  }, " Retry ")
156
- ])) : A("", !0),
157
- d.showPayButton && !u.value && !s.value ? (C(), P("div", z, [
158
- y("button", {
159
- disabled: r.value,
156
+ ])) : C("", !0),
157
+ h.showPayButton && !u.value && !c.value ? (b(), v("div", O, [
158
+ o("button", {
159
+ disabled: n.value,
160
160
  class: "payment-button",
161
- onClick: S
162
- }, F(r.value ? "Processing..." : `Pay ${D.value}${_.value}`), 9, H)
163
- ])) : A("", !0)
161
+ onClick: k
162
+ }, _(n.value ? "Processing..." : `Pay ${U.value}${K.value}`), 9, M)
163
+ ])) : C("", !0)
164
164
  ]));
165
165
  }
166
- }), U = (d, g) => {
167
- const i = d.__vccOpts || d;
168
- for (const [t, o] of g)
169
- i[t] = o;
170
- return i;
171
- }, L = /* @__PURE__ */ U(O, [["__scopeId", "data-v-adbdf3c5"]]), $ = /* @__PURE__ */ R({
166
+ }), F = (h, P) => {
167
+ const m = h.__vccOpts || h;
168
+ for (const [e, a] of P)
169
+ m[e] = a;
170
+ return m;
171
+ }, ne = /* @__PURE__ */ F(H, [["__scopeId", "data-v-adbdf3c5"]]), z = /* @__PURE__ */ R({
172
172
  __name: "AdyenPayment",
173
173
  props: {
174
174
  paymentId: {},
@@ -181,64 +181,64 @@ const x = { class: "stripe-elements" }, M = {
181
181
  onCancel: { type: Function }
182
182
  },
183
183
  emits: ["submit", "additionalDetails", "error", "ready", "success"],
184
- setup(d, { emit: g }) {
185
- const i = d, t = g, o = h(null), b = () => {
186
- if (!i.clientData)
184
+ setup(h, { emit: P }) {
185
+ const m = h, e = P, a = D(null), p = () => {
186
+ if (!m.clientData)
187
187
  return console.error("No clientData provided"), null;
188
188
  try {
189
- const r = JSON.parse(i.clientData);
190
- return console.log("Parsed Adyen session data:", r), {
191
- id: r.id,
192
- sessionData: r.sessionData,
193
- amount: r.amount,
194
- reference: r.reference,
195
- returnUrl: r.returnUrl,
196
- merchantAccount: r.merchantAccount
189
+ const n = JSON.parse(m.clientData);
190
+ return console.log("Parsed Adyen session data:", n), {
191
+ id: n.id,
192
+ sessionData: n.sessionData,
193
+ amount: n.amount,
194
+ reference: n.reference,
195
+ returnUrl: n.returnUrl,
196
+ merchantAccount: n.merchantAccount
197
197
  };
198
- } catch (r) {
199
- return console.error("Failed to parse clientData:", r), null;
198
+ } catch (n) {
199
+ return console.error("Failed to parse clientData:", n), null;
200
200
  }
201
201
  }, u = async () => {
202
- var s;
203
- if (!i.clientKey || !o.value) {
202
+ var c;
203
+ if (!m.clientKey || !a.value) {
204
204
  console.error("Initialization failed: Missing clientKey or container.");
205
205
  return;
206
206
  }
207
- const r = b();
208
- if (!r) {
209
- console.error("Failed to parse session data"), t("error", new Error("Failed to parse session data"));
207
+ const n = p();
208
+ if (!n) {
209
+ console.error("Failed to parse session data"), e("error", new Error("Failed to parse session data"));
210
210
  return;
211
211
  }
212
212
  try {
213
- const { AdyenCheckout: l, Card: m, ApplePay: c, GooglePay: D, Klarna: _, Blik: k, Dropin: p } = await import("@adyen/adyen-web"), S = {
214
- environment: i.environment || "test",
215
- clientKey: i.clientKey,
216
- session: r,
217
- onPaymentCompleted: (e, v) => {
218
- console.info("Payment Completed:", e, v), t("submit", e), e.resultCode === "Authorised" || e.resultCode === "Received" ? (console.info("Payment Successful:", e), t("success", {
213
+ const { AdyenCheckout: d, Card: f, ApplePay: y, GooglePay: U, Klarna: K, Blik: s, Dropin: i } = await import("@adyen/adyen-web"), k = {
214
+ environment: m.environment || "test",
215
+ clientKey: m.clientKey,
216
+ session: n,
217
+ onPaymentCompleted: (t, w) => {
218
+ console.info("Payment Completed:", t, w), e("submit", t), t.resultCode === "Authorised" || t.resultCode === "Received" ? (console.info("Payment Successful:", t), e("success", {
219
219
  status: "succeeded",
220
220
  message: "Payment completed successfully",
221
- resultCode: e.resultCode,
222
- pspReference: e.pspReference,
223
- paymentData: e
224
- })) : e.resultCode === "Pending" ? (console.info("Payment Pending:", e), t("success", {
221
+ resultCode: t.resultCode,
222
+ pspReference: t.pspReference,
223
+ paymentData: t
224
+ })) : t.resultCode === "Pending" ? (console.info("Payment Pending:", t), e("success", {
225
225
  status: "processing",
226
226
  message: "Payment is being processed",
227
- resultCode: e.resultCode,
228
- pspReference: e.pspReference,
229
- paymentData: e
230
- })) : (e.resultCode === "Refused" || e.resultCode === "Error") && (console.error("Payment Failed:", e), t("error", {
231
- message: e.refusalReason || "Payment was declined",
232
- resultCode: e.resultCode,
233
- paymentData: e
227
+ resultCode: t.resultCode,
228
+ pspReference: t.pspReference,
229
+ paymentData: t
230
+ })) : (t.resultCode === "Refused" || t.resultCode === "Error") && (console.error("Payment Failed:", t), e("error", {
231
+ message: t.refusalReason || "Payment was declined",
232
+ resultCode: t.resultCode,
233
+ paymentData: t
234
234
  }));
235
235
  },
236
- onError: (e, v) => {
237
- console.error("Adyen Error:", e.name, e.message, e.stack, v), t("error", e);
236
+ onError: (t, w) => {
237
+ console.error("Adyen Error:", t.name, t.message, t.stack, w), e("error", t);
238
238
  }
239
- }, f = {
239
+ }, g = {
240
240
  showPayButton: !0,
241
- paymentMethodComponents: [m, c, D, _, k],
241
+ paymentMethodComponents: [f, y, U, K, s],
242
242
  paymentMethodsConfiguration: {
243
243
  card: {
244
244
  hasHolderName: !0,
@@ -259,26 +259,162 @@ const x = { class: "stripe-elements" }, M = {
259
259
  // BLIK configuration for Polish market
260
260
  }
261
261
  }
262
- }, n = await l(S);
263
- console.log("Adyen Checkout created:", n), console.log("Available payment methods from session:", (s = n.paymentMethodsResponse) == null ? void 0 : s.paymentMethods);
264
- const a = new p(n, f);
265
- console.log("Adyen Drop-in created with session payment methods"), o.value && (a.mount(o.value), console.log("Adyen Drop-in mounted successfully"), t("ready"));
266
- } catch (l) {
267
- console.error("Error creating Adyen Drop-in:", l), t("error", l);
262
+ }, r = await d(k);
263
+ console.log("Adyen Checkout created:", r), console.log("Available payment methods from session:", (c = r.paymentMethodsResponse) == null ? void 0 : c.paymentMethods);
264
+ const l = new i(r, g);
265
+ console.log("Adyen Drop-in created with session payment methods"), a.value && (l.mount(a.value), console.log("Adyen Drop-in mounted successfully"), e("ready"));
266
+ } catch (d) {
267
+ console.error("Error creating Adyen Drop-in:", d), e("error", d);
268
268
  }
269
269
  };
270
- return B(() => {
270
+ return A(() => {
271
271
  u();
272
- }), E(() => i.clientData, () => {
273
- o.value && (o.value.innerHTML = "", u());
274
- }), (r, s) => (C(), P("div", {
272
+ }), E(() => m.clientData, () => {
273
+ a.value && (a.value.innerHTML = "", u());
274
+ }), (n, c) => (b(), v("div", {
275
275
  ref_key: "dropinContainer",
276
- ref: o,
276
+ ref: a,
277
277
  class: "payment-dropin"
278
278
  }, null, 512));
279
279
  }
280
- }), J = /* @__PURE__ */ U($, [["__scopeId", "data-v-ef2ec054"]]);
280
+ }), ae = /* @__PURE__ */ F(z, [["__scopeId", "data-v-ef2ec054"]]), T = { class: "delayed-payment" }, L = { class: "payment-form" }, q = { class: "amount-display" }, J = { class: "amount-value" }, V = {
281
+ key: 0,
282
+ class: "session-info"
283
+ }, G = {
284
+ key: 0,
285
+ class: "info-row"
286
+ }, j = { class: "value" }, W = {
287
+ key: 1,
288
+ class: "info-row"
289
+ }, X = { class: "value" }, Y = {
290
+ key: 1,
291
+ class: "error-message"
292
+ }, Z = { class: "button-container" }, Q = ["disabled"], ee = /* @__PURE__ */ R({
293
+ __name: "DelayedPayment",
294
+ props: {
295
+ paymentId: { default: void 0 },
296
+ clientData: { default: void 0 },
297
+ amount: {},
298
+ currency: {},
299
+ tenantId: { default: void 0 }
300
+ },
301
+ emits: ["submit", "success", "error", "ready"],
302
+ setup(h, { expose: P, emit: m }) {
303
+ const e = h, a = m, p = D(!1), u = D(""), n = D({}), c = S(() => ({
304
+ EUR: "€",
305
+ USD: "$",
306
+ GBP: "£",
307
+ CHF: "CHF",
308
+ NOK: "kr",
309
+ SEK: "kr",
310
+ DKK: "kr",
311
+ PLN: "zł"
312
+ })[e.currency] || e.currency), d = S(() => e.amount.toFixed(2)), f = S(() => n.value.invoiceNumber && n.value.providerUid), y = () => {
313
+ if (!e.clientData) {
314
+ console.error("No clientData provided for delayed payment");
315
+ return;
316
+ }
317
+ try {
318
+ const s = JSON.parse(e.clientData);
319
+ console.log("Parsed delayed payment session data:", s), n.value = {
320
+ invoiceNumber: s.invoiceNumber,
321
+ merchantReference: s.merchantReference,
322
+ providerUid: s.providerUid,
323
+ paymentUid: s.paymentUid,
324
+ baseUrl: s.baseUrl
325
+ }, a("ready");
326
+ } catch (s) {
327
+ console.error("Failed to parse clientData:", s), u.value = "Invalid session data", a("error", s);
328
+ }
329
+ }, U = async () => {
330
+ if (!(!f.value || p.value)) {
331
+ p.value = !0, u.value = "";
332
+ try {
333
+ const s = {
334
+ provider: "delayed-payment",
335
+ amount: e.amount,
336
+ currency: e.currency,
337
+ invoiceNumber: n.value.invoiceNumber,
338
+ merchantReference: n.value.merchantReference,
339
+ providerUid: n.value.providerUid,
340
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
341
+ };
342
+ if (a("submit", s), !e.paymentId)
343
+ throw new Error("Payment ID not provided");
344
+ const i = n.value.baseUrl || window.location.origin, k = {
345
+ "Content-Type": "application/json"
346
+ };
347
+ e.tenantId && (k["X-Tenant-ID"] = e.tenantId);
348
+ const g = await fetch(
349
+ `${i}/api/v1/webhooks/delayed-payments/confirm/${e.paymentId}`,
350
+ {
351
+ method: "POST",
352
+ headers: k
353
+ }
354
+ );
355
+ if (!g.ok) {
356
+ const r = await g.text();
357
+ throw new Error(`Failed to confirm payment: ${r}`);
358
+ }
359
+ a("success", {
360
+ status: "succeeded",
361
+ message: "Payment confirmed successfully. You will receive a receipt shortly.",
362
+ resultCode: "Authorised",
363
+ invoiceNumber: n.value.invoiceNumber,
364
+ providerUid: n.value.providerUid,
365
+ paymentData: s
366
+ });
367
+ } catch (s) {
368
+ u.value = s instanceof Error ? s.message : "Failed to confirm payment", a("error", s);
369
+ } finally {
370
+ p.value = !1;
371
+ }
372
+ }
373
+ }, K = () => {
374
+ u.value = "";
375
+ };
376
+ return A(() => {
377
+ y();
378
+ }), P({
379
+ clearError: K
380
+ }), (s, i) => (b(), v("div", T, [
381
+ o("div", L, [
382
+ i[4] || (i[4] = o("div", { class: "info-section" }, [
383
+ o("div", { class: "info-icon" }, " 📄 "),
384
+ o("h3", { class: "info-title" }, " Delayed Payment "),
385
+ o("p", { class: "info-description" }, " Payment will be processed manually via invoice or bank transfer ")
386
+ ], -1)),
387
+ o("div", q, [
388
+ i[0] || (i[0] = o("span", { class: "amount-label" }, "Amount to pay:", -1)),
389
+ o("span", J, _(c.value) + _(d.value), 1)
390
+ ]),
391
+ f.value ? (b(), v("div", V, [
392
+ n.value.invoiceNumber ? (b(), v("div", G, [
393
+ i[1] || (i[1] = o("span", { class: "label" }, "Invoice Number:", -1)),
394
+ o("span", j, _(n.value.invoiceNumber), 1)
395
+ ])) : C("", !0),
396
+ n.value.merchantReference ? (b(), v("div", W, [
397
+ i[2] || (i[2] = o("span", { class: "label" }, "Reference:", -1)),
398
+ o("span", X, _(n.value.merchantReference), 1)
399
+ ])) : C("", !0)
400
+ ])) : C("", !0),
401
+ u.value ? (b(), v("div", Y, [
402
+ i[3] || (i[3] = o("div", { class: "error-icon" }, " ⚠️ ", -1)),
403
+ o("p", null, _(u.value), 1)
404
+ ])) : C("", !0),
405
+ o("div", Z, [
406
+ o("button", {
407
+ disabled: p.value || !f.value,
408
+ class: "submit-button",
409
+ onClick: U
410
+ }, _(p.value ? "Processing..." : `Confirm Payment ${c.value}${d.value}`), 9, Q)
411
+ ])
412
+ ])
413
+ ]));
414
+ }
415
+ }), oe = /* @__PURE__ */ F(ee, [["__scopeId", "data-v-cb30346d"]]);
281
416
  export {
282
- J as AdyenPayment,
283
- L as StripePayment
417
+ ae as AdyenPayment,
418
+ oe as DelayedPayment,
419
+ ne as StripePayment
284
420
  };