@revenexx/cover 0.19.0 → 0.21.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.
Files changed (95) hide show
  1. package/app/api/marketing.ts +24 -0
  2. package/app/app.config.ts +22 -0
  3. package/app/components/account/approvals/AccountPendingApprovals.vue +54 -13
  4. package/app/components/account/approvals/AccountPendingOrderDetail.vue +156 -0
  5. package/app/components/account/loyalty/AccountLoyalty.vue +205 -0
  6. package/app/components/account/orders/AccountOrderContents.vue +142 -0
  7. package/app/components/account/orders/AccountOrderDetail.vue +16 -178
  8. package/app/components/account/orders/AccountOrderHead.vue +79 -0
  9. package/app/components/account/orders/AccountOrderPay.vue +13 -3
  10. package/app/components/account/orders/AccountOrdersTable.vue +2 -0
  11. package/app/components/cart/position/CartPosition.vue +6 -6
  12. package/app/components/cart/view/CartSummaryPanel.vue +4 -0
  13. package/app/components/checkout/onepage/CheckoutPaymentSection.vue +20 -8
  14. package/app/components/checkout/onepage/CheckoutSummarySection.vue +4 -0
  15. package/app/components/checkout/return/CheckoutPaymentReturn.vue +209 -0
  16. package/app/components/loyalty/hint/LoyaltyPerkHint.vue +28 -0
  17. package/app/components/newsletter/confirm/NewsletterConfirmation.vue +54 -0
  18. package/app/components/newsletter/preferences/NewsletterPreferenceCentre.vue +183 -0
  19. package/app/components/newsletter/state/NewsletterLinkRefusal.vue +45 -0
  20. package/app/components/review/form/ReviewForm.vue +211 -0
  21. package/app/composables/useAccountDashboard.ts +1 -0
  22. package/app/composables/useCampaignAttribution.ts +120 -0
  23. package/app/composables/useCheckoutOnePage.ts +80 -7
  24. package/app/composables/useLoyaltyAccount.ts +79 -0
  25. package/app/composables/useMarketingConsent.ts +49 -0
  26. package/app/composables/usePendingApprovals.ts +11 -3
  27. package/app/composables/usePspCheckout.ts +130 -29
  28. package/app/config/colorRamp.ts +55 -0
  29. package/app/config/navigation.ts +1 -1
  30. package/app/config/quickActions.ts +1 -0
  31. package/app/interfaces/account/approvals.ts +34 -1
  32. package/app/interfaces/account/order-list.ts +8 -1
  33. package/app/interfaces/cart-calculation.ts +7 -1
  34. package/app/interfaces/cart-item.ts +12 -0
  35. package/app/interfaces/payment.ts +22 -0
  36. package/app/pages/account/points.vue +26 -0
  37. package/app/pages/checkout/payment-return.vue +17 -0
  38. package/app/pages/newsletter/confirm/[token].vue +23 -0
  39. package/app/pages/newsletter/preferences/[token].vue +24 -0
  40. package/app/pages/review/[token].vue +23 -0
  41. package/app/payments/psp/novalnet.ts +255 -0
  42. package/app/payments/psp/registry.ts +7 -3
  43. package/app/payments/psp/rules.ts +99 -0
  44. package/app/payments/psp/stripe.ts +6 -2
  45. package/app/payments/psp/types.ts +72 -6
  46. package/app/plugins/campaign-attribution.client.ts +47 -0
  47. package/app/shared/campaignAttribution.ts +281 -0
  48. package/app/shared/personalisation.ts +107 -0
  49. package/app/shared/pspReturn.ts +62 -0
  50. package/i18n/locales/de/account.json +20 -5
  51. package/i18n/locales/de/cart.json +4 -2
  52. package/i18n/locales/de/checkout.json +32 -0
  53. package/i18n/locales/de/editor.json +10 -0
  54. package/i18n/locales/de/marketing.json +71 -0
  55. package/i18n/locales/en/account.json +20 -5
  56. package/i18n/locales/en/cart.json +4 -2
  57. package/i18n/locales/en/checkout.json +32 -0
  58. package/i18n/locales/en/editor.json +10 -0
  59. package/i18n/locales/en/marketing.json +71 -0
  60. package/package.json +3 -2
  61. package/server/api/account/orders/[id]/pay.post.ts +47 -7
  62. package/server/api/account/pending-approvals/index.get.ts +16 -12
  63. package/server/api/account/pending-approvals/orders/[number]/approve.post.ts +6 -0
  64. package/server/api/account/pending-approvals/orders/[number]/reject.post.ts +6 -0
  65. package/server/api/account/pending-approvals/orders/[number].get.ts +15 -0
  66. package/server/api/campaigns/touches.post.ts +42 -0
  67. package/server/api/cart/attribution.put.ts +31 -0
  68. package/server/api/checkout/payment-return.post.ts +30 -0
  69. package/server/api/loyalty/account.get.ts +27 -0
  70. package/server/api/newsletter/confirm/[token].post.ts +21 -0
  71. package/server/api/newsletter/preferences/[token].get.ts +14 -0
  72. package/server/api/newsletter/preferences/[token].post.ts +36 -0
  73. package/server/api/orders/index.post.ts +47 -12
  74. package/server/api/payment/methods.post.ts +19 -9
  75. package/server/api/payment/psp-config.get.ts +5 -4
  76. package/server/api/reviews/requests/[token].get.ts +14 -0
  77. package/server/api/reviews/submit/[token].post.ts +31 -0
  78. package/server/interfaces/cart.ts +6 -0
  79. package/server/interfaces/marketing.ts +150 -0
  80. package/server/services/ApiCartService.ts +22 -0
  81. package/server/services/ApiMarketingService.ts +292 -0
  82. package/server/services/ApiProductService.ts +6 -2
  83. package/server/services/MockCartCalculationService.ts +29 -0
  84. package/server/services/MockMarketingService.ts +178 -0
  85. package/server/utils/cartItemHints.ts +29 -0
  86. package/server/utils/checkoutSession.ts +16 -0
  87. package/server/utils/liveCatalog.ts +244 -31
  88. package/server/utils/liveOrders.ts +33 -0
  89. package/server/utils/marketingService.ts +63 -0
  90. package/server/utils/orderAttribution.ts +65 -0
  91. package/server/utils/orderPayment.ts +79 -0
  92. package/server/utils/pendingApprovals.ts +157 -2
  93. package/server/utils/personalisationViewer.ts +28 -0
  94. package/server/utils/pspConfig.ts +125 -13
  95. package/server/utils/pspReturn.ts +267 -0
