@unchainedshop/plugins 3.1.11 → 4.0.0-rc.2
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/delivery/pick-mup.js +0 -2
- package/lib/delivery/pick-mup.js.map +1 -1
- package/lib/files/gridfs/module.d.ts +2 -2
- package/lib/files/gridfs/module.d.ts.map +1 -1
- package/lib/filters/local-search.d.ts.map +1 -1
- package/lib/filters/local-search.js +9 -2
- package/lib/filters/local-search.js.map +1 -1
- package/lib/payment/apple-iap/adapter.js +5 -12
- package/lib/payment/apple-iap/adapter.js.map +1 -1
- package/lib/payment/apple-iap/fix-periods.d.ts.map +1 -1
- package/lib/payment/apple-iap/fix-periods.js +3 -5
- package/lib/payment/apple-iap/fix-periods.js.map +1 -1
- package/lib/payment/apple-iap/handler-express.js +3 -3
- package/lib/payment/apple-iap/handler-express.js.map +1 -1
- package/lib/payment/apple-iap/handler-fastify.js +3 -3
- package/lib/payment/apple-iap/handler-fastify.js.map +1 -1
- package/lib/payment/apple-iap/module.d.ts +2 -2
- package/lib/payment/apple-iap/module.d.ts.map +1 -1
- package/lib/payment/braintree.js +3 -4
- package/lib/payment/braintree.js.map +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts +1 -2
- package/lib/payment/cryptopay/db/CryptopayTransactions.d.ts.map +1 -1
- package/lib/payment/cryptopay/db/CryptopayTransactions.js.map +1 -1
- package/lib/payment/cryptopay/de.d.ts +2 -0
- package/lib/payment/cryptopay/de.d.ts.map +1 -0
- package/lib/payment/cryptopay/de.js +10 -0
- package/lib/payment/cryptopay/de.js.map +1 -0
- package/lib/payment/cryptopay/denote-amount.d.ts +25 -0
- package/lib/payment/cryptopay/denote-amount.d.ts.map +1 -0
- package/lib/payment/cryptopay/denote-amount.js +31 -0
- package/lib/payment/cryptopay/denote-amount.js.map +1 -0
- package/lib/payment/cryptopay/derive-btc-address.d.ts +3 -0
- package/lib/payment/cryptopay/derive-btc-address.d.ts.map +1 -0
- package/lib/payment/cryptopay/derive-btc-address.js +39 -0
- package/lib/payment/cryptopay/derive-btc-address.js.map +1 -0
- package/lib/payment/cryptopay/derive-btc-address.test copy.d.ts +2 -0
- package/lib/payment/cryptopay/derive-btc-address.test copy.d.ts.map +1 -0
- package/lib/payment/cryptopay/derive-btc-address.test copy.js +10 -0
- package/lib/payment/cryptopay/derive-btc-address.test copy.js.map +1 -0
- package/lib/payment/cryptopay/derive-eth-address.d.ts +3 -0
- package/lib/payment/cryptopay/derive-eth-address.d.ts.map +1 -0
- package/lib/payment/cryptopay/derive-eth-address.js +32 -0
- package/lib/payment/cryptopay/derive-eth-address.js.map +1 -0
- package/lib/payment/cryptopay/handle-webhook.d.ts +26 -0
- package/lib/payment/cryptopay/handle-webhook.d.ts.map +1 -0
- package/lib/payment/cryptopay/handle-webhook.js +61 -0
- package/lib/payment/cryptopay/handle-webhook.js.map +1 -0
- package/lib/payment/cryptopay/handler-express.d.ts.map +1 -1
- package/lib/payment/cryptopay/handler-express.js +3 -56
- package/lib/payment/cryptopay/handler-express.js.map +1 -1
- package/lib/payment/cryptopay/handler-fastify.d.ts.map +1 -1
- package/lib/payment/cryptopay/handler-fastify.js +3 -55
- package/lib/payment/cryptopay/handler-fastify.js.map +1 -1
- package/lib/payment/cryptopay/module.d.ts +26 -26
- package/lib/payment/cryptopay/module.d.ts.map +1 -1
- package/lib/payment/cryptopay/module.js +26 -24
- package/lib/payment/cryptopay/module.js.map +1 -1
- package/lib/payment/cryptopay/plugin.d.ts.map +1 -1
- package/lib/payment/cryptopay/plugin.js +33 -79
- package/lib/payment/cryptopay/plugin.js.map +1 -1
- package/lib/payment/datatrans-v2/api/types.d.ts +41 -41
- package/lib/payment/datatrans-v2/api/types.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/getPaths.d.ts +2 -2
- package/lib/payment/datatrans-v2/getPaths.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/index.js +16 -14
- package/lib/payment/datatrans-v2/index.js.map +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts.map +1 -1
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js +3 -3
- package/lib/payment/datatrans-v2/roundedAmountFromOrder.js.map +1 -1
- package/lib/payment/paypal-checkout.js +1 -1
- package/lib/payment/paypal-checkout.js.map +1 -1
- package/lib/payment/payrexx/api/index.d.ts +2 -2
- package/lib/payment/payrexx/api/index.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.d.ts.map +1 -1
- package/lib/payment/payrexx/api/makeFetcher.js.map +1 -1
- package/lib/payment/payrexx/index.js +4 -4
- package/lib/payment/payrexx/index.js.map +1 -1
- package/lib/payment/payrexx/payrexx.js +2 -2
- package/lib/payment/payrexx/payrexx.js.map +1 -1
- package/lib/payment/postfinance-checkout/index.js +3 -5
- package/lib/payment/postfinance-checkout/index.js.map +1 -1
- package/lib/payment/postfinance-checkout/types.d.ts +4 -4
- package/lib/payment/postfinance-checkout/types.d.ts.map +1 -1
- package/lib/payment/postfinance-checkout/utils.js +2 -2
- package/lib/payment/postfinance-checkout/utils.js.map +1 -1
- package/lib/payment/saferpay/adapter.d.ts.map +1 -1
- package/lib/payment/saferpay/adapter.js +4 -6
- package/lib/payment/saferpay/adapter.js.map +1 -1
- package/lib/payment/saferpay/api/models/Transaction.d.ts +2 -2
- package/lib/payment/saferpay/api/models/Transaction.d.ts.map +1 -1
- package/lib/payment/saferpay/module.d.ts +2 -2
- package/lib/payment/saferpay/module.d.ts.map +1 -1
- package/lib/payment/stripe/index.js +5 -5
- package/lib/payment/stripe/index.js.map +1 -1
- package/lib/payment/stripe/stripe.js +3 -3
- package/lib/payment/stripe/stripe.js.map +1 -1
- package/lib/presets/all.d.ts +12 -12
- package/lib/presets/all.d.ts.map +1 -1
- package/lib/pricing/delivery-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/delivery-swiss-tax.js +2 -2
- package/lib/pricing/delivery-swiss-tax.js.map +1 -1
- package/lib/pricing/order-delivery.js +1 -1
- package/lib/pricing/order-delivery.js.map +1 -1
- package/lib/pricing/order-discount.js +3 -3
- package/lib/pricing/order-discount.js.map +1 -1
- package/lib/pricing/order-items-discount.js +1 -1
- package/lib/pricing/order-items-discount.js.map +1 -1
- package/lib/pricing/order-items.js +1 -1
- package/lib/pricing/order-items.js.map +1 -1
- package/lib/pricing/order-payment.js +1 -1
- package/lib/pricing/order-payment.js.map +1 -1
- package/lib/pricing/order-round.d.ts +1 -1
- package/lib/pricing/order-round.d.ts.map +1 -1
- package/lib/pricing/order-round.js +8 -8
- package/lib/pricing/order-round.js.map +1 -1
- package/lib/pricing/product-catalog-price.d.ts +0 -1
- package/lib/pricing/product-catalog-price.d.ts.map +1 -1
- package/lib/pricing/product-catalog-price.js +6 -18
- package/lib/pricing/product-catalog-price.js.map +1 -1
- package/lib/pricing/product-price-rateconversion.js +2 -2
- package/lib/pricing/product-price-rateconversion.js.map +1 -1
- package/lib/pricing/product-round.d.ts +1 -1
- package/lib/pricing/product-round.d.ts.map +1 -1
- package/lib/pricing/product-round.js +2 -2
- package/lib/pricing/product-round.js.map +1 -1
- package/lib/pricing/product-swiss-tax.d.ts +1 -1
- package/lib/pricing/product-swiss-tax.d.ts.map +1 -1
- package/lib/pricing/product-swiss-tax.js +2 -2
- package/lib/pricing/product-swiss-tax.js.map +1 -1
- package/lib/warehousing/eth-minter.js +2 -2
- package/lib/warehousing/eth-minter.js.map +1 -1
- package/lib/worker/bulk-import.js +1 -1
- package/lib/worker/bulk-import.js.map +1 -1
- package/lib/worker/enrollment-order-generator.js +1 -1
- package/lib/worker/enrollment-order-generator.js.map +1 -1
- package/lib/worker/error-notifications.d.ts +4 -4
- package/lib/worker/error-notifications.d.ts.map +1 -1
- package/lib/worker/message.d.ts +1 -1
- package/lib/worker/message.d.ts.map +1 -1
- package/lib/worker/sms.js +16 -16
- package/lib/worker/sms.js.map +1 -1
- package/lib/worker/update-coinbase-rates.js +1 -1
- package/lib/worker/update-coinbase-rates.js.map +1 -1
- package/lib/worker/update-ecb-rates.js.map +1 -1
- package/package.json +37 -53
- package/src/delivery/pick-mup.ts +0 -2
- package/src/files/gridfs/module.ts +2 -2
- package/src/filters/local-search.ts +11 -2
- package/src/payment/apple-iap/adapter.ts +6 -13
- package/src/payment/apple-iap/fix-periods.ts +4 -7
- package/src/payment/apple-iap/handler-express.ts +3 -3
- package/src/payment/apple-iap/handler-fastify.ts +3 -3
- package/src/payment/apple-iap/module.ts +2 -2
- package/src/payment/braintree.ts +3 -4
- package/src/payment/cryptopay/db/CryptopayTransactions.ts +1 -2
- package/src/payment/cryptopay/denote-amount.test.ts +28 -0
- package/src/payment/cryptopay/denote-amount.ts +29 -0
- package/src/payment/cryptopay/derive-btc-address.test.ts +22 -0
- package/src/payment/cryptopay/derive-btc-address.ts +48 -0
- package/src/payment/cryptopay/derive-eth-address.test.ts +22 -0
- package/src/payment/cryptopay/derive-eth-address.ts +38 -0
- package/src/payment/cryptopay/handle-webhook.ts +103 -0
- package/src/payment/cryptopay/handler-express.ts +3 -69
- package/src/payment/cryptopay/handler-fastify.ts +5 -70
- package/src/payment/cryptopay/module.ts +44 -40
- package/src/payment/cryptopay/plugin.ts +50 -87
- package/src/payment/cryptopay/readme.md +23 -1
- package/src/payment/datatrans-v2/api/types.ts +41 -41
- package/src/payment/datatrans-v2/getPaths.ts +2 -2
- package/src/payment/datatrans-v2/index.ts +17 -15
- package/src/payment/datatrans-v2/roundedAmountFromOrder.ts +4 -4
- package/src/payment/paypal-checkout.ts +1 -1
- package/src/payment/payrexx/api/index.ts +2 -2
- package/src/payment/payrexx/api/makeFetcher.ts +1 -1
- package/src/payment/payrexx/index.ts +4 -4
- package/src/payment/payrexx/payrexx.ts +2 -2
- package/src/payment/postfinance-checkout/index.ts +3 -5
- package/src/payment/postfinance-checkout/types.ts +6 -6
- package/src/payment/postfinance-checkout/utils.ts +2 -2
- package/src/payment/saferpay/adapter.ts +4 -6
- package/src/payment/saferpay/api/models/Transaction.ts +2 -2
- package/src/payment/saferpay/module.ts +2 -2
- package/src/payment/stripe/index.ts +5 -5
- package/src/payment/stripe/stripe.ts +3 -3
- package/src/pricing/delivery-swiss-tax.ts +6 -2
- package/src/pricing/order-delivery.ts +1 -1
- package/src/pricing/order-discount.ts +3 -3
- package/src/pricing/order-items-discount.ts +1 -1
- package/src/pricing/order-items.ts +1 -1
- package/src/pricing/order-payment.ts +1 -1
- package/src/pricing/order-round.ts +9 -9
- package/src/pricing/product-catalog-price.ts +6 -25
- package/src/pricing/product-price-rateconversion.ts +2 -2
- package/src/pricing/product-round.ts +3 -3
- package/src/pricing/product-swiss-tax.test.ts +6 -6
- package/src/pricing/product-swiss-tax.ts +2 -2
- package/src/warehousing/eth-minter.ts +2 -2
- package/src/worker/bulk-import.ts +1 -1
- package/src/worker/enrollment-order-generator.ts +3 -3
- package/src/worker/error-notifications.ts +4 -4
- package/src/worker/heartbeat.ts +2 -2
- package/src/worker/message.ts +1 -1
- package/src/worker/push-notification.ts +2 -2
- package/src/worker/sms.ts +19 -17
- package/src/worker/update-coinbase-rates.ts +3 -6
- package/src/worker/update-ecb-rates.ts +3 -3
- package/src/worker/BaseWorker.ts +0 -116
- package/src/worker/EventListenerWorker.ts +0 -61
- package/src/worker/FailedRescheduler.ts +0 -80
- package/src/worker/IntervalWorker.ts +0 -54
|
@@ -59,7 +59,7 @@ const Payrexx: IPaymentAdapter = {
|
|
|
59
59
|
// Order Checkout signing (One-time payment)
|
|
60
60
|
const pricing = OrderPricingSheet({
|
|
61
61
|
calculation: order.calculation,
|
|
62
|
-
|
|
62
|
+
currencyCode: order.currencyCode,
|
|
63
63
|
});
|
|
64
64
|
const gatewayObject = mapOrderDataToGatewayObject(
|
|
65
65
|
{ order, orderPayment, pricing },
|
|
@@ -183,9 +183,9 @@ const Payrexx: IPaymentAdapter = {
|
|
|
183
183
|
|
|
184
184
|
const pricing = OrderPricingSheet({
|
|
185
185
|
calculation: order.calculation,
|
|
186
|
-
|
|
186
|
+
currencyCode: order.currencyCode,
|
|
187
187
|
});
|
|
188
|
-
const {
|
|
188
|
+
const { currencyCode, amount } = pricing.total({ useNetPrice: false });
|
|
189
189
|
|
|
190
190
|
if (
|
|
191
191
|
// gatewayObject.status === 'authorized' || // authorized is only used for tokenization!
|
|
@@ -194,7 +194,7 @@ const Payrexx: IPaymentAdapter = {
|
|
|
194
194
|
) {
|
|
195
195
|
try {
|
|
196
196
|
if (
|
|
197
|
-
gatewayObject.currency !==
|
|
197
|
+
gatewayObject.currency !== currencyCode.toUpperCase() ||
|
|
198
198
|
gatewayObject.amount !== Math.round(amount)
|
|
199
199
|
) {
|
|
200
200
|
throw new Error('The price has changed since the intent has been created');
|
|
@@ -14,7 +14,7 @@ const getRedirects = () => {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export const mapOrderDataToGatewayObject = ({ order, orderPayment, pricing }, options = {}) => {
|
|
17
|
-
const {
|
|
17
|
+
const { currencyCode, amount } = pricing.total({ useNetPrice: false });
|
|
18
18
|
|
|
19
19
|
const customerData = {};
|
|
20
20
|
if (order.contact?.emailAddress) {
|
|
@@ -29,7 +29,7 @@ export const mapOrderDataToGatewayObject = ({ order, orderPayment, pricing }, op
|
|
|
29
29
|
|
|
30
30
|
const gatewayObject = {
|
|
31
31
|
amount: Math.round(amount),
|
|
32
|
-
currency:
|
|
32
|
+
currency: currencyCode.toUpperCase(),
|
|
33
33
|
purpose: encodeURIComponent(`${process.env.EMAIL_WEBSITE_NAME || 'Unchained'} #${order._id}`),
|
|
34
34
|
reservation: true,
|
|
35
35
|
skipResultPage: true,
|
|
@@ -66,9 +66,7 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
66
66
|
);
|
|
67
67
|
},
|
|
68
68
|
|
|
69
|
-
// eslint-disable-next-line
|
|
70
69
|
configurationError() {
|
|
71
|
-
// eslint-disable-line
|
|
72
70
|
if (
|
|
73
71
|
!PFCHECKOUT_SPACE_ID ||
|
|
74
72
|
!PFCHECKOUT_USER_ID ||
|
|
@@ -105,13 +103,13 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
105
103
|
const completionMode = adapter.getCompletionMode();
|
|
106
104
|
const pricing = OrderPricingSheet({
|
|
107
105
|
calculation: order.calculation,
|
|
108
|
-
|
|
106
|
+
currencyCode: order.currencyCode,
|
|
109
107
|
});
|
|
110
108
|
|
|
111
109
|
const totalAmount = pricing?.total({ useNetPrice: false }).amount;
|
|
112
110
|
const transaction = new PostFinanceCheckout.model.TransactionCreate();
|
|
113
111
|
const userId = order?.userId || context?.userId;
|
|
114
|
-
transaction.currency = order.
|
|
112
|
+
transaction.currency = order.currencyCode;
|
|
115
113
|
transaction.metaData = {
|
|
116
114
|
orderPaymentId: orderPayment._id,
|
|
117
115
|
};
|
|
@@ -219,7 +217,7 @@ const PostfinanceCheckout: IPaymentAdapter = {
|
|
|
219
217
|
const refund = transaction.state === PostFinanceCheckout.model.TransactionState.FULFILL;
|
|
220
218
|
const pricing = OrderPricingSheet({
|
|
221
219
|
calculation: order.calculation,
|
|
222
|
-
|
|
220
|
+
currencyCode: order.currencyCode,
|
|
223
221
|
});
|
|
224
222
|
|
|
225
223
|
const totalAmount = pricing?.total({ useNetPrice: false }).amount;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
export enum IntegrationModes {
|
|
1
|
+
export enum IntegrationModes {
|
|
2
2
|
PaymentPage = 'PaymentPage',
|
|
3
3
|
Lightbox = 'Lightbox',
|
|
4
4
|
iFrame = 'iFrame',
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
export enum CompletionModes {
|
|
7
|
+
export enum CompletionModes {
|
|
8
8
|
Immediate = 'Immediate',
|
|
9
9
|
Deferred = 'Deferred',
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export
|
|
12
|
+
export interface SignResponse {
|
|
13
13
|
transactionId: number;
|
|
14
14
|
location: string | null;
|
|
15
|
-
}
|
|
15
|
+
}
|
|
16
16
|
|
|
17
17
|
export type listenerEntityTechnicalNames = 'TransactionCompletion';
|
|
18
18
|
|
|
19
|
-
export
|
|
19
|
+
export interface WebhookData {
|
|
20
20
|
eventId: number;
|
|
21
21
|
entityId: number;
|
|
22
22
|
listenerEntityId: number;
|
|
@@ -24,4 +24,4 @@ export type WebhookData = {
|
|
|
24
24
|
spaceId: number;
|
|
25
25
|
webhookListenerId: number;
|
|
26
26
|
timestamp: string; // "YYYY-MM-DDTHH:MM:ss+0000", e.g. "2022-02-18T12:40:42+0000"
|
|
27
|
-
}
|
|
27
|
+
}
|
|
@@ -32,8 +32,8 @@ export const orderIsPaid = async (
|
|
|
32
32
|
): Promise<boolean> => {
|
|
33
33
|
const pricing = OrderPricingSheet({
|
|
34
34
|
calculation: order.calculation,
|
|
35
|
-
|
|
35
|
+
currencyCode: order.currencyCode,
|
|
36
36
|
});
|
|
37
37
|
const totalAmount = pricing.total({ useNetPrice: false }).amount / 100;
|
|
38
|
-
return transactionIsPaid(transaction, order.
|
|
38
|
+
return transactionIsPaid(transaction, order.currencyCode, totalAmount);
|
|
39
39
|
};
|
|
@@ -68,9 +68,7 @@ export const WordlineSaferpay: IPaymentAdapter = {
|
|
|
68
68
|
return config.find((item) => item.key === 'terminalId')?.value;
|
|
69
69
|
},
|
|
70
70
|
|
|
71
|
-
// eslint-disable-next-line
|
|
72
71
|
configurationError() {
|
|
73
|
-
// eslint-disable-line
|
|
74
72
|
if (
|
|
75
73
|
!SAFERPAY_BASE_URL ||
|
|
76
74
|
!SAFERPAY_CUSTOMER_ID ||
|
|
@@ -100,7 +98,7 @@ export const WordlineSaferpay: IPaymentAdapter = {
|
|
|
100
98
|
}
|
|
101
99
|
const pricing = OrderPricingSheet({
|
|
102
100
|
calculation: order.calculation,
|
|
103
|
-
|
|
101
|
+
currencyCode: order.currencyCode,
|
|
104
102
|
});
|
|
105
103
|
const totalAmount = pricing?.total({ useNetPrice: false }).amount;
|
|
106
104
|
|
|
@@ -115,7 +113,7 @@ export const WordlineSaferpay: IPaymentAdapter = {
|
|
|
115
113
|
Payment: {
|
|
116
114
|
Amount: {
|
|
117
115
|
Value: totalAmount.toString(),
|
|
118
|
-
CurrencyCode: order.
|
|
116
|
+
CurrencyCode: order.currencyCode,
|
|
119
117
|
},
|
|
120
118
|
OrderId: order._id,
|
|
121
119
|
Description: transactionContext.description || 'Bestellung',
|
|
@@ -160,7 +158,7 @@ export const WordlineSaferpay: IPaymentAdapter = {
|
|
|
160
158
|
}
|
|
161
159
|
const pricing = OrderPricingSheet({
|
|
162
160
|
calculation: order.calculation,
|
|
163
|
-
|
|
161
|
+
currencyCode: order.currencyCode,
|
|
164
162
|
});
|
|
165
163
|
const totalAmount = pricing.total({ useNetPrice: false }).amount;
|
|
166
164
|
|
|
@@ -176,7 +174,7 @@ export const WordlineSaferpay: IPaymentAdapter = {
|
|
|
176
174
|
const success =
|
|
177
175
|
!paymentPageAssert.ErrorMessage &&
|
|
178
176
|
paymentPageAssert.Transaction.Amount.Value === totalAmount.toString() &&
|
|
179
|
-
paymentPageAssert.Transaction.Amount.CurrencyCode === order.
|
|
177
|
+
paymentPageAssert.Transaction.Amount.CurrencyCode === order.currencyCode &&
|
|
180
178
|
(paymentPageAssert.Transaction.Status === 'AUTHORIZED' ||
|
|
181
179
|
paymentPageAssert.Transaction.Status === 'CAPTURED');
|
|
182
180
|
if (success) {
|
|
@@ -90,7 +90,7 @@ const Stripe: IPaymentAdapter = {
|
|
|
90
90
|
if (orderPayment) {
|
|
91
91
|
const pricing = OrderPricingSheet({
|
|
92
92
|
calculation: order.calculation,
|
|
93
|
-
|
|
93
|
+
currencyCode: order.currencyCode,
|
|
94
94
|
});
|
|
95
95
|
const { userId, name, email } = await getUserData(order?.userId);
|
|
96
96
|
const paymentIntent = await createOrderPaymentIntent(
|
|
@@ -121,7 +121,7 @@ const Stripe: IPaymentAdapter = {
|
|
|
121
121
|
const { userId, name, email } = await getUserData(order?.userId);
|
|
122
122
|
const pricing = OrderPricingSheet({
|
|
123
123
|
calculation: order.calculation,
|
|
124
|
-
|
|
124
|
+
currencyCode: order.currencyCode,
|
|
125
125
|
});
|
|
126
126
|
|
|
127
127
|
const paymentIntentObject = paymentIntentId
|
|
@@ -132,15 +132,15 @@ const Stripe: IPaymentAdapter = {
|
|
|
132
132
|
customer: paymentCredentials.meta?.customer,
|
|
133
133
|
confirm: true,
|
|
134
134
|
payment_method: paymentCredentials.token,
|
|
135
|
-
payment_method_types: paymentCredentials.meta?.payment_method_types,
|
|
135
|
+
payment_method_types: paymentCredentials.meta?.payment_method_types,
|
|
136
136
|
// payment_method_options: paymentCredentials.meta?.payment_method_options, // eslint-disable-line
|
|
137
137
|
},
|
|
138
138
|
);
|
|
139
139
|
|
|
140
|
-
const {
|
|
140
|
+
const { currencyCode, amount } = pricing.total({ useNetPrice: false });
|
|
141
141
|
|
|
142
142
|
if (
|
|
143
|
-
paymentIntentObject.currency !==
|
|
143
|
+
paymentIntentObject.currency !== currencyCode.toLowerCase() ||
|
|
144
144
|
paymentIntentObject.amount !== Math.round(amount)
|
|
145
145
|
) {
|
|
146
146
|
throw new Error('The price has changed since the intent has been created');
|
|
@@ -18,7 +18,7 @@ export const initStripeClient = async (): Promise<StripeType> => {
|
|
|
18
18
|
// @ts-ignore
|
|
19
19
|
const { default: Stripe } = await import('stripe');
|
|
20
20
|
stripe = new Stripe(STRIPE_SECRET, {
|
|
21
|
-
apiVersion: '2025-
|
|
21
|
+
apiVersion: '2025-05-28.basil',
|
|
22
22
|
});
|
|
23
23
|
return stripe;
|
|
24
24
|
};
|
|
@@ -122,11 +122,11 @@ export const createOrderPaymentIntent = async (
|
|
|
122
122
|
const description = `${descriptorPrefix || EMAIL_WEBSITE_NAME || 'Unchained'}`.trim();
|
|
123
123
|
const customer = options?.customer || (await upsertCustomer({ userId, name, email }));
|
|
124
124
|
|
|
125
|
-
const {
|
|
125
|
+
const { currencyCode, amount } = pricing.total({ useNetPrice: false });
|
|
126
126
|
|
|
127
127
|
const paymentIntent = await stripe.paymentIntents.create({
|
|
128
128
|
amount: Math.round(amount),
|
|
129
|
-
currency:
|
|
129
|
+
currency: currencyCode.toLowerCase(),
|
|
130
130
|
description,
|
|
131
131
|
statement_descriptor_suffix: `${order._id.substring(0, 4)}..${order._id.substring(order._id.length - 4)}`,
|
|
132
132
|
setup_future_usage: 'off_session', // Verify your integration in this guide by including this parameter
|
|
@@ -19,8 +19,12 @@ const getTaxRate = ({ order, provider }: { order?: Order; provider?: DeliveryPro
|
|
|
19
19
|
return taxCategory.rate(order?.ordered);
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
const isDeliveryAddressInSwitzerland = ({
|
|
23
|
-
|
|
22
|
+
const isDeliveryAddressInSwitzerland = ({
|
|
23
|
+
orderDelivery,
|
|
24
|
+
order,
|
|
25
|
+
countryCode: forceCountryCode = null,
|
|
26
|
+
}) => {
|
|
27
|
+
let countryCode = forceCountryCode?.toUpperCase().trim() || order.countryCode;
|
|
24
28
|
|
|
25
29
|
const address = orderDelivery?.context?.address || order?.billingAddress;
|
|
26
30
|
|
|
@@ -29,7 +29,7 @@ export const OrderDelivery: IOrderPricingAdapter = {
|
|
|
29
29
|
if (!orderDelivery) return null;
|
|
30
30
|
const pricing = DeliveryPricingSheet({
|
|
31
31
|
calculation: orderDelivery.calculation,
|
|
32
|
-
|
|
32
|
+
currencyCode: order.currencyCode,
|
|
33
33
|
});
|
|
34
34
|
const tax = pricing.taxSum();
|
|
35
35
|
const shipping = pricing.gross();
|
|
@@ -48,7 +48,7 @@ export const OrderDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
|
48
48
|
resolveRatioAndTaxDivisorForPricingSheet(
|
|
49
49
|
ProductPricingSheet({
|
|
50
50
|
calculation: orderPosition.calculation,
|
|
51
|
-
|
|
51
|
+
currencyCode: order.currencyCode,
|
|
52
52
|
quantity: orderPosition.quantity,
|
|
53
53
|
}),
|
|
54
54
|
totalAmountOfItems,
|
|
@@ -58,7 +58,7 @@ export const OrderDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
|
58
58
|
const deliveryShare = resolveRatioAndTaxDivisorForPricingSheet(
|
|
59
59
|
DeliveryPricingSheet({
|
|
60
60
|
calculation: orderDelivery.calculation || [],
|
|
61
|
-
|
|
61
|
+
currencyCode: order.currencyCode,
|
|
62
62
|
}),
|
|
63
63
|
totalAmountOfPaymentAndDelivery,
|
|
64
64
|
);
|
|
@@ -66,7 +66,7 @@ export const OrderDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
|
66
66
|
const paymentShare = resolveRatioAndTaxDivisorForPricingSheet(
|
|
67
67
|
PaymentPricingSheet({
|
|
68
68
|
calculation: orderPayment.calculation || [],
|
|
69
|
-
|
|
69
|
+
currencyCode: order.currencyCode,
|
|
70
70
|
}),
|
|
71
71
|
totalAmountOfPaymentAndDelivery,
|
|
72
72
|
);
|
|
@@ -42,7 +42,7 @@ const OrderItemsDiscount: IOrderPricingAdapter<OrderDiscountConfiguration> = {
|
|
|
42
42
|
resolveRatioAndTaxDivisorForPricingSheet(
|
|
43
43
|
ProductPricingSheet({
|
|
44
44
|
calculation: orderPosition.calculation,
|
|
45
|
-
|
|
45
|
+
currencyCode: order.currencyCode,
|
|
46
46
|
quantity: orderPosition.quantity,
|
|
47
47
|
}),
|
|
48
48
|
totalAmountOfItems,
|
|
@@ -30,7 +30,7 @@ const OrderItems: IOrderPricingAdapter = {
|
|
|
30
30
|
(current, orderPosition) => {
|
|
31
31
|
const pricing = ProductPricingSheet({
|
|
32
32
|
calculation: orderPosition.calculation,
|
|
33
|
-
|
|
33
|
+
currencyCode: order.currencyCode,
|
|
34
34
|
quantity: orderPosition.quantity,
|
|
35
35
|
});
|
|
36
36
|
const tax = pricing.taxSum();
|
|
@@ -30,7 +30,7 @@ const OrderPayment: IOrderPricingAdapter = {
|
|
|
30
30
|
|
|
31
31
|
const pricing = PaymentPricingSheet({
|
|
32
32
|
calculation: orderPayment.calculation,
|
|
33
|
-
|
|
33
|
+
currencyCode: order.currencyCode,
|
|
34
34
|
});
|
|
35
35
|
const tax = pricing.taxSum();
|
|
36
36
|
const paymentFees = pricing.gross();
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
|
|
8
8
|
interface PriceRoundSettings {
|
|
9
9
|
defaultPrecision: number;
|
|
10
|
-
roundTo: (value: number, precision: number,
|
|
10
|
+
roundTo: (value: number, precision: number, currencyCode: string) => number;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export const OrderPriceRound: IOrderPricingAdapter & {
|
|
@@ -39,11 +39,11 @@ export const OrderPriceRound: IOrderPricingAdapter & {
|
|
|
39
39
|
actions: (params) => {
|
|
40
40
|
const pricingAdapter = OrderPricingAdapter.actions(params);
|
|
41
41
|
|
|
42
|
-
const calculateDifference = (amount: number,
|
|
42
|
+
const calculateDifference = (amount: number, currencyCode: string) => {
|
|
43
43
|
const roundedAmount = OrderPriceRound.settings.roundTo(
|
|
44
44
|
amount,
|
|
45
45
|
OrderPriceRound.settings.defaultPrecision,
|
|
46
|
-
|
|
46
|
+
currencyCode,
|
|
47
47
|
);
|
|
48
48
|
return roundedAmount - amount;
|
|
49
49
|
};
|
|
@@ -52,7 +52,7 @@ export const OrderPriceRound: IOrderPricingAdapter & {
|
|
|
52
52
|
...pricingAdapter,
|
|
53
53
|
|
|
54
54
|
calculate: async () => {
|
|
55
|
-
const {
|
|
55
|
+
const { currencyCode } = params.context;
|
|
56
56
|
|
|
57
57
|
const { amount: deliveryAmount } = params.calculationSheet.total({
|
|
58
58
|
category: OrderPricingRowCategory.Delivery,
|
|
@@ -60,7 +60,7 @@ export const OrderPriceRound: IOrderPricingAdapter & {
|
|
|
60
60
|
});
|
|
61
61
|
if (deliveryAmount) {
|
|
62
62
|
pricingAdapter.resultSheet().addDelivery({
|
|
63
|
-
amount: calculateDifference(deliveryAmount,
|
|
63
|
+
amount: calculateDifference(deliveryAmount, currencyCode),
|
|
64
64
|
taxAmount: 0,
|
|
65
65
|
meta: {
|
|
66
66
|
adapter: OrderPriceRound.key,
|
|
@@ -74,7 +74,7 @@ export const OrderPriceRound: IOrderPricingAdapter & {
|
|
|
74
74
|
});
|
|
75
75
|
if (discountAmount) {
|
|
76
76
|
pricingAdapter.resultSheet().addDiscount({
|
|
77
|
-
amount: calculateDifference(discountAmount,
|
|
77
|
+
amount: calculateDifference(discountAmount, currencyCode),
|
|
78
78
|
taxAmount: 0,
|
|
79
79
|
meta: {
|
|
80
80
|
adapter: OrderPriceRound.key,
|
|
@@ -89,7 +89,7 @@ export const OrderPriceRound: IOrderPricingAdapter & {
|
|
|
89
89
|
});
|
|
90
90
|
if (itemsAmount) {
|
|
91
91
|
pricingAdapter.resultSheet().addItems({
|
|
92
|
-
amount: calculateDifference(itemsAmount,
|
|
92
|
+
amount: calculateDifference(itemsAmount, currencyCode),
|
|
93
93
|
taxAmount: 0,
|
|
94
94
|
meta: {
|
|
95
95
|
adapter: OrderPriceRound.key,
|
|
@@ -103,7 +103,7 @@ export const OrderPriceRound: IOrderPricingAdapter & {
|
|
|
103
103
|
});
|
|
104
104
|
if (paymentAmount) {
|
|
105
105
|
pricingAdapter.resultSheet().addPayment({
|
|
106
|
-
amount: calculateDifference(paymentAmount,
|
|
106
|
+
amount: calculateDifference(paymentAmount, currencyCode),
|
|
107
107
|
taxAmount: 0,
|
|
108
108
|
meta: {
|
|
109
109
|
adapter: OrderPriceRound.key,
|
|
@@ -115,7 +115,7 @@ export const OrderPriceRound: IOrderPricingAdapter & {
|
|
|
115
115
|
category: OrderPricingRowCategory.Taxes,
|
|
116
116
|
});
|
|
117
117
|
if (taxesAmount) {
|
|
118
|
-
const taxDifference = calculateDifference(taxesAmount,
|
|
118
|
+
const taxDifference = calculateDifference(taxesAmount, currencyCode);
|
|
119
119
|
pricingAdapter.resultSheet().calculation.push({
|
|
120
120
|
category: OrderPricingRowCategory.Taxes,
|
|
121
121
|
amount: taxDifference,
|
|
@@ -3,28 +3,6 @@ import {
|
|
|
3
3
|
ProductPricingAdapter,
|
|
4
4
|
IProductPricingAdapter,
|
|
5
5
|
} from '@unchainedshop/core';
|
|
6
|
-
import { resolveBestCurrency } from '@unchainedshop/utils';
|
|
7
|
-
import pMemoize from 'p-memoize';
|
|
8
|
-
import ExpiryMap from 'expiry-map';
|
|
9
|
-
|
|
10
|
-
const { NODE_ENV } = process.env;
|
|
11
|
-
|
|
12
|
-
const memoizeCache = new ExpiryMap(NODE_ENV === 'production' ? 1000 * 60 : 100); // Cached values expire after 10 seconds
|
|
13
|
-
|
|
14
|
-
export const resolveCurrency = pMemoize(
|
|
15
|
-
async (context) => {
|
|
16
|
-
const { country, currency: forcedCurrency, modules } = context;
|
|
17
|
-
const countryObject = await modules.countries.findCountry({ isoCode: country });
|
|
18
|
-
const currencies = await modules.currencies.findCurrencies({ includeInactive: false });
|
|
19
|
-
const currency =
|
|
20
|
-
forcedCurrency || resolveBestCurrency(countryObject.defaultCurrencyCode, currencies);
|
|
21
|
-
return currency;
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
cache: memoizeCache,
|
|
25
|
-
cacheKey: ([{ currency, country }]) => `${currency}-${country}`,
|
|
26
|
-
},
|
|
27
|
-
);
|
|
28
6
|
|
|
29
7
|
export const ProductPrice: IProductPricingAdapter = {
|
|
30
8
|
...ProductPricingAdapter,
|
|
@@ -45,9 +23,12 @@ export const ProductPrice: IProductPricingAdapter = {
|
|
|
45
23
|
...pricingAdapter,
|
|
46
24
|
|
|
47
25
|
calculate: async () => {
|
|
48
|
-
const { product,
|
|
49
|
-
const
|
|
50
|
-
|
|
26
|
+
const { product, countryCode, currencyCode, quantity, modules } = params.context;
|
|
27
|
+
const price = await modules.products.prices.price(product, {
|
|
28
|
+
countryCode,
|
|
29
|
+
currencyCode,
|
|
30
|
+
quantity,
|
|
31
|
+
});
|
|
51
32
|
if (price) {
|
|
52
33
|
const itemTotal = price.amount * quantity;
|
|
53
34
|
pricingAdapter.resultSheet().addItem({
|
|
@@ -23,7 +23,7 @@ export const ProductPriceRateConversion: IProductPricingAdapter = {
|
|
|
23
23
|
...pricingAdapter,
|
|
24
24
|
|
|
25
25
|
calculate: async () => {
|
|
26
|
-
const { product,
|
|
26
|
+
const { product, countryCode, quantity, currencyCode: targetCurrency } = params.context;
|
|
27
27
|
|
|
28
28
|
const { calculation = [] } = params.calculationSheet;
|
|
29
29
|
if (calculation?.length) {
|
|
@@ -33,7 +33,7 @@ export const ProductPriceRateConversion: IProductPricingAdapter = {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
const productPrice = await modules.products.prices.price(product, {
|
|
36
|
-
|
|
36
|
+
countryCode,
|
|
37
37
|
quantity,
|
|
38
38
|
});
|
|
39
39
|
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
|
|
7
7
|
interface PriceRoundSettings {
|
|
8
8
|
defaultPrecision: number;
|
|
9
|
-
roundTo: (value: number, precision: number,
|
|
9
|
+
roundTo: (value: number, precision: number, currencyCode: string) => number;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export const ProductRound: IProductPricingAdapter & {
|
|
@@ -41,7 +41,7 @@ export const ProductRound: IProductPricingAdapter & {
|
|
|
41
41
|
...pricingAdapter,
|
|
42
42
|
|
|
43
43
|
calculate: async () => {
|
|
44
|
-
const {
|
|
44
|
+
const { currencyCode } = params.context;
|
|
45
45
|
const { defaultPrecision, roundTo } = ProductRound.settings;
|
|
46
46
|
const { calculation = [] } = params.calculationSheet;
|
|
47
47
|
|
|
@@ -49,7 +49,7 @@ export const ProductRound: IProductPricingAdapter & {
|
|
|
49
49
|
pricingAdapter.resultSheet().resetCalculation(params.calculationSheet);
|
|
50
50
|
|
|
51
51
|
calculation.forEach((item) => {
|
|
52
|
-
const newAmount = roundTo(item.amount, defaultPrecision,
|
|
52
|
+
const newAmount = roundTo(item.amount, defaultPrecision, currencyCode);
|
|
53
53
|
pricingAdapter.resultSheet().calculation.push({
|
|
54
54
|
...item,
|
|
55
55
|
amount: newAmount,
|
|
@@ -70,25 +70,25 @@ describe('ProductSwissTax', () => {
|
|
|
70
70
|
deliveryId: 'CH',
|
|
71
71
|
billingAddress: { countryCode: 'LI' },
|
|
72
72
|
},
|
|
73
|
-
|
|
73
|
+
countryCode: 'CH',
|
|
74
74
|
};
|
|
75
75
|
it('Should return true when passed country code CH', async () => {
|
|
76
76
|
assert.strictEqual(
|
|
77
|
-
await isDeliveryAddressInSwitzerland({ ...context,
|
|
77
|
+
await isDeliveryAddressInSwitzerland({ ...context, countryCode: 'ch', order: null } as any),
|
|
78
78
|
true,
|
|
79
79
|
);
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
it('Should return true when passed country code LI', async () => {
|
|
83
83
|
assert.strictEqual(
|
|
84
|
-
await isDeliveryAddressInSwitzerland({ ...context,
|
|
84
|
+
await isDeliveryAddressInSwitzerland({ ...context, countryCode: 'LI', order: null } as any),
|
|
85
85
|
true,
|
|
86
86
|
);
|
|
87
87
|
});
|
|
88
88
|
|
|
89
89
|
it('Should return false when country is neither CH nor LI and order is null', async () => {
|
|
90
90
|
assert.strictEqual(
|
|
91
|
-
await isDeliveryAddressInSwitzerland({ ...context,
|
|
91
|
+
await isDeliveryAddressInSwitzerland({ ...context, countryCode: 'ET', order: null } as any),
|
|
92
92
|
false,
|
|
93
93
|
);
|
|
94
94
|
});
|
|
@@ -98,7 +98,7 @@ describe('ProductSwissTax', () => {
|
|
|
98
98
|
assert.strictEqual(
|
|
99
99
|
await isDeliveryAddressInSwitzerland({
|
|
100
100
|
...context,
|
|
101
|
-
|
|
101
|
+
countryCode: 'CH',
|
|
102
102
|
order: {
|
|
103
103
|
deliveryId: 'ET',
|
|
104
104
|
billingAddress: { countryCode: 'ET' },
|
|
@@ -112,7 +112,7 @@ describe('ProductSwissTax', () => {
|
|
|
112
112
|
assert.strictEqual(
|
|
113
113
|
await isDeliveryAddressInSwitzerland({
|
|
114
114
|
...context,
|
|
115
|
-
|
|
115
|
+
countryCode: 'IT',
|
|
116
116
|
order: {
|
|
117
117
|
deliveryId: null,
|
|
118
118
|
billingAddress: { countryCode: 'CH' },
|
|
@@ -24,10 +24,10 @@ export const getTaxRate = (context: ProductPricingAdapterContext) => {
|
|
|
24
24
|
|
|
25
25
|
export const isDeliveryAddressInSwitzerland = async ({
|
|
26
26
|
order,
|
|
27
|
-
|
|
27
|
+
countryCode: forceCountryCode,
|
|
28
28
|
modules,
|
|
29
29
|
}: ProductPricingAdapterContext & { modules: UnchainedCore['modules'] }) => {
|
|
30
|
-
let countryCode =
|
|
30
|
+
let countryCode = forceCountryCode?.toUpperCase().trim() || order.countryCode;
|
|
31
31
|
|
|
32
32
|
if (order) {
|
|
33
33
|
const orderDelivery = await modules.orders.deliveries.findDelivery({
|
|
@@ -119,12 +119,12 @@ const ETHMinter: IWarehousingAdapter = {
|
|
|
119
119
|
const url = signedUrl && (await modules.files.normalizeUrl(signedUrl, {}));
|
|
120
120
|
const text = await modules.products.texts.findLocalizedText({
|
|
121
121
|
productId: product._id,
|
|
122
|
-
locale: locale
|
|
122
|
+
locale: locale || systemLocale,
|
|
123
123
|
});
|
|
124
124
|
|
|
125
125
|
const name = `${text.title} #${chainTokenId}`;
|
|
126
126
|
|
|
127
|
-
const isDefaultLanguageActive = locale ? locale
|
|
127
|
+
const isDefaultLanguageActive = locale ? locale.language === systemLocale.language : true;
|
|
128
128
|
const localization = isDefaultLanguageActive
|
|
129
129
|
? {
|
|
130
130
|
uri: `${ROOT_URL}/erc-metadata/${product._id}/{locale}/${tokenId}.json`,
|
|
@@ -44,7 +44,7 @@ const streamPayloadToBulkImporter = async (
|
|
|
44
44
|
{ highWaterMark: 100, lowWaterMark: 5 },
|
|
45
45
|
);
|
|
46
46
|
|
|
47
|
-
for await (const event of eventIterator) {
|
|
47
|
+
for await (const event of eventIterator) {
|
|
48
48
|
await bulkImporter.prepare(event, unchainedAPI);
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
const generateOrder = async (
|
|
13
13
|
enrollment: Enrollment,
|
|
14
14
|
params: {
|
|
15
|
-
orderPositions:
|
|
16
|
-
} &
|
|
15
|
+
orderPositions: OrderPosition[];
|
|
16
|
+
} & Record<string, any>,
|
|
17
17
|
unchainedAPI: Pick<UnchainedCore, 'modules' | 'services'>,
|
|
18
18
|
) => {
|
|
19
19
|
if (!enrollment.payment || !enrollment.delivery) return null;
|
|
@@ -22,7 +22,7 @@ const generateOrder = async (
|
|
|
22
22
|
const { orderPositions, ...configuration } = params;
|
|
23
23
|
let order = await modules.orders.create({
|
|
24
24
|
userId: enrollment.userId,
|
|
25
|
-
|
|
25
|
+
currencyCode: enrollment.currencyCode,
|
|
26
26
|
countryCode: enrollment.countryCode,
|
|
27
27
|
contact: enrollment.contact,
|
|
28
28
|
billingAddress: enrollment.billingAddress,
|
|
@@ -2,13 +2,13 @@ import { WorkStatus } from '@unchainedshop/core-worker';
|
|
|
2
2
|
import { IWorkerAdapter, WorkerDirector, WorkerAdapter } from '@unchainedshop/core';
|
|
3
3
|
import later from '@breejs/later';
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
interface Arg {
|
|
6
6
|
secondsPassed?: number;
|
|
7
|
-
}
|
|
7
|
+
}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
interface Result {
|
|
10
10
|
forked?: string;
|
|
11
|
-
}
|
|
11
|
+
}
|
|
12
12
|
|
|
13
13
|
const everyDayAtFourInTheNight = later.parse.cron('0 3 * * *');
|
|
14
14
|
|