@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.
- 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 +28 -0
- package/dist/presets.js +105 -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 +37 -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 +365 -0
- package/dist/template/src/jarshop-config.ts +462 -0
- package/dist/template/src/jarshop-features.test.ts +222 -0
- package/dist/template/src/jarshop-features.ts +112 -0
- package/dist/template/src/migrations/1788100000000-jarshop-guest-order-session.ts +27 -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/index.ts +4 -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 +167 -58
- package/dist/template/src/plugins/jarshop-checkout/market-active-order-core.ts +108 -0
- package/dist/template/src/plugins/jarshop-checkout/market-active-order.test.ts +205 -0
- package/dist/template/src/plugins/jarshop-checkout/market-active-order.ts +186 -0
- 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 +473 -185
- 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
|
@@ -5,6 +5,12 @@ import { Allow, Permission } from "@vendure/core";
|
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
6
|
import { parse } from "graphql";
|
|
7
7
|
import { IsNull, MoreThan, type Repository } from "typeorm";
|
|
8
|
+
import {
|
|
9
|
+
JarShopShippingSelection,
|
|
10
|
+
JarShopPaymentReconciliationService,
|
|
11
|
+
JarShopRedirectPaymentPlugin,
|
|
12
|
+
paymentFlowOf,
|
|
13
|
+
} from "@jarwizz/feature-adapter-kit/server";
|
|
8
14
|
import {
|
|
9
15
|
ActiveOrderService,
|
|
10
16
|
Ctx,
|
|
@@ -12,6 +18,7 @@ import {
|
|
|
12
18
|
isGraphQlErrorResult,
|
|
13
19
|
Order,
|
|
14
20
|
OrderService,
|
|
21
|
+
PaymentMethodService,
|
|
15
22
|
PluginCommonModule,
|
|
16
23
|
ProductVariantService,
|
|
17
24
|
RequestContext,
|
|
@@ -20,16 +27,19 @@ import {
|
|
|
20
27
|
TransactionalConnection,
|
|
21
28
|
VendurePlugin,
|
|
22
29
|
} from "@vendure/core";
|
|
30
|
+
import { marketForChannel } from "../../jarshop-config-loader.js";
|
|
23
31
|
import { CheckoutAttempt } from "./checkout-attempt.entity.js";
|
|
24
32
|
import { JarShopConfirmationToken } from "./confirmation-token.entity.js";
|
|
25
33
|
import {
|
|
26
34
|
CONFIRMATION_COOKIE_NAME,
|
|
27
35
|
canExchangeConfirmationToken,
|
|
36
|
+
canReconcilePaymentWithConfirmationCredential,
|
|
28
37
|
canReadConfirmationCredential,
|
|
29
38
|
createConfirmationToken,
|
|
30
39
|
createConfirmationTokenPair,
|
|
31
40
|
hashConfirmationToken,
|
|
32
41
|
readCookieValue,
|
|
42
|
+
toOrderConfirmation,
|
|
33
43
|
} from "./confirmation.js";
|
|
34
44
|
import { JarShopLegalConfiguration } from "./legal.entity.js";
|
|
35
45
|
import { JarShopOrderEmailDelivery } from "./order-email-delivery.entity.js";
|
|
@@ -44,6 +54,9 @@ import {
|
|
|
44
54
|
isOrderAvailableInChannel,
|
|
45
55
|
toOrderEmailDeliveryStatus,
|
|
46
56
|
} from "./order-email-delivery-status.js";
|
|
57
|
+
import { registerJarShopMarketActiveOrder } from "./market-active-order.js";
|
|
58
|
+
import { JarShopMarketChannelCheck } from "./market-channels.js";
|
|
59
|
+
import { JarShopOperationCodeCheck } from "./operation-code-check.js";
|
|
47
60
|
import { createPendingOrderEmailDelivery } from "./order-email-outbox.js";
|
|
48
61
|
import { toOrderEmailLanguageCode } from "./order-email-delivery-core.js";
|
|
49
62
|
import {
|
|
@@ -54,7 +67,10 @@ import { JarShopOrderConsent } from "./order-consent.entity.js";
|
|
|
54
67
|
import { registerJarShopOrderLifecycle } from "./order-lifecycle-process.js";
|
|
55
68
|
import {
|
|
56
69
|
compareCheckoutSnapshot,
|
|
70
|
+
mapPaymentTransitionFailure,
|
|
57
71
|
resolveLocalizedShippingMethodName,
|
|
72
|
+
shouldUnsetShippingAddress,
|
|
73
|
+
validateCheckoutMarket,
|
|
58
74
|
validateShippingSelection,
|
|
59
75
|
type CheckoutCartSnapshot,
|
|
60
76
|
type ShippingAddressInput,
|
|
@@ -124,11 +140,23 @@ const schema = parse(`
|
|
|
124
140
|
state: String!
|
|
125
141
|
totalWithTax: Int!
|
|
126
142
|
currencyCode: String!
|
|
143
|
+
shippingAddress: JarShopOrderConfirmationAddress
|
|
144
|
+
}
|
|
145
|
+
type JarShopOrderConfirmationAddress {
|
|
146
|
+
fullName: String!
|
|
147
|
+
streetLine1: String!
|
|
148
|
+
streetLine2: String!
|
|
149
|
+
postalCode: String!
|
|
150
|
+
city: String!
|
|
151
|
+
countryCode: String!
|
|
127
152
|
}
|
|
128
153
|
type JarShopOrderConfirmationExchange {
|
|
129
154
|
credential: String!
|
|
130
155
|
confirmation: JarShopOrderConfirmation!
|
|
131
156
|
}
|
|
157
|
+
type JarShopGuestPaymentReconciliation {
|
|
158
|
+
status: String!
|
|
159
|
+
}
|
|
132
160
|
input JarShopLegalConfigurationInput {
|
|
133
161
|
languageCode: String!
|
|
134
162
|
termsVersion: String!
|
|
@@ -143,6 +171,7 @@ const schema = parse(`
|
|
|
143
171
|
extend type Mutation {
|
|
144
172
|
placeJarShopOrder(input: JarShopPlaceOrderInput!): JarShopPlaceOrderResult!
|
|
145
173
|
exchangeJarShopOrderConfirmation(token: String!): JarShopOrderConfirmationExchange
|
|
174
|
+
reconcileJarShopPayment(orderCode: String!): JarShopGuestPaymentReconciliation
|
|
146
175
|
updateJarShopLegalConfiguration(input: JarShopLegalConfigurationInput!): JarShopLegalConfiguration!
|
|
147
176
|
}
|
|
148
177
|
`);
|
|
@@ -255,10 +284,14 @@ class JarShopCheckoutResolver {
|
|
|
255
284
|
private readonly customerService: CustomerService,
|
|
256
285
|
@Inject(ShippingMethodService)
|
|
257
286
|
private readonly shippingMethodService: ShippingMethodService,
|
|
287
|
+
@Inject(PaymentMethodService)
|
|
288
|
+
private readonly paymentMethodService: PaymentMethodService,
|
|
258
289
|
@Inject(ProductVariantService)
|
|
259
290
|
private readonly productVariantService: ProductVariantService,
|
|
260
291
|
@Inject(TransactionalConnection)
|
|
261
292
|
private readonly connection: TransactionalConnection,
|
|
293
|
+
@Inject(JarShopPaymentReconciliationService)
|
|
294
|
+
private readonly paymentReconciliation: JarShopPaymentReconciliationService,
|
|
262
295
|
) {}
|
|
263
296
|
|
|
264
297
|
@Query()
|
|
@@ -328,6 +361,27 @@ class JarShopCheckoutResolver {
|
|
|
328
361
|
@Ctx() ctx: RequestContext,
|
|
329
362
|
@Args("orderCode") orderCode: string,
|
|
330
363
|
) {
|
|
364
|
+
const order = await this.orderForConfirmationCredential(ctx, orderCode);
|
|
365
|
+
return order ? toOrderConfirmation(order) : null;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Reconciliation is an explicit mutation: a protected confirmation query is
|
|
370
|
+
* cacheable and must never quietly grow a provider-side effect.
|
|
371
|
+
*/
|
|
372
|
+
@Mutation()
|
|
373
|
+
async reconcileJarShopPayment(
|
|
374
|
+
@Ctx() ctx: RequestContext,
|
|
375
|
+
@Args("orderCode") orderCode: string,
|
|
376
|
+
) {
|
|
377
|
+
const order = await this.orderForConfirmationCredential(ctx, orderCode);
|
|
378
|
+
return order ? this.paymentReconciliation.reconcileOrder(order.code) : null;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
private async orderForConfirmationCredential(
|
|
382
|
+
ctx: RequestContext,
|
|
383
|
+
orderCode: string,
|
|
384
|
+
): Promise<Order | null> {
|
|
331
385
|
const credential = readCookieValue(
|
|
332
386
|
ctx.req?.headers.cookie ?? "",
|
|
333
387
|
CONFIRMATION_COOKIE_NAME,
|
|
@@ -340,18 +394,22 @@ class JarShopCheckoutResolver {
|
|
|
340
394
|
const record = await repository.findOne({
|
|
341
395
|
where: { tokenHash: hashConfirmationToken(credential) },
|
|
342
396
|
});
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
397
|
+
const credentialPresent = Boolean(
|
|
398
|
+
record &&
|
|
399
|
+
canReadConfirmationCredential({
|
|
346
400
|
expiresAt: record.expiresAt,
|
|
347
401
|
consumedAt: record.consumedAt,
|
|
348
|
-
})
|
|
349
|
-
)
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
return
|
|
354
|
-
|
|
402
|
+
}),
|
|
403
|
+
);
|
|
404
|
+
const order = credentialPresent
|
|
405
|
+
? await this.orderService.findOne(ctx, record!.orderId)
|
|
406
|
+
: null;
|
|
407
|
+
return canReconcilePaymentWithConfirmationCredential({
|
|
408
|
+
credentialPresent,
|
|
409
|
+
credentialOrderCode: order?.code,
|
|
410
|
+
requestedOrderCode: orderCode,
|
|
411
|
+
})
|
|
412
|
+
? (order ?? null)
|
|
355
413
|
: null;
|
|
356
414
|
}
|
|
357
415
|
|
|
@@ -455,6 +513,17 @@ class JarShopCheckoutResolver {
|
|
|
455
513
|
return failure("TEMPORARY_FAILURE", "Checkout attempt is not available");
|
|
456
514
|
}
|
|
457
515
|
|
|
516
|
+
const market = marketForChannel(ctx.channel.token);
|
|
517
|
+
const marketValidation = validateCheckoutMarket(input, market);
|
|
518
|
+
if (!marketValidation.ok) {
|
|
519
|
+
return await this.failAttempt(
|
|
520
|
+
repository,
|
|
521
|
+
attempt,
|
|
522
|
+
marketValidation.errorCode,
|
|
523
|
+
marketValidation.message,
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
|
|
458
527
|
const activeOrderReference = await this.activeOrderService.getActiveOrder(
|
|
459
528
|
ctx,
|
|
460
529
|
undefined,
|
|
@@ -496,7 +565,10 @@ class JarShopCheckoutResolver {
|
|
|
496
565
|
"Legal configuration is not available for this locale",
|
|
497
566
|
);
|
|
498
567
|
}
|
|
499
|
-
const shippingValidation = validateShippingSelection(
|
|
568
|
+
const shippingValidation = validateShippingSelection(
|
|
569
|
+
input,
|
|
570
|
+
market.countries,
|
|
571
|
+
);
|
|
500
572
|
if (!shippingValidation.ok) {
|
|
501
573
|
return await this.failAttempt(
|
|
502
574
|
repository,
|
|
@@ -564,12 +636,15 @@ class JarShopCheckoutResolver {
|
|
|
564
636
|
);
|
|
565
637
|
}
|
|
566
638
|
await this.orderService.addCustomerToOrder(ctx, activeOrder.id, customer);
|
|
639
|
+
const unsetShippingAddress = shouldUnsetShippingAddress(input);
|
|
567
640
|
if (input.shippingAddress) {
|
|
568
641
|
await this.orderService.setShippingAddress(
|
|
569
642
|
ctx,
|
|
570
643
|
activeOrder.id,
|
|
571
644
|
input.shippingAddress,
|
|
572
645
|
);
|
|
646
|
+
} else if (unsetShippingAddress) {
|
|
647
|
+
await this.orderService.unsetShippingAddress(ctx, activeOrder.id);
|
|
573
648
|
}
|
|
574
649
|
if (input.billingAddress) {
|
|
575
650
|
await this.orderService.setBillingAddress(
|
|
@@ -604,55 +679,77 @@ class JarShopCheckoutResolver {
|
|
|
604
679
|
"Selected shipping method is not eligible",
|
|
605
680
|
);
|
|
606
681
|
}
|
|
682
|
+
if (unsetShippingAddress) {
|
|
683
|
+
await this.connection.getRepository(ctx, JarShopShippingSelection).update(
|
|
684
|
+
{
|
|
685
|
+
channelId: Number(ctx.channelId),
|
|
686
|
+
orderCode: activeOrder.code,
|
|
687
|
+
status: "current",
|
|
688
|
+
},
|
|
689
|
+
{ status: "superseded" },
|
|
690
|
+
);
|
|
691
|
+
}
|
|
607
692
|
const paymentState = await this.orderService.transitionToState(
|
|
608
693
|
ctx,
|
|
609
694
|
activeOrder.id,
|
|
610
695
|
"ArrangingPayment",
|
|
611
696
|
);
|
|
612
697
|
if (isGraphQlErrorResult(paymentState)) {
|
|
698
|
+
const failure = mapPaymentTransitionFailure(paymentState.transitionError);
|
|
613
699
|
return await this.failAttempt(
|
|
614
700
|
repository,
|
|
615
701
|
attempt,
|
|
616
|
-
|
|
617
|
-
|
|
702
|
+
failure.errorCode,
|
|
703
|
+
failure.message,
|
|
618
704
|
);
|
|
619
705
|
}
|
|
620
|
-
|
|
706
|
+
let paymentFlow: "synchronous" | "redirect";
|
|
707
|
+
try {
|
|
708
|
+
const { handler } =
|
|
709
|
+
await this.paymentMethodService.getMethodAndOperations(
|
|
710
|
+
ctx,
|
|
711
|
+
input.paymentMethodCode,
|
|
712
|
+
);
|
|
713
|
+
paymentFlow = paymentFlowOf(handler);
|
|
714
|
+
} catch {
|
|
621
715
|
return await this.failAttempt(
|
|
622
716
|
repository,
|
|
623
717
|
attempt,
|
|
624
718
|
"PAYMENT_METHOD_INELIGIBLE",
|
|
625
|
-
"
|
|
719
|
+
"Selected payment method is not available",
|
|
626
720
|
);
|
|
627
721
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
if (isGraphQlErrorResult(paymentResult)) {
|
|
637
|
-
const paymentErrorCode = paymentResult.errorCode;
|
|
638
|
-
return await this.failAttempt(
|
|
639
|
-
repository,
|
|
640
|
-
attempt,
|
|
641
|
-
paymentErrorCode === "INSUFFICIENT_STOCK_ERROR"
|
|
642
|
-
? "INSUFFICIENT_STOCK"
|
|
643
|
-
: "TEMPORARY_FAILURE",
|
|
644
|
-
paymentErrorCode === "INSUFFICIENT_STOCK_ERROR"
|
|
645
|
-
? "Some cart items are no longer available in the requested quantity"
|
|
646
|
-
: "Payment could not be authorized",
|
|
722
|
+
if (paymentFlow === "synchronous") {
|
|
723
|
+
const added = await this.orderService.addPaymentToOrder(
|
|
724
|
+
ctx,
|
|
725
|
+
activeOrder.id,
|
|
726
|
+
{
|
|
727
|
+
method: input.paymentMethodCode,
|
|
728
|
+
metadata: { attemptId: input.attemptId },
|
|
729
|
+
},
|
|
647
730
|
);
|
|
731
|
+
if (isGraphQlErrorResult(added)) {
|
|
732
|
+
const paymentErrorCode = added.errorCode;
|
|
733
|
+
return await this.failAttempt(
|
|
734
|
+
repository,
|
|
735
|
+
attempt,
|
|
736
|
+
paymentErrorCode === "INSUFFICIENT_STOCK_ERROR"
|
|
737
|
+
? "INSUFFICIENT_STOCK"
|
|
738
|
+
: "TEMPORARY_FAILURE",
|
|
739
|
+
paymentErrorCode === "INSUFFICIENT_STOCK_ERROR"
|
|
740
|
+
? "Some cart items are no longer available in the requested quantity"
|
|
741
|
+
: "Payment could not be authorized",
|
|
742
|
+
);
|
|
743
|
+
}
|
|
648
744
|
}
|
|
649
745
|
const consentRepository = this.connection.getRepository(
|
|
650
746
|
ctx,
|
|
651
747
|
JarShopOrderConsent,
|
|
652
748
|
);
|
|
749
|
+
const orderId = Number(activeOrder.id);
|
|
653
750
|
await consentRepository.save(
|
|
654
751
|
consentRepository.create({
|
|
655
|
-
orderId
|
|
752
|
+
orderId,
|
|
656
753
|
termsVersion: legalConfiguration.termsVersion,
|
|
657
754
|
termsUrl: legalConfiguration.termsUrl,
|
|
658
755
|
privacyUrl: legalConfiguration.privacyUrl,
|
|
@@ -667,13 +764,13 @@ class JarShopCheckoutResolver {
|
|
|
667
764
|
await tokenRepository.save([
|
|
668
765
|
tokenRepository.create({
|
|
669
766
|
tokenHash: confirmations.browser.tokenHash,
|
|
670
|
-
orderId
|
|
767
|
+
orderId,
|
|
671
768
|
expiresAt: confirmations.browser.expiresAt,
|
|
672
769
|
consumedAt: null,
|
|
673
770
|
}),
|
|
674
771
|
tokenRepository.create({
|
|
675
772
|
tokenHash: confirmations.email.tokenHash,
|
|
676
|
-
orderId
|
|
773
|
+
orderId,
|
|
677
774
|
expiresAt: confirmations.email.expiresAt,
|
|
678
775
|
consumedAt: null,
|
|
679
776
|
}),
|
|
@@ -684,7 +781,7 @@ class JarShopCheckoutResolver {
|
|
|
684
781
|
);
|
|
685
782
|
const orderEmailSnapshotSource = await this.orderService.findOne(
|
|
686
783
|
ctx,
|
|
687
|
-
|
|
784
|
+
orderId,
|
|
688
785
|
[
|
|
689
786
|
"customer",
|
|
690
787
|
"lines.productVariant",
|
|
@@ -699,7 +796,7 @@ class JarShopCheckoutResolver {
|
|
|
699
796
|
await emailDeliveryRepository.save(
|
|
700
797
|
emailDeliveryRepository.create(
|
|
701
798
|
createPendingOrderEmailDelivery({
|
|
702
|
-
orderId
|
|
799
|
+
orderId,
|
|
703
800
|
checkoutAttemptId: attempt.attemptId,
|
|
704
801
|
snapshot: {
|
|
705
802
|
recipient: orderEmailSnapshotSource.customer.emailAddress,
|
|
@@ -708,9 +805,10 @@ class JarShopCheckoutResolver {
|
|
|
708
805
|
currencyCode: orderEmailSnapshotSource.currencyCode,
|
|
709
806
|
totalWithTax: orderEmailSnapshotSource.totalWithTax,
|
|
710
807
|
shippingWithTax: orderEmailSnapshotSource.shippingWithTax,
|
|
711
|
-
paymentMethod:
|
|
712
|
-
.
|
|
713
|
-
|
|
808
|
+
paymentMethod:
|
|
809
|
+
orderEmailSnapshotSource.payments
|
|
810
|
+
.map((payment) => payment.method)
|
|
811
|
+
.join(", ") || input.paymentMethodCode,
|
|
714
812
|
shippingMethod: orderEmailSnapshotSource.shippingLines
|
|
715
813
|
.map((line) =>
|
|
716
814
|
resolveLocalizedShippingMethodName(
|
|
@@ -720,6 +818,18 @@ class JarShopCheckoutResolver {
|
|
|
720
818
|
)
|
|
721
819
|
.filter(Boolean)
|
|
722
820
|
.join(", "),
|
|
821
|
+
shippingAddress: {
|
|
822
|
+
fullName: orderEmailSnapshotSource.shippingAddress.fullName ?? "",
|
|
823
|
+
streetLine1:
|
|
824
|
+
orderEmailSnapshotSource.shippingAddress.streetLine1 ?? "",
|
|
825
|
+
streetLine2:
|
|
826
|
+
orderEmailSnapshotSource.shippingAddress.streetLine2 ?? "",
|
|
827
|
+
postalCode:
|
|
828
|
+
orderEmailSnapshotSource.shippingAddress.postalCode ?? "",
|
|
829
|
+
city: orderEmailSnapshotSource.shippingAddress.city ?? "",
|
|
830
|
+
countryCode:
|
|
831
|
+
orderEmailSnapshotSource.shippingAddress.countryCode ?? "",
|
|
832
|
+
},
|
|
723
833
|
confirmationToken: confirmations.email.token,
|
|
724
834
|
lines: orderEmailSnapshotSource.lines.map((line) => ({
|
|
725
835
|
name: line.productVariant.name,
|
|
@@ -731,10 +841,10 @@ class JarShopCheckoutResolver {
|
|
|
731
841
|
),
|
|
732
842
|
);
|
|
733
843
|
attempt.status = "completed";
|
|
734
|
-
attempt.orderId =
|
|
844
|
+
attempt.orderId = orderId;
|
|
735
845
|
attempt.errorCode = null;
|
|
736
846
|
await repository.save(attempt);
|
|
737
|
-
const placedOrder = await this.orderService.findOne(ctx,
|
|
847
|
+
const placedOrder = await this.orderService.findOne(ctx, orderId);
|
|
738
848
|
return placedOrder
|
|
739
849
|
? success(
|
|
740
850
|
placedOrder,
|
|
@@ -743,7 +853,7 @@ class JarShopCheckoutResolver {
|
|
|
743
853
|
confirmations.browser.token,
|
|
744
854
|
)
|
|
745
855
|
: success(
|
|
746
|
-
|
|
856
|
+
activeOrder,
|
|
747
857
|
activeOrder.totalWithTax,
|
|
748
858
|
activeOrder.currencyCode,
|
|
749
859
|
confirmations.browser.token,
|
|
@@ -976,16 +1086,6 @@ function toLegalConfiguration(configuration: JarShopLegalConfiguration) {
|
|
|
976
1086
|
};
|
|
977
1087
|
}
|
|
978
1088
|
|
|
979
|
-
function toOrderConfirmation(order: Order) {
|
|
980
|
-
return {
|
|
981
|
-
orderId: order.id,
|
|
982
|
-
orderCode: order.code,
|
|
983
|
-
state: order.state,
|
|
984
|
-
totalWithTax: order.totalWithTax,
|
|
985
|
-
currencyCode: order.currencyCode,
|
|
986
|
-
};
|
|
987
|
-
}
|
|
988
|
-
|
|
989
1089
|
/**
|
|
990
1090
|
* JarShop's server-owned checkout seam.
|
|
991
1091
|
*
|
|
@@ -994,10 +1094,19 @@ function toOrderConfirmation(order: Order) {
|
|
|
994
1094
|
*/
|
|
995
1095
|
@VendurePlugin({
|
|
996
1096
|
dashboard: "./dashboard/index.tsx",
|
|
997
|
-
imports: [PluginCommonModule],
|
|
998
|
-
providers: [
|
|
1097
|
+
imports: [PluginCommonModule, JarShopRedirectPaymentPlugin],
|
|
1098
|
+
providers: [
|
|
1099
|
+
JarShopMarketChannelCheck,
|
|
1100
|
+
JarShopOperationCodeCheck,
|
|
1101
|
+
JarShopOrderEmailLifecycleOutbox,
|
|
1102
|
+
JarShopOrderEmailWorker,
|
|
1103
|
+
],
|
|
999
1104
|
configuration: (config) =>
|
|
1000
|
-
|
|
1105
|
+
registerJarShopMarketActiveOrder(
|
|
1106
|
+
registerJarShopOrderEmailWorkerTask(
|
|
1107
|
+
registerJarShopOrderLifecycle(config),
|
|
1108
|
+
),
|
|
1109
|
+
),
|
|
1001
1110
|
entities: [
|
|
1002
1111
|
CheckoutAttempt,
|
|
1003
1112
|
JarShopConfirmationToken,
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Market-scoped active Order selection.
|
|
3
|
+
*
|
|
4
|
+
* One market is one Vendure Channel, and a client such as the mobile app sends
|
|
5
|
+
* ONE session token for every market (the local storefront does the same: all
|
|
6
|
+
* markets share one session cookie on `localhost`). Vendure's default strategy
|
|
7
|
+
* looks up `session.activeOrderId` in the current Channel and, for a guest that
|
|
8
|
+
* finds nothing, creates a new Order and overwrites `activeOrderId`. A guest
|
|
9
|
+
* who switches SK -> CZ -> SK would therefore lose the SK cart.
|
|
10
|
+
*
|
|
11
|
+
* This module keeps the decision free of Vendure runtime imports so it can be
|
|
12
|
+
* unit-tested: the storage access is injected as {@link MarketOrderStore}.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** Name of the internal Order custom field that remembers a guest's session. */
|
|
16
|
+
export const GUEST_SESSION_FIELD = "jarshopGuestSessionId";
|
|
17
|
+
|
|
18
|
+
/** The part of an Order the selection needs. */
|
|
19
|
+
export interface MarketOrder {
|
|
20
|
+
readonly id: string | number;
|
|
21
|
+
readonly active: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The part of the RequestContext the selection needs. */
|
|
25
|
+
export interface MarketOrderContext {
|
|
26
|
+
readonly channelId: string | number;
|
|
27
|
+
readonly activeUserId?: string | number | undefined;
|
|
28
|
+
readonly session?:
|
|
29
|
+
| {
|
|
30
|
+
readonly id: string | number;
|
|
31
|
+
readonly activeOrderId?: string | number | undefined;
|
|
32
|
+
}
|
|
33
|
+
| undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface MarketOrderStore<
|
|
37
|
+
Ctx extends MarketOrderContext,
|
|
38
|
+
Order extends MarketOrder,
|
|
39
|
+
> {
|
|
40
|
+
/** The Order with this id when it belongs to the context's Channel. */
|
|
41
|
+
findInChannel(ctx: Ctx, orderId: string | number): Promise<Order | undefined>;
|
|
42
|
+
/** Vendure's Channel-scoped lookup of a signed-in user's active Order. */
|
|
43
|
+
findActiveForUser(
|
|
44
|
+
ctx: Ctx,
|
|
45
|
+
userId: string | number,
|
|
46
|
+
): Promise<Order | undefined>;
|
|
47
|
+
/**
|
|
48
|
+
* The most recently updated active Order of the context's Channel that was
|
|
49
|
+
* stamped with this guest session id.
|
|
50
|
+
*/
|
|
51
|
+
findActiveForGuestSession(
|
|
52
|
+
ctx: Ctx,
|
|
53
|
+
sessionId: string,
|
|
54
|
+
): Promise<Order | undefined>;
|
|
55
|
+
/** Detaches an inactive Order that is still referenced by the session. */
|
|
56
|
+
unsetSessionOrder(ctx: Ctx): Promise<void>;
|
|
57
|
+
create(ctx: Ctx, userId: string | number | undefined): Promise<Order>;
|
|
58
|
+
/** Stamps the guest session id on the Order custom field. */
|
|
59
|
+
stampGuestSession(ctx: Ctx, order: Order, sessionId: string): Promise<Order>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function guestSessionKey(ctx: MarketOrderContext): string | undefined {
|
|
63
|
+
const id = ctx.session?.id;
|
|
64
|
+
return id === undefined || id === null || id === "" ? undefined : String(id);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function determineMarketActiveOrder<
|
|
68
|
+
Ctx extends MarketOrderContext,
|
|
69
|
+
Order extends MarketOrder,
|
|
70
|
+
>(store: MarketOrderStore<Ctx, Order>, ctx: Ctx): Promise<Order | undefined> {
|
|
71
|
+
if (!ctx.session) {
|
|
72
|
+
throw new Error("A market-scoped active Order needs a session");
|
|
73
|
+
}
|
|
74
|
+
if (
|
|
75
|
+
ctx.session.activeOrderId !== undefined &&
|
|
76
|
+
ctx.session.activeOrderId !== null
|
|
77
|
+
) {
|
|
78
|
+
const current = await store.findInChannel(ctx, ctx.session.activeOrderId);
|
|
79
|
+
if (current?.active === false) {
|
|
80
|
+
// An inactive Order that the interrupted regular process left on the
|
|
81
|
+
// session; Vendure's default strategy detaches it the same way.
|
|
82
|
+
await store.unsetSessionOrder(ctx);
|
|
83
|
+
} else if (current) {
|
|
84
|
+
return current;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (ctx.activeUserId !== undefined && ctx.activeUserId !== null) {
|
|
88
|
+
return store.findActiveForUser(ctx, ctx.activeUserId);
|
|
89
|
+
}
|
|
90
|
+
const sessionKey = guestSessionKey(ctx);
|
|
91
|
+
return sessionKey
|
|
92
|
+
? store.findActiveForGuestSession(ctx, sessionKey)
|
|
93
|
+
: undefined;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function createMarketActiveOrder<
|
|
97
|
+
Ctx extends MarketOrderContext,
|
|
98
|
+
Order extends MarketOrder,
|
|
99
|
+
>(store: MarketOrderStore<Ctx, Order>, ctx: Ctx): Promise<Order> {
|
|
100
|
+
const hasUser = ctx.activeUserId !== undefined && ctx.activeUserId !== null;
|
|
101
|
+
const order = await store.create(ctx, hasUser ? ctx.activeUserId : undefined);
|
|
102
|
+
const sessionKey = guestSessionKey(ctx);
|
|
103
|
+
// A signed-in user's carts are found through their Customer, so only a guest
|
|
104
|
+
// Order needs the session stamp.
|
|
105
|
+
return hasUser || !sessionKey
|
|
106
|
+
? order
|
|
107
|
+
: store.stampGuestSession(ctx, order, sessionKey);
|
|
108
|
+
}
|