@unchainedshop/plugins 4.8.5 → 5.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -2
- package/lib/events/node-event-emitter.d.ts +3 -1
- package/lib/events/node-event-emitter.js +3 -3
- package/lib/files/gridfs/adapter.d.ts +2 -2
- package/lib/files/gridfs/adapter.js +2 -5
- package/lib/files/gridfs/index.d.ts +5 -4
- package/lib/files/gridfs/index.js +30 -3
- package/lib/files/minio/api.js +1 -2
- package/lib/files/minio/index.d.ts +4 -5
- package/lib/files/minio/index.js +18 -157
- package/lib/files/temp-upload/api.d.ts +2 -0
- package/lib/files/temp-upload/api.js +1 -2
- package/lib/payment/apple-iap/adapter.d.ts +2 -1
- package/lib/payment/apple-iap/adapter.js +2 -3
- package/lib/payment/apple-iap/api.js +1 -1
- package/lib/payment/apple-iap/index.d.ts +6 -4
- package/lib/payment/apple-iap/index.js +28 -3
- package/lib/payment/cryptopay/api.js +1 -1
- package/lib/payment/cryptopay/handle-webhook.js +2 -1
- package/lib/payment/cryptopay/index.d.ts +5 -4
- package/lib/payment/cryptopay/index.js +31 -3
- package/lib/payment/datatrans-v2/adapter.js +11 -3
- package/lib/payment/datatrans-v2/api/authorize.js +1 -1
- package/lib/payment/datatrans-v2/api/authorizeAuthenticated.js +1 -1
- package/lib/payment/datatrans-v2/api/cancel.js +1 -1
- package/lib/payment/datatrans-v2/api/init.js +1 -1
- package/lib/payment/datatrans-v2/api/secureFields.js +1 -1
- package/lib/payment/datatrans-v2/api/settle.js +1 -1
- package/lib/payment/datatrans-v2/api/status.js +1 -1
- package/lib/payment/datatrans-v2/api/validate.js +1 -1
- package/lib/payment/datatrans-v2/index.d.ts +4 -1
- package/lib/payment/datatrans-v2/index.js +17 -411
- package/lib/payment/payrexx/api/index.js +2 -2
- package/lib/payment/payrexx/api.js +1 -1
- package/lib/payment/payrexx/index.d.ts +4 -1
- package/lib/payment/payrexx/index.js +19 -158
- package/lib/payment/postfinance-checkout/index.d.ts +5 -0
- package/lib/payment/postfinance-checkout/index.js +25 -186
- package/lib/payment/saferpay/adapter.js +1 -2
- package/lib/payment/saferpay/index.d.ts +5 -4
- package/lib/payment/saferpay/index.js +29 -3
- package/lib/payment/stripe/index.d.ts +4 -1
- package/lib/payment/stripe/index.js +22 -116
- package/lib/payment/stripe/stripe.js +1 -4
- package/lib/presets/all.d.ts +1 -70
- package/lib/presets/all.js +41 -27
- package/lib/presets/base.d.ts +1 -25
- package/lib/presets/base.js +56 -25
- package/lib/presets/countries/ch.d.ts +1 -2
- package/lib/presets/countries/ch.js +7 -2
- package/lib/presets/crypto.d.ts +3 -7
- package/lib/presets/crypto.js +18 -7
- package/lib/worker/bulk-import/api.d.ts +2 -0
- package/lib/worker/bulk-import/api.js +1 -2
- package/lib/worker/bulkgate/adapter.js +1 -1
- package/lib/worker/twilio/adapter.js +1 -1
- package/lib/worker/update-coinbase-rates/adapter.js +3 -5
- package/package.json +25 -30
|
@@ -1,192 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { CompletionModes, IntegrationModes } from "./types.js";
|
|
6
|
-
import { LineItemType, TokenizationMode, TransactionCompletionBehavior, TransactionState, CreationEntityState, } from "./api-types.js";
|
|
7
|
-
const { PFCHECKOUT_SPACE_ID, PFCHECKOUT_USER_ID, PFCHECKOUT_SECRET, PFCHECKOUT_SUCCESS_URL, PFCHECKOUT_FAILED_URL, } = process.env;
|
|
8
|
-
const logger = createLogger('unchained:postfinance-checkout');
|
|
9
|
-
const newError = ({ code, message }) => {
|
|
10
|
-
const error = new Error(message);
|
|
11
|
-
error.name = `POSTFINANCE_${code}`;
|
|
12
|
-
return error;
|
|
13
|
-
};
|
|
14
|
-
const PostfinanceCheckout = {
|
|
15
|
-
...PaymentAdapter,
|
|
1
|
+
import { PostfinanceCheckout } from "./adapter.js";
|
|
2
|
+
import { postfinanceCheckoutWebhookHandler } from "./webhook.js";
|
|
3
|
+
const { PFCHECKOUT_WEBHOOK_PATH = '/payment/postfinance-checkout' } = process.env;
|
|
4
|
+
export const PostfinanceCheckoutPlugin = {
|
|
16
5
|
key: 'shop.unchained.payment.postfinance-checkout',
|
|
17
|
-
label: 'Postfinance Checkout',
|
|
6
|
+
label: 'Postfinance Checkout Payment Plugin',
|
|
18
7
|
version: '1.0.0',
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
return null;
|
|
38
|
-
},
|
|
39
|
-
isActive() {
|
|
40
|
-
if (adapter.configurationError() === null)
|
|
41
|
-
return true;
|
|
42
|
-
return false;
|
|
43
|
-
},
|
|
44
|
-
isPayLaterAllowed() {
|
|
45
|
-
return false;
|
|
46
|
-
},
|
|
47
|
-
async validate(credentials) {
|
|
48
|
-
if (!credentials.meta)
|
|
49
|
-
return false;
|
|
50
|
-
const { linkedSpaceId } = credentials.meta;
|
|
51
|
-
const tokenData = await getToken(linkedSpaceId, credentials.token);
|
|
52
|
-
return tokenData.state === CreationEntityState.ACTIVE;
|
|
53
|
-
},
|
|
54
|
-
sign: async (transactionContext = {}) => {
|
|
55
|
-
const { orderPayment, order } = context;
|
|
56
|
-
if (!order)
|
|
57
|
-
throw new Error('No order in context, can only sign with order context');
|
|
58
|
-
if (!orderPayment)
|
|
59
|
-
throw new Error('No order payment in context, can only sign with order payment context');
|
|
60
|
-
const { integrationMode = IntegrationModes.PaymentPage } = transactionContext;
|
|
61
|
-
const completionMode = adapter.getCompletionMode();
|
|
62
|
-
const pricing = OrderPricingSheet({
|
|
63
|
-
calculation: order.calculation,
|
|
64
|
-
currencyCode: order.currencyCode,
|
|
65
|
-
});
|
|
66
|
-
const totalAmount = pricing?.total({ useNetPrice: false }).amount;
|
|
67
|
-
const transaction = {
|
|
68
|
-
currency: order.currencyCode,
|
|
69
|
-
metaData: {
|
|
70
|
-
orderPaymentId: orderPayment._id,
|
|
71
|
-
},
|
|
72
|
-
successUrl: `${transactionContext?.successUrl || PFCHECKOUT_SUCCESS_URL}?order_id=${orderPayment.orderId}`,
|
|
73
|
-
failedUrl: `${transactionContext?.failedUrl || PFCHECKOUT_FAILED_URL}?order_id=${orderPayment.orderId}`,
|
|
74
|
-
customerId: order?.userId || context?.userId,
|
|
75
|
-
tokenizationMode: TokenizationMode.ALLOW_ONE_CLICK_PAYMENT,
|
|
76
|
-
};
|
|
77
|
-
if (completionMode === CompletionModes.Immediate) {
|
|
78
|
-
transaction.completionBehavior = TransactionCompletionBehavior.COMPLETE_IMMEDIATELY;
|
|
79
|
-
}
|
|
80
|
-
else if (completionMode === CompletionModes.Deferred) {
|
|
81
|
-
transaction.completionBehavior = TransactionCompletionBehavior.COMPLETE_DEFERRED;
|
|
82
|
-
}
|
|
83
|
-
if (totalAmount) {
|
|
84
|
-
const lineItemSum = {
|
|
85
|
-
name: `Bestellung ${orderPayment.orderId}`,
|
|
86
|
-
type: LineItemType.FEE,
|
|
87
|
-
quantity: 1,
|
|
88
|
-
uniqueId: orderPayment.orderId,
|
|
89
|
-
amountIncludingTax: totalAmount / 100,
|
|
90
|
-
};
|
|
91
|
-
transaction.lineItems = [lineItemSum];
|
|
92
|
-
}
|
|
93
|
-
const transactionId = await createTransaction(transaction);
|
|
94
|
-
if (!transactionId)
|
|
95
|
-
throw new Error('Could not create transaction');
|
|
96
|
-
let location = null;
|
|
97
|
-
if (integrationMode === IntegrationModes.PaymentPage) {
|
|
98
|
-
location = await getPaymentPageUrl(transactionId);
|
|
99
|
-
}
|
|
100
|
-
else if (integrationMode === IntegrationModes.Lightbox) {
|
|
101
|
-
location = await getLightboxJavascriptUrl(transactionId);
|
|
102
|
-
}
|
|
103
|
-
else if (integrationMode === IntegrationModes.iFrame) {
|
|
104
|
-
location = await getIframeJavascriptUrl(transactionId);
|
|
105
|
-
}
|
|
106
|
-
const res = {
|
|
107
|
-
transactionId,
|
|
108
|
-
location,
|
|
109
|
-
};
|
|
110
|
-
return JSON.stringify(res);
|
|
111
|
-
},
|
|
112
|
-
charge: async ({ transactionId, paymentCredentials, }) => {
|
|
113
|
-
if (paymentCredentials && !transactionId) {
|
|
114
|
-
throw new Error('Not implemented yet');
|
|
115
|
-
}
|
|
116
|
-
if (!transactionId)
|
|
117
|
-
return false;
|
|
118
|
-
const transaction = await getTransaction(transactionId);
|
|
119
|
-
if (!transaction) {
|
|
120
|
-
logger.error(`Transaction #${transactionId}: Transaction not found`);
|
|
121
|
-
throw newError({
|
|
122
|
-
code: `TRANSACTION_NOT_FOUND`,
|
|
123
|
-
message: 'Payment declined',
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
const { order, orderPayment } = context;
|
|
127
|
-
if (!orderPayment)
|
|
128
|
-
throw new Error('No order payment in context, cannot charge payment');
|
|
129
|
-
if (!order)
|
|
130
|
-
throw new Error('No order in context, can only sign with order context');
|
|
131
|
-
const isPaid = await orderIsPaid(order, transaction);
|
|
132
|
-
if (!isPaid) {
|
|
133
|
-
logger.error(`Transaction #${transactionId}: Invalid state / Amount incorrect`);
|
|
134
|
-
throw newError({
|
|
135
|
-
code: `STATE_${transaction.state?.toUpperCase()}`,
|
|
136
|
-
message: 'Invalid state / Amount incorrect',
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
if (transaction.metaData?.orderPaymentId !== orderPayment._id) {
|
|
140
|
-
logger.error(`Transaction #${transactionId}: Invalid state / Amount incorrect`);
|
|
141
|
-
throw newError({
|
|
142
|
-
code: `TRANSACTION_ALREADY_USED`,
|
|
143
|
-
message: 'Transaction already used in previous checkout',
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
const { id, ...tokenMeta } = transaction.token || {};
|
|
147
|
-
return {
|
|
148
|
-
transaction,
|
|
149
|
-
transactionId,
|
|
150
|
-
credentials: id && {
|
|
151
|
-
...tokenMeta,
|
|
152
|
-
token: id.toString(),
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
},
|
|
156
|
-
cancel: async () => {
|
|
157
|
-
const { orderPayment, order } = context;
|
|
158
|
-
if (!order)
|
|
159
|
-
throw new Error('No order in context, can only cancel with order context');
|
|
160
|
-
if (!orderPayment?.transactionId) {
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
const { transactionId } = orderPayment;
|
|
164
|
-
const transaction = await getTransaction(transactionId);
|
|
165
|
-
const refund = transaction.state === TransactionState.FULFILL;
|
|
166
|
-
const pricing = OrderPricingSheet({
|
|
167
|
-
calculation: order.calculation,
|
|
168
|
-
currencyCode: order.currencyCode,
|
|
169
|
-
});
|
|
170
|
-
const totalAmount = pricing?.total({ useNetPrice: false }).amount;
|
|
171
|
-
return ((refund && refundTransaction(transactionId, order._id, totalAmount / 100)) ||
|
|
172
|
-
voidTransaction(transactionId));
|
|
173
|
-
},
|
|
174
|
-
confirm: async () => {
|
|
175
|
-
const { orderPayment } = context;
|
|
176
|
-
if (!orderPayment?.transactionId) {
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
const { transactionId } = orderPayment;
|
|
180
|
-
const transaction = await getTransaction(transactionId);
|
|
181
|
-
if (transaction.state === TransactionState.AUTHORIZED) {
|
|
182
|
-
return confirmDeferredTransaction(transactionId);
|
|
183
|
-
}
|
|
184
|
-
return false;
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
return adapter;
|
|
8
|
+
adapters: [PostfinanceCheckout],
|
|
9
|
+
routes: [
|
|
10
|
+
{
|
|
11
|
+
path: PFCHECKOUT_WEBHOOK_PATH,
|
|
12
|
+
method: 'POST',
|
|
13
|
+
handler: postfinanceCheckoutWebhookHandler,
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
onRegister: () => {
|
|
17
|
+
const { PFCHECKOUT_SPACE_ID, PFCHECKOUT_USER_ID, PFCHECKOUT_SECRET, PFCHECKOUT_SUCCESS_URL, PFCHECKOUT_FAILED_URL, } = process.env;
|
|
18
|
+
if (!PFCHECKOUT_SPACE_ID ||
|
|
19
|
+
!PFCHECKOUT_USER_ID ||
|
|
20
|
+
!PFCHECKOUT_SECRET ||
|
|
21
|
+
!PFCHECKOUT_SUCCESS_URL ||
|
|
22
|
+
!PFCHECKOUT_FAILED_URL) {
|
|
23
|
+
throw new Error('Postfinance Checkout environment variables not fully configured');
|
|
24
|
+
}
|
|
188
25
|
},
|
|
189
26
|
};
|
|
190
|
-
|
|
27
|
+
export default PostfinanceCheckoutPlugin;
|
|
28
|
+
export { PostfinanceCheckout } from "./adapter.js";
|
|
191
29
|
export * from "./types.js";
|
|
192
30
|
export * from "./api-types.js";
|
|
31
|
+
export * from "./utils.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mongodb } from '@unchainedshop/mongodb';
|
|
2
2
|
import { SaferpayClient } from "./api/index.js";
|
|
3
3
|
import { buildSignature } from "./buildSignature.js";
|
|
4
|
-
import { OrderPricingSheet, PaymentAdapter,
|
|
4
|
+
import { OrderPricingSheet, PaymentAdapter, PaymentError, } from '@unchainedshop/core';
|
|
5
5
|
const newSaferpayError = ({ code, message }) => {
|
|
6
6
|
const error = new Error(message || code);
|
|
7
7
|
error.name = `SAFERPAY_${code}`;
|
|
@@ -187,4 +187,3 @@ export const WordlineSaferpay = {
|
|
|
187
187
|
return adapter;
|
|
188
188
|
},
|
|
189
189
|
};
|
|
190
|
-
PaymentDirector.registerAdapter(WordlineSaferpay);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
import type { IPlugin } from '@unchainedshop/core';
|
|
2
|
+
export declare const SaferpayPlugin: IPlugin;
|
|
3
|
+
export default SaferpayPlugin;
|
|
4
|
+
export { WordlineSaferpay } from './adapter.ts';
|
|
5
|
+
export { type SaferpayTransactionsModule } from './module.ts';
|
|
@@ -1,3 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { WordlineSaferpay } from "./adapter.js";
|
|
2
|
+
import saferpayModules from "./module.js";
|
|
3
|
+
import { saferpayWebhookHandler } from "./webhook.js";
|
|
4
|
+
const { SAFERPAY_WEBHOOK_PATH = '/payment/saferpay/webhook' } = process.env;
|
|
5
|
+
export const SaferpayPlugin = {
|
|
6
|
+
key: 'shop.unchained.payment.saferpay',
|
|
7
|
+
label: 'Wordline Saferpay Payment Plugin',
|
|
8
|
+
version: '1.0.0',
|
|
9
|
+
adapters: [WordlineSaferpay],
|
|
10
|
+
module: ({ db }) => ({
|
|
11
|
+
saferpayTransactions: saferpayModules.saferpayTransactions.configure({ db }),
|
|
12
|
+
}),
|
|
13
|
+
routes: [
|
|
14
|
+
{
|
|
15
|
+
path: SAFERPAY_WEBHOOK_PATH,
|
|
16
|
+
method: 'GET',
|
|
17
|
+
handler: saferpayWebhookHandler,
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
onRegister: () => {
|
|
21
|
+
const { SAFERPAY_CUSTOMER_ID, SAFERPAY_TERMINAL_ID, SAFERPAY_API_USER, SAFERPAY_API_PASSWORD } = process.env;
|
|
22
|
+
if (!SAFERPAY_CUSTOMER_ID || !SAFERPAY_TERMINAL_ID || !SAFERPAY_API_USER || !SAFERPAY_API_PASSWORD) {
|
|
23
|
+
throw new Error('Saferpay environment variables not fully configured');
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
export default SaferpayPlugin;
|
|
28
|
+
export { WordlineSaferpay } from "./adapter.js";
|
|
29
|
+
export {} from "./module.js";
|
|
@@ -1,122 +1,28 @@
|
|
|
1
1
|
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { Stripe } from "./adapter.js";
|
|
3
|
+
import { stripeWebhookHandler } from "./api.js";
|
|
4
|
+
const { STRIPE_WEBHOOK_PATH = '/payment/stripe/webhook' } = process.env;
|
|
4
5
|
const logger = createLogger('unchained:stripe');
|
|
5
|
-
const
|
|
6
|
-
...PaymentAdapter,
|
|
6
|
+
export const StripePlugin = {
|
|
7
7
|
key: 'shop.unchained.payment.stripe',
|
|
8
|
-
label: 'Stripe',
|
|
8
|
+
label: 'Stripe Payment Plugin',
|
|
9
9
|
version: '2.0.0',
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
name,
|
|
26
|
-
userId,
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
const adapterActions = {
|
|
30
|
-
...PaymentAdapter.actions(config, context),
|
|
31
|
-
configurationError() {
|
|
32
|
-
if (!stripe)
|
|
33
|
-
return PaymentError.INCOMPLETE_CONFIGURATION;
|
|
34
|
-
return null;
|
|
35
|
-
},
|
|
36
|
-
isActive: () => {
|
|
37
|
-
if (adapterActions.configurationError() === null)
|
|
38
|
-
return true;
|
|
39
|
-
return false;
|
|
40
|
-
},
|
|
41
|
-
isPayLaterAllowed() {
|
|
42
|
-
return false;
|
|
43
|
-
},
|
|
44
|
-
validate: async ({ token }) => {
|
|
45
|
-
const paymentMethod = await stripe.paymentMethods.retrieve(token);
|
|
46
|
-
return !!paymentMethod;
|
|
47
|
-
},
|
|
48
|
-
register: async ({ setupIntentId }) => {
|
|
49
|
-
if (!setupIntentId) {
|
|
50
|
-
throw new Error('You have to provide a setupIntentId');
|
|
51
|
-
}
|
|
52
|
-
const setupIntent = await stripe.setupIntents.retrieve(setupIntentId);
|
|
53
|
-
if (setupIntent.status === 'succeeded') {
|
|
54
|
-
return {
|
|
55
|
-
token: setupIntent.payment_method,
|
|
56
|
-
customer: setupIntent.customer,
|
|
57
|
-
payment_method_types: setupIntent.payment_method_types,
|
|
58
|
-
usage: setupIntent.usage,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
logger.warn('Registration declined', setupIntentId);
|
|
62
|
-
return null;
|
|
63
|
-
},
|
|
64
|
-
sign: async (transactionContext = {}) => {
|
|
65
|
-
const { orderPayment, order, paymentProvider } = context;
|
|
66
|
-
const { userId, name, email } = await assertUserData(order?.userId);
|
|
67
|
-
if (orderPayment) {
|
|
68
|
-
if (!order)
|
|
69
|
-
throw new Error('order not found in context');
|
|
70
|
-
const pricing = OrderPricingSheet({
|
|
71
|
-
calculation: order?.calculation,
|
|
72
|
-
currencyCode: order?.currencyCode,
|
|
73
|
-
});
|
|
74
|
-
const paymentIntent = await createOrderPaymentIntent({ userId, name, email, order, orderPayment, pricing, descriptorPrefix }, transactionContext);
|
|
75
|
-
return paymentIntent.client_secret;
|
|
76
|
-
}
|
|
77
|
-
const paymentIntent = await createRegistrationIntent({ userId, name, email, paymentProviderId: paymentProvider._id, descriptorPrefix }, transactionContext);
|
|
78
|
-
return paymentIntent.client_secret;
|
|
79
|
-
},
|
|
80
|
-
charge: async ({ paymentIntentId, paymentCredentials }) => {
|
|
81
|
-
if (!paymentIntentId && !paymentCredentials) {
|
|
82
|
-
throw new Error('You have to provide paymentIntentId or paymentCredentials');
|
|
83
|
-
}
|
|
84
|
-
const { order, orderPayment } = context;
|
|
85
|
-
if (!order)
|
|
86
|
-
throw new Error('order not found in context');
|
|
87
|
-
if (!orderPayment)
|
|
88
|
-
throw new Error('orderPayment not found in context');
|
|
89
|
-
const { userId, name, email } = await assertUserData(order?.userId);
|
|
90
|
-
const pricing = OrderPricingSheet({
|
|
91
|
-
calculation: order.calculation,
|
|
92
|
-
currencyCode: order.currencyCode,
|
|
93
|
-
});
|
|
94
|
-
const paymentIntentObject = paymentIntentId
|
|
95
|
-
? await stripe.paymentIntents.retrieve(paymentIntentId)
|
|
96
|
-
: await createOrderPaymentIntent({ userId, name, email, orderPayment, order, pricing, descriptorPrefix }, {
|
|
97
|
-
customer: paymentCredentials.meta?.customer,
|
|
98
|
-
confirm: true,
|
|
99
|
-
payment_method: paymentCredentials.token,
|
|
100
|
-
payment_method_types: paymentCredentials.meta?.payment_method_types,
|
|
101
|
-
});
|
|
102
|
-
const { currencyCode, amount } = pricing.total({ useNetPrice: false });
|
|
103
|
-
if (paymentIntentObject.currency !== currencyCode.toLowerCase() ||
|
|
104
|
-
paymentIntentObject.amount !== Math.round(amount)) {
|
|
105
|
-
throw new Error('The price has changed since the intent has been created');
|
|
106
|
-
}
|
|
107
|
-
if (paymentIntentObject.metadata?.orderPaymentId !== orderPayment?._id) {
|
|
108
|
-
throw new Error('The order payment is different from the initiating intent');
|
|
109
|
-
}
|
|
110
|
-
if (paymentIntentObject.status === 'succeeded') {
|
|
111
|
-
return paymentIntentObject;
|
|
112
|
-
}
|
|
113
|
-
logger.info('Charge postponed because paymentIntent has wrong status', {
|
|
114
|
-
orderPaymentId: paymentIntentObject.id,
|
|
115
|
-
});
|
|
116
|
-
return false;
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
return adapterActions;
|
|
10
|
+
adapters: [Stripe],
|
|
11
|
+
routes: [
|
|
12
|
+
{
|
|
13
|
+
path: STRIPE_WEBHOOK_PATH,
|
|
14
|
+
method: 'POST',
|
|
15
|
+
handler: stripeWebhookHandler,
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
onRegister: () => {
|
|
19
|
+
if (!process.env.STRIPE_SECRET) {
|
|
20
|
+
throw new Error('STRIPE_SECRET not set');
|
|
21
|
+
}
|
|
22
|
+
if (!process.env.STRIPE_ENDPOINT_SECRET) {
|
|
23
|
+
logger.warn('STRIPE_ENDPOINT_SECRET not set - webhooks will not work');
|
|
24
|
+
}
|
|
120
25
|
},
|
|
121
26
|
};
|
|
122
|
-
|
|
27
|
+
export default StripePlugin;
|
|
28
|
+
export { Stripe } from "./adapter.js";
|
|
@@ -3,10 +3,7 @@ const logger = createLogger('unchained:stripe');
|
|
|
3
3
|
const { STRIPE_SECRET, STRIPE_WEBHOOK_ENVIRONMENT, EMAIL_WEBSITE_NAME } = process.env;
|
|
4
4
|
export let stripe;
|
|
5
5
|
const environment = STRIPE_WEBHOOK_ENVIRONMENT ?? null;
|
|
6
|
-
if (
|
|
7
|
-
logger.warn('STRIPE_SECRET is not set, skipping initialization');
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
6
|
+
if (STRIPE_SECRET) {
|
|
10
7
|
try {
|
|
11
8
|
const { default: Stripe } = await import('stripe');
|
|
12
9
|
stripe = new Stripe(STRIPE_SECRET, {
|
package/lib/presets/all.d.ts
CHANGED
|
@@ -1,70 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import '../delivery/send-message.ts';
|
|
3
|
-
import '../delivery/stores.ts';
|
|
4
|
-
import '../payment/invoice-prepaid.ts';
|
|
5
|
-
import '../payment/paypal-checkout.ts';
|
|
6
|
-
import '../payment/stripe/index.ts';
|
|
7
|
-
import '../payment/postfinance-checkout/index.ts';
|
|
8
|
-
import '../payment/datatrans-v2/index.ts';
|
|
9
|
-
import '../payment/payrexx/index.ts';
|
|
10
|
-
import '../filters/strict-equal.ts';
|
|
11
|
-
import '../filters/local-search.ts';
|
|
12
|
-
import '../worker/twilio.ts';
|
|
13
|
-
import '../worker/bulkgate.ts';
|
|
14
|
-
import '../worker/budgetsms.ts';
|
|
15
|
-
import '../worker/push-notification.ts';
|
|
16
|
-
import '../worker/enrollment-order-generator.ts';
|
|
17
|
-
declare const modules: {
|
|
18
|
-
saferpayTransactions: {
|
|
19
|
-
configure: ({ db }: {
|
|
20
|
-
db: import("mongodb").Db;
|
|
21
|
-
}) => Promise<{
|
|
22
|
-
findTransactionById: (_id: import("bson").ObjectId) => Promise<import("mongodb").WithId<import("../payment/saferpay/db/SaferpayTransactionsCollection.ts").SaferpayTransaction> | null>;
|
|
23
|
-
createTransaction: (orderPaymentId: any) => Promise<import("bson").ObjectId>;
|
|
24
|
-
setToken: (_id: import("bson").ObjectId, token: string) => Promise<void>;
|
|
25
|
-
}>;
|
|
26
|
-
};
|
|
27
|
-
appleTransactions: {
|
|
28
|
-
configure: ({ db }: {
|
|
29
|
-
db: any;
|
|
30
|
-
}) => Promise<{
|
|
31
|
-
findTransactionById: (transactionIdentifier: string) => Promise<import("../payment/apple-iap/db/AppleTransactionsCollection.ts").AppleTransaction | null>;
|
|
32
|
-
createTransaction: (doc: Omit<import("../payment/apple-iap/db/AppleTransactionsCollection.ts").AppleTransaction, "_id" | "created"> & Pick<Partial<import("../payment/apple-iap/db/AppleTransactionsCollection.ts").AppleTransaction>, "_id" | "created">) => Promise<string>;
|
|
33
|
-
}>;
|
|
34
|
-
};
|
|
35
|
-
cryptopay: {
|
|
36
|
-
configure: ({ db }: {
|
|
37
|
-
db: any;
|
|
38
|
-
}) => {
|
|
39
|
-
getWalletAddress: (address: string, contract?: string) => Promise<import("../payment/cryptopay/db/CryptopayTransactions.ts").CryptopayTransaction | null>;
|
|
40
|
-
updateMostRecentBlock: (currencyCode: string, blockHeight: number) => Promise<void>;
|
|
41
|
-
updateWalletAddress: ({ address, blockHeight, amount, contract, currencyCode, decimals, }: {
|
|
42
|
-
address: string;
|
|
43
|
-
blockHeight: number;
|
|
44
|
-
amount: string | number;
|
|
45
|
-
contract?: string;
|
|
46
|
-
currencyCode: string;
|
|
47
|
-
decimals: number;
|
|
48
|
-
}) => Promise<import("../payment/cryptopay/db/CryptopayTransactions.ts").CryptopayTransaction>;
|
|
49
|
-
mapOrderPaymentToWalletAddress: ({ address, contract, currencyCode, orderPaymentId, }: {
|
|
50
|
-
address: string;
|
|
51
|
-
contract?: string;
|
|
52
|
-
currencyCode: string;
|
|
53
|
-
orderPaymentId: string;
|
|
54
|
-
}) => Promise<import("../payment/cryptopay/db/CryptopayTransactions.ts").CryptopayTransaction>;
|
|
55
|
-
getNextDerivationNumber: (currencyCode: string) => Promise<number>;
|
|
56
|
-
getWalletAddressesByOrderPaymentId: (orderPaymentId: string) => Promise<import("../payment/cryptopay/db/CryptopayTransactions.ts").CryptopayTransaction[]>;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
gridfsFileUploads: {
|
|
60
|
-
configure: ({ db }: {
|
|
61
|
-
db: any;
|
|
62
|
-
}) => {
|
|
63
|
-
createWriteStream: (directoryName: any, fileId: any, fileName: any, uploadOptions: import("mongodb").GridFSBucketWriteStream["options"]) => Promise<import("mongodb").GridFSBucketWriteStream>;
|
|
64
|
-
getFileInfo: (directoryName: any, fileId: any) => Promise<import("mongodb").GridFSFile | null>;
|
|
65
|
-
createReadStream: (directoryName: any, fileId: any) => Promise<import("mongodb").GridFSBucketReadStream>;
|
|
66
|
-
removeFileFromBucket: (directoryName: any, fileId: any) => Promise<void>;
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
export default modules;
|
|
1
|
+
export declare function registerAllPlugins(): void;
|
package/lib/presets/all.js
CHANGED
|
@@ -1,27 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "./
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import "../
|
|
6
|
-
import "../payment/
|
|
7
|
-
import "../payment/
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import "../payment/
|
|
11
|
-
import "../payment/
|
|
12
|
-
import "../payment/
|
|
13
|
-
import "../payment/
|
|
14
|
-
import "../filters/strict-equal.js";
|
|
15
|
-
import "../filters/local-search.js";
|
|
16
|
-
import "../worker/twilio.js";
|
|
17
|
-
import "../worker/bulkgate.js";
|
|
18
|
-
import "../worker/budgetsms.js";
|
|
19
|
-
import "../worker/push-notification.js";
|
|
20
|
-
import "../worker/enrollment-order-generator.js";
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
import { registerBasePlugins } from "./base.js";
|
|
2
|
+
import { registerCryptoPlugins } from "./crypto.js";
|
|
3
|
+
import { registerSwissTaxPlugins } from "./countries/ch.js";
|
|
4
|
+
import { pluginRegistry } from '@unchainedshop/core';
|
|
5
|
+
import { DatatransPlugin } from "../payment/datatrans-v2/index.js";
|
|
6
|
+
import { StripePlugin } from "../payment/stripe/index.js";
|
|
7
|
+
import { InvoicePrepaidPlugin } from "../payment/invoice-prepaid/index.js";
|
|
8
|
+
import { SendMessagePlugin } from "../delivery/send-message/index.js";
|
|
9
|
+
import { PickMupPlugin } from "../delivery/stores/index.js";
|
|
10
|
+
import { AppleIAPPlugin } from "../payment/apple-iap/index.js";
|
|
11
|
+
import { PayrexxPlugin } from "../payment/payrexx/index.js";
|
|
12
|
+
import { PostfinanceCheckoutPlugin } from "../payment/postfinance-checkout/index.js";
|
|
13
|
+
import { SaferpayPlugin } from "../payment/saferpay/index.js";
|
|
14
|
+
import { StrictQualFilterPlugin } from "../filters/strict-equal/index.js";
|
|
15
|
+
import { LocalSearchPlugin } from "../filters/local-search/index.js";
|
|
16
|
+
import { TwilioPlugin } from "../worker/twilio/index.js";
|
|
17
|
+
import { BulkGatePlugin } from "../worker/bulkgate/index.js";
|
|
18
|
+
import { BudgetSMSPlugin } from "../worker/budgetsms/index.js";
|
|
19
|
+
import { PushNotificationPlugin } from "../worker/push-notification/index.js";
|
|
20
|
+
import { EnrollmentOrderGeneratorPlugin } from "../worker/enrollment-order-generator/index.js";
|
|
21
|
+
export function registerAllPlugins() {
|
|
22
|
+
registerBasePlugins();
|
|
23
|
+
registerCryptoPlugins();
|
|
24
|
+
registerSwissTaxPlugins();
|
|
25
|
+
pluginRegistry.register(DatatransPlugin);
|
|
26
|
+
pluginRegistry.register(StripePlugin);
|
|
27
|
+
pluginRegistry.register(AppleIAPPlugin);
|
|
28
|
+
pluginRegistry.register(PayrexxPlugin);
|
|
29
|
+
pluginRegistry.register(PostfinanceCheckoutPlugin);
|
|
30
|
+
pluginRegistry.register(SaferpayPlugin);
|
|
31
|
+
pluginRegistry.register(InvoicePrepaidPlugin);
|
|
32
|
+
pluginRegistry.register(SendMessagePlugin);
|
|
33
|
+
pluginRegistry.register(PickMupPlugin);
|
|
34
|
+
pluginRegistry.register(StrictQualFilterPlugin);
|
|
35
|
+
pluginRegistry.register(LocalSearchPlugin);
|
|
36
|
+
pluginRegistry.register(TwilioPlugin);
|
|
37
|
+
pluginRegistry.register(BulkGatePlugin);
|
|
38
|
+
pluginRegistry.register(BudgetSMSPlugin);
|
|
39
|
+
pluginRegistry.register(PushNotificationPlugin);
|
|
40
|
+
pluginRegistry.register(EnrollmentOrderGeneratorPlugin);
|
|
41
|
+
}
|
package/lib/presets/base.d.ts
CHANGED
|
@@ -1,25 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import '../payment/invoice.ts';
|
|
3
|
-
import '../warehousing/store.ts';
|
|
4
|
-
import '../pricing/free-payment.ts';
|
|
5
|
-
import '../pricing/free-delivery.ts';
|
|
6
|
-
import '../pricing/order-items.ts';
|
|
7
|
-
import '../pricing/order-discount.ts';
|
|
8
|
-
import '../pricing/order-delivery.ts';
|
|
9
|
-
import '../pricing/order-payment.ts';
|
|
10
|
-
import '../pricing/product-catalog-price.ts';
|
|
11
|
-
import '../pricing/product-discount.ts';
|
|
12
|
-
import '../quotations/manual.ts';
|
|
13
|
-
import '../enrollments/licensed.ts';
|
|
14
|
-
import '../events/node-event-emitter.ts';
|
|
15
|
-
import '../worker/bulk-import.ts';
|
|
16
|
-
import '../worker/zombie-killer.ts';
|
|
17
|
-
import '../worker/message.ts';
|
|
18
|
-
import '../worker/external.ts';
|
|
19
|
-
import '../worker/http-request.ts';
|
|
20
|
-
import '../worker/heartbeat.ts';
|
|
21
|
-
import '../worker/email.ts';
|
|
22
|
-
import '../worker/error-notifications.ts';
|
|
23
|
-
import '../worker/bulk-export.ts';
|
|
24
|
-
import gridfsModules from '../files/gridfs/index.ts';
|
|
25
|
-
export default gridfsModules;
|
|
1
|
+
export declare function registerBasePlugins(): void;
|