@jarwizz/create-jarshop 0.1.9 → 0.4.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 (120) hide show
  1. package/README.md +15 -0
  2. package/dist/cli.d.ts +1 -0
  3. package/dist/cli.js +1 -0
  4. package/dist/cli.js.map +1 -1
  5. package/dist/generator.d.ts +11 -1
  6. package/dist/generator.js +45 -11
  7. package/dist/generator.js.map +1 -1
  8. package/dist/presets.d.ts +28 -0
  9. package/dist/presets.js +105 -0
  10. package/dist/presets.js.map +1 -0
  11. package/dist/template/CONTEXT.md +4 -2
  12. package/dist/template/README.md +255 -3
  13. package/dist/template/env.example.template +19 -0
  14. package/dist/template/gitignore.template +1 -0
  15. package/dist/template/jarshop.config.ts +37 -0
  16. package/dist/template/package.json +4 -0
  17. package/dist/template/pnpm-lock.yaml +3284 -1815
  18. package/dist/template/pnpm-workspace.yaml +6 -1
  19. package/dist/template/src/client/features.ts +41 -0
  20. package/dist/template/src/client/invoicing.ts +29 -0
  21. package/dist/template/src/dev-storefront-environment.test.ts +45 -0
  22. package/dist/template/src/dev-storefront-environment.ts +32 -0
  23. package/dist/template/src/dev-storefront.ts +3 -12
  24. package/dist/template/src/environment.d.ts +8 -0
  25. package/dist/template/src/invoice-email-recover.ts +59 -0
  26. package/dist/template/src/jarshop-config-loader.ts +118 -0
  27. package/dist/template/src/jarshop-config.test.ts +365 -0
  28. package/dist/template/src/jarshop-config.ts +462 -0
  29. package/dist/template/src/jarshop-features.test.ts +222 -0
  30. package/dist/template/src/jarshop-features.ts +112 -0
  31. package/dist/template/src/migrations/1788100000000-jarshop-guest-order-session.ts +27 -0
  32. package/dist/template/src/operation-codes.ts +34 -0
  33. package/dist/template/src/packeta-config.test.ts +95 -0
  34. package/dist/template/src/packeta-countries.test.ts +161 -0
  35. package/dist/template/src/packeta-countries.ts +120 -0
  36. package/dist/template/src/packeta-validation.test.ts +35 -0
  37. package/dist/template/src/packeta-validation.ts +52 -0
  38. package/dist/template/src/payment-return-url.test.ts +57 -0
  39. package/dist/template/src/payment-return-url.ts +34 -0
  40. package/dist/template/src/plugins/jarshop-checkout/confirmation-view.test.ts +79 -0
  41. package/dist/template/src/plugins/jarshop-checkout/confirmation.ts +51 -0
  42. package/dist/template/src/plugins/jarshop-checkout/dashboard/index.tsx +1 -0
  43. package/dist/template/src/plugins/jarshop-checkout/index.ts +4 -0
  44. package/dist/template/src/plugins/jarshop-checkout/invoice-delivery.plugin.ts +79 -0
  45. package/dist/template/src/plugins/jarshop-checkout/invoice-email-events.ts +35 -0
  46. package/dist/template/src/plugins/jarshop-checkout/invoice-email-lifecycle.ts +235 -0
  47. package/dist/template/src/plugins/jarshop-checkout/invoice-email-worker.test.ts +426 -0
  48. package/dist/template/src/plugins/jarshop-checkout/invoice-email.test.ts +107 -0
  49. package/dist/template/src/plugins/jarshop-checkout/jarshop-checkout.plugin.ts +167 -58
  50. package/dist/template/src/plugins/jarshop-checkout/market-active-order-core.ts +108 -0
  51. package/dist/template/src/plugins/jarshop-checkout/market-active-order.test.ts +205 -0
  52. package/dist/template/src/plugins/jarshop-checkout/market-active-order.ts +186 -0
  53. package/dist/template/src/plugins/jarshop-checkout/market-channels.test.ts +58 -0
  54. package/dist/template/src/plugins/jarshop-checkout/market-channels.ts +87 -0
  55. package/dist/template/src/plugins/jarshop-checkout/operation-code-check.ts +36 -0
  56. package/dist/template/src/plugins/jarshop-checkout/order-email-configuration.entity.ts +1 -1
  57. package/dist/template/src/plugins/jarshop-checkout/order-email-configuration.ts +1 -0
  58. package/dist/template/src/plugins/jarshop-checkout/order-email-delivery-core.ts +94 -1
  59. package/dist/template/src/plugins/jarshop-checkout/order-email-delivery.entity.ts +1 -0
  60. package/dist/template/src/plugins/jarshop-checkout/order-email-outbox.ts +83 -1
  61. package/dist/template/src/plugins/jarshop-checkout/order-email-worker.ts +136 -1
  62. package/dist/template/src/plugins/jarshop-checkout/shipping-tax.test.ts +109 -0
  63. package/dist/template/src/plugins/jarshop-checkout/shipping.test.ts +156 -0
  64. package/dist/template/src/plugins/jarshop-checkout/shipping.ts +75 -11
  65. package/dist/template/src/seed.ts +473 -185
  66. package/dist/template/src/vendure-config.ts +258 -113
  67. package/dist/template/storefront/README.md +7 -0
  68. package/dist/template/storefront/app/[locale]/[slug]/page.tsx +3 -2
  69. package/dist/template/storefront/app/[locale]/account/login/page.tsx +3 -2
  70. package/dist/template/storefront/app/[locale]/account/page.tsx +10 -4
  71. package/dist/template/storefront/app/[locale]/account/password-reset/callback/route.ts +4 -2
  72. package/dist/template/storefront/app/[locale]/account/password-reset/complete/page.tsx +3 -2
  73. package/dist/template/storefront/app/[locale]/account/password-reset/page.tsx +3 -2
  74. package/dist/template/storefront/app/[locale]/account/register/page.tsx +3 -2
  75. package/dist/template/storefront/app/[locale]/account/verify/complete/route.ts +4 -2
  76. package/dist/template/storefront/app/[locale]/account/verify/page.tsx +3 -2
  77. package/dist/template/storefront/app/[locale]/cart/page.tsx +3 -2
  78. package/dist/template/storefront/app/[locale]/checkout/actions.ts +43 -0
  79. package/dist/template/storefront/app/[locale]/checkout/checkout-form.tsx +188 -36
  80. package/dist/template/storefront/app/[locale]/checkout/confirmation/route.ts +2 -2
  81. package/dist/template/storefront/app/[locale]/checkout/packeta-chooser.tsx +96 -0
  82. package/dist/template/storefront/app/[locale]/checkout/page.tsx +60 -2
  83. package/dist/template/storefront/app/[locale]/checkout/payment-return/actions.ts +55 -0
  84. package/dist/template/storefront/app/[locale]/checkout/payment-return/page.tsx +32 -0
  85. package/dist/template/storefront/app/[locale]/checkout/payment-return/payment-return.tsx +84 -0
  86. package/dist/template/storefront/app/[locale]/checkout/success/page.tsx +32 -2
  87. package/dist/template/storefront/app/[locale]/layout.tsx +3 -2
  88. package/dist/template/storefront/app/[locale]/page.tsx +3 -2
  89. package/dist/template/storefront/app/globals.css +16 -0
  90. package/dist/template/storefront/app/layout.tsx +6 -2
  91. package/dist/template/storefront/lib/cart.ts +2 -4
  92. package/dist/template/storefront/lib/checkout-contract.test.ts +18 -1
  93. package/dist/template/storefront/lib/checkout-contract.ts +8 -0
  94. package/dist/template/storefront/lib/checkout-countries.test.ts +61 -0
  95. package/dist/template/storefront/lib/checkout-countries.ts +67 -0
  96. package/dist/template/storefront/lib/checkout.ts +22 -11
  97. package/dist/template/storefront/lib/commerce.ts +262 -2
  98. package/dist/template/storefront/lib/confirmation.test.ts +116 -0
  99. package/dist/template/storefront/lib/confirmation.ts +13 -7
  100. package/dist/template/storefront/lib/i18n.test.ts +32 -12
  101. package/dist/template/storefront/lib/i18n.ts +29 -8
  102. package/dist/template/storefront/lib/market-config.ts +40 -0
  103. package/dist/template/storefront/lib/market-routing.test.ts +107 -0
  104. package/dist/template/storefront/lib/market-routing.ts +57 -0
  105. package/dist/template/storefront/lib/market.ts +51 -0
  106. package/dist/template/storefront/lib/packeta-selection.test.ts +141 -0
  107. package/dist/template/storefront/lib/packeta-selection.ts +98 -0
  108. package/dist/template/storefront/lib/payment-return-actions.test.ts +61 -0
  109. package/dist/template/storefront/lib/payment-return-page.test.ts +30 -0
  110. package/dist/template/storefront/lib/payment-return-polling.test.ts +37 -0
  111. package/dist/template/storefront/lib/payment-return-polling.ts +58 -0
  112. package/dist/template/storefront/messages/en.json +13 -1
  113. package/dist/template/storefront/messages/sk.json +13 -1
  114. package/dist/template/storefront/package.json +2 -1
  115. package/dist/template/storefront/proxy.ts +35 -0
  116. package/dist/template/turbo.json +5 -1
  117. package/dist/template-manifest.json +1 -1
  118. package/dist/template.js +1 -0
  119. package/dist/template.js.map +1 -1
  120. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
