@bcc-code/payment-client 1.1.3 → 1.1.4

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