@@ -0,0 +1,211 @@
1
+ <script setup lang="ts">
2
+ import { linkRefusalOf, marketingApi } from "../../../api/marketing";
3
+ import NewsletterLinkRefusal from "../../newsletter/state/NewsletterLinkRefusal.vue";
4
+
5
+ /**
6
+ * The review form behind a review request link (RAD-293). The buyer rates
7
+ * the products of one order — as many as they like, a star rating each, a
8
+ * headline and a text if they want — and sends them together. A product they
9
+ * already rated is shown as done and cannot be rated twice.
10
+ *
11
+ * Nothing appears in the shop straight away: the merchant moderates.
12
+ */
13
+ const props = defineProps<{ token: string }>();
14
+
15
+ interface ReviewProduct {
16
+ productId: string;
17
+ sku: string | null;
18
+ name: string;
19
+ reviewed: boolean;
20
+ }
21
+
22
+ interface ReviewRequest {
23
+ orderNumber: string | null;
24
+ products: ReviewProduct[];
25
+ }
26
+
27
+ interface Draft {
28
+ rating: number;
29
+ title: string;
30
+ body: string;
31
+ }
32
+
33
+ const { t } = useI18n();
34
+ const { icon } = useIcons();
35
+
36
+ const { data, error, status, refresh } = await useFetch<ReviewRequest>(() => marketingApi.reviewRequest(props.token), {
37
+ key: `review-request:${props.token}`,
38
+ });
39
+
40
+ const drafts = reactive<Record<string, Draft>>({});
41
+ watch(data, (request) => {
42
+ for (const product of request?.products ?? []) {
43
+ drafts[product.productId] ??= { rating: 0, title: "", body: "" };
44
+ }
45
+ }, { immediate: true });
46
+
47
+ const refusal = computed(() => (error.value ? linkRefusalOf(error.value) : null));
48
+ const open = computed(() => (data.value?.products ?? []).filter(product => !product.reviewed));
49
+
50
+ const sending = ref(false);
51
+ const formError = ref<string | null>(null);
52
+ const result = ref<{ accepted: number; rejected: number } | null>(null);
53
+
54
+ async function submit(): Promise<void> {
55
+ const reviews = open.value
56
+ .filter(product => (drafts[product.productId]?.rating ?? 0) > 0)
57
+ .map((product) => {
58
+ const draft = drafts[product.productId]!;
59
+ return {
60
+ product_id: product.productId,
61
+ rating: draft.rating,
62
+ ...(draft.title.trim() ? { title: draft.title.trim() } : {}),
63
+ ...(draft.body.trim() ? { body: draft.body.trim() } : {}),
64
+ };
65
+ });
66
+ if (!reviews.length) {
67
+ formError.value = t("marketing.review.nothingRated");
68
+ return;
69
+ }
70
+ formError.value = null;
71
+ sending.value = true;
72
+ try {
73
+ const answer = await $fetch<{ accepted: string[]; rejected: unknown[] }>(marketingApi.reviewSubmit(props.token), {
74
+ method: "POST",
75
+ body: { reviews },
76
+ });
77
+ result.value = { accepted: answer.accepted.length, rejected: answer.rejected.length };
78
+ await refresh();
79
+ }
80
+ catch (err) {
81
+ const kind = linkRefusalOf(err);
82
+ formError.value = kind === "expired" ? t("marketing.review.expiredText") : t("marketing.link.errorText");
83
+ }
84
+ finally {
85
+ sending.value = false;
86
+ }
87
+ }
88
+ </script>
89
+
90
+ <template>
91
+ <div data-review-form>
92
+ <NewsletterLinkRefusal
93
+ v-if="refusal"
94
+ :refusal="refusal"
95
+ :expired-text="t('marketing.review.expiredText')"
96
+ />
97
+ <USkeleton
98
+ v-else-if="status === 'pending' && !data"
99
+ class="h-40 w-full"
100
+ />
101
+ <template v-else-if="data">
102
+ <UAlert
103
+ v-if="result && result.accepted"
104
+ class="mb-6"
105
+ color="success"
106
+ variant="soft"
107
+ role="status"
108
+ :title="t('marketing.review.doneTitle')"
109
+ :description="t('marketing.review.doneText')"
110
+ />
111
+ <UAlert
112
+ v-if="result && result.rejected"
113
+ class="mb-6"
114
+ color="warning"
115
+ variant="soft"
116
+ :description="t('marketing.review.partlyRejected', { count: result.rejected })"
117
+ />
118
+
119
+ <p
120
+ v-if="!open.length"
121
+ class="text-muted"
122
+ data-review-all-done
123
+ >
124
+ {{ t('marketing.review.allDone') }}
125
+ </p>
126
+ <template v-else>
127
+ <p class="text-muted mb-6">
128
+ {{ data.orderNumber ? t('marketing.review.intro', { order: data.orderNumber }) : t('marketing.review.introNoOrder') }}
129
+ </p>
130
+ <form
131
+ class="space-y-6"
132
+ novalidate
133
+ @submit.prevent="submit"
134
+ >
135
+ <fieldset
136
+ v-for="product in data.products"
137
+ :key="product.productId"
138
+ class="border border-(--ui-border) rounded-lg p-4 space-y-3"
139
+ :disabled="product.reviewed"
140
+ :data-review-product="product.productId"
141
+ >
142
+ <legend class="px-1 font-medium text-highlighted">
143
+ {{ product.name }}
144
+ </legend>
145
+ <p
146
+ v-if="product.reviewed"
147
+ class="text-sm text-success"
148
+ >
149
+ {{ t('marketing.review.reviewed') }}
150
+ </p>
151
+ <template v-else>
152
+ <div
153
+ role="radiogroup"
154
+ class="flex gap-1"
155
+ :aria-label="t('marketing.review.rating', { name: product.name })"
156
+ >
157
+ <button
158
+ v-for="star in 5"
159
+ :key="star"
160
+ type="button"
161
+ role="radio"
162
+ class="p-1 rounded-md focus-visible:outline-2 focus-visible:outline-primary"
163
+ :aria-checked="drafts[product.productId]?.rating === star"
164
+ :aria-label="t('marketing.review.star', { count: star })"
165
+ :data-star="star"
166
+ @click="drafts[product.productId]!.rating = star"
167
+ >
168
+ <UIcon
169
+ :name="icon('star')"
170
+ class="size-6"
171
+ :class="star <= (drafts[product.productId]?.rating ?? 0) ? 'text-primary' : 'text-dimmed'"
172
+ />
173
+ </button>
174
+ </div>
175
+ <UFormField :label="t('marketing.review.titleField')">
176
+ <UInput
177
+ v-model="drafts[product.productId]!.title"
178
+ :maxlength="200"
179
+ class="w-full"
180
+ />
181
+ </UFormField>
182
+ <UFormField :label="t('marketing.review.bodyField')">
183
+ <UTextarea
184
+ v-model="drafts[product.productId]!.body"
185
+ :maxlength="5000"
186
+ :rows="4"
187
+ class="w-full"
188
+ />
189
+ </UFormField>
190
+ </template>
191
+ </fieldset>
192
+
193
+ <p
194
+ v-if="formError"
195
+ class="text-sm text-error"
196
+ role="alert"
197
+ >
198
+ {{ formError }}
199
+ </p>
200
+
201
+ <UButton
202
+ type="submit"
203
+ :loading="sending"
204
+ >
205
+ {{ t('marketing.review.submit') }}
206
+ </UButton>
207
+ </form>
208
+ </template>
209
+ </template>
210
+ </div>
211
+ </template>
@@ -65,6 +65,7 @@ export const useAccountDashboard = () => {
65
65
  "shipped": "primary",
66
66
  "delivered": "success",
67
67
  "cancelled": "error",
68
+ "rejected": "error",
68
69
  };