- import { createTranslator, parseLocale } from "../../../../lib/i18n";
1
+ import { createTranslator } from "../../../../lib/i18n";
2
+ import { resolveRequestLocale } from "../../../../lib/market";
2
3
  import { getOrderConfirmation } from "../../../../lib/confirmation";
3
4
 
4
5
  interface CheckoutSuccessProps {
@@ -12,17 +13,46 @@ export default async function CheckoutSuccess({
12
13
  }: CheckoutSuccessProps) {
13
14
  const { locale } = await params;
14
15
  const { order } = await searchParams;
15
- const language = parseLocale(locale);
16
+ const { language } = await resolveRequestLocale(locale);
16
17
  const t = createTranslator(language);
17
18
  const confirmation = order
18
19
  ? await getOrderConfirmation(language, order)
19
20
  : null;
21
+ const shippingAddress = confirmation?.shippingAddress;
22
+ const streetLine2 = shippingAddress?.streetLine2.trim() ?? "";
23
+ const locality = shippingAddress
24
+ ? [shippingAddress.postalCode, shippingAddress.city]
25
+ .map((value) => value.trim())
26
+ .filter(Boolean)
27
+ .join(" ")
28
+ : "";
29
+ const shippingAddressLines = shippingAddress
30
+ ? [
31
+ shippingAddress.fullName,
32
+ shippingAddress.streetLine1,
33
+ streetLine2,
34
+ locality === streetLine2 ? "" : locality,
35
+ shippingAddress.countryCode,
36
+ ]
37
+ .map((value) => value.trim())
38
+ .filter(Boolean)
39
+ : [];
20
40
  return (
21
41
  <main lang={language}>
22
42
  <h1>{t("success.title")}</h1>
23
43
  <p>
24
44
  {t("success.orderCode")}: {confirmation?.orderCode ?? "—"}
25
45
  </p>
46
+ {shippingAddressLines.length > 0 ? (
47
+ <section>
48
+ <h2>{t("success.shippingAddress")}</h2>
49
+ <address>
50
+ {shippingAddressLines.map((line, index) => (
51
+ <div key={`${index}-${line}`}>{line}</div>
52
+ ))}
53
+ </address>
54
+ </section>
55
+ ) : null}
26
56
  </main>
27
57
  );
28
58
  }
@@ -2,7 +2,8 @@ import Link from "next/link";
2
2
  import type { ReactNode } from "react";
3
3
 
4
4
  import { getCart } from "../../lib/cart";
5
- import { formatMessage, parseLocale } from "../../lib/i18n";
5
+ import { formatMessage } from "../../lib/i18n";
6
+ import { resolveRequestLocale } from "../../lib/market";
6
7
 
7
8
  interface LocaleLayoutProps {
8
9
  readonly children: ReactNode;
@@ -14,7 +15,7 @@ export default async function LocaleLayout({
14
15
  params,
15
16
  }: LocaleLayoutProps) {
16
17
  const { locale } = await params;
17
- const language = parseLocale(locale);
18
+ const { language } = await resolveRequestLocale(locale);
18
19
  const cart = await getCart(language);
19
20
  const itemCount =
20
21
  cart?.lines.reduce((total, line) => total + line.quantity, 0) ?? 0;
@@ -1,5 +1,6 @@
1
1
  import { getCatalog } from "../../lib/commerce";
2
- import { createTranslator, parseLocale } from "../../lib/i18n";
2
+ import { createTranslator } from "../../lib/i18n";
3
+ import { resolveRequestLocale } from "../../lib/market";
3
4
 
4
5
  interface LocalePageProps {
5
6
  params: Promise<{ locale: string }>;
@@ -7,7 +8,7 @@ interface LocalePageProps {
7
8
 
8
9
  export default async function LocalePage({ params }: LocalePageProps) {
9
10
  const { locale } = await params;
10
- const language = parseLocale(locale);
11
+ const { language } = await resolveRequestLocale(locale);
11
12
  const result = await getCatalog(language);
12
13
  const t = createTranslator(language);
13
14
 
@@ -364,6 +364,22 @@ select:focus {
364
364
  min-height: auto;
365
365
  }
366
366
 
367
+ .packeta-chooser {
368
+ display: grid;
369
+ gap: 0.65rem;
370
+ justify-items: start;
371
+ }
372
+
373
+ .checkout-form address {
374
+ padding: 0.85rem 1rem;
375
+ border: 1px solid #9cdcc0;
376
+ border-radius: 0.7rem;
377
+ background: #effaf4;
378
+ color: #155c3d;
379
+ font-style: normal;
380
+ line-height: 1.5;
381
+ }
382
+
367
383
  @media (max-width: 42rem) {
368
384
  .site-header__inner,
369
385
  .page {
@@ -1,12 +1,16 @@
1
1
  import type { ReactNode } from "react";
2
2
 
3
+ import { getRequestMarket } from "../lib/market";
3
4
  import "./globals.css";
4
5
 
5
- export default function RootLayout({
6
+ export default async function RootLayout({
6
7
  children,
7
8
  }: Readonly<{ children: ReactNode }>) {
9
+ // Pages mark their own language on <main>; the document carries the
10
+ // language of the market the request host selects.
11
+ const market = await getRequestMarket();
8
12
  return (
9
- <html lang="sk">
13
+ <html lang={market.defaultLanguage}>
10
14
  <body>{children}</body>
11
15
  </html>
12
16
  );
@@ -5,6 +5,7 @@ import { revalidatePath } from "next/cache";
5
5
 
6
6
  import type { CommerceLocale } from "./commerce";
7
7
  import { mapCart, type CartView } from "./cart-contract";
8
+ import { marketFetch } from "./market";
8
9
  import {
9
10
  commerceSessionAuthorization,
10
11
  persistCommerceSession,
@@ -41,13 +42,10 @@ async function request<T>(
41
42
  );
42
43
  endpoint.searchParams.set("languageCode", locale);
43
44
  const authorization = commerceSessionAuthorization(store);
44
- const response = await fetch(endpoint, {
45
+ const response = await marketFetch(endpoint, {
45
46
  method: "POST",
46
47
  headers: {
47
48
  "content-type": "application/json",
48
- ...(process.env.JARSHOP_CHANNEL_TOKEN
49
- ? { "vendure-token": process.env.JARSHOP_CHANNEL_TOKEN }
50
- : {}),
51
49
  ...(authorization ? { authorization } : {}),
52
50
  },
53
51
  body: JSON.stringify({ query, variables }),
@@ -1,6 +1,9 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
 
3
- import { PLACE_JARSHOP_ORDER_MUTATION } from "./checkout-contract";
3
+ import {
4
+ PLACE_JARSHOP_ORDER_MUTATION,
5
+ START_JARSHOP_PAYMENT_MUTATION,
6
+ } from "./checkout-contract";
4
7
 
5
8
  describe("checkout GraphQL contract", () => {
6
9
  it("selects every field required by the storefront success hand-off", () => {
@@ -17,4 +20,18 @@ describe("checkout GraphQL contract", () => {
17
20
  );
18
21
  }
19
22
  });
23
+
24
+ it("selects the redirect target fields for a redirect payment", () => {
25
+ for (const field of [
26
+ "success",
27
+ "redirectUrl",
28
+ "transactionReference",
29
+ "errorCode",
30
+ "message",
31
+ ]) {
32
+ expect(START_JARSHOP_PAYMENT_MUTATION).toMatch(
33
+ new RegExp(`\\b${field}\\b`, "u"),
34
+ );
35
+ }
36
+ });
20
37
  });
@@ -14,3 +14,11 @@ export const PLACE_JARSHOP_ORDER_MUTATION = `
14
14
  }
15
15
  }
16
16
  `;
17
+
18
+ export const START_JARSHOP_PAYMENT_MUTATION = `
19
+ mutation StartJarShopPayment($paymentMethodCode: String!) {
20
+ startJarShopPayment(paymentMethodCode: $paymentMethodCode) {
21
+ success redirectUrl transactionReference errorCode message
22
+ }
23
+ }
24
+ `;
@@ -0,0 +1,61 @@
1
+ import { describe, expect, it, vi } from "vitest";
2
+
3
+ import type { ShippingMethod } from "@jarwizz/commerce-sdk/types";
4
+ import type { PacketaWidgetConfiguration } from "@jarwizz/feature-packeta/storefront";
5
+
6
+ import {
7
+ planCheckoutCountries,
8
+ resolvePacketaConfiguration,
9
+ } from "./checkout-countries";
10
+
11
+ const method = (code: string, requiresSelection: boolean) =>
12
+ ({ code, name: code, requiresSelection }) as unknown as ShippingMethod;
13
+ const configuration = {
14
+ apiKey: "k",
15
+ options: { country: "sk", carriers: "packeta", vendors: [] },
16
+ } as unknown as PacketaWidgetConfiguration;
17
+
18
+ describe("checkout destinations", () => {
19
+ it("quotes every market country while the order has no address", () => {
20
+ expect(planCheckoutCountries(["SK", "CZ"], null)).toEqual({
21
+ initialCountry: "SK",
22
+ quotedCountries: ["SK", "CZ"],
23
+ });
24
+ });
25
+
26
+ it("quotes only the pinned country and preselects it, leaving the others to a release", () => {
27
+ // An order whose pickup point is in CZ can only be quoted for CZ; SK is
28
+ // quoted after the form releases the address on a country switch, instead
29
+ // of rendering an empty method list.
30
+ expect(planCheckoutCountries(["SK", "CZ"], "CZ")).toEqual({
31
+ initialCountry: "CZ",
32
+ quotedCountries: ["CZ"],
33
+ });
34
+ expect(planCheckoutCountries(["SK", "CZ"], "AT")).toEqual({
35
+ initialCountry: "SK",
36
+ quotedCountries: [],
37
+ });
38
+ });
39
+ });
40
+
41
+ describe("Packeta widget configuration state", () => {
42
+ it("does not ask for a configuration where no method needs a pickup point", async () => {
43
+ const load = vi.fn(async () => configuration);
44
+ await expect(
45
+ resolvePacketaConfiguration([method("courier", false)], load),
46
+ ).resolves.toEqual({ status: "unavailable" });
47
+ expect(load).not.toHaveBeenCalled();
48
+ });
49
+
50
+ it("reports a failed request for a served country as a retryable error", async () => {
51
+ const methods = [method("courier", false), method("packeta", true)];
52
+ await expect(
53
+ resolvePacketaConfiguration(methods, async () => configuration),
54
+ ).resolves.toEqual({ status: "ready", configuration });
55
+ await expect(
56
+ resolvePacketaConfiguration(methods, async () => {
57
+ throw new Error("Packeta configuration returned 503");
58
+ }),
59
+ ).resolves.toEqual({ status: "error" });
60
+ });
61
+ });
@@ -0,0 +1,67 @@
1
+ import type { ShippingMethod } from "@jarwizz/commerce-sdk/types";
2
+ import type { PacketaWidgetConfiguration } from "@jarwizz/feature-packeta/storefront";
3
+
4
+ export interface CheckoutCountryPlan {
5
+ /** The destination preselected in the form. */
6
+ readonly initialCountry: string;
7
+ /**
8
+ * The destinations whose shipping methods can be quoted now. Vendure quotes
9
+ * against the order's address, so an order already pinned to a country (by
10
+ * a pickup point or a courier address) is quoted for that country only; the
11
+ * form releases the address and reloads when the shopper picks another one.
12
+ */
13
+ readonly quotedCountries: readonly string[];
14
+ }
15
+
16
+ export function planCheckoutCountries(
17
+ marketCountries: readonly string[],
18
+ addressCountry: string | null,
19
+ ): CheckoutCountryPlan {
20
+ if (addressCountry === null) {
21
+ return {
22
+ initialCountry: marketCountries[0] ?? "",
23
+ quotedCountries: marketCountries,
24
+ };
25
+ }
26
+ const served = marketCountries.includes(addressCountry);
27
+ return {
28
+ initialCountry: served ? addressCountry : (marketCountries[0] ?? ""),
29
+ quotedCountries: served ? [addressCountry] : [],
30
+ };
31
+ }
32
+
33
+ /**
34
+ * Packeta's widget configuration for one destination.
35
+ *
36
+ * - `unavailable`: no eligible method needs a pickup point there, so Packeta
37
+ * is simply not offered.
38
+ * - `ready`: the widget can open.
39
+ * - `error`: Packeta is offered but its configuration could not be read; the
40
+ * form shows a retryable error instead of silently hiding the method.
41
+ */
42
+ export type PacketaConfigurationState =
43
+ | { readonly status: "unavailable" }
44
+ | {
45
+ readonly status: "ready";
46
+ readonly configuration: PacketaWidgetConfiguration;
47
+ }
48
+ | { readonly status: "error" };
49
+
50
+ /**
51
+ * Whether Packeta serves a country is decided by the server's eligible
52
+ * methods, not by a failing configuration request: the configuration is read
53
+ * only where a method needs a pickup point, so any failure is transient.
54
+ */
55
+ export async function resolvePacketaConfiguration(
56
+ methods: readonly ShippingMethod[],
57
+ load: () => Promise<PacketaWidgetConfiguration>,
58
+ ): Promise<PacketaConfigurationState> {
59
+ if (!methods.some((method) => method.requiresSelection)) {
60
+ return { status: "unavailable" };
61
+ }
62
+ try {
63
+ return { status: "ready", configuration: await load() };
64
+ } catch {
65
+ return { status: "error" };
66
+ }
67
+ }
@@ -9,7 +9,9 @@ import {
9
9
  persistCommerceSession,
10
10
  } from "./commerce-session";
11
11
  import { PLACE_JARSHOP_ORDER_MUTATION } from "./checkout-contract";
12
+ import { startPayment } from "./commerce";
12
13
  import { exchangeOrderConfirmation } from "./confirmation";
14
+ import { getRequestMarket, marketFetch } from "./market";
13
15
 
14
16
  export interface CheckoutCartSnapshot {
15
17
  currencyCode: string;
@@ -21,7 +23,7 @@ export interface CheckoutCartSnapshot {
21
23
  }>;
22
24
  }
23
25
 
24
- export type CheckoutShippingMethod = "pickup" | "courier";
26
+ export type CheckoutShippingMethod = string;
25
27
 
26
28
  type CheckoutResponse = {
27
29
  data?: {
@@ -54,18 +56,16 @@ export async function placeOrder(
54
56
  formData: FormData,
55
57
  ): Promise<CheckoutActionState> {
56
58
  const store = await cookies();
59
+ const market = await getRequestMarket();
57
60
  const authorization = commerceSessionAuthorization(store);
58
61
  const endpoint = new URL(
59
62
  process.env.JARSHOP_COMMERCE_ENDPOINT ?? "http://localhost:3000/shop-api",
60
63
  );
61
64
  endpoint.searchParams.set("languageCode", locale);
62
- const response = await fetch(endpoint, {
65
+ const response = await marketFetch(endpoint, {
63
66
  method: "POST",
64
67
  headers: {
65
68
  "content-type": "application/json",
66
- ...(process.env.JARSHOP_CHANNEL_TOKEN
67
- ? { "vendure-token": process.env.JARSHOP_CHANNEL_TOKEN }
68
- : {}),
69
69
  ...(authorization ? { authorization } : {}),
70
70
  },
71
71
  body: JSON.stringify({
@@ -73,19 +73,17 @@ export async function placeOrder(
73
73
  variables: {
74
74
  input: {
75
75
  attemptId,
76
- marketCode: "sk",
76
+ marketCode: market.code,
77
77
  languageCode: locale,
78
- currencyCode: "EUR",
78
+ currencyCode: market.currency,
79
79
  customer: {
80
80
  emailAddress: String(formData.get("emailAddress") ?? ""),
81
81
  firstName: String(formData.get("firstName") ?? ""),
82
82
  lastName: String(formData.get("lastName") ?? ""),
83
83
  phoneNumber: String(formData.get("phoneNumber") ?? ""),
84
84
  },
85
- shippingMethodCode: String(
86
- formData.get("shippingMethodCode") ?? "pickup",
87
- ),
88
- paymentMethodCode: "cod",
85
+ shippingMethodCode: String(formData.get("shippingMethodCode") ?? ""),
86
+ paymentMethodCode: String(formData.get("paymentMethodCode") ?? ""),
89
87
  termsAccepted: formData.get("termsAccepted") === "on",
90
88
  ...(cartSnapshot ? { cartSnapshot } : {}),
91
89
  ...(formData.get("shippingMethodCode") === "courier"
@@ -130,6 +128,19 @@ export async function placeOrder(
130
128
  affectedLineIds: result?.affectedLineIds ?? [],
131
129
  };
132
130
  }
131
+ const paymentMethodCode = String(formData.get("paymentMethodCode") ?? "");
132
+ if (paymentMethodCode !== "cod") {
133
+ const started = await startPayment(locale, paymentMethodCode);
134
+ if (!started.ok) {
135
+ return {
136
+ ok: false,
137
+ errorCode: started.error.code,
138
+ message: started.error.message,
139
+ affectedLineIds: [],
140
+ };
141
+ }
142
+ redirect(started.data.redirectUrl);
143
+ }
133
144
  const confirmation = await exchangeOrderConfirmation(
134
145
  locale,
135
146
  result.confirmationToken,