@revenexx/cover 0.20.0 → 0.21.1
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.
- package/app/components/account/approvals/AccountPendingApprovals.vue +54 -13
- package/app/components/account/approvals/AccountPendingOrderDetail.vue +156 -0
- package/app/components/account/orders/AccountOrderContents.vue +142 -0
- package/app/components/account/orders/AccountOrderDetail.vue +16 -178
- package/app/components/account/orders/AccountOrderHead.vue +79 -0
- package/app/components/account/orders/AccountOrderPay.vue +13 -3
- package/app/components/account/orders/AccountOrdersTable.vue +2 -0
- package/app/components/cart/position/CartPosition.vue +6 -6
- package/app/components/checkout/onepage/CheckoutPaymentSection.vue +20 -8
- package/app/components/checkout/return/CheckoutPaymentReturn.vue +209 -0
- package/app/composables/useAccountDashboard.ts +1 -0
- package/app/composables/useCheckoutOnePage.ts +71 -7
- package/app/composables/usePendingApprovals.ts +11 -3
- package/app/composables/usePspCheckout.ts +130 -29
- package/app/config/colorRamp.ts +55 -0
- package/app/interfaces/account/approvals.ts +34 -1
- package/app/interfaces/account/order-list.ts +8 -1
- package/app/interfaces/cart-calculation.ts +7 -1
- package/app/interfaces/cart-item.ts +12 -0
- package/app/interfaces/payment.ts +22 -0
- package/app/pages/checkout/payment-return.vue +17 -0
- package/app/payments/psp/novalnet.ts +254 -0
- package/app/payments/psp/registry.ts +7 -3
- package/app/payments/psp/rules.ts +99 -0
- package/app/payments/psp/stripe.ts +6 -2
- package/app/payments/psp/types.ts +72 -6
- package/app/shared/pspReturn.ts +62 -0
- package/i18n/locales/de/account.json +17 -3
- package/i18n/locales/de/cart.json +4 -2
- package/i18n/locales/de/checkout.json +32 -0
- package/i18n/locales/de/editor.json +10 -0
- package/i18n/locales/en/account.json +17 -3
- package/i18n/locales/en/cart.json +4 -2
- package/i18n/locales/en/checkout.json +32 -0
- package/i18n/locales/en/editor.json +10 -0
- package/package.json +3 -2
- package/server/api/account/orders/[id]/pay.post.ts +47 -7
- package/server/api/account/pending-approvals/index.get.ts +16 -12
- package/server/api/account/pending-approvals/orders/[number]/approve.post.ts +6 -0
- package/server/api/account/pending-approvals/orders/[number]/reject.post.ts +6 -0
- package/server/api/account/pending-approvals/orders/[number].get.ts +15 -0
- package/server/api/checkout/payment-return.post.ts +30 -0
- package/server/api/orders/index.post.ts +37 -11
- package/server/api/payment/methods.post.ts +19 -9
- package/server/api/payment/psp-config.get.ts +5 -4
- package/server/services/ApiCartService.ts +6 -0
- package/server/services/ApiProductService.ts +6 -2
- package/server/services/MockCartCalculationService.ts +29 -0
- package/server/utils/cartItemHints.ts +29 -0
- package/server/utils/checkoutSession.ts +16 -0
- package/server/utils/liveCatalog.ts +244 -31
- package/server/utils/liveOrders.ts +33 -0
- package/server/utils/orderPayment.ts +79 -0
- package/server/utils/pendingApprovals.ts +157 -2
- package/server/utils/procurementCheckout.ts +5 -0
- package/server/utils/pspConfig.ts +125 -13
- package/server/utils/pspReturn.ts +267 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { AccountOrder, AccountOrderStatus, AccountOrderPaymentStatus } from "../../../interfaces/account/order-list";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The facts an order is recognised by: when, the buyer's own number, what it
|
|
6
|
+
* comes to, and where it stands. Shared by the buyer's own order page and the
|
|
7
|
+
* approver's view of a colleague's (RAD-229), which must read the same.
|
|
8
|
+
*/
|
|
9
|
+
defineProps<{
|
|
10
|
+
order: AccountOrder;
|
|
11
|
+
}>();
|
|
12
|
+
|
|
13
|
+
const { t, d } = useI18n();
|
|
14
|
+
const { formatCurrency } = useCartSummaryFormatting();
|
|
15
|
+
|
|
16
|
+
const statusColors: Record<AccountOrderStatus, "info" | "warning" | "primary" | "success" | "error"> = {
|
|
17
|
+
"processing": "info",
|
|
18
|
+
"approval-pending": "warning",
|
|
19
|
+
"shipped": "primary",
|
|
20
|
+
"delivered": "success",
|
|
21
|
+
"cancelled": "error",
|
|
22
|
+
"rejected": "error",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const paymentColors: Record<AccountOrderPaymentStatus, "warning" | "success" | "neutral"> = {
|
|
26
|
+
open: "warning",
|
|
27
|
+
paid: "success",
|
|
28
|
+
refunded: "neutral",
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const formatDate = (value: string) => {
|
|
32
|
+
const parsed = new Date(value);
|
|
33
|
+
return Number.isNaN(parsed.getTime()) ? value : d(parsed, { dateStyle: "medium" });
|
|
34
|
+
};
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<template>
|
|
38
|
+
<div
|
|
39
|
+
class="border border-(--ui-border) rounded-xl p-4 sm:p-5
|
|
40
|
+
flex flex-wrap items-center gap-x-8 gap-y-3"
|
|
41
|
+
>
|
|
42
|
+
<div>
|
|
43
|
+
<p class="text-xs text-muted">
|
|
44
|
+
{{ t('orders.card.date') }}
|
|
45
|
+
</p>
|
|
46
|
+
<p class="text-sm font-medium text-highlighted">
|
|
47
|
+
{{ formatDate(order.date) }}
|
|
48
|
+
</p>
|
|
49
|
+
</div>
|
|
50
|
+
<div v-if="order.orderNumber">
|
|
51
|
+
<p class="text-xs text-muted">
|
|
52
|
+
{{ t('orders.card.yourOrderNumber') }}
|
|
53
|
+
</p>
|
|
54
|
+
<p class="text-sm font-medium text-highlighted">
|
|
55
|
+
{{ order.orderNumber }}
|
|
56
|
+
</p>
|
|
57
|
+
</div>
|
|
58
|
+
<div>
|
|
59
|
+
<p class="text-xs text-muted">
|
|
60
|
+
{{ t('orders.card.total') }}
|
|
61
|
+
</p>
|
|
62
|
+
<p class="text-sm font-semibold text-highlighted tabular-nums">
|
|
63
|
+
{{ formatCurrency(order.total) }}
|
|
64
|
+
</p>
|
|
65
|
+
</div>
|
|
66
|
+
<div class="flex items-center gap-2 ms-auto">
|
|
67
|
+
<UBadge
|
|
68
|
+
:color="statusColors[order.status]"
|
|
69
|
+
variant="subtle"
|
|
70
|
+
:label="t(`orders.status.${order.status}`)"
|
|
71
|
+
/>
|
|
72
|
+
<UBadge
|
|
73
|
+
:color="paymentColors[order.paymentStatus]"
|
|
74
|
+
variant="outline"
|
|
75
|
+
:label="t(`orders.payment.${order.paymentStatus}`)"
|
|
76
|
+
/>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
</template>
|
|
@@ -69,8 +69,10 @@ async function syncCardField(): Promise<void> {
|
|
|
69
69
|
try {
|
|
70
70
|
await psp.mount(cardEl.value, option.value);
|
|
71
71
|
}
|
|
72
|
-
catch
|
|
73
|
-
|
|
72
|
+
catch {
|
|
73
|
+
// The field did not come up and the provider has no page to fall
|
|
74
|
+
// back to: say so in words, not the loader's error.
|
|
75
|
+
cardError.value = t("onepage.payment.cardFieldUnavailable");
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
else {
|
|
@@ -93,9 +95,10 @@ onBeforeUnmount(() => psp.destroy());
|
|
|
93
95
|
async function pay(): Promise<void> {
|
|
94
96
|
paying.value = true;
|
|
95
97
|
try {
|
|
98
|
+
// Where the provider returns the buyer is built by the BFF (FE-5): the
|
|
99
|
+
// return page confirms the payment and lands on the confirmation.
|
|
96
100
|
const body: Record<string, unknown> = {
|
|
97
101
|
idempotencyKey: attempt.value,
|
|
98
|
-
returnUrl: window.location.href,
|
|
99
102
|
};
|
|
100
103
|
if (psp.hasActive()) {
|
|
101
104
|
const instrument = await psp.tokenize();
|
|
@@ -178,9 +181,16 @@ async function pay(): Promise<void> {
|
|
|
178
181
|
>
|
|
179
182
|
<label class="block text-sm font-medium text-muted">{{ t('onepage.payment.cardDetails') }}</label>
|
|
180
183
|
<div
|
|
184
|
+
v-show="!psp.hostedFallback.value"
|
|
181
185
|
ref="cardEl"
|
|
182
186
|
class="w-full p-3 rounded-lg border border-(--ui-border) bg-(--ui-bg)"
|
|
183
187
|
/>
|
|
188
|
+
<p
|
|
189
|
+
v-if="psp.hostedFallback.value"
|
|
190
|
+
class="text-sm text-muted"
|
|
191
|
+
>
|
|
192
|
+
{{ t('onepage.payment.cardOnProviderPage') }}
|
|
193
|
+
</p>
|
|
184
194
|
<p
|
|
185
195
|
v-if="cardError"
|
|
186
196
|
class="text-sm text-error-500"
|
|
@@ -32,6 +32,7 @@ const statusColors: Record<AccountOrderStatus, "info" | "warning" | "primary" |
|
|
|
32
32
|
"shipped": "primary",
|
|
33
33
|
"delivered": "success",
|
|
34
34
|
"cancelled": "error",
|
|
35
|
+
"rejected": "error",
|
|
35
36
|
};
|
|
36
37
|
|
|
37
38
|
const paymentColors: Record<AccountOrderPaymentStatus, "warning" | "success" | "neutral"> = {
|
|
@@ -67,6 +68,7 @@ const ORDER_STATUSES: AccountOrderStatus[] = [
|
|
|
67
68
|
"shipped",
|
|
68
69
|
"delivered",
|
|
69
70
|
"cancelled",
|
|
71
|
+
"rejected",
|
|
70
72
|
];
|
|
71
73
|
|
|
72
74
|
const filterItems = computed(() => [
|
|
@@ -76,11 +76,11 @@ const {
|
|
|
76
76
|
apply: next => cart.updateQuantityByKey(lineKey.value, next),
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
-
// A position nobody can order reads as a warning,
|
|
80
|
-
// too
|
|
81
|
-
// Everything else is a note.
|
|
79
|
+
// A position nobody can order reads as a warning, one missing a cost centre
|
|
80
|
+
// too, and one whose unit was switched: the buyer has to act on or check each
|
|
81
|
+
// before ordering. Everything else is a note.
|
|
82
82
|
const hintColor = (type: string) =>
|
|
83
|
-
type === "missing-cost-center" || type === "not-orderable"
|
|
83
|
+
type === "missing-cost-center" || type === "not-orderable" || type === "unit-changed"
|
|
84
84
|
? "warning" as const
|
|
85
85
|
: "info" as const;
|
|
86
86
|
</script>
|
|
@@ -96,8 +96,8 @@ const hintColor = (type: string) =>
|
|
|
96
96
|
class="mb-3 space-y-1.5"
|
|
97
97
|
>
|
|
98
98
|
<UAlert
|
|
99
|
-
v-for="hint in line.hints"
|
|
100
|
-
:key="hint.type"
|
|
99
|
+
v-for="(hint, index) in line.hints"
|
|
100
|
+
:key="`${hint.type}-${index}`"
|
|
101
101
|
:color="hintColor(hint.type)"
|
|
102
102
|
variant="soft"
|
|
103
103
|
:icon="icon(hintColor(hint.type) === 'warning' ? 'warning' : 'info')"
|
|
@@ -6,7 +6,7 @@ import { cartEcommerce } from "../../../shared/themeEvents";
|
|
|
6
6
|
|
|
7
7
|
const { icon } = useIcons();
|
|
8
8
|
const { t, locale } = useI18n();
|
|
9
|
-
const { form, profile, profileLoading, fieldErrors, validateField } = useCheckoutOnePage();
|
|
9
|
+
const { form, profile, profileLoading, fieldErrors, validateField, pspMountDetails } = useCheckoutOnePage();
|
|
10
10
|
const cartStore = useCartStore();
|
|
11
11
|
|
|
12
12
|
// "What can THIS buyer pay with?" — the BFF resolves it (live: payments
|
|
@@ -111,9 +111,14 @@ const showCostCenter = computed(() =>
|
|
|
111
111
|
form.value.paymentMethod === "cost_center"
|
|
112
112
|
&& (profile.value?.costCenters.length ?? 0) > 0);
|
|
113
113
|
|
|
114
|
-
// PSP card entry (Stripe Elements, …). The provider's
|
|
115
|
-
// when a PSP card method is selected; the registry
|
|
116
|
-
// one, so this is
|
|
114
|
+
// PSP card entry (Stripe Elements, Novalnet's card iframe, …). The provider's
|
|
115
|
+
// secure field is mounted when a PSP card method is selected; the registry and
|
|
116
|
+
// the provider's checkout mode decide which one needs a field, so this is
|
|
117
|
+
// generic. THEME CONTRACT (FE-5): a theme overriding this section keeps
|
|
118
|
+
// `psp.mount(cardEl, option, pspMountDetails())` — the third argument is
|
|
119
|
+
// optional (without it the field is told the cart total only) — and may show
|
|
120
|
+
// `psp.hostedFallback` (the field could not be used; the buyer pays on the
|
|
121
|
+
// provider's page instead).
|
|
117
122
|
const psp = usePspCheckout();
|
|
118
123
|
const selectedOption = computed<PaymentOption | null>(() =>
|
|
119
124
|
paymentOptions.value.find(o => o.method === form.value.paymentMethod) ?? null);
|
|
@@ -126,10 +131,12 @@ async function syncCardField(): Promise<void> {
|
|
|
126
131
|
await nextTick();
|
|
127
132
|
if (needsCardField.value && cardEl.value && selectedOption.value) {
|
|
128
133
|
try {
|
|
129
|
-
await psp.mount(cardEl.value, selectedOption.value);
|
|
134
|
+
await psp.mount(cardEl.value, selectedOption.value, pspMountDetails());
|
|
130
135
|
}
|
|
131
|
-
catch
|
|
132
|
-
|
|
136
|
+
catch {
|
|
137
|
+
// The field did not come up and the provider has no page to fall
|
|
138
|
+
// back to: say so in words, not the loader's error.
|
|
139
|
+
cardError.value = t("onepage.payment.cardFieldUnavailable");
|
|
133
140
|
}
|
|
134
141
|
}
|
|
135
142
|
else {
|
|
@@ -263,7 +270,12 @@ if (import.meta.client) {
|
|
|
263
270
|
<!-- PSP secure card field (mounted client-side by the provider) -->
|
|
264
271
|
<div v-if="needsCardField" class="space-y-1.5">
|
|
265
272
|
<label class="block text-sm font-medium text-muted">{{ t('onepage.payment.cardDetails') }}</label>
|
|
266
|
-
<div
|
|
273
|
+
<div
|
|
274
|
+
v-show="!psp.hostedFallback.value"
|
|
275
|
+
ref="cardEl"
|
|
276
|
+
class="w-full sm:max-w-sm p-3 rounded-lg border border-(--ui-border) bg-(--ui-bg)"
|
|
277
|
+
/>
|
|
278
|
+
<p v-if="psp.hostedFallback.value" class="text-sm text-muted">{{ t('onepage.payment.cardOnProviderPage') }}</p>
|
|
267
279
|
<p v-if="cardError" class="text-sm text-error-500">{{ cardError }}</p>
|
|
268
280
|
</div>
|
|
269
281
|
</div>
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { PSP_RETURN_ORDER_PARAM, type PspReturnOutcome } from "../../../shared/pspReturn";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Where a payment provider returns the buyer (FE-5), whichever provider it
|
|
6
|
+
* was. The page hands what it was given to the BFF, which confirms the payment
|
|
7
|
+
* with the payments app, and then:
|
|
8
|
+
*
|
|
9
|
+
* - paid → the order confirmation the checkout shows after any order;
|
|
10
|
+
* - failed → says the payment did not go through, and offers to pay again;
|
|
11
|
+
* - retry → the buyer left the provider's page without paying; the same
|
|
12
|
+
* payment's page is offered again (guests too — the checkout's claim covers it);
|
|
13
|
+
* - pending → says the payment is being processed, with a way to look again;
|
|
14
|
+
* - unverified → says the payment could not be verified (the payments app
|
|
15
|
+
* refused the return): not paid, not failed — a case for the merchant.
|
|
16
|
+
*
|
|
17
|
+
* The confirm runs in the browser, once, after hydration: a server render and
|
|
18
|
+
* a hydration would otherwise ask the provider twice.
|
|
19
|
+
*/
|
|
20
|
+
const { t } = useI18n();
|
|
21
|
+
const { icon } = useIcons();
|
|
22
|
+
const { to } = useAppUrl();
|
|
23
|
+
const localePath = useLocalePath();
|
|
24
|
+
const route = useRoute();
|
|
25
|
+
|
|
26
|
+
const orderId = computed(() => {
|
|
27
|
+
const raw = route.query[PSP_RETURN_ORDER_PARAM];
|
|
28
|
+
return typeof raw === "string" ? raw : "";
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
type State = "checking" | Exclude<PspReturnOutcome, "paid"> | "error";
|
|
32
|
+
const state = ref<State>("checking");
|
|
33
|
+
const canRetryFromAccount = ref(false);
|
|
34
|
+
const retryUrl = ref<string | null>(null);
|
|
35
|
+
const checking = ref(false);
|
|
36
|
+
|
|
37
|
+
const orderLink = computed(() => (orderId.value ? localePath(`/account/orders/${orderId.value}`) : localePath("/")));
|
|
38
|
+
|
|
39
|
+
async function confirm(): Promise<void> {
|
|
40
|
+
if (checking.value) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!orderId.value) {
|
|
44
|
+
state.value = "error";
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
checking.value = true;
|
|
48
|
+
try {
|
|
49
|
+
const answer = await $fetch<{ outcome: PspReturnOutcome; orderId: string; canRetryFromAccount: boolean; retryUrl?: string }>(
|
|
50
|
+
"/api/checkout/payment-return",
|
|
51
|
+
{ method: "POST", body: { order: orderId.value, params: route.query } },
|
|
52
|
+
);
|
|
53
|
+
canRetryFromAccount.value = answer.canRetryFromAccount;
|
|
54
|
+
retryUrl.value = answer.retryUrl ?? null;
|
|
55
|
+
if (answer.outcome === "paid") {
|
|
56
|
+
await navigateTo(to("/checkout/confirmation", { id: answer.orderId }), { replace: true });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
state.value = answer.outcome;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
state.value = "error";
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
checking.value = false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
onMounted(() => void confirm());
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
<template>
|
|
73
|
+
<div class="max-w-xl mx-auto py-16 px-4 space-y-6">
|
|
74
|
+
<div
|
|
75
|
+
v-if="state === 'checking'"
|
|
76
|
+
class="flex flex-col items-center gap-4 text-center"
|
|
77
|
+
role="status"
|
|
78
|
+
>
|
|
79
|
+
<UIcon
|
|
80
|
+
:name="icon('loading')"
|
|
81
|
+
class="w-8 h-8 animate-spin text-muted"
|
|
82
|
+
/>
|
|
83
|
+
<p class="text-default">
|
|
84
|
+
{{ t('paymentReturn.checking') }}
|
|
85
|
+
</p>
|
|
86
|
+
</div>
|
|
87
|
+
|
|
88
|
+
<template v-else-if="state === 'failed'">
|
|
89
|
+
<UAlert
|
|
90
|
+
color="error"
|
|
91
|
+
variant="soft"
|
|
92
|
+
:icon="icon('error')"
|
|
93
|
+
:title="t('paymentReturn.failed.title')"
|
|
94
|
+
:description="t('paymentReturn.failed.text', { id: orderId })"
|
|
95
|
+
/>
|
|
96
|
+
<div class="flex flex-wrap gap-3">
|
|
97
|
+
<UButton
|
|
98
|
+
v-if="canRetryFromAccount"
|
|
99
|
+
color="primary"
|
|
100
|
+
:to="orderLink"
|
|
101
|
+
:label="t('paymentReturn.failed.payAgain')"
|
|
102
|
+
/>
|
|
103
|
+
<p
|
|
104
|
+
v-else
|
|
105
|
+
class="text-sm text-muted"
|
|
106
|
+
>
|
|
107
|
+
{{ t('paymentReturn.failed.guestHint') }}
|
|
108
|
+
</p>
|
|
109
|
+
<UButton
|
|
110
|
+
color="neutral"
|
|
111
|
+
variant="outline"
|
|
112
|
+
:to="localePath('/')"
|
|
113
|
+
:label="t('paymentReturn.toShop')"
|
|
114
|
+
/>
|
|
115
|
+
</div>
|
|
116
|
+
</template>
|
|
117
|
+
|
|
118
|
+
<template v-else-if="state === 'retry'">
|
|
119
|
+
<UAlert
|
|
120
|
+
color="warning"
|
|
121
|
+
variant="soft"
|
|
122
|
+
:icon="icon('info')"
|
|
123
|
+
:title="t('paymentReturn.retry.title')"
|
|
124
|
+
:description="t('paymentReturn.retry.text', { id: orderId })"
|
|
125
|
+
/>
|
|
126
|
+
<div class="flex flex-wrap gap-3">
|
|
127
|
+
<UButton
|
|
128
|
+
v-if="retryUrl"
|
|
129
|
+
color="primary"
|
|
130
|
+
:to="retryUrl"
|
|
131
|
+
external
|
|
132
|
+
:label="t('paymentReturn.retry.again')"
|
|
133
|
+
/>
|
|
134
|
+
<UButton
|
|
135
|
+
color="neutral"
|
|
136
|
+
variant="outline"
|
|
137
|
+
:to="localePath('/')"
|
|
138
|
+
:label="t('paymentReturn.toShop')"
|
|
139
|
+
/>
|
|
140
|
+
</div>
|
|
141
|
+
</template>
|
|
142
|
+
|
|
143
|
+
<template v-else-if="state === 'pending'">
|
|
144
|
+
<UAlert
|
|
145
|
+
color="info"
|
|
146
|
+
variant="soft"
|
|
147
|
+
:icon="icon('info')"
|
|
148
|
+
:title="t('paymentReturn.pending.title')"
|
|
149
|
+
:description="t('paymentReturn.pending.text', { id: orderId })"
|
|
150
|
+
/>
|
|
151
|
+
<div class="flex flex-wrap gap-3">
|
|
152
|
+
<UButton
|
|
153
|
+
color="primary"
|
|
154
|
+
:loading="checking"
|
|
155
|
+
:label="t('paymentReturn.pending.checkAgain')"
|
|
156
|
+
@click="confirm"
|
|
157
|
+
/>
|
|
158
|
+
<UButton
|
|
159
|
+
v-if="canRetryFromAccount"
|
|
160
|
+
color="neutral"
|
|
161
|
+
variant="outline"
|
|
162
|
+
:to="orderLink"
|
|
163
|
+
:label="t('paymentReturn.toOrder')"
|
|
164
|
+
/>
|
|
165
|
+
</div>
|
|
166
|
+
</template>
|
|
167
|
+
|
|
168
|
+
<template v-else-if="state === 'unverified'">
|
|
169
|
+
<UAlert
|
|
170
|
+
color="warning"
|
|
171
|
+
variant="soft"
|
|
172
|
+
:icon="icon('alert')"
|
|
173
|
+
:title="t('paymentReturn.unverified.title')"
|
|
174
|
+
:description="t('paymentReturn.unverified.text', { id: orderId })"
|
|
175
|
+
/>
|
|
176
|
+
<div class="flex flex-wrap gap-3">
|
|
177
|
+
<UButton
|
|
178
|
+
v-if="canRetryFromAccount"
|
|
179
|
+
color="neutral"
|
|
180
|
+
variant="outline"
|
|
181
|
+
:to="orderLink"
|
|
182
|
+
:label="t('paymentReturn.toOrder')"
|
|
183
|
+
/>
|
|
184
|
+
<UButton
|
|
185
|
+
color="neutral"
|
|
186
|
+
variant="outline"
|
|
187
|
+
:to="localePath('/')"
|
|
188
|
+
:label="t('paymentReturn.toShop')"
|
|
189
|
+
/>
|
|
190
|
+
</div>
|
|
191
|
+
</template>
|
|
192
|
+
|
|
193
|
+
<template v-else>
|
|
194
|
+
<UAlert
|
|
195
|
+
color="warning"
|
|
196
|
+
variant="soft"
|
|
197
|
+
:icon="icon('alert')"
|
|
198
|
+
:title="t('paymentReturn.error.title')"
|
|
199
|
+
:description="t('paymentReturn.error.text')"
|
|
200
|
+
/>
|
|
201
|
+
<UButton
|
|
202
|
+
color="neutral"
|
|
203
|
+
variant="outline"
|
|
204
|
+
:to="localePath('/')"
|
|
205
|
+
:label="t('paymentReturn.toShop')"
|
|
206
|
+
/>
|
|
207
|
+
</template>
|
|
208
|
+
</div>
|
|
209
|
+
</template>
|
|
@@ -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,11 @@ 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();
|
|
62
64
|
const campaignAttribution = useCampaignAttribution();
|
|
63
65
|
// The server-calculated totals the summary shows (shared state) — read when
|
|
64
66
|
// an order is placed, so the confirmation can report what was bought.
|
|
@@ -312,6 +314,47 @@ export function useCheckoutOnePage() {
|
|
|
312
314
|
};
|
|
313
315
|
}
|
|
314
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
|
+
|
|
315
358
|
interface SubmitResult {
|
|
316
359
|
orderId: string;
|
|
317
360
|
approvalRequired: boolean;
|
|
@@ -341,11 +384,26 @@ export function useCheckoutOnePage() {
|
|
|
341
384
|
if (attribution) {
|
|
342
385
|
payload.attribution = attribution;
|
|
343
386
|
}
|
|
344
|
-
// PSP card methods (Stripe Elements,
|
|
345
|
-
// the single-use token
|
|
346
|
-
//
|
|
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.
|
|
347
393
|
if (psp.hasActive()) {
|
|
348
|
-
|
|
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
|
+
}
|
|
349
407
|
if (instrument) {
|
|
350
408
|
payload.paymentInstrument = instrument;
|
|
351
409
|
}
|
|
@@ -365,13 +423,18 @@ export function useCheckoutOnePage() {
|
|
|
365
423
|
);
|
|
366
424
|
}
|
|
367
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.
|
|
368
428
|
const order = await $fetch(checkoutApi.orders(), {
|
|
369
429
|
method: "POST",
|
|
370
430
|
body: payload,
|
|
431
|
+
headers: { "x-locale": locale.value },
|
|
371
432
|
}) as { orderId: string; approvalRequired?: boolean; approvers?: string[]; requiresAction?: boolean; redirectUrl?: string };
|
|
372
433
|
|
|
373
|
-
// Redirect-based PSPs (3DS step-up, wallets, …) —
|
|
374
|
-
// handler for every provider: hand the buyer to the PSP
|
|
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).
|
|
375
438
|
if (order.requiresAction && order.redirectUrl) {
|
|
376
439
|
cart.clearCart();
|
|
377
440
|
window.location.href = order.redirectUrl;
|
|
@@ -511,6 +574,7 @@ export function useCheckoutOnePage() {
|
|
|
511
574
|
validateAll,
|
|
512
575
|
clearFieldError,
|
|
513
576
|
buildOrderPayload,
|
|
577
|
+
pspMountDetails,
|
|
514
578
|
submitOrder,
|
|
515
579
|
submitRequisition,
|
|
516
580
|
reset,
|
|
@@ -19,10 +19,18 @@ export function usePendingApprovals() {
|
|
|
19
19
|
|
|
20
20
|
const deciding = ref<string | null>(null);
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
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(
|
|
33
|
+
await $fetch(path, {
|
|
26
34
|
method: "POST",
|
|
27
35
|
body: reason?.trim() ? { reason: reason.trim() } : {},
|
|
28
36
|
});
|