@revenexx/cover 0.15.0 → 0.16.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.
- package/app/api/account.ts +1 -0
- package/app/components/RevenexxForm.vue +183 -19
- package/app/components/account/address/AccountAddressCard.vue +8 -2
- package/app/components/account/address/AccountAddressView.vue +5 -1
- package/app/components/account/carts/AccountCartsTable.vue +85 -3
- package/app/components/account/dashboard/AccountDashboardBudgets.vue +2 -1
- package/app/components/account/dashboard/AccountDashboardRecentOrders.vue +2 -1
- package/app/components/account/dashboard/AccountDashboardRequisitions.vue +2 -1
- package/app/components/account/directorder/AccountDirectOrder.vue +100 -12
- package/app/components/account/governance/AccountApprovalLimitsTable.vue +124 -8
- package/app/components/account/governance/AccountCostCenterDetail.vue +3 -2
- package/app/components/account/governance/AccountCostCentersTable.vue +133 -6
- package/app/components/account/governance/AccountRequisitionDetail.vue +2 -1
- package/app/components/account/governance/AccountRequisitionsTable.vue +102 -6
- package/app/components/account/governance/AccountWorkflowDetail.vue +3 -2
- package/app/components/account/governance/AccountWorkflowsTable.vue +76 -1
- package/app/components/account/governance/GovernanceApprovalLimitModal.vue +8 -0
- package/app/components/account/governance/GovernanceCostCenterModal.vue +7 -0
- package/app/components/account/governance/GovernanceWorkflowModal.vue +7 -0
- package/app/components/account/orderlists/AccountOrderListDetail.vue +14 -4
- package/app/components/account/orderlists/AccountOrderListsTable.vue +115 -7
- package/app/components/account/orders/AccountOrderDetail.vue +67 -3
- package/app/components/account/orders/AccountOrderPay.vue +211 -0
- package/app/components/account/orders/AccountOrdersTable.vue +119 -10
- package/app/components/account/organization/AccountOrganization.vue +6 -0
- package/app/components/account/profile/AccountPasswordForm.vue +2 -0
- package/app/components/account/profile/AccountProfileForm.vue +4 -0
- package/app/components/account/quotes/AccountQuoteDetail.vue +7 -10
- package/app/components/account/team/AccountTeam.vue +91 -0
- package/app/components/auth/AuthLoginTeaser.vue +1 -1
- package/app/components/auth/AuthRegisterPanel.vue +22 -3
- package/app/components/cart/manage/CartNameModal.vue +4 -0
- package/app/components/checkout/onepage/CheckoutAddressSection.vue +5 -1
- package/app/components/checkout/onepage/CheckoutGuestDetailsSection.vue +9 -1
- package/app/components/checkout/onepage/CheckoutSummarySection.vue +6 -1
- package/app/components/form/FormPage.vue +7 -4
- package/app/components/layout/footer/Footer.vue +15 -2
- package/app/components/ui/forms/PasswordInput.vue +2 -0
- package/app/components/ui/table/TableCardList.vue +69 -0
- package/app/components/ui/table/TableSortButton.vue +1 -1
- package/app/components/ui/table/TableToolbar.vue +2 -0
- package/app/components/withdrawal/WithdrawalDeclaration.vue +286 -0
- package/app/composables/useCheckoutOnePage.ts +22 -0
- package/app/composables/useMobileTableSort.ts +82 -0
- package/app/config/forms.ts +8 -0
- package/app/config/navigation.ts +8 -0
- package/app/formkit.config.ts +21 -0
- package/app/interfaces/account/order-list.ts +11 -0
- package/app/interfaces/account/quotes.ts +7 -3
- package/app/pages/punchout/transfer.vue +36 -1
- package/app/pages/widerruf.vue +33 -0
- package/app/shared/addressLines.ts +66 -0
- package/app/shared/checkoutAddressRefusal.ts +63 -0
- package/i18n/locales/de/account.json +13 -1
- package/i18n/locales/de/cart.json +1 -0
- package/i18n/locales/de/checkout.json +1 -1
- package/i18n/locales/de/common.json +7 -0
- package/i18n/locales/de/withdrawal.json +34 -0
- package/i18n/locales/en/account.json +13 -1
- package/i18n/locales/en/cart.json +1 -0
- package/i18n/locales/en/checkout.json +1 -1
- package/i18n/locales/en/common.json +7 -0
- package/i18n/locales/en/withdrawal.json +34 -0
- package/nuxt.config.ts +3 -0
- package/package.json +1 -1
- package/server/api/account/orders/[id]/pay.post.ts +100 -0
- package/server/api/account/orders/[id].get.ts +5 -1
- package/server/api/account/quotes/[id]/order.post.ts +22 -22
- package/server/api/forms/[slug].get.ts +1 -3
- package/server/api/orders/index.post.ts +33 -50
- package/server/api/punchout/return.post.ts +3 -1
- package/server/data/forms/authored.json +69 -8
- package/server/dev/errorHandler.ts +47 -0
- package/server/interfaces/punchout.ts +5 -0
- package/server/middleware/missing-media.ts +35 -0
- package/server/middleware/punchout-hand-back-csp.ts +17 -0
- package/server/plugins/vue-devtools-sink.ts +28 -0
- package/server/services/MockFormsService.ts +3 -1
- package/server/utils/addressRefusal.ts +63 -0
- package/server/utils/country.ts +23 -0
- package/server/utils/forms.ts +23 -1
- package/server/utils/liveOrders.ts +44 -2
- package/server/utils/orderPayment.ts +155 -0
- package/server/utils/punchoutFormAction.ts +44 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { orderAwaitsPayment, orderPaymentRequest, recordOrderPaymentStatus } from "../../../../utils/orderPayment";
|
|
2
|
+
|
|
3
|
+
interface PayOrderPayload {
|
|
4
|
+
/** PSP single-use token from the order page's card field. */
|
|
5
|
+
paymentInstrument?: { token?: string };
|
|
6
|
+
/** Where the PSP returns the buyer after a redirect/3DS step-up. */
|
|
7
|
+
returnUrl?: string;
|
|
8
|
+
/** One per attempt, so a double click pays once. */
|
|
9
|
+
idempotencyKey?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The buyer pays an order that took no payment at the checkout (RAD-173).
|
|
14
|
+
*
|
|
15
|
+
* An order that waited for somebody's approval was not paid when it was
|
|
16
|
+
* requested — there was nothing to pay for yet. Once approved it is placed and
|
|
17
|
+
* open, and this is where its payment is made: the order's own method, over the
|
|
18
|
+
* order's own total, naming the order so the payments app can refuse a payment
|
|
19
|
+
* the order does not owe.
|
|
20
|
+
*
|
|
21
|
+
* Their own order only, as with cancelling: somebody else's is a 404.
|
|
22
|
+
*/
|
|
23
|
+
export default defineEventHandler(async (event) => {
|
|
24
|
+
const number = getRouterParam(event, "id") ?? "";
|
|
25
|
+
const body = await readBody<PayOrderPayload>(event).catch(() => ({} as PayOrderPayload));
|
|
26
|
+
|
|
27
|
+
const user = await getAuthService(event).me(event);
|
|
28
|
+
if (!user) {
|
|
29
|
+
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
30
|
+
}
|
|
31
|
+
if (resolveOrderServiceKey(event) !== "api" || resolvePaymentServiceKey(event) !== "api") {
|
|
32
|
+
throw createError({ statusCode: 501, message: "This storefront does not take payments on demo data" });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const order = await getLiveOrderByNumber(number, user.contactId);
|
|
36
|
+
if (!order) {
|
|
37
|
+
throw createError({ statusCode: 404, message: "Order not found" });
|
|
38
|
+
}
|
|
39
|
+
const idempotencyKey = typeof body?.idempotencyKey === "string" && body.idempotencyKey.trim()
|
|
40
|
+
? `order-${order.id}-${body.idempotencyKey.trim()}`
|
|
41
|
+
: `order-${order.id}-${crypto.randomUUID()}`;
|
|
42
|
+
|
|
43
|
+
// Asked again here, the same question the page asked: a stale page must not
|
|
44
|
+
// pay an order that meanwhile was paid, called off, or is still waiting for
|
|
45
|
+
// its approval — nor one an older payment already sits on. The payment this
|
|
46
|
+
// same attempt made is not in the way: it goes through to payments, which
|
|
47
|
+
// replays it. A method is part of the answer; read here so the type says so.
|
|
48
|
+
//
|
|
49
|
+
// 409 and not a refusal: nothing went wrong, the order simply owes nothing
|
|
50
|
+
// now, and the page tells the buyer that rather than "did not go through".
|
|
51
|
+
const method = order.payment?.method;
|
|
52
|
+
if (!method || !(await orderAwaitsPayment(event, order, idempotencyKey))) {
|
|
53
|
+
throw createError({
|
|
54
|
+
statusCode: 409,
|
|
55
|
+
message: "This order is not waiting for a payment",
|
|
56
|
+
data: { type: "not_awaiting_payment" },
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let created: { id: string; status: string; error_message?: string | null; next_action?: { type?: string; url?: string } | null };
|
|
61
|
+
try {
|
|
62
|
+
created = await useRevenexxSdk().call<typeof created>("POST", "/v1/payments", {
|
|
63
|
+
body: orderPaymentRequest({
|
|
64
|
+
method,
|
|
65
|
+
amount: Number(order.grand_total),
|
|
66
|
+
currency: order.currency,
|
|
67
|
+
country: paymentCountry(order) ?? "",
|
|
68
|
+
orderRef: order.number,
|
|
69
|
+
orderId: order.id,
|
|
70
|
+
contactId: principalContactId(event),
|
|
71
|
+
idempotencyKey,
|
|
72
|
+
token: body?.paymentInstrument?.token,
|
|
73
|
+
returnUrl: body?.returnUrl,
|
|
74
|
+
}),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
// 409 is payments saying the order does not owe this — already paid, or
|
|
79
|
+
// in another currency; 400/422 a method or instrument it refused. All of
|
|
80
|
+
// them are the buyer's to read.
|
|
81
|
+
if (err instanceof RevenexxException && [400, 409, 422].includes(err.code)) {
|
|
82
|
+
getLogService().error(`Payment for order ${number} rejected`, apiErrorContext(err));
|
|
83
|
+
throw createError({ statusCode: 422, message: err.message });
|
|
84
|
+
}
|
|
85
|
+
getLogService().error(`Payment for order ${number} failed`, apiErrorContext(err));
|
|
86
|
+
throw createError({ statusCode: 502, message: "Payment service unavailable" });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (created.status === "failed") {
|
|
90
|
+
throw createError({ statusCode: 402, message: created.error_message ?? "Payment was declined" });
|
|
91
|
+
}
|
|
92
|
+
await recordOrderPaymentStatus(order.id, created.status);
|
|
93
|
+
|
|
94
|
+
// The PSP needs the buyer (3DS / redirect PSPs): hand the redirect back, the
|
|
95
|
+
// payment settles on their return.
|
|
96
|
+
if (created.status === "requires_action" && created.next_action?.url) {
|
|
97
|
+
return { status: "requires-action" as const, requiresAction: true, redirectUrl: created.next_action.url, paymentId: created.id };
|
|
98
|
+
}
|
|
99
|
+
return { status: created.status, requiresAction: false, paymentId: created.id };
|
|
100
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AccountOrder, AccountOrderListResponse } from "../../../../app/interfaces/account/order-list";
|
|
2
|
+
import { orderAwaitsPayment } from "../../../utils/orderPayment";
|
|
2
3
|
|
|
3
4
|
/** Single order from the account history (live: by display number). */
|
|
4
5
|
export default defineEventHandler(async (event) => {
|
|
@@ -15,7 +16,10 @@ export default defineEventHandler(async (event) => {
|
|
|
15
16
|
if (!order) {
|
|
16
17
|
throw createError({ statusCode: 404, message: "Order not found" });
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
+
// Whether it waits for the buyer's payment (RAD-173) — asked here, on
|
|
20
|
+
// the one order the page shows, because only the payments app can say
|
|
21
|
+
// whether a payment already sits on it.
|
|
22
|
+
return { ...mapLiveOrderToAccount(order), payable: await orderAwaitsPayment(event, order) };
|
|
19
23
|
}
|
|
20
24
|
catch (err) {
|
|
21
25
|
if (isError(err)) {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { OrderPaymentStatus } from "@revenexx/sdk";
|
|
2
1
|
import type { Models } from "@revenexx/sdk";
|
|
3
2
|
|
|
4
3
|
import type { QuoteOrderPayload, QuoteOrderResult } from "../../../../../app/interfaces/account/quotes";
|
|
4
|
+
import { addressRefusalOf } from "../../../../utils/addressRefusal";
|
|
5
|
+
import { toIsoCountry } from "../../../../utils/country";
|
|
6
|
+
import { orderPaymentRequest, recordOrderPaymentStatus } from "../../../../utils/orderPayment";
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Order a quote at the quoted figures (RX-783).
|
|
@@ -17,15 +19,6 @@ import type { QuoteOrderPayload, QuoteOrderResult } from "../../../../../app/int
|
|
|
17
19
|
* stacking a campaign on top of it is a decision the merchant makes in the
|
|
18
20
|
* price, not one the storefront makes afterwards.
|
|
19
21
|
*/
|
|
20
|
-
function toIsoCountry(value: unknown): string {
|
|
21
|
-
const raw = String(value ?? "").trim();
|
|
22
|
-
if (/^[A-Za-z]{2}$/.test(raw)) {
|
|
23
|
-
return raw.toUpperCase();
|
|
24
|
-
}
|
|
25
|
-
const names: Record<string, string> = { deutschland: "DE", germany: "DE", österreich: "AT", austria: "AT", schweiz: "CH", switzerland: "CH" };
|
|
26
|
-
return names[raw.toLowerCase()] ?? raw;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
22
|
export default defineEventHandler(async (event): Promise<QuoteOrderResult> => {
|
|
30
23
|
const id = getRouterParam(event, "id") ?? "";
|
|
31
24
|
const body = await readBody<QuoteOrderPayload>(event).catch(() => ({} as QuoteOrderPayload));
|
|
@@ -136,6 +129,11 @@ export default defineEventHandler(async (event): Promise<QuoteOrderResult> => {
|
|
|
136
129
|
// order and can place it by hand, which beats a buyer retrying into a
|
|
137
130
|
// second acceptance of a quote that has nothing left open.
|
|
138
131
|
getLogService().error(`Order placement for quote ${quote.number} failed after acceptance`, apiErrorContext(err));
|
|
132
|
+
// An address the orders app refuses names the field; say which (RAD-236).
|
|
133
|
+
const badAddress = addressRefusalOf(err);
|
|
134
|
+
if (badAddress) {
|
|
135
|
+
throw createError({ statusCode: 422, message: badAddress.message, data: { type: "invalid_address", ...badAddress } });
|
|
136
|
+
}
|
|
139
137
|
if (err instanceof RevenexxException && (err.code === 400 || err.code === 422)) {
|
|
140
138
|
throw createError({ statusCode: 422, message: err.message });
|
|
141
139
|
}
|
|
@@ -146,22 +144,24 @@ export default defineEventHandler(async (event): Promise<QuoteOrderResult> => {
|
|
|
146
144
|
const payerContactId = principalContactId(event);
|
|
147
145
|
try {
|
|
148
146
|
const payment = await sdk.call<{ id: string; status: string }>("POST", "/v1/payments", {
|
|
149
|
-
body: {
|
|
150
|
-
|
|
151
|
-
amount:
|
|
147
|
+
body: orderPaymentRequest({
|
|
148
|
+
method: paymentMethod,
|
|
149
|
+
amount: placed.grand_total ?? view.grandTotal,
|
|
152
150
|
currency: draft.currency,
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
// The type's key first; the old flat one is what a draft carried before (RAD-236).
|
|
152
|
+
country: toIsoCountry(
|
|
153
|
+
draft.billing_address?.country_code ?? draft.billing_address?.country
|
|
154
|
+
?? draft.shipping_address?.country_code ?? draft.shipping_address?.country,
|
|
155
|
+
),
|
|
156
|
+
orderRef: placed.number,
|
|
157
|
+
orderId: placed.id,
|
|
155
158
|
// The buyer's own payment, listed on their payments page (RAD-171).
|
|
156
|
-
|
|
157
|
-
|
|
159
|
+
contactId: payerContactId,
|
|
160
|
+
idempotencyKey: `quote-${quote.id}-${placed.id}`,
|
|
158
161
|
metadata: { quote_number: quote.number },
|
|
159
|
-
},
|
|
162
|
+
}),
|
|
160
163
|
});
|
|
161
|
-
|
|
162
|
-
? OrderPaymentStatus.Paid
|
|
163
|
-
: payment.status === "authorized" ? OrderPaymentStatus.Authorized : OrderPaymentStatus.Pending;
|
|
164
|
-
await useTenantSdk().orders.ordersPaymentStatusUpdate({ id: placed.id, status: mapped });
|
|
164
|
+
await recordOrderPaymentStatus(placed.id, payment.status);
|
|
165
165
|
}
|
|
166
166
|
catch (err) {
|
|
167
167
|
// An invoice order stands without a captured payment; the payment
|
|
@@ -25,9 +25,7 @@ export default defineEventHandler(async (event): Promise<FormPublic> => {
|
|
|
25
25
|
name: form.name,
|
|
26
26
|
slug: form.slug,
|
|
27
27
|
definition: localizeDefinition(definition, form.settings, locale),
|
|
28
|
-
settings: form.settings
|
|
29
|
-
? { submit_label: form.settings.submit_label, success_message: form.settings.success_message }
|
|
30
|
-
: null,
|
|
28
|
+
settings: localizeSettings(form.settings, locale),
|
|
31
29
|
// Never a name the form itself declares: a decoy that collides with a
|
|
32
30
|
// real field would drop the visitor's own answer.
|
|
33
31
|
honeypot: policy.honeypotField && !namedFields(definition).has(policy.honeypotField)
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PromotionsRedemptionsReleaseReason } from "@revenexx/sdk";
|
|
2
2
|
import type { Models } from "@revenexx/sdk";
|
|
3
3
|
|
|
4
|
+
import { addressRefusalOf } from "../../utils/addressRefusal";
|
|
4
5
|
import { type EligibleMethodFee, paymentFee } from "../../utils/paymentFee";
|
|
5
6
|
import { orderLinePrices, type PriceResolveAnswer } from "../../utils/orderLinePrices";
|
|
7
|
+
import { toIsoCountry } from "../../utils/country";
|
|
8
|
+
import { checkoutTakesPayment, orderPaymentRequest, recordOrderPaymentStatus } from "../../utils/orderPayment";
|
|
6
9
|
|
|
7
10
|
// Method codes are generic — live mode validates them against the
|
|
8
11
|
// payments app; the demo-only methods keep their extra fields.
|
|
@@ -47,30 +50,6 @@ function isNonEmptyString(v: unknown): v is string {
|
|
|
47
50
|
return typeof v === "string" && v.trim().length > 0;
|
|
48
51
|
}
|
|
49
52
|
|
|
50
|
-
// Customer addresses may carry the country as a display name ("Deutschland",
|
|
51
|
-
// "Austria") — the payments app's eligibility check expects ISO 3166-1
|
|
52
|
-
// alpha-2 codes. Two-letter values pass through unchanged.
|
|
53
|
-
const COUNTRY_NAME_TO_ISO: Record<string, string> = {
|
|
54
|
-
deutschland: "DE", germany: "DE",
|
|
55
|
-
österreich: "AT", austria: "AT",
|
|
56
|
-
schweiz: "CH", switzerland: "CH",
|
|
57
|
-
niederlande: "NL", netherlands: "NL",
|
|
58
|
-
frankreich: "FR", france: "FR",
|
|
59
|
-
italien: "IT", italy: "IT",
|
|
60
|
-
spanien: "ES", spain: "ES",
|
|
61
|
-
belgien: "BE", belgium: "BE",
|
|
62
|
-
polen: "PL", poland: "PL",
|
|
63
|
-
tschechien: "CZ", "czech republic": "CZ", czechia: "CZ",
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
function toIsoCountry(value: unknown): string {
|
|
67
|
-
const raw = String(value ?? "").trim();
|
|
68
|
-
if (/^[A-Za-z]{2}$/.test(raw)) {
|
|
69
|
-
return raw.toUpperCase();
|
|
70
|
-
}
|
|
71
|
-
return COUNTRY_NAME_TO_ISO[raw.toLowerCase()] ?? raw;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
53
|
function validateAddress(address: Record<string, unknown>, customerType: "business" | "private"): string | null {
|
|
75
54
|
const requiredFields = customerType === "private"
|
|
76
55
|
? REQUIRED_ADDRESS_FIELDS_PRIVATE
|
|
@@ -539,6 +518,17 @@ export default defineEventHandler(async (event) => {
|
|
|
539
518
|
if (isError(err)) {
|
|
540
519
|
throw err;
|
|
541
520
|
}
|
|
521
|
+
// An address the orders app holds to its country's rules and
|
|
522
|
+
// refuses: the sentence goes to the field it names, so the buyer
|
|
523
|
+
// corrects that rather than reading a generic failure (RAD-236).
|
|
524
|
+
const badAddress = addressRefusalOf(err);
|
|
525
|
+
if (badAddress) {
|
|
526
|
+
throw createError({
|
|
527
|
+
status: 422,
|
|
528
|
+
message: badAddress.message,
|
|
529
|
+
data: { type: "invalid_address", ...badAddress },
|
|
530
|
+
});
|
|
531
|
+
}
|
|
542
532
|
if (err instanceof RevenexxException && (err.code === 400 || err.code === 422)) {
|
|
543
533
|
throw createError({ status: 422, message: err.message });
|
|
544
534
|
}
|
|
@@ -563,11 +553,15 @@ export default defineEventHandler(async (event) => {
|
|
|
563
553
|
// eligibility (countries, order-value bounds) is enforced there
|
|
564
554
|
// again; a declined payment fails the order with 402 (and cancels
|
|
565
555
|
// the already placed live order).
|
|
556
|
+
//
|
|
557
|
+
// Not for a purchase that waits for a (demo) approval (RAD-173): there
|
|
558
|
+
// is no order to pay yet, and the approval may never produce one. It is
|
|
559
|
+
// paid from the order's page once somebody approved it.
|
|
566
560
|
let livePaymentStatus: string | null = null;
|
|
567
561
|
// Set when the PSP needs buyer action (3DS step-up / redirect PSPs) —
|
|
568
562
|
// the checkout hands the buyer to redirectUrl and confirms on return.
|
|
569
563
|
let pendingAction: { paymentId: string; redirectUrl: string } | null = null;
|
|
570
|
-
if (livePayments) {
|
|
564
|
+
if (checkoutTakesPayment(livePayments, blockingApprovals.length > 0)) {
|
|
571
565
|
const totalRow = calculation.totals.find(row => row.key === "total");
|
|
572
566
|
const address = body.address as Record<string, unknown> | undefined;
|
|
573
567
|
const billing = address?.billingAddressSameAsShipping === false
|
|
@@ -584,25 +578,23 @@ export default defineEventHandler(async (event) => {
|
|
|
584
578
|
"POST",
|
|
585
579
|
"/v1/payments",
|
|
586
580
|
{
|
|
587
|
-
body: {
|
|
588
|
-
|
|
581
|
+
body: orderPaymentRequest({
|
|
582
|
+
method: payment.method,
|
|
589
583
|
// Charge exactly what the orders app computed (incl. shipping tax).
|
|
590
|
-
amount:
|
|
584
|
+
amount: liveOrderTotal ?? totalRow?.amount ?? 0,
|
|
591
585
|
currency: selectedCurrency ?? calculation.currency,
|
|
592
586
|
country,
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
...(instrument?.token ? { token: instrument.token } : {}),
|
|
600
|
-
...(body.returnUrl ? { return_url: body.returnUrl } : {}),
|
|
587
|
+
orderRef: orderId,
|
|
588
|
+
orderId: liveOrderUuid,
|
|
589
|
+
contactId: payerContactId,
|
|
590
|
+
idempotencyKey: body.checkoutSessionToken,
|
|
591
|
+
token: instrument?.token,
|
|
592
|
+
returnUrl: body.returnUrl,
|
|
601
593
|
metadata: {
|
|
602
594
|
...(payment.poNumber ? { po_number: payment.poNumber } : {}),
|
|
603
595
|
...(payment.costCenter ? { cost_center: payment.costCenter } : {}),
|
|
604
596
|
},
|
|
605
|
-
},
|
|
597
|
+
}),
|
|
606
598
|
},
|
|
607
599
|
);
|
|
608
600
|
if (created.status === "failed") {
|
|
@@ -627,7 +619,8 @@ export default defineEventHandler(async (event) => {
|
|
|
627
619
|
if (isError(err)) {
|
|
628
620
|
throw err;
|
|
629
621
|
}
|
|
630
|
-
|
|
622
|
+
// 409 is payments refusing a payment its order does not owe.
|
|
623
|
+
if (err instanceof RevenexxException && [400, 409, 422].includes(err.code)) {
|
|
631
624
|
getLogService().error("Payment rejected", apiErrorContext(err));
|
|
632
625
|
throw createError({ status: 422, message: err.message });
|
|
633
626
|
}
|
|
@@ -637,18 +630,8 @@ export default defineEventHandler(async (event) => {
|
|
|
637
630
|
}
|
|
638
631
|
|
|
639
632
|
// The payment dimension of the live order follows the payment outcome.
|
|
640
|
-
// The payments app's terminal "paid" state is `captured` (PSP auto/
|
|
641
|
-
// manual capture); `succeeded`/`paid` are accepted as synonyms.
|
|
642
633
|
if (liveOrderUuid && livePaymentStatus) {
|
|
643
|
-
|
|
644
|
-
? OrderPaymentStatus.Paid
|
|
645
|
-
: livePaymentStatus === "authorized" ? OrderPaymentStatus.Authorized : OrderPaymentStatus.Pending;
|
|
646
|
-
try {
|
|
647
|
-
await useTenantSdk().orders.ordersPaymentStatusUpdate({ id: liveOrderUuid, status: mapped });
|
|
648
|
-
}
|
|
649
|
-
catch (err) {
|
|
650
|
-
getLogService().error("Order payment-status sync failed", apiErrorContext(err));
|
|
651
|
-
}
|
|
634
|
+
await recordOrderPaymentStatus(liveOrderUuid, livePaymentStatus);
|
|
652
635
|
}
|
|
653
636
|
|
|
654
637
|
// The live cart freezes as the order source (best-effort).
|
|
@@ -51,7 +51,9 @@ export default defineEventHandler(async (event): Promise<PunchoutReturnPayload>
|
|
|
51
51
|
throw createError({ statusCode: 503, data: { type: "service_unavailable" } });
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
// The origin goes on the visit so the hand-back page can be answered with a
|
|
55
|
+
// `form-action` that lets the browser submit there (PE-994).
|
|
56
|
+
updatePunchoutVisit(event, { handedBack: true, handBackOrigin: handBackOrigin(payload.target_url) });
|
|
55
57
|
|
|
56
58
|
// Sign out only once the payload is in hand: a logout that ran first would
|
|
57
59
|
// be a visit closed with the cart still here.
|
|
@@ -121,13 +121,6 @@
|
|
|
121
121
|
"slug": "price-request",
|
|
122
122
|
"status": "live",
|
|
123
123
|
"definition": [
|
|
124
|
-
{
|
|
125
|
-
"$el": "p",
|
|
126
|
-
"children": "Für einen Artikel und eine Frage. Ganze Warenkörbe gehen als Angebotsanfrage.",
|
|
127
|
-
"attrs": {
|
|
128
|
-
"class": "text-sm text-muted"
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
124
|
{
|
|
132
125
|
"$formkit": "text",
|
|
133
126
|
"name": "product",
|
|
@@ -166,13 +159,14 @@
|
|
|
166
159
|
"$formkit": "email",
|
|
167
160
|
"name": "email",
|
|
168
161
|
"label": "E-Mail",
|
|
169
|
-
"validation": "
|
|
162
|
+
"validation": "requiredIf:reply_via,email|email",
|
|
170
163
|
"autocomplete": "email"
|
|
171
164
|
},
|
|
172
165
|
{
|
|
173
166
|
"$formkit": "tel",
|
|
174
167
|
"name": "phone",
|
|
175
168
|
"label": "Telefon",
|
|
169
|
+
"validation": "requiredIf:reply_via,phone",
|
|
176
170
|
"autocomplete": "tel"
|
|
177
171
|
},
|
|
178
172
|
{
|
|
@@ -222,6 +216,13 @@
|
|
|
222
216
|
"slug": "callback",
|
|
223
217
|
"status": "live",
|
|
224
218
|
"definition": [
|
|
219
|
+
{
|
|
220
|
+
"$rxStep": {
|
|
221
|
+
"id": "step_1",
|
|
222
|
+
"kind": "fields",
|
|
223
|
+
"title": "Ihre Kontaktdaten"
|
|
224
|
+
}
|
|
225
|
+
},
|
|
225
226
|
{
|
|
226
227
|
"$formkit": "text",
|
|
227
228
|
"name": "name",
|
|
@@ -333,5 +334,65 @@
|
|
|
333
334
|
}
|
|
334
335
|
}
|
|
335
336
|
}
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
"id": "demo-form-widerruf",
|
|
340
|
+
"name": "Widerruf",
|
|
341
|
+
"slug": "widerruf",
|
|
342
|
+
"status": "live",
|
|
343
|
+
"definition": [
|
|
344
|
+
{
|
|
345
|
+
"$formkit": "text",
|
|
346
|
+
"name": "name",
|
|
347
|
+
"label": "Name",
|
|
348
|
+
"validation": "required",
|
|
349
|
+
"autocomplete": "name"
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
"$formkit": "email",
|
|
353
|
+
"name": "email",
|
|
354
|
+
"label": "E-Mail-Adresse",
|
|
355
|
+
"validation": "required|email",
|
|
356
|
+
"autocomplete": "email"
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
"$formkit": "text",
|
|
360
|
+
"name": "order_id",
|
|
361
|
+
"label": "Bestellnummer",
|
|
362
|
+
"validation": "required"
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
"$formkit": "textarea",
|
|
366
|
+
"name": "statement",
|
|
367
|
+
"label": "Ihre Erklärung",
|
|
368
|
+
"validation": "required",
|
|
369
|
+
"rows": 5
|
|
370
|
+
}
|
|
371
|
+
],
|
|
372
|
+
"settings": {
|
|
373
|
+
"submit_label": "Widerruf bestätigen",
|
|
374
|
+
"success_message": "Ihr Widerruf ist eingegangen.",
|
|
375
|
+
"default_locale": "de",
|
|
376
|
+
"locales": [
|
|
377
|
+
"de",
|
|
378
|
+
"en"
|
|
379
|
+
],
|
|
380
|
+
"i18n": {
|
|
381
|
+
"en": {
|
|
382
|
+
"name": {
|
|
383
|
+
"label": "Name"
|
|
384
|
+
},
|
|
385
|
+
"email": {
|
|
386
|
+
"label": "Email address"
|
|
387
|
+
},
|
|
388
|
+
"order_id": {
|
|
389
|
+
"label": "Order number"
|
|
390
|
+
},
|
|
391
|
+
"statement": {
|
|
392
|
+
"label": "Your declaration"
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
336
397
|
}
|
|
337
398
|
]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { NitroErrorHandler } from "nitropack";
|
|
2
|
+
import { getRequestHeader, send, setResponseHeader, setResponseStatus } from "h3";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Dev-only replacement for Nitro's error handler.
|
|
6
|
+
*
|
|
7
|
+
* Nitro's dev handler resolves every stack frame through `source-map@0.7`, which
|
|
8
|
+
* keeps each parsed map in WebAssembly memory until `destroy()` is called — and
|
|
9
|
+
* Nitro never calls it. With a ~3 MB bundle map that is tens of MB per error,
|
|
10
|
+
* never released: a few hundred 404s, or one broken endpoint called on every
|
|
11
|
+
* page view, exhaust the dev container (the wasm heap is capped at 4 GB, which
|
|
12
|
+
* is also the point where the parser starts failing with `unreachable`).
|
|
13
|
+
*
|
|
14
|
+
* So no error is run through the source maps. Client errors are answered with
|
|
15
|
+
* a bare status; server errors (5xx) keep their raw stack in the log and in the
|
|
16
|
+
* JSON body, which is what Nitro's default handler would print minus the
|
|
17
|
+
* source-mapped code frame.
|
|
18
|
+
*/
|
|
19
|
+
const handler: NitroErrorHandler = async function devErrorHandler(error, event) {
|
|
20
|
+
const statusCode = error.statusCode || 500;
|
|
21
|
+
const statusMessage = error.statusMessage || (statusCode >= 500 ? "Server Error" : "Not Found");
|
|
22
|
+
const wantsHtml = getRequestHeader(event, "accept")?.includes("text/html") ?? false;
|
|
23
|
+
|
|
24
|
+
setResponseStatus(event, statusCode, statusMessage);
|
|
25
|
+
setResponseHeader(event, "cache-control", "no-cache");
|
|
26
|
+
setResponseHeader(event, "content-type", wantsHtml ? "text/html" : "application/json");
|
|
27
|
+
|
|
28
|
+
if (statusCode < 500) {
|
|
29
|
+
return send(
|
|
30
|
+
event,
|
|
31
|
+
wantsHtml
|
|
32
|
+
? `<!doctype html><title>${statusCode} ${statusMessage}</title><h1>${statusCode} ${statusMessage}</h1>`
|
|
33
|
+
: JSON.stringify({ error: true, statusCode, statusMessage }),
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
console.error(`[request error] [${event.method}] ${event.path}\n`, error.stack ?? error.message);
|
|
38
|
+
const stack = error.stack?.split("\n").map(line => line.trim());
|
|
39
|
+
return send(
|
|
40
|
+
event,
|
|
41
|
+
wantsHtml
|
|
42
|
+
? `<!doctype html><title>${statusCode} ${statusMessage}</title><h1>${statusCode} ${statusMessage}</h1><pre>${(error.stack ?? error.message).replace(/</g, "<")}</pre>`
|
|
43
|
+
: JSON.stringify({ error: true, url: event.path, statusCode, statusMessage, message: error.message, stack }, null, 2),
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default handler;
|
|
@@ -47,6 +47,11 @@ export interface PunchoutVisit {
|
|
|
47
47
|
readonly readOnly: boolean;
|
|
48
48
|
/** Set once the cart has been handed back; a repeat ask replays the payload. */
|
|
49
49
|
readonly handedBack: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* The origin the hand-back form posts to, once the punchout app has
|
|
52
|
+
* answered it — what the hand-back page's `form-action` allows (PE-994).
|
|
53
|
+
*/
|
|
54
|
+
readonly handBackOrigin?: string | null;
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
/** Where a claimed visit lands the buyer, before it is turned into a path. */
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getMethod } from "h3";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Paths that own their own 404 handling, or that Vite serves in dev.
|
|
5
|
+
* `/_nuxt` and `/@` are the dev bundler's, `/api` and `/cdn` answer for
|
|
6
|
+
* themselves, `/_ipx` is @nuxt/image.
|
|
7
|
+
*/
|
|
8
|
+
const OWN_NOT_FOUND = ["/api/", "/cdn/", "/_nuxt/", "/_ipx/", "/@", "/node_modules/"];
|
|
9
|
+
|
|
10
|
+
const MEDIA_EXTENSION = /\.(?:png|jpe?g|gif|webp|avif|svg|ico)$/i;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Answer a request for a media file nothing serves with a bare 404.
|
|
14
|
+
*
|
|
15
|
+
* A URL such as `/de/5498-1.png` matches no route, so it falls into the
|
|
16
|
+
* storefront's catch-all page, which throws a 404 inside SSR. Rendering that
|
|
17
|
+
* error costs a full page render per broken image, and in dev the formatted
|
|
18
|
+
* stack (source maps, code frame) is retained until the process is restarted —
|
|
19
|
+
* a cart of broken thumbnails was enough to exhaust the container's memory.
|
|
20
|
+
*
|
|
21
|
+
* Public assets are served before middleware runs, so only requests that no
|
|
22
|
+
* file answers reach this handler.
|
|
23
|
+
*/
|
|
24
|
+
export default defineEventHandler((event) => {
|
|
25
|
+
const method = getMethod(event);
|
|
26
|
+
if (method !== "GET" && method !== "HEAD") {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const path = event.path.split("?")[0] ?? "";
|
|
30
|
+
if (!MEDIA_EXTENSION.test(path) || OWN_NOT_FOUND.some(prefix => path.startsWith(prefix))) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
setResponseStatus(event, 404, "Not Found");
|
|
34
|
+
return "";
|
|
35
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { setResponseHeader } from "h3";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Let the hand-back page submit its form to the visit's return address
|
|
5
|
+
* (PE-994). Which origin: the one the punchout app answered on the first
|
|
6
|
+
* hand-back, kept on the visit cookie. The page is rendered with it in
|
|
7
|
+
* `event.context` so it can tell whether THIS document may submit the form, or
|
|
8
|
+
* has to be loaded once more with the header that allows it.
|
|
9
|
+
*/
|
|
10
|
+
export default defineEventHandler((event) => {
|
|
11
|
+
if (!isHandBackPath(event.path)) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const visit = readPunchoutVisit(event);
|
|
15
|
+
event.context.punchoutHandBackOrigin = visit?.handBackOrigin ?? null;
|
|
16
|
+
setResponseHeader(event, "Content-Security-Policy", handBackFormAction(visit));
|
|
17
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stop the dev server from keeping every rendered page alive.
|
|
3
|
+
*
|
|
4
|
+
* In dev, vue-router, pinia and vue-i18n register a Vue devtools plugin per app
|
|
5
|
+
* through `setupDevtoolsPlugin`. With no devtools hook present — which is always
|
|
6
|
+
* the case on the server — it queues the registration on
|
|
7
|
+
* `globalThis.__VUE_DEVTOOLS_PLUGINS__`, a list nobody ever drains. SSR creates
|
|
8
|
+
* a fresh app per request, so the list grows by one app per page view, and each
|
|
9
|
+
* entry holds that app's whole context: the head tags, the payload and a deep
|
|
10
|
+
* copy of every locale message (~4 MB per request). A few hundred page views
|
|
11
|
+
* exhausted the dev container's memory.
|
|
12
|
+
*
|
|
13
|
+
* The list is only meant for a browser devtools extension, so on the server it
|
|
14
|
+
* is replaced by a sink that discards what is pushed. Builds never queue
|
|
15
|
+
* registrations (devtools-api is compiled out), hence dev only.
|
|
16
|
+
*/
|
|
17
|
+
export default defineNitroPlugin(() => {
|
|
18
|
+
if (!import.meta.dev) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const sink: unknown[] = [];
|
|
22
|
+
sink.push = () => sink.length;
|
|
23
|
+
Object.defineProperty(globalThis, "__VUE_DEVTOOLS_PLUGINS__", {
|
|
24
|
+
configurable: true,
|
|
25
|
+
get: () => sink,
|
|
26
|
+
set: () => {},
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -5,7 +5,9 @@ import type { FormRow, FormSpamPolicy, FormSubmissionResult, FormSummary, IForms
|
|
|
5
5
|
* can produce rather than to look tidy: a contact form (text, email, tel,
|
|
6
6
|
* select, textarea, checkbox), a price request (the `rxKind: product` field a
|
|
7
7
|
* product page pre-fills, plus a radio group), and a two-step return request
|
|
8
|
-
* with a designed thank-you page.
|
|
8
|
+
* with a designed thank-you page. Beside them the `widerruf` form the
|
|
9
|
+
* withdrawal page (§ 356a BGB) submits to: not rendered from its definition,
|
|
10
|
+
* but its fields have to be declared or the submit route drops them.
|
|
9
11
|
*
|
|
10
12
|
* They are authored in German with an English overlay, which is the shape a
|
|
11
13
|
* live form has: the app stores one base definition and per-locale field texts
|