Add DHL checkout integrations (autocomplete, postnummer, return label)
Wires the new backend DHL endpoints into checkout: an address-autocomplete dropdown on the street fields, live Postnummer validation for Packstation delivery, and a return-label download link on the order-detail page. Proxied through Next.js API routes since DHL credentials are tenant- specific and CheckoutContent is a Client Component. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
// Thin client for the backend's DHL custom endpoints (src/lib/endpoints/
|
||||
// dhlValidatePostNumber.ts, dhlAutocompleteAddress.ts) — own copy per repo,
|
||||
// same "no shared package yet" convention as app/lib/tracking.ts.
|
||||
const PAYLOAD_URL = process.env.PAYLOAD_URL || "https://payload.mk360.de";
|
||||
const TENANT_SLUG = "einfach-produktiv";
|
||||
|
||||
export async function validateDhlPostNumber(args: {
|
||||
postNumber: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
}): Promise<{ ok: true; valid: boolean } | { ok: false; reason: string }> {
|
||||
const params = new URLSearchParams({ tenantSlug: TENANT_SLUG, ...args });
|
||||
try {
|
||||
const res = await fetch(`${PAYLOAD_URL}/api/dhl/validate-post-number?${params}`, {
|
||||
signal: AbortSignal.timeout(8000),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok || !data.ok) return { ok: false, reason: data.reason ?? "Postnummer konnte nicht geprüft werden." };
|
||||
return { ok: true, valid: Boolean(data.valid) };
|
||||
} catch {
|
||||
return { ok: false, reason: "Postnummer-Prüfung ist gerade nicht erreichbar." };
|
||||
}
|
||||
}
|
||||
|
||||
export type DhlAddressSuggestion = {
|
||||
street: string;
|
||||
houseNumber?: string;
|
||||
zip: string;
|
||||
city: string;
|
||||
country: string;
|
||||
};
|
||||
|
||||
export async function autocompleteDhlAddress(query: string): Promise<DhlAddressSuggestion[]> {
|
||||
if (query.trim().length < 3) return [];
|
||||
const params = new URLSearchParams({ tenantSlug: TENANT_SLUG, query });
|
||||
try {
|
||||
const res = await fetch(`${PAYLOAD_URL}/api/dhl/autocomplete-address?${params}`, {
|
||||
signal: AbortSignal.timeout(5000),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok || !data.ok) return [];
|
||||
return data.suggestions as DhlAddressSuggestion[];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user