69
70
 
70
71
  const utilization = (used: number, total: number): number =>
@@ -0,0 +1,120 @@
1
+ import type { Attribution, LandingTouch, StoredAttribution } from "../shared/campaignAttribution";
2
+ import {
3
+ ATTRIBUTION_STORAGE_KEY,
4
+ landingTouchOf,
5
+ mergeTouch,
6
+ parseStoredAttribution,
7
+ toAttribution,
8
+ withoutClickId,
9
+ } from "../shared/campaignAttribution";
10
+
11
+ function storage(): Storage | null {
12
+ try {
13
+ return import.meta.client ? window.localStorage : null;
14
+ }
15
+ catch {
16
+ return null;
17
+ }
18
+ }
19
+
20
+ /**
21
+ * Where the visit came from (RAD-293): captured from the address a visitor
22
+ * lands on, kept in the browser, written onto the cart and sent with the
23
+ * order.
24
+ *
25
+ * Nothing is written anywhere before the cookie choice allows it. A campaign
26
+ * address seen before the visitor decided is held in memory only, for the
27
+ * rest of the visit, and kept the moment they allow statistics or marketing.
28
+ * Withdrawing both takes everything off again — the browser's copy and the
29
+ * cart's. The ad click id needs the marketing purpose on its own.
30
+ */
31
+ export function useCampaignAttribution() {
32
+ const consent = useMarketingConsent();
33
+ const pending = useState<LandingTouch | null>("cover:attribution:pending", () => null);
34
+
35
+ function read(): StoredAttribution | null {
36
+ return parseStoredAttribution(storage()?.getItem(ATTRIBUTION_STORAGE_KEY) ?? null, new Date());
37
+ }
38
+
39
+ function write(value: StoredAttribution | null): void {
40
+ try {
41
+ if (value) {
42
+ storage()?.setItem(ATTRIBUTION_STORAGE_KEY, JSON.stringify(value));
43
+ }
44
+ else {
45
+ storage()?.removeItem(ATTRIBUTION_STORAGE_KEY);
46
+ }
47
+ }
48
+ catch {
49
+ // Storage full or blocked: attribution is a nicety, never an error.
50
+ }
51
+ }
52
+
53
+ function allowed(): boolean {
54
+ const c = consent.attributionConsent.value;
55
+ return c.analytics || c.ads;
56
+ }
57
+
58
+ /** The attribution as it stands, or null when there is none or nothing allows it. */
59
+ function current(options: { objectionNoticeShown?: boolean } = {}): Attribution | null {
60
+ if (!allowed()) {
61
+ return null;
62
+ }
63
+ const stored = read();
64
+ return stored ? toAttribution(stored, consent.attributionConsent.value, options) : null;
65
+ }
66
+
67
+ async function syncToCart(): Promise<void> {
68
+ const attribution = current();
69
+ if (!attribution) {
70
+ return;
71
+ }
72
+ await $fetch("/api/cart/attribution", { method: "PUT", body: { attribution } }).catch(() => {});
73
+ }
74
+
75
+ /** Keeps what is pending, if the cookie choice now allows it, and tells the cart. */
76
+ async function flush(): Promise<void> {
77
+ if (!allowed()) {
78
+ return;
79
+ }
80
+ const ads = consent.attributionConsent.value.ads;
81
+ let stored = read();
82
+ if (pending.value) {
83
+ stored = mergeTouch(stored, pending.value, { allowClickId: ads });
84
+ pending.value = null;
85
+ }
86
+ else if (stored && !ads) {
87
+ stored = withoutClickId(stored);
88
+ }
89
+ else if (!stored) {
90
+ return;
91
+ }
92
+ write(stored);
93
+ await syncToCart();
94
+ }
95
+
96
+ /** A page was reached: remember its campaign, if it carries one. */
97
+ async function capture(url: URL, referrer: string | null): Promise<void> {
98
+ const touch = landingTouchOf(url, referrer, new Date());
99
+ if (!touch) {
100
+ return;
101
+ }
102
+ pending.value = touch;
103
+ await flush();
104
+ }
105
+
106
+ /** The cookie choice changed: keep what may be kept, drop what may not. */
107
+ async function consentChanged(): Promise<void> {
108
+ if (allowed()) {
109
+ await flush();
110
+ return;
111
+ }
112
+ const had = read() !== null;
113
+ write(null);
114
+ if (had) {
115
+ await $fetch("/api/cart/attribution", { method: "PUT", body: { attribution: null } }).catch(() => {});
116
+ }
117
+ }
118
+
119
+ return { capture, consentChanged, current, syncToCart };
120
+ }
@@ -1,4 +1,5 @@
1
1
  import { checkoutApi } from "../api/checkout";
