@jarwizz/create-jarshop 0.1.9 → 0.3.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/README.md +15 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +1 -0
- package/dist/cli.js.map +1 -1
- package/dist/generator.d.ts +11 -1
- package/dist/generator.js +45 -11
- package/dist/generator.js.map +1 -1
- package/dist/presets.d.ts +26 -0
- package/dist/presets.js +94 -0
- package/dist/presets.js.map +1 -0
- package/dist/template/CONTEXT.md +4 -2
- package/dist/template/README.md +255 -3
- package/dist/template/env.example.template +19 -0
- package/dist/template/gitignore.template +1 -0
- package/dist/template/jarshop.config.ts +31 -0
- package/dist/template/package.json +4 -0
- package/dist/template/pnpm-lock.yaml +3284 -1815
- package/dist/template/pnpm-workspace.yaml +6 -1
- package/dist/template/src/client/features.ts +41 -0
- package/dist/template/src/client/invoicing.ts +29 -0
- package/dist/template/src/dev-storefront-environment.test.ts +45 -0
- package/dist/template/src/dev-storefront-environment.ts +32 -0
- package/dist/template/src/dev-storefront.ts +3 -12
- package/dist/template/src/environment.d.ts +8 -0
- package/dist/template/src/invoice-email-recover.ts +59 -0
- package/dist/template/src/jarshop-config-loader.ts +118 -0
- package/dist/template/src/jarshop-config.test.ts +335 -0
- package/dist/template/src/jarshop-config.ts +439 -0
- package/dist/template/src/jarshop-features.test.ts +222 -0
- package/dist/template/src/jarshop-features.ts +112 -0
- package/dist/template/src/operation-codes.ts +34 -0
- package/dist/template/src/packeta-config.test.ts +95 -0
- package/dist/template/src/packeta-countries.test.ts +161 -0
- package/dist/template/src/packeta-countries.ts +120 -0
- package/dist/template/src/packeta-validation.test.ts +35 -0
- package/dist/template/src/packeta-validation.ts +52 -0
- package/dist/template/src/payment-return-url.test.ts +57 -0
- package/dist/template/src/payment-return-url.ts +34 -0
- package/dist/template/src/plugins/jarshop-checkout/confirmation-view.test.ts +79 -0
- package/dist/template/src/plugins/jarshop-checkout/confirmation.ts +51 -0
- package/dist/template/src/plugins/jarshop-checkout/dashboard/index.tsx +1 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-delivery.plugin.ts +79 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-email-events.ts +35 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-email-lifecycle.ts +235 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-email-worker.test.ts +426 -0
- package/dist/template/src/plugins/jarshop-checkout/invoice-email.test.ts +107 -0
- package/dist/template/src/plugins/jarshop-checkout/jarshop-checkout.plugin.ts +161 -57
- package/dist/template/src/plugins/jarshop-checkout/market-channels.test.ts +58 -0
- package/dist/template/src/plugins/jarshop-checkout/market-channels.ts +87 -0
- package/dist/template/src/plugins/jarshop-checkout/operation-code-check.ts +36 -0
- package/dist/template/src/plugins/jarshop-checkout/order-email-configuration.entity.ts +1 -1
- package/dist/template/src/plugins/jarshop-checkout/order-email-configuration.ts +1 -0
- package/dist/template/src/plugins/jarshop-checkout/order-email-delivery-core.ts +94 -1
- package/dist/template/src/plugins/jarshop-checkout/order-email-delivery.entity.ts +1 -0
- package/dist/template/src/plugins/jarshop-checkout/order-email-outbox.ts +83 -1
- package/dist/template/src/plugins/jarshop-checkout/order-email-worker.ts +136 -1
- package/dist/template/src/plugins/jarshop-checkout/shipping-tax.test.ts +109 -0
- package/dist/template/src/plugins/jarshop-checkout/shipping.test.ts +156 -0
- package/dist/template/src/plugins/jarshop-checkout/shipping.ts +75 -11
- package/dist/template/src/seed.ts +427 -184
- package/dist/template/src/vendure-config.ts +258 -113
- package/dist/template/storefront/README.md +7 -0
- package/dist/template/storefront/app/[locale]/[slug]/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/login/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/page.tsx +10 -4
- package/dist/template/storefront/app/[locale]/account/password-reset/callback/route.ts +4 -2
- package/dist/template/storefront/app/[locale]/account/password-reset/complete/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/password-reset/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/register/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/account/verify/complete/route.ts +4 -2
- package/dist/template/storefront/app/[locale]/account/verify/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/cart/page.tsx +3 -2
- package/dist/template/storefront/app/[locale]/checkout/actions.ts +43 -0
- package/dist/template/storefront/app/[locale]/checkout/checkout-form.tsx +188 -36
- package/dist/template/storefront/app/[locale]/checkout/confirmation/route.ts +2 -2
- package/dist/template/storefront/app/[locale]/checkout/packeta-chooser.tsx +96 -0
- package/dist/template/storefront/app/[locale]/checkout/page.tsx +60 -2
- package/dist/template/storefront/app/[locale]/checkout/payment-return/actions.ts +55 -0
- package/dist/template/storefront/app/[locale]/checkout/payment-return/page.tsx +32 -0
- package/dist/template/storefront/app/[locale]/checkout/payment-return/payment-return.tsx +84 -0
- package/dist/template/storefront/app/[locale]/checkout/success/page.tsx +32 -2
- package/dist/template/storefront/app/[locale]/layout.tsx +3 -2
- package/dist/template/storefront/app/[locale]/page.tsx +3 -2
- package/dist/template/storefront/app/globals.css +16 -0
- package/dist/template/storefront/app/layout.tsx +6 -2
- package/dist/template/storefront/lib/cart.ts +2 -4
- package/dist/template/storefront/lib/checkout-contract.test.ts +18 -1
- package/dist/template/storefront/lib/checkout-contract.ts +8 -0
- package/dist/template/storefront/lib/checkout-countries.test.ts +61 -0
- package/dist/template/storefront/lib/checkout-countries.ts +67 -0
- package/dist/template/storefront/lib/checkout.ts +22 -11
- package/dist/template/storefront/lib/commerce.ts +262 -2
- package/dist/template/storefront/lib/confirmation.test.ts +116 -0
- package/dist/template/storefront/lib/confirmation.ts +13 -7
- package/dist/template/storefront/lib/i18n.test.ts +32 -12
- package/dist/template/storefront/lib/i18n.ts +29 -8
- package/dist/template/storefront/lib/market-config.ts +40 -0
- package/dist/template/storefront/lib/market-routing.test.ts +107 -0
- package/dist/template/storefront/lib/market-routing.ts +57 -0
- package/dist/template/storefront/lib/market.ts +51 -0
- package/dist/template/storefront/lib/packeta-selection.test.ts +141 -0
- package/dist/template/storefront/lib/packeta-selection.ts +98 -0
- package/dist/template/storefront/lib/payment-return-actions.test.ts +61 -0
- package/dist/template/storefront/lib/payment-return-page.test.ts +30 -0
- package/dist/template/storefront/lib/payment-return-polling.test.ts +37 -0
- package/dist/template/storefront/lib/payment-return-polling.ts +58 -0
- package/dist/template/storefront/messages/en.json +13 -1
- package/dist/template/storefront/messages/sk.json +13 -1
- package/dist/template/storefront/package.json +2 -1
- package/dist/template/storefront/proxy.ts +35 -0
- package/dist/template/turbo.json +5 -1
- package/dist/template-manifest.json +1 -1
- package/dist/template.js +1 -0
- package/dist/template.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { createTranslator
|
|
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 =
|
|
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
|
|
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 =
|
|
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
|
|
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 =
|
|
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=
|
|
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
|
|
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 {
|
|
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 =
|
|
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
|
|
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:
|
|
76
|
+
marketCode: market.code,
|
|
77
77
|
languageCode: locale,
|
|
78
|
-
currencyCode:
|
|
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
|
-
|
|
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,
|