@unchainedshop/plugins 3.0.0-alpha3 → 3.0.0-alpha5
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/lib/payment/stripe/index.js +5 -1
- package/lib/payment/stripe/index.js.map +1 -1
- package/lib/payment/stripe/middleware.d.ts.map +1 -1
- package/lib/payment/stripe/middleware.js +2 -1
- package/lib/payment/stripe/middleware.js.map +1 -1
- package/lib/payment/stripe/stripe.d.ts +5 -5
- package/lib/payment/stripe/stripe.d.ts.map +1 -1
- package/lib/payment/stripe/stripe.js +16 -7
- package/lib/payment/stripe/stripe.js.map +1 -1
- package/lib/plugins-index.d.ts +2 -1
- package/lib/plugins-index.d.ts.map +1 -1
- package/lib/plugins-index.js.map +1 -1
- package/lib/presets/base-modules.d.ts +1 -1
- package/lib/presets/base-modules.d.ts.map +1 -1
- package/lib/presets/crypto-modules.d.ts +1 -1
- package/lib/presets/crypto-modules.d.ts.map +1 -1
- package/package.json +23 -23
- package/src/files/gridfs/gridfs-adapter.ts +1 -1
- package/src/files/minio/minio-adapter.ts +1 -1
- package/src/payment/stripe/index.ts +5 -1
- package/src/payment/stripe/middleware.ts +2 -1
- package/src/payment/stripe/stripe.ts +23 -8
- package/src/plugins-index.ts +2 -1
- package/src/presets/base-modules.ts +1 -1
- package/src/presets/crypto-modules.ts +1 -1
- package/src/pricing/discount-100-off.test.ts +13 -7
- package/src/pricing/discount-half-price-manual.test.ts +13 -7
- package/src/pricing/discount-half-price.test.ts +15 -7
- package/src/pricing/free-delivery.test.ts +3 -8
- package/src/pricing/licenced-enrollment.test.ts +33 -34
- package/src/pricing/order-delivery.test.ts +3 -5
- package/src/pricing/order-discount.test.ts +3 -3
- package/src/pricing/plugins-index.test.ts +1 -1
- package/src/pricing/product-swiss-tax.test.ts +112 -87
- package/src/pricing/tax/ch.test.ts +16 -16
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PaymentAdapter, PaymentDirector, PaymentError } from '@unchainedshop/core-payment';
|
|
2
2
|
import { createLogger } from '@unchainedshop/logger';
|
|
3
|
-
import
|
|
3
|
+
import stripeClient, { createOrderPaymentIntent, createRegistrationIntent } from './stripe.js';
|
|
4
4
|
export * from './middleware.js';
|
|
5
5
|
const logger = createLogger('unchained:core-payment:stripe');
|
|
6
6
|
const Stripe = {
|
|
@@ -28,6 +28,7 @@ const Stripe = {
|
|
|
28
28
|
const adapterActions = {
|
|
29
29
|
...PaymentAdapter.actions(params),
|
|
30
30
|
configurationError() {
|
|
31
|
+
const stripe = stripeClient();
|
|
31
32
|
if (!stripe) {
|
|
32
33
|
return PaymentError.INCOMPLETE_CONFIGURATION;
|
|
33
34
|
}
|
|
@@ -42,10 +43,12 @@ const Stripe = {
|
|
|
42
43
|
return false;
|
|
43
44
|
},
|
|
44
45
|
validate: async ({ token }) => {
|
|
46
|
+
const stripe = stripeClient();
|
|
45
47
|
const paymentMethod = await stripe.paymentMethods.retrieve(token);
|
|
46
48
|
return !!paymentMethod;
|
|
47
49
|
},
|
|
48
50
|
register: async ({ setupIntentId }) => {
|
|
51
|
+
const stripe = stripeClient();
|
|
49
52
|
if (!setupIntentId) {
|
|
50
53
|
throw new Error('You have to provide a setupIntentId');
|
|
51
54
|
}
|
|
@@ -75,6 +78,7 @@ const Stripe = {
|
|
|
75
78
|
return paymentIntent.client_secret;
|
|
76
79
|
},
|
|
77
80
|
charge: async ({ paymentIntentId, paymentCredentials }) => {
|
|
81
|
+
const stripe = stripeClient();
|
|
78
82
|
if (!paymentIntentId && !paymentCredentials) {
|
|
79
83
|
throw new Error('You have to provide paymentIntentId or paymentCredentials');
|
|
80
84
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/payment/stripe/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC5F,OAAO,EAAE,YAAY,EAAE,MA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EACjD,CAAC;oBACD,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAC;gBAC7E,CAAC;gBACD,IAAI,mBAAmB,CAAC,QAAQ,EAAE,cAAc,KAAK,YAAY,EAAE,GAAG,EAAE,CAAC;oBACvE,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;gBAC/E,CAAC;gBAED,IAAI,mBAAmB,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;oBAC/C,OAAO,mBAAmB,CAAC;gBAC7B,CAAC;gBAED,MAAM,CAAC,OAAO,CAAC,yDAAyD,EAAE;oBACxE,cAAc,EAAE,mBAAmB,CAAC,EAAE;iBACvC,CAAC,CAAC;gBAEH,OAAO,KAAK,CAAC;YACf,CAAC;SACF,CAAC;QAEF,OAAO,cAAc,CAAC;IACxB,CAAC;CACF,CAAC;AAEF,eAAe,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/payment/stripe/middleware.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,iBAAiB;;;CAG7B,CAAC;AAEF,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../src/payment/stripe/middleware.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,iBAAiB;;;CAG7B,CAAC;AAEF,eAAO,MAAM,aAAa,gDAoIzB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
-
import
|
|
2
|
+
import stripeClient from './stripe.js';
|
|
3
3
|
const logger = createLogger('unchained:core-payment:stripe:webhook');
|
|
4
4
|
export const WebhookEventTypes = {
|
|
5
5
|
PAYMENT_INTENT_SUCCEEDED: 'payment_intent.succeeded',
|
|
@@ -10,6 +10,7 @@ export const stripeHandler = async (request, response) => {
|
|
|
10
10
|
const { modules } = resolvedContext;
|
|
11
11
|
let event;
|
|
12
12
|
try {
|
|
13
|
+
const stripe = stripeClient();
|
|
13
14
|
const sig = request.headers['stripe-signature'];
|
|
14
15
|
event = stripe.webhooks.constructEvent(request.body, sig, process.env.STRIPE_ENDPOINT_SECRET);
|
|
15
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/payment/stripe/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../src/payment/stripe/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,YAAY,MAAM,aAAa,CAAC;AAEvC,MAAM,MAAM,GAAG,YAAY,CAAC,uCAAuC,CAAC,CAAC;AAErE,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,wBAAwB,EAAE,0BAA0B;IACpD,sBAAsB,EAAE,wBAAwB;CACjD,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE;IACvD,MAAM,eAAe,GAAG,OAAO,CAAC,gBAA2B,CAAC;IAC5D,MAAM,EAAE,OAAO,EAAE,GAAG,eAAe,CAAC;IAEpC,IAAI,KAAK,CAAC;IAEV,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;QAC9B,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QAChD,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;IAChG,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,KAAK,CAAC,6BAA6B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C;IAC9B,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Order } from '@unchainedshop/core-orders';
|
|
2
2
|
import { OrderPayment } from '@unchainedshop/core-orders';
|
|
3
3
|
import { IOrderPricingSheet } from '@unchainedshop/core-orders';
|
|
4
|
-
import Stripe from 'stripe';
|
|
5
|
-
declare const
|
|
6
|
-
export default
|
|
4
|
+
import type { Stripe as StripeType } from 'stripe';
|
|
5
|
+
export declare const initStripeClient: () => Promise<StripeType>;
|
|
6
|
+
export default function (): StripeType;
|
|
7
7
|
export declare const upsertCustomer: ({ userId, name, email }: {
|
|
8
8
|
userId: any;
|
|
9
9
|
name: any;
|
|
@@ -15,7 +15,7 @@ export declare const createRegistrationIntent: ({ userId, name, email, paymentPr
|
|
|
15
15
|
email: string;
|
|
16
16
|
paymentProviderId: string;
|
|
17
17
|
descriptorPrefix?: string;
|
|
18
|
-
}, options?: Record<string, any>) => Promise<
|
|
18
|
+
}, options?: Record<string, any>) => Promise<StripeType.Response<StripeType.SetupIntent>>;
|
|
19
19
|
export declare const createOrderPaymentIntent: ({ userId, name, email, order, orderPayment, pricing, descriptorPrefix, }: {
|
|
20
20
|
userId: string;
|
|
21
21
|
name: string;
|
|
@@ -24,5 +24,5 @@ export declare const createOrderPaymentIntent: ({ userId, name, email, order, or
|
|
|
24
24
|
orderPayment: OrderPayment;
|
|
25
25
|
pricing: IOrderPricingSheet;
|
|
26
26
|
descriptorPrefix?: string;
|
|
27
|
-
}, options?: Record<string, any>) => Promise<
|
|
27
|
+
}, options?: Record<string, any>) => Promise<StripeType.Response<StripeType.PaymentIntent>>;
|
|
28
28
|
//# sourceMappingURL=stripe.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe.d.ts","sourceRoot":"","sources":["../../../src/payment/stripe/stripe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"stripe.d.ts","sourceRoot":"","sources":["../../../src/payment/stripe/stripe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,QAAQ,CAAC;AAQnD,eAAO,MAAM,gBAAgB,2BAO5B,CAAC;AAIF,MAAM,CAAC,OAAO,yBAEb;AAID,eAAO,MAAM,cAAc;;;;MAAoC,OAAO,CAAC,MAAM,CAiC5E,CAAC;AAEF,eAAO,MAAM,wBAAwB,kEAOhC;IACD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,YACQ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,yDAiB7B,CAAC;AAEF,eAAO,MAAM,wBAAwB,6EAShC;IACD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,KAAK,CAAC;IACb,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE,kBAAkB,CAAC;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,YACQ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,2DAwB7B,CAAC"}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
+
const logger = createLogger('unchained:core-payment:stripe');
|
|
2
3
|
const { STRIPE_SECRET, STRIPE_WEBHOOK_ENVIRONMENT, EMAIL_WEBSITE_NAME } = process.env;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
4
|
+
let stripe;
|
|
5
|
+
export const initStripeClient = async () => {
|
|
6
|
+
const { default: Stripe } = await import('stripe');
|
|
7
|
+
stripe = new Stripe(STRIPE_SECRET, {
|
|
8
|
+
apiVersion: '2024-09-30.acacia',
|
|
9
|
+
});
|
|
10
|
+
return stripe;
|
|
11
|
+
};
|
|
12
|
+
initStripeClient().catch(logger.error);
|
|
13
|
+
export default function () {
|
|
14
|
+
return stripe;
|
|
15
|
+
}
|
|
6
16
|
const environment = STRIPE_WEBHOOK_ENVIRONMENT ?? null;
|
|
7
|
-
export default stripe;
|
|
8
17
|
export const upsertCustomer = async ({ userId, name, email }) => {
|
|
9
18
|
try {
|
|
10
19
|
const { data } = await stripe.customers.search({ query: `metadata["userId"]:"${userId}"` });
|
|
@@ -38,7 +47,7 @@ export const upsertCustomer = async ({ userId, name, email }) => {
|
|
|
38
47
|
};
|
|
39
48
|
export const createRegistrationIntent = async ({ userId, name, email, paymentProviderId, descriptorPrefix, }, options = {}) => {
|
|
40
49
|
const customer = options?.customer || (await upsertCustomer({ userId, name, email }));
|
|
41
|
-
const description = `${descriptorPrefix || EMAIL_WEBSITE_NAME || 'Unchained'}
|
|
50
|
+
const description = `${descriptorPrefix || EMAIL_WEBSITE_NAME || 'Unchained'}`.trim();
|
|
42
51
|
const setupIntent = await stripe.setupIntents.create({
|
|
43
52
|
description,
|
|
44
53
|
customer,
|
|
@@ -53,7 +62,7 @@ export const createRegistrationIntent = async ({ userId, name, email, paymentPro
|
|
|
53
62
|
return setupIntent;
|
|
54
63
|
};
|
|
55
64
|
export const createOrderPaymentIntent = async ({ userId, name, email, order, orderPayment, pricing, descriptorPrefix, }, options = {}) => {
|
|
56
|
-
const description = `${descriptorPrefix || EMAIL_WEBSITE_NAME || 'Unchained'}
|
|
65
|
+
const description = `${descriptorPrefix || EMAIL_WEBSITE_NAME || 'Unchained'}`.trim();
|
|
57
66
|
const customer = options?.customer || (await upsertCustomer({ userId, name, email }));
|
|
58
67
|
const { currency, amount } = pricing.total({ useNetPrice: false });
|
|
59
68
|
const paymentIntent = await stripe.paymentIntents.create({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe.js","sourceRoot":"","sources":["../../../src/payment/stripe/stripe.ts"],"names":[],"mappings":"AAGA,OAAO,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"stripe.js","sourceRoot":"","sources":["../../../src/payment/stripe/stripe.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAGrD,MAAM,MAAM,GAAG,YAAY,CAAC,+BAA+B,CAAC,CAAC;AAE7D,MAAM,EAAE,aAAa,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAEtF,IAAI,MAAkB,CAAC;AAEvB,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,IAAI,EAAE;IACzC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC;IAEnD,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,EAAE;QACjC,UAAU,EAAE,mBAAmB;KAChC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,gBAAgB,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAEvC,MAAM,CAAC,OAAO;IACZ,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,WAAW,GAAG,0BAA0B,IAAI,IAAI,CAAC;AAEvD,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,EAAmB,EAAE;IAC/E,IAAI,CAAC;QACH,MAAM,EAAE,I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EAAE,YAAY;QAC1C,QAAQ,EAAE;YACR,cAAc,EAAE,YAAY,CAAC,GAAG;YAChC,OAAO,EAAE,KAAK,CAAC,GAAG;YAClB,MAAM;YACN,WAAW;SACZ;QACD,GAAG,OAAO;KACX,CAAC,CAAC;IACH,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC"}
|
package/lib/plugins-index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UnchainedCore } from '@unchainedshop/core';
|
|
2
|
+
import { ModuleInput } from '@unchainedshop/mongodb';
|
|
2
3
|
import './presets/countries/ch.js';
|
|
3
4
|
import './delivery/send-message.js';
|
|
4
5
|
import './delivery/stores.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins-index.d.ts","sourceRoot":"","sources":["../src/plugins-index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugins-index.d.ts","sourceRoot":"","sources":["../src/plugins-index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,OAAO,2BAA2B,CAAC;AAOnC,OAAO,4BAA4B,CAAC;AACpC,OAAO,sBAAsB,CAAC;AAG9B,OAAO,8BAA8B,CAAC;AACtC,OAAO,8BAA8B,CAAC;AAStC,OAAO,2BAA2B,CAAC;AACnC,OAAO,2BAA2B,CAAC;AAGnC,OAAO,iBAAiB,CAAC;AACzB,OAAO,+BAA+B,CAAC;AAYvC,eAAO,MAAM,cAAc,EAAE,MAAM,CACjC,MAAM,EACN;IACE,SAAS,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC;CAC9C,CAUF,CAAC;AAEF,eAAO,MAAM,+BAA+B,+BAExB;IAAE,YAAY,EAAE,aAAa,CAAA;CAAE,SA4BlD,CAAC"}
|
package/lib/plugins-index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins-index.js","sourceRoot":"","sources":["../src/plugins-index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugins-index.js","sourceRoot":"","sources":["../src/plugins-index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAI9B,OAAO,WAAW,MAAM,2BAA2B,CAAC;AACpD,OAAO,2BAA2B,CAAC;AACnC,OAAO,aAAa,MAAM,6BAA6B,CAAC;AAExD,OAAO,sBAAsB,MAAM,6BAA6B,CAAC;AACjE,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAE7D,WAAW;AACX,OAAO,4BAA4B,CAAC;AACpC,OAAO,sBAAsB,CAAC;AAE9B,UAAU;AACV,OAAO,8BAA8B,CAAC;AACtC,OAAO,8BAA8B,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,gCAAgC,EAAE,MAAM,8BAA8B,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,mCAAmC,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnG,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,kBAAkB;AAClB,OAAO,2BAA2B,CAAC;AACnC,OAAO,2BAA2B,CAAC;AAEnC,UAAU;AACV,OAAO,iBAAiB,CAAC;AACzB,OAAO,+BAA+B,CAAC;AACvC,OAAO,EAAE,oCAAoC,EAAE,MAAM,wCAAwC,CAAC;AAE9F,MAAM,EACJ,mBAAmB,GAAG,iBAAiB,EACvC,oBAAoB,GAAG,kBAAkB,EACzC,uBAAuB,GAAG,+BAA+B,EACzD,sBAAsB,GAAG,4BAA4B,EACrD,sBAAsB,GAAG,oBAAoB,EAC7C,qBAAqB,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ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"base-modules.d.ts","sourceRoot":"","sources":["../../src/presets/base-modules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,OAAO,qBAAqB,CAAC;AAG7B,OAAO,uBAAuB,CAAC;AAG/B,OAAO,yBAAyB,CAAC;AAGjC,OAAO,4BAA4B,CAAC;AACpC,OAAO,6BAA6B,CAAC;AACrC,OAAO,2BAA2B,CAAC;AACnC,OAAO,8BAA8B,CAAC;AACtC,OAAO,8BAA8B,CAAC;AACtC,OAAO,6BAA6B,CAAC;AACrC,OAAO,qCAAqC,CAAC;AAC7C,OAAO,gCAAgC,CAAC;AAGxC,OAAO,yBAAyB,CAAC;AAGjC,OAAO,4BAA4B,CAAC;AAGpC,OAAO,iCAAiC,CAAC;AAGzC,OAAO,0BAA0B,CAAC;AAClC,OAAO,4BAA4B,CAAC;AACpC,OAAO,sBAAsB,CAAC;AAC9B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,2BAA2B,CAAC;AACnC,OAAO,wBAAwB,CAAC;AAChC,OAAO,oBAAoB,CAAC;AAC5B,OAAO,kCAAkC,CAAC;AAG1C,OAAO,mCAAmC,CAAC;AAG3C,QAAA,MAAM,OAAO,EAAE,MAAM,CACnB,MAAM,EACN;IACE,SAAS,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC;CAC9C,CAKF,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-modules.d.ts","sourceRoot":"","sources":["../../src/presets/crypto-modules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"crypto-modules.d.ts","sourceRoot":"","sources":["../../src/presets/crypto-modules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAIrD,OAAO,8BAA8B,CAAC;AAEtC,OAAO,4CAA4C,CAAC;AACpD,OAAO,+BAA+B,CAAC;AACvC,OAAO,oCAAoC,CAAC;AAC5C,OAAO,2BAA2B,CAAC;AAEnC,QAAA,MAAM,OAAO,EAAE,MAAM,CACnB,MAAM,EACN;IACE,SAAS,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC;CAC9C,CAKF,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/plugins",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-alpha5",
|
|
4
4
|
"main": "lib/plugins-index.js",
|
|
5
5
|
"types": "lib/plugins-index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -76,47 +76,47 @@
|
|
|
76
76
|
"@redis/client": "^1.5.8",
|
|
77
77
|
"bip32": "^4.0.0",
|
|
78
78
|
"bitcoinjs-lib": "^6.1.6",
|
|
79
|
-
"ethers": "^6.13.
|
|
79
|
+
"ethers": "^6.13.4",
|
|
80
80
|
"express": "^4.x",
|
|
81
81
|
"memoizee": "^0.4.17",
|
|
82
82
|
"open": "^10.0.0",
|
|
83
83
|
"postfinancecheckout": "^4.1.1",
|
|
84
|
-
"stripe": "^
|
|
84
|
+
"stripe": "^17.2.1",
|
|
85
85
|
"tiny-secp256k1": "^2.2.3",
|
|
86
|
-
"twilio": "^5.3.
|
|
86
|
+
"twilio": "^5.3.5",
|
|
87
87
|
"web-push": "^3.6.3"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@redis/client": "^1.6.0",
|
|
91
|
-
"@types/node": "^22.
|
|
92
|
-
"@unchainedshop/api": "^3.0.0-
|
|
93
|
-
"@unchainedshop/core-delivery": "^3.0.0-
|
|
94
|
-
"@unchainedshop/core-enrollments": "^3.0.0-
|
|
95
|
-
"@unchainedshop/core-filters": "^3.0.0-
|
|
96
|
-
"@unchainedshop/core-messaging": "^3.0.0-
|
|
97
|
-
"@unchainedshop/core-orders": "^3.0.0-
|
|
98
|
-
"@unchainedshop/core-payment": "^3.0.0-
|
|
99
|
-
"@unchainedshop/core-products": "^3.0.0-
|
|
100
|
-
"@unchainedshop/core-quotations": "^3.0.0-
|
|
101
|
-
"@unchainedshop/core-warehousing": "^3.0.0-
|
|
102
|
-
"@unchainedshop/core-worker": "^3.0.0-
|
|
103
|
-
"@unchainedshop/events": "^3.0.0-
|
|
104
|
-
"@unchainedshop/file-upload": "^3.0.0-
|
|
105
|
-
"@unchainedshop/logger": "^3.0.0-
|
|
106
|
-
"@unchainedshop/utils": "^3.0.0-
|
|
91
|
+
"@types/node": "^22.8.1",
|
|
92
|
+
"@unchainedshop/api": "^3.0.0-alpha4",
|
|
93
|
+
"@unchainedshop/core-delivery": "^3.0.0-alpha4",
|
|
94
|
+
"@unchainedshop/core-enrollments": "^3.0.0-alpha4",
|
|
95
|
+
"@unchainedshop/core-filters": "^3.0.0-alpha4",
|
|
96
|
+
"@unchainedshop/core-messaging": "^3.0.0-alpha4",
|
|
97
|
+
"@unchainedshop/core-orders": "^3.0.0-alpha4",
|
|
98
|
+
"@unchainedshop/core-payment": "^3.0.0-alpha4",
|
|
99
|
+
"@unchainedshop/core-products": "^3.0.0-alpha4",
|
|
100
|
+
"@unchainedshop/core-quotations": "^3.0.0-alpha4",
|
|
101
|
+
"@unchainedshop/core-warehousing": "^3.0.0-alpha4",
|
|
102
|
+
"@unchainedshop/core-worker": "^3.0.0-alpha4",
|
|
103
|
+
"@unchainedshop/events": "^3.0.0-alpha4",
|
|
104
|
+
"@unchainedshop/file-upload": "^3.0.0-alpha4",
|
|
105
|
+
"@unchainedshop/logger": "^3.0.0-alpha4",
|
|
106
|
+
"@unchainedshop/utils": "^3.0.0-alpha4",
|
|
107
107
|
"bluebird": "^3.7.2",
|
|
108
108
|
"event-iterator": "^2.0.0",
|
|
109
|
-
"express": "^4.21.
|
|
109
|
+
"express": "^4.21.1",
|
|
110
110
|
"jest": "^29.7.0",
|
|
111
111
|
"JSONStream": "^1.3.5",
|
|
112
|
-
"minio": "^8.0.
|
|
112
|
+
"minio": "^8.0.2",
|
|
113
113
|
"node-sheets": "^1.2.0",
|
|
114
114
|
"nodemailer": "^6.9.15",
|
|
115
115
|
"open": "^10.1.0",
|
|
116
116
|
"postfinancecheckout": "^4.5.0",
|
|
117
117
|
"request": "^2.88.2",
|
|
118
118
|
"ts-jest": "^29.2.5",
|
|
119
|
-
"typescript": "^5.6.
|
|
119
|
+
"typescript": "^5.6.3",
|
|
120
120
|
"web-push": "^3.6.7",
|
|
121
121
|
"xml-js": "^1.6.11"
|
|
122
122
|
}
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
resolveExpirationDate,
|
|
11
11
|
IFileAdapter,
|
|
12
12
|
} from '@unchainedshop/file-upload';
|
|
13
|
-
import { UploadFileData } from '@unchainedshop/
|
|
13
|
+
import { UploadFileData } from '@unchainedshop/file-upload';
|
|
14
14
|
import sign from './sign.js';
|
|
15
15
|
|
|
16
16
|
const { ROOT_URL } = process.env;
|
|
@@ -2,7 +2,7 @@ import https from 'https';
|
|
|
2
2
|
import http, { OutgoingHttpHeaders } from 'http';
|
|
3
3
|
import { Readable } from 'stream';
|
|
4
4
|
import { URL } from 'url';
|
|
5
|
-
import { UploadFileData } from '@unchainedshop/
|
|
5
|
+
import { UploadFileData } from '@unchainedshop/file-upload';
|
|
6
6
|
import {
|
|
7
7
|
FileAdapter,
|
|
8
8
|
FileDirector,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IPaymentAdapter } from '@unchainedshop/core-payment';
|
|
2
2
|
import { PaymentAdapter, PaymentDirector, PaymentError } from '@unchainedshop/core-payment';
|
|
3
3
|
import { createLogger } from '@unchainedshop/logger';
|
|
4
|
-
import
|
|
4
|
+
import stripeClient, { createOrderPaymentIntent, createRegistrationIntent } from './stripe.js';
|
|
5
5
|
|
|
6
6
|
export * from './middleware.js';
|
|
7
7
|
|
|
@@ -38,6 +38,7 @@ const Stripe: IPaymentAdapter = {
|
|
|
38
38
|
...PaymentAdapter.actions(params),
|
|
39
39
|
|
|
40
40
|
configurationError() {
|
|
41
|
+
const stripe = stripeClient();
|
|
41
42
|
if (!stripe) {
|
|
42
43
|
return PaymentError.INCOMPLETE_CONFIGURATION;
|
|
43
44
|
}
|
|
@@ -54,11 +55,13 @@ const Stripe: IPaymentAdapter = {
|
|
|
54
55
|
},
|
|
55
56
|
|
|
56
57
|
validate: async ({ token }) => {
|
|
58
|
+
const stripe = stripeClient();
|
|
57
59
|
const paymentMethod = await stripe.paymentMethods.retrieve(token);
|
|
58
60
|
return !!paymentMethod;
|
|
59
61
|
},
|
|
60
62
|
|
|
61
63
|
register: async ({ setupIntentId }) => {
|
|
64
|
+
const stripe = stripeClient();
|
|
62
65
|
if (!setupIntentId) {
|
|
63
66
|
throw new Error('You have to provide a setupIntentId');
|
|
64
67
|
}
|
|
@@ -100,6 +103,7 @@ const Stripe: IPaymentAdapter = {
|
|
|
100
103
|
},
|
|
101
104
|
|
|
102
105
|
charge: async ({ paymentIntentId, paymentCredentials }) => {
|
|
106
|
+
const stripe = stripeClient();
|
|
103
107
|
if (!paymentIntentId && !paymentCredentials) {
|
|
104
108
|
throw new Error('You have to provide paymentIntentId or paymentCredentials');
|
|
105
109
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Context } from '@unchainedshop/api';
|
|
2
2
|
import { createLogger } from '@unchainedshop/logger';
|
|
3
|
-
import
|
|
3
|
+
import stripeClient from './stripe.js';
|
|
4
4
|
|
|
5
5
|
const logger = createLogger('unchained:core-payment:stripe:webhook');
|
|
6
6
|
|
|
@@ -16,6 +16,7 @@ export const stripeHandler = async (request, response) => {
|
|
|
16
16
|
let event;
|
|
17
17
|
|
|
18
18
|
try {
|
|
19
|
+
const stripe = stripeClient();
|
|
19
20
|
const sig = request.headers['stripe-signature'];
|
|
20
21
|
event = stripe.webhooks.constructEvent(request.body, sig, process.env.STRIPE_ENDPOINT_SECRET);
|
|
21
22
|
} catch (err) {
|
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
import { Order } from '@unchainedshop/core-orders';
|
|
2
2
|
import { OrderPayment } from '@unchainedshop/core-orders';
|
|
3
3
|
import { IOrderPricingSheet } from '@unchainedshop/core-orders';
|
|
4
|
-
import
|
|
4
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
5
|
+
import type { Stripe as StripeType } from 'stripe';
|
|
6
|
+
|
|
7
|
+
const logger = createLogger('unchained:core-payment:stripe');
|
|
5
8
|
|
|
6
9
|
const { STRIPE_SECRET, STRIPE_WEBHOOK_ENVIRONMENT, EMAIL_WEBSITE_NAME } = process.env;
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
apiVersion: '2024-06-20',
|
|
10
|
-
});
|
|
11
|
+
let stripe: StripeType;
|
|
11
12
|
|
|
12
|
-
const
|
|
13
|
+
export const initStripeClient = async () => {
|
|
14
|
+
const { default: Stripe } = await import('stripe');
|
|
15
|
+
|
|
16
|
+
stripe = new Stripe(STRIPE_SECRET, {
|
|
17
|
+
apiVersion: '2024-09-30.acacia',
|
|
18
|
+
});
|
|
19
|
+
return stripe;
|
|
20
|
+
};
|
|
13
21
|
|
|
14
|
-
|
|
22
|
+
initStripeClient().catch(logger.error);
|
|
23
|
+
|
|
24
|
+
export default function () {
|
|
25
|
+
return stripe;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const environment = STRIPE_WEBHOOK_ENVIRONMENT ?? null;
|
|
15
29
|
|
|
16
30
|
export const upsertCustomer = async ({ userId, name, email }): Promise<string> => {
|
|
17
31
|
try {
|
|
@@ -65,7 +79,7 @@ export const createRegistrationIntent = async (
|
|
|
65
79
|
options: Record<string, any> = {},
|
|
66
80
|
) => {
|
|
67
81
|
const customer = options?.customer || (await upsertCustomer({ userId, name, email }));
|
|
68
|
-
const description = `${descriptorPrefix || EMAIL_WEBSITE_NAME || 'Unchained'}
|
|
82
|
+
const description = `${descriptorPrefix || EMAIL_WEBSITE_NAME || 'Unchained'}`.trim();
|
|
69
83
|
|
|
70
84
|
const setupIntent = await stripe.setupIntents.create({
|
|
71
85
|
description,
|
|
@@ -101,8 +115,9 @@ export const createOrderPaymentIntent = async (
|
|
|
101
115
|
},
|
|
102
116
|
options: Record<string, any> = {},
|
|
103
117
|
) => {
|
|
104
|
-
const description = `${descriptorPrefix || EMAIL_WEBSITE_NAME || 'Unchained'}
|
|
118
|
+
const description = `${descriptorPrefix || EMAIL_WEBSITE_NAME || 'Unchained'}`.trim();
|
|
105
119
|
const customer = options?.customer || (await upsertCustomer({ userId, name, email }));
|
|
120
|
+
|
|
106
121
|
const { currency, amount } = pricing.total({ useNetPrice: false });
|
|
107
122
|
|
|
108
123
|
const paymentIntent = await stripe.paymentIntents.create({
|
package/src/plugins-index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ModuleInput, UnchainedCore } from '@unchainedshop/core';
|
|
2
1
|
import express from 'express';
|
|
2
|
+
import { UnchainedCore } from '@unchainedshop/core';
|
|
3
|
+
import { ModuleInput } from '@unchainedshop/mongodb';
|
|
3
4
|
|
|
4
5
|
import baseModules from './presets/base-modules.js';
|
|
5
6
|
import './presets/countries/ch.js';
|
|
@@ -2,17 +2,17 @@ import { HundredOff } from './discount-100-off.js';
|
|
|
2
2
|
|
|
3
3
|
describe('HundredOff', () => {
|
|
4
4
|
it('isManualAdditionAllowed', async () => {
|
|
5
|
-
let x
|
|
6
|
-
|
|
5
|
+
let x;
|
|
6
|
+
expect(await HundredOff.isManualAdditionAllowed(x)).toBeTruthy();
|
|
7
7
|
});
|
|
8
8
|
it('isManualRemovalAllowed', async () => {
|
|
9
|
-
|
|
9
|
+
expect(await HundredOff.isManualRemovalAllowed()).toBeTruthy();
|
|
10
10
|
});
|
|
11
11
|
it('isValidForSystemTriggering', async () => {
|
|
12
12
|
const context = {};
|
|
13
13
|
const actions = await HundredOff.actions({ context } as any);
|
|
14
14
|
expect(await actions.isValidForSystemTriggering()).toBeFalsy();
|
|
15
|
-
|
|
15
|
+
});
|
|
16
16
|
it('isValidForCodeTriggering', async () => {
|
|
17
17
|
const context = {};
|
|
18
18
|
const actions = await HundredOff.actions({ context } as any);
|
|
@@ -24,8 +24,14 @@ describe('HundredOff', () => {
|
|
|
24
24
|
const context = {};
|
|
25
25
|
const actions = await HundredOff.actions({ context } as any);
|
|
26
26
|
expect(
|
|
27
|
-
|
|
27
|
+
actions.discountForPricingAdapterKey({
|
|
28
|
+
pricingAdapterKey: 'shop.unchained.pricing.order-discount',
|
|
29
|
+
} as any),
|
|
28
30
|
).toEqual({ fixedRate: 10000 });
|
|
29
|
-
expect(
|
|
30
|
-
|
|
31
|
+
expect(
|
|
32
|
+
actions.discountForPricingAdapterKey({
|
|
33
|
+
pricingAdapterKey: 'shop.unchained.pricing.other-discount',
|
|
34
|
+
} as any),
|
|
35
|
+
).toBeNull();
|
|
36
|
+
});
|
|
31
37
|
});
|
|
@@ -5,31 +5,37 @@ describe('HalfPriceManual', () => {
|
|
|
5
5
|
let x;
|
|
6
6
|
expect(await HalfPriceManual.isManualAdditionAllowed(x)).toBeTruthy();
|
|
7
7
|
});
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
it('isManualRemovalAllowed', async () => {
|
|
10
10
|
expect(await HalfPriceManual.isManualRemovalAllowed()).toBeTruthy();
|
|
11
11
|
});
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
it('isValidForSystemTriggering', async () => {
|
|
14
14
|
const context = {};
|
|
15
15
|
const actions = await HalfPriceManual.actions({ context } as any);
|
|
16
16
|
expect(await actions.isValidForSystemTriggering()).toBeFalsy();
|
|
17
17
|
});
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
it('isValidForCodeTriggering', async () => {
|
|
20
20
|
const context = {};
|
|
21
21
|
const actions = await HalfPriceManual.actions({ context } as any);
|
|
22
22
|
expect(await actions.isValidForCodeTriggering({ code: 'HALFPRICE' })).toBeTruthy();
|
|
23
23
|
expect(await actions.isValidForCodeTriggering({ code: 'othercode' })).toBeFalsy();
|
|
24
24
|
});
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
it('discountForPricingAdapterKey', async () => {
|
|
27
27
|
const context = {};
|
|
28
28
|
const actions = await HalfPriceManual.actions({ context } as any);
|
|
29
29
|
expect(
|
|
30
|
-
actions.discountForPricingAdapterKey({
|
|
30
|
+
actions.discountForPricingAdapterKey({
|
|
31
|
+
pricingAdapterKey: 'shop.unchained.pricing.product-discount',
|
|
32
|
+
} as any),
|
|
31
33
|
).toEqual({ rate: 0.5 });
|
|
32
|
-
expect(
|
|
34
|
+
expect(
|
|
35
|
+
actions.discountForPricingAdapterKey({
|
|
36
|
+
pricingAdapterKey: 'shop.unchained.pricing.other-discount',
|
|
37
|
+
} as any),
|
|
38
|
+
).toBeNull();
|
|
33
39
|
});
|
|
34
40
|
|
|
35
41
|
it('Actions', async () => {
|
|
@@ -39,4 +45,4 @@ describe('HalfPriceManual', () => {
|
|
|
39
45
|
expect(typeof actions.isValidForCodeTriggering).toBe('function');
|
|
40
46
|
expect(typeof actions.discountForPricingAdapterKey).toBe('function');
|
|
41
47
|
});
|
|
42
|
-
});
|
|
48
|
+
});
|
|
@@ -13,10 +13,10 @@ describe('HalfPrice', () => {
|
|
|
13
13
|
const context = {
|
|
14
14
|
modules: {
|
|
15
15
|
users: {
|
|
16
|
-
findUserById: import.meta.jest.fn(() => Promise.resolve({ tags: ['half-price'] }))
|
|
17
|
-
}
|
|
16
|
+
findUserById: import.meta.jest.fn(() => Promise.resolve({ tags: ['half-price'] })),
|
|
17
|
+
},
|
|
18
18
|
},
|
|
19
|
-
order: { userId: 'user-id' }
|
|
19
|
+
order: { userId: 'user-id' },
|
|
20
20
|
};
|
|
21
21
|
const actions = await HalfPrice.actions({ context } as any);
|
|
22
22
|
expect(await actions.isValidForSystemTriggering()).toBeTruthy();
|
|
@@ -27,14 +27,22 @@ describe('HalfPrice', () => {
|
|
|
27
27
|
it('discountForPricingAdapterKey', async () => {
|
|
28
28
|
const context = {};
|
|
29
29
|
const actions = await HalfPrice.actions({ context } as any);
|
|
30
|
-
expect(
|
|
31
|
-
|
|
30
|
+
expect(
|
|
31
|
+
actions.discountForPricingAdapterKey({
|
|
32
|
+
pricingAdapterKey: 'shop.unchained.pricing.product-discount',
|
|
33
|
+
} as any),
|
|
34
|
+
).toEqual({ rate: 0.5 });
|
|
35
|
+
expect(
|
|
36
|
+
actions.discountForPricingAdapterKey({
|
|
37
|
+
pricingAdapterKey: 'shop.unchained.pricing.other-discount',
|
|
38
|
+
} as any),
|
|
39
|
+
).toBeNull();
|
|
32
40
|
});
|
|
33
41
|
|
|
34
42
|
it('isValidForCodeTriggering', async () => {
|
|
35
43
|
const context = {};
|
|
36
44
|
const actions = await HalfPrice.actions({ context } as any);
|
|
37
|
-
|
|
38
|
-
expect(await actions.isValidForCodeTriggering({code: ''})).toBeFalsy();
|
|
45
|
+
|
|
46
|
+
expect(await actions.isValidForCodeTriggering({ code: '' })).toBeFalsy();
|
|
39
47
|
});
|
|
40
48
|
});
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { DeliveryFreePrice } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
describe("DeliveryFreePrice", () => {
|
|
1
|
+
import { DeliveryFreePrice } from './free-delivery.js';
|
|
6
2
|
|
|
3
|
+
describe('DeliveryFreePrice', () => {
|
|
7
4
|
it('should return true', () => {
|
|
8
5
|
expect(DeliveryFreePrice.isActivatedFor(undefined as any)).toBeTruthy();
|
|
9
|
-
|
|
10
6
|
});
|
|
11
|
-
|
|
12
|
-
})
|
|
7
|
+
});
|
|
@@ -1,37 +1,36 @@
|
|
|
1
|
-
import { rangeMatcher } from
|
|
1
|
+
import { rangeMatcher } from '../enrollments/licensed.js';
|
|
2
2
|
|
|
3
3
|
describe('rangeMatcher', () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
4
|
+
const now = new Date();
|
|
5
|
+
|
|
6
|
+
const tomorrow = new Date();
|
|
7
|
+
tomorrow.setDate(tomorrow.getDate() + 1);
|
|
8
|
+
const tomorrowTimestamp = tomorrow.getTime();
|
|
9
|
+
const yesterday = new Date();
|
|
10
|
+
yesterday.setDate(yesterday.getDate() - 1);
|
|
11
|
+
const yesterdayTimestamp = yesterday.getTime();
|
|
12
|
+
|
|
13
|
+
it('matches correctly when the date is within the range', () => {
|
|
14
|
+
const range = { start: yesterday, end: tomorrow };
|
|
15
|
+
const matcher = rangeMatcher(now);
|
|
16
|
+
expect(matcher(range)).toBe(true);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('does not match when the date is before the start of the range', () => {
|
|
20
|
+
const range = { start: tomorrow, end: tomorrow };
|
|
21
|
+
const matcher = rangeMatcher(yesterday);
|
|
22
|
+
expect(matcher(range)).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('does not match when the date is after the end of the range', () => {
|
|
26
|
+
const range = { start: yesterday, end: yesterday };
|
|
27
|
+
const matcher = rangeMatcher(tomorrow);
|
|
28
|
+
expect(matcher(range)).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('matches correctly when the date is not provided', () => {
|
|
32
|
+
const range = { start: yesterdayTimestamp, end: tomorrowTimestamp };
|
|
33
|
+
const matcher = rangeMatcher();
|
|
34
|
+
expect(matcher(range)).toBe(true);
|
|
36
35
|
});
|
|
37
|
-
|
|
36
|
+
});
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { OrderDelivery } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
describe("OrderDelivery ", () => {
|
|
1
|
+
import { OrderDelivery } from './order-delivery.js';
|
|
5
2
|
|
|
3
|
+
describe('OrderDelivery ', () => {
|
|
6
4
|
it('isActivatedFor', () => {
|
|
7
5
|
expect(OrderDelivery.isActivatedFor({} as any)).toBeTruthy();
|
|
8
6
|
});
|
|
9
|
-
})
|
|
7
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { OrderDiscount } from
|
|
1
|
+
import { OrderDiscount } from './order-discount.js';
|
|
2
2
|
|
|
3
|
-
describe(
|
|
3
|
+
describe('OrderDelivery ', () => {
|
|
4
4
|
it('isActivatedFor', () => {
|
|
5
5
|
expect(OrderDiscount.isActivatedFor({} as any)).toBeTruthy();
|
|
6
6
|
});
|
|
7
|
-
})
|
|
7
|
+
});
|
|
@@ -1,101 +1,126 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
1
|
import { getTaxRate, isDeliveryAddressInSwitzerland } from './product-swiss-tax.js';
|
|
3
2
|
|
|
4
|
-
describe(
|
|
3
|
+
describe('ProductSwissTax', () => {
|
|
4
|
+
describe('getTaxRate', () => {
|
|
5
|
+
it('default rate', () => {
|
|
6
|
+
expect(
|
|
7
|
+
getTaxRate({
|
|
8
|
+
product: {} as any,
|
|
9
|
+
order: {} as any,
|
|
10
|
+
} as any),
|
|
11
|
+
).toBe(0.081);
|
|
12
|
+
});
|
|
5
13
|
|
|
14
|
+
it('reduced rate', () => {
|
|
15
|
+
expect(
|
|
16
|
+
getTaxRate({
|
|
17
|
+
product: {
|
|
18
|
+
tags: ['swiss-tax-category:reduced'],
|
|
19
|
+
},
|
|
20
|
+
order: {},
|
|
21
|
+
} as any),
|
|
22
|
+
).toBe(0.026);
|
|
23
|
+
});
|
|
6
24
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
25
|
+
it('special rate', () => {
|
|
26
|
+
expect(
|
|
27
|
+
getTaxRate({
|
|
28
|
+
product: {
|
|
29
|
+
tags: ['swiss-tax-category:special'],
|
|
30
|
+
},
|
|
31
|
+
order: {},
|
|
32
|
+
} as any),
|
|
33
|
+
).toBe(0.038);
|
|
34
|
+
});
|
|
14
35
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
36
|
+
it('default rate', () => {
|
|
37
|
+
expect(
|
|
38
|
+
getTaxRate({
|
|
39
|
+
product: {
|
|
40
|
+
tags: ['swiss-tax-category:default'],
|
|
41
|
+
},
|
|
42
|
+
order: {},
|
|
43
|
+
} as any),
|
|
44
|
+
).toBe(0.081);
|
|
45
|
+
});
|
|
22
46
|
});
|
|
23
47
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
48
|
+
describe('isDeliveryAddressInSwitzerland', () => {
|
|
49
|
+
const context = {
|
|
50
|
+
modules: {
|
|
51
|
+
orders: {
|
|
52
|
+
deliveries: {
|
|
53
|
+
findDelivery: import.meta.jest.fn(async ({ orderDeliveryId }) => {
|
|
54
|
+
if (orderDeliveryId === 'CH' || orderDeliveryId === 'LI')
|
|
55
|
+
return { context: { address: { countryCode: 'CH' } } };
|
|
56
|
+
if (orderDeliveryId === null) return { context: { address: null } };
|
|
57
|
+
return { context: { address: { countryCode: 'RT' } } };
|
|
58
|
+
}),
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
order: {
|
|
63
|
+
deliveryId: 'CH',
|
|
64
|
+
billingAddress: { countryCode: 'LI' },
|
|
65
|
+
},
|
|
66
|
+
country: 'CH',
|
|
67
|
+
};
|
|
68
|
+
it('Should return true when passed country code CH', async () => {
|
|
69
|
+
expect(
|
|
70
|
+
await isDeliveryAddressInSwitzerland({ ...context, country: 'ch', order: null } as any),
|
|
71
|
+
).toBe(true);
|
|
72
|
+
});
|
|
32
73
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
order: {} as any,
|
|
39
|
-
})).toBe(0.081);
|
|
40
|
-
});
|
|
74
|
+
it('Should return true when passed country code LI', async () => {
|
|
75
|
+
expect(
|
|
76
|
+
await isDeliveryAddressInSwitzerland({ ...context, country: 'LI', order: null } as any),
|
|
77
|
+
).toBe(true);
|
|
78
|
+
});
|
|
41
79
|
|
|
42
|
-
|
|
80
|
+
it('Should return false when country is neither CH nor LI and order is null', async () => {
|
|
81
|
+
expect(
|
|
82
|
+
await isDeliveryAddressInSwitzerland({ ...context, country: 'ET', order: null } as any),
|
|
83
|
+
).toBe(false);
|
|
84
|
+
});
|
|
43
85
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
order : {
|
|
60
|
-
deliveryId: 'CH',
|
|
61
|
-
billingAddress: {countryCode: 'LI'}
|
|
62
|
-
},
|
|
63
|
-
country: 'CH'
|
|
64
|
-
}
|
|
65
|
-
it('Should return true when passed country code CH', async () => {
|
|
66
|
-
expect(await isDeliveryAddressInSwitzerland({...context, country: 'ch', order: null})).toBe(true);
|
|
67
|
-
});
|
|
86
|
+
it('Order should take precedence over country parameter', async () => {
|
|
87
|
+
// not CH or LI order so returns false
|
|
88
|
+
expect(
|
|
89
|
+
await isDeliveryAddressInSwitzerland({
|
|
90
|
+
...context,
|
|
91
|
+
country: 'CH',
|
|
92
|
+
order: {
|
|
93
|
+
deliveryId: 'ET',
|
|
94
|
+
billingAddress: { countryCode: 'ET' },
|
|
95
|
+
},
|
|
96
|
+
} as any),
|
|
97
|
+
).toBe(false);
|
|
98
|
+
});
|
|
68
99
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
100
|
+
it('If order is not from CH and LI but billingAddress is, it should take precedence over country ', async () => {
|
|
101
|
+
expect(
|
|
102
|
+
await isDeliveryAddressInSwitzerland({
|
|
103
|
+
...context,
|
|
104
|
+
country: 'IT',
|
|
105
|
+
order: {
|
|
106
|
+
deliveryId: null,
|
|
107
|
+
billingAddress: { countryCode: 'CH' },
|
|
108
|
+
},
|
|
109
|
+
} as any),
|
|
110
|
+
).toBe(true);
|
|
111
|
+
});
|
|
76
112
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}})).toBe(true);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('Should return false if billingAddress is neither CH or LI and order does not have address', async () => {
|
|
93
|
-
expect(await isDeliveryAddressInSwitzerland({...context, country: null, order : {
|
|
94
|
-
deliveryId: null,
|
|
95
|
-
billingAddress: {countryCode: 'HH'}
|
|
96
|
-
}})).toBe(false);
|
|
113
|
+
it('Should return false if billingAddress is neither CH or LI and order does not have address', async () => {
|
|
114
|
+
expect(
|
|
115
|
+
await isDeliveryAddressInSwitzerland({
|
|
116
|
+
...context,
|
|
117
|
+
country: null,
|
|
118
|
+
order: {
|
|
119
|
+
deliveryId: null,
|
|
120
|
+
billingAddress: { countryCode: 'HH' },
|
|
121
|
+
},
|
|
122
|
+
} as any),
|
|
123
|
+
).toBe(false);
|
|
124
|
+
});
|
|
97
125
|
});
|
|
98
126
|
});
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
})
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { SwissTaxCategories } from
|
|
1
|
+
import { SwissTaxCategories } from './ch';
|
|
2
2
|
|
|
3
3
|
describe('SwissTaxCategories', () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
4
|
+
it('DEFAULT rate', () => {
|
|
5
|
+
expect(SwissTaxCategories.DEFAULT.rate(new Date(2023, 1, 1))).toBe(0.077);
|
|
6
|
+
expect(SwissTaxCategories.DEFAULT.rate(new Date(2024, 1, 1))).toBe(0.081);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('REDUCED rate', () => {
|
|
10
|
+
expect(SwissTaxCategories.REDUCED.rate(new Date(2023, 1, 1))).toBe(0.025);
|
|
11
|
+
expect(SwissTaxCategories.REDUCED.rate(new Date(2024, 1, 1))).toBe(0.026);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('SPECIAL rate', () => {
|
|
15
|
+
expect(SwissTaxCategories.SPECIAL.rate(new Date(2023, 1, 1))).toBe(0.037);
|
|
16
|
+
expect(SwissTaxCategories.SPECIAL.rate(new Date(2024, 1, 1))).toBe(0.038);
|
|
17
|
+
});
|
|
18
|
+
});
|