2
+ import { PspInputError } from "../payments/psp/types";
2
3
  import type { CartCalculation } from "../interfaces/cart-calculation";
3
4
  import type { CheckoutOnePageForm, CheckoutProfile } from "../interfaces/checkout";
4
5
  import { checkoutAddressFieldOf, checkoutAddressRefusalOf } from "../shared/checkoutAddressRefusal";
@@ -55,10 +56,12 @@ const EMPTY_FORM: CheckoutOnePageForm = {
55
56
  const REQUESTED_DATE_MAX_DAYS = 100;
56
57
 
57
58
  export function useCheckoutOnePage() {
58
- const { t } = useI18n();
59
+ const { t, locale } = useI18n();
59
60
  const cart = useCartStore();
60
61
  const { settings } = useB2BContext();
61
62
  const psp = usePspCheckout();
63
+ const auth = useAuthStore();
64
+ const campaignAttribution = useCampaignAttribution();
62
65
  // The server-calculated totals the summary shows (shared state) — read when
63
66
  // an order is placed, so the confirmation can report what was bought.
64
67
  const calculation = useState<CartCalculation | null>("cart-calculation", () => null);
@@ -311,6 +314,47 @@ export function useCheckoutOnePage() {
311
314
  };
312
315
  }
313
316
 
317
+ /**
318
+ * What a PSP card field may prefill or check (Novalnet's card holder and
319
+ * 3-D Secure data): who pays and what. Best-effort — every part is optional,
320
+ * and the charge is always the server's total, never this one.
321
+ */
322
+ function pspMountDetails(): PspMountDetails {
323
+ const total = calculation.value?.totals.find(row => row.key === "total")?.amount;
324
+ let fullName = "";
325
+ let email = "";
326
+ let billing: { street?: string; city?: string; zip?: string; countryCode?: string } | undefined;
327
+ if (isGuest.value) {
328
+ const address = form.value.billingSameAsShipping ? guestShipping.value : guestBilling.value;
329
+ fullName = `${address.firstName} ${address.lastName}`.trim();
330
+ email = guestContact.value.email;
331
+ billing = { street: address.street, city: address.city, zip: address.postalCode, countryCode: address.country };
332
+ }
333
+ else {
334
+ const id = form.value.billingSameAsShipping ? form.value.shippingAddressId : form.value.billingAddressId;
335
+ const address = profile.value?.addresses.find(a => a.id === id);
336
+ fullName = address?.contactName?.trim() ?? "";
337
+ email = auth.user?.email ?? "";
338
+ if (address) {
339
+ billing = { street: address.street, city: address.city, zip: address.postalCode, countryCode: address.country };
340
+ }
341
+ }
342
+ const [firstName, ...rest] = fullName.split(/\s+/).filter(Boolean);
343
+ const countryCode = billing?.countryCode && /^[A-Za-z]{2}$/.test(billing.countryCode)
344
+ ? billing.countryCode.toUpperCase()
345
+ : undefined;
346
+ return {
347
+ ...(typeof total === "number" ? { amount: total } : {}),
348
+ ...(calculation.value?.currency ? { currency: calculation.value.currency } : {}),
349
+ customer: {
350
+ ...(firstName ? { firstName } : {}),
351
+ ...(rest.length ? { lastName: rest.join(" ") } : {}),
352
+ ...(email ? { email } : {}),
353
+ ...(billing ? { billing: { ...billing, countryCode } } : {}),
354
+ },
355
+ };
356
+ }
357
+
314
358
  interface SubmitResult {
315
359
  orderId: string;
316
360
  approvalRequired: boolean;
@@ -332,11 +376,34 @@ export function useCheckoutOnePage() {
332
376
  await fetchSessionToken();
333
377
 
334
378
  const payload = buildOrderPayload() as Record<string, unknown>;
335
- // PSP card methods (Stripe Elements, …) tokenize client-side; only
336
- // the single-use token reaches the BFF (PCI-safe). Self-managed and
337
- // redirect methods carry no instrument here.
379
+ // Where the visit came from, if the cookie choice allows keeping it
380
+ // (RAD-293). The orders app takes it from the order, never from the
381
+ // cart, so it travels here. The objection notice for advertising to
382
+ // existing customers is not shown by this checkout, and is said so.
383
+ const attribution = campaignAttribution.current({ objectionNoticeShown: false });
384
+ if (attribution) {
385
+ payload.attribution = attribution;
386
+ }
387
+ // PSP card methods (Stripe Elements, Novalnet's card iframe) tokenize
388
+ // client-side; only the single-use token or the provider's instrument
389
+ // (Novalnet: pan_hash + unique_id) reaches the BFF (PCI-safe).
390
+ // Self-managed and redirect methods carry no instrument here, and
391
+ // neither does a card field that hands over to the provider's hosted
392
+ // page — the order then answers with the redirect.
338
393
  if (psp.hasActive()) {
339
- const instrument = await psp.tokenize();
394
+ let instrument: Awaited<ReturnType<typeof psp.tokenize>>;
395
+ try {
396
+ instrument = await psp.tokenize();
397
+ }
398
+ catch (err) {
399
+ // Nothing is placed: the card stays at the field. A card the
400
+ // buyer typed wrong says what is wrong; a field that does not
401
+ // work (and has no hosted page behind it) says so plainly.
402
+ submitError.value = err instanceof PspInputError
403
+ ? err.message
404
+ : t("onepage.payment.cardFieldUnavailable");
405
+ return null;
406
+ }
340
407
  if (instrument) {
341
408
  payload.paymentInstrument = instrument;
342
409
  }
@@ -356,13 +423,18 @@ export function useCheckoutOnePage() {
356
423
  );
357
424
  }
358
425
 
426
+ // The locale travels so the BFF can address the return page in the
427
+ // buyer's language; the address itself is built on the server.
359
428
  const order = await $fetch(checkoutApi.orders(), {
360
429
  method: "POST",
361
430
  body: payload,
431
+ headers: { "x-locale": locale.value },
362
432
  }) as { orderId: string; approvalRequired?: boolean; approvers?: string[]; requiresAction?: boolean; redirectUrl?: string };
363
433
 
364
- // Redirect-based PSPs (3DS step-up, wallets, …) — one generic
365
- // handler for every provider: hand the buyer to the PSP, return later.
434
+ // Redirect-based PSPs (hosted payment pages, 3DS step-up, wallets, …) —
435
+ // one generic handler for every provider: hand the buyer to the PSP.
436
+ // It returns them to /checkout/payment-return, which confirms the
437
+ // payment and moves on to the confirmation (FE-5).
366
438
  if (order.requiresAction && order.redirectUrl) {
367
439
  cart.clearCart();
368
440
  window.location.href = order.redirectUrl;
@@ -502,6 +574,7 @@ export function useCheckoutOnePage() {
502
574
  validateAll,
503
575
  clearFieldError,
504
576
  buildOrderPayload,
577
+ pspMountDetails,
505
578
  submitOrder,
506
579
  submitRequisition,
507
580
  reset,
@@ -0,0 +1,79 @@
1
+ import { marketingApi } from "../api/marketing";
2
+
3
+ type Labels = Record<string, string> | null;
4
+
5
+ export interface LoyaltyAccountView {
6
+ memberships: {
7
+ program: { code: string; labels: Labels; kind: string };
8
+ tier: { code: string; labels: Labels; perks: Labels[] } | null;
9
+ pointsBalance: number | null;
10
+ agreementId: string | null;
11
+ }[];
12
+ progress: {
13
+ period: string | number | null;
14
+ currency: string;
15
+ turnoverYtd: number;
16
+ projectedTurnover: number | null;
17
+ tiers: { code: string; labels: Labels; threshold: number | null; bonusPercent: number; reached: boolean; current: boolean }[];
18
+ nextTier: { code: string; labels: Labels; gap: number; bonusPercent: number } | null;
19
+ bonusNow: number | null;
20
+ expectedBonus: number | null;
21
+ requiresNoOverdue: boolean;
22
+ } | null;
23
+ }
24
+
25
+ /**
26
+ * The signed-in buyer's loyalty membership (RAD-293), fetched once per page
27
+ * and shared by the account page and the perk hint in cart and checkout.
28
+ * Guests ask nothing: a membership is a signed-in buyer's.
29
+ */
30
+ export function useLoyaltyAccount() {
31
+ const auth = useAuthStore();
32
+ const { locale } = useI18n();
33
+ const signedIn = computed(() => Boolean(auth.user));
34
+
35
+ const request = useFetch<LoyaltyAccountView | null>(marketingApi.loyaltyAccount(), {
36
+ key: "loyalty-account",
37
+ immediate: signedIn.value,
38
+ watch: false,
39
+ default: () => null,
40
+ // Anything but the expected shape — an HTML error page, a proxy's
41
+ // answer — reads as no membership rather than breaking the cart.
42
+ transform: (value: unknown) =>
43
+ value && typeof value === "object" && Array.isArray((value as LoyaltyAccountView).memberships)
44
+ ? value as LoyaltyAccountView
45
+ : null,
46
+ });
47
+
48
+ // Signing in asks; signing out forgets — a guest never asks at all.
49
+ watch(signedIn, (now) => {
50
+ if (now) {
51
+ void request.refresh();
52
+ }
53
+ else {
54
+ request.data.value = null;
55
+ }
56
+ });
57
+
58
+ /** A label in the shop's language, else German, else whatever there is. */
59
+ function label(labels: Labels | undefined, fallback = ""): string {
60
+ if (!labels) {
61
+ return fallback;
62
+ }
63
+ return labels[locale.value] ?? labels.de ?? Object.values(labels)[0] ?? fallback;
64
+ }
65
+
66
+ /** The tier whose perks a buyer has, and the perks in their language. */
67
+ const perks = computed(() => {
68
+ const membership = request.data.value?.memberships.find(m => m.tier?.perks.length);
69
+ if (!membership?.tier) {
70
+ return null;
71
+ }
72
+ return {
73
+ tier: label(membership.tier.labels, membership.tier.code),
74
+ items: membership.tier.perks.map(perk => label(perk)).filter(Boolean),
75
+ };
76
+ });
77
+
78
+ return { ...request, signedIn, label, perks };
79
+ }
@@ -0,0 +1,49 @@
1
+ import type { AttributionConsent } from "../shared/campaignAttribution";
2
+ import { grantedPurposes } from "../shared/personalisation";
3
+
4
+ /** The marketing functions that rest on the visitor's cookie choice. */
5
+ export type MarketingFunction = "analytics" | "ads" | "personalisation" | "touches";
6
+
7
+ const DEFAULT_PURPOSES: Record<MarketingFunction, string> = {
8
+ analytics: "statistics",
9
+ ads: "marketing",
10
+ personalisation: "marketing",
11
+ touches: "statistics",
12
+ };
13
+
14
+ /**
15
+ * What the visitor's cookie choice allows the marketing functions (RAD-293),
16
+ * read from the Consent Manager. The purpose each function rests on is the
17
+ * storefront's `marketing.purposes` app config; a function whose purpose is
18
+ * not granted does nothing.
19
+ *
20
+ * Without a published policy nothing is granted, so a shop that has not set
21
+ * up its cookie choice tracks nothing — the Consent Manager fails closed and
22
+ * this follows it.
23
+ */
24
+ export function useMarketingConsent() {
25
+ const consents = useConsents();
26
+ const appConfig = useAppConfig() as { marketing?: { purposes?: Partial<Record<MarketingFunction, string>> } };
27
+ const purposeOf = (fn: MarketingFunction): string =>
28
+ appConfig.marketing?.purposes?.[fn] ?? DEFAULT_PURPOSES[fn];
29
+
30
+ /** Every purpose the visitor allowed, as policy codes, sorted. */
31
+ const granted = computed<string[]>(() => grantedPurposes(consents.state.value?.purposes));
32
+
33
+ function allows(fn: MarketingFunction): boolean {
34
+ return granted.value.includes(purposeOf(fn));
35
+ }
36
+
37
+ /** The consent half of a cart's or an order's attribution. */
38
+ const attributionConsent = computed<AttributionConsent>(() => {
39
+ const version = consents.policy.value?.version?.number;
40
+ return {
41
+ ads: allows("ads"),
42
+ analytics: allows("analytics"),
43
+ policy_version: typeof version === "number" ? String(version) : null,
44
+ purposes: granted.value,
45
+ };
46
+ });
47
+
48
+ return { granted, allows, attributionConsent, onChange: consents.onChange };
49
+ }
@@ -19,10 +19,18 @@ export function usePendingApprovals() {
19
19
 
20
20
  const deciding = ref<string | null>(null);
21
21
 
22
- async function decide(id: string, decision: "approve" | "decline", reason?: string): Promise<void> {
23
- deciding.value = id;
22
+ /**
23
+ * Yes or no, routed by what is waiting: a procurement layer goes to the
24
+ * procurement app, an order to the orders app, whose no is a rejection that
25
+ * always carries its reason (RAD-229).
26
+ */
27
+ async function decide(approval: Pick<PendingApproval, "kind" | "id">, decision: "approve" | "decline", reason?: string): Promise<void> {
28
+ const path = approval.kind === "order"
29
+ ? `/api/account/pending-approvals/orders/${encodeURIComponent(approval.id)}/${decision === "approve" ? "approve" : "reject"}`
30
+ : `/api/account/pending-approvals/${approval.id}/${decision}`;
31
+ deciding.value = approval.id;
24
32
  try {
25
- await $fetch(`/api/account/pending-approvals/${id}/${decision}`, {
33
+ await $fetch(path, {
26
34
  method: "POST",
27
35
  body: reason?.trim() ? { reason: reason.trim() } : {},
28
36
  });