@unchainedshop/plugins 1.1.4 → 1.1.9

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.
Files changed (69) hide show
  1. package/lib/files/gridfs/gridfs-adapter.js +1 -1
  2. package/lib/files/gridfs/gridfs-adapter.js.map +1 -1
  3. package/lib/files/gridfs/gridfs-webhook.d.ts +2 -1
  4. package/lib/files/gridfs/gridfs-webhook.js +3 -3
  5. package/lib/files/gridfs/gridfs-webhook.js.map +1 -1
  6. package/lib/files/minio/minio-webhook.d.ts +2 -1
  7. package/lib/files/minio/minio-webhook.js +31 -29
  8. package/lib/files/minio/minio-webhook.js.map +1 -1
  9. package/lib/payment/apple-iap/adapter.d.ts +2 -1
  10. package/lib/payment/apple-iap/adapter.js +94 -92
  11. package/lib/payment/apple-iap/adapter.js.map +1 -1
  12. package/lib/payment/apple-iap/db/AppleTransactionsCollection.d.ts +2 -2
  13. package/lib/payment/apple-iap/index.d.ts +2 -1
  14. package/lib/payment/apple-iap/index.js +2 -1
  15. package/lib/payment/apple-iap/index.js.map +1 -1
  16. package/lib/payment/bity/adapter.d.ts +2 -1
  17. package/lib/payment/bity/adapter.js +50 -48
  18. package/lib/payment/bity/adapter.js.map +1 -1
  19. package/lib/payment/bity/db/BityCredentialsCollection.d.ts +2 -2
  20. package/lib/payment/bity/index.d.ts +2 -1
  21. package/lib/payment/bity/index.js +2 -1
  22. package/lib/payment/bity/index.js.map +1 -1
  23. package/lib/payment/cryptopay.d.ts +2 -1
  24. package/lib/payment/cryptopay.js +60 -58
  25. package/lib/payment/cryptopay.js.map +1 -1
  26. package/lib/payment/datatrans-v2/index.d.ts +2 -1
  27. package/lib/payment/datatrans-v2/index.js +2 -1
  28. package/lib/payment/datatrans-v2/index.js.map +1 -1
  29. package/lib/payment/datatrans-v2/middleware.d.ts +2 -1
  30. package/lib/payment/datatrans-v2/middleware.js +100 -98
  31. package/lib/payment/datatrans-v2/middleware.js.map +1 -1
  32. package/lib/payment/datatrans-v2/roundedAmountFromOrder.d.ts +0 -2
  33. package/lib/payment/paypal-checkout.js +1 -1
  34. package/lib/payment/paypal-checkout.js.map +1 -1
  35. package/lib/payment/postfinance-checkout/index.d.ts +2 -1
  36. package/lib/payment/postfinance-checkout/index.js +2 -1
  37. package/lib/payment/postfinance-checkout/index.js.map +1 -1
  38. package/lib/payment/postfinance-checkout/middleware.d.ts +2 -1
  39. package/lib/payment/postfinance-checkout/middleware.js +36 -34
  40. package/lib/payment/postfinance-checkout/middleware.js.map +1 -1
  41. package/lib/payment/postfinance-checkout/utils.d.ts +0 -1
  42. package/lib/payment/stripe.d.ts +2 -1
  43. package/lib/payment/stripe.js +63 -60
  44. package/lib/payment/stripe.js.map +1 -1
  45. package/lib/pricing/product-price-cryptopay.d.ts +2 -1
  46. package/lib/pricing/product-price-cryptopay.js +20 -18
  47. package/lib/pricing/product-price-cryptopay.js.map +1 -1
  48. package/lib/pricing/utils/cache.d.ts +1 -2
  49. package/lib/worker/ZombieKillerWorker.js.map +1 -1
  50. package/license +274 -0
  51. package/package.json +20 -19
  52. package/src/files/gridfs/gridfs-adapter.ts +1 -1
  53. package/src/files/gridfs/gridfs-webhook.js +42 -41
  54. package/src/files/minio/minio-webhook.js +34 -31
  55. package/src/payment/apple-iap/adapter.ts +113 -110
  56. package/src/payment/apple-iap/index.ts +2 -1
  57. package/src/payment/bity/adapter.ts +51 -49
  58. package/src/payment/bity/index.ts +2 -1
  59. package/src/payment/cryptopay.ts +69 -67
  60. package/src/payment/datatrans-v2/index.ts +3 -1
  61. package/src/payment/datatrans-v2/middleware.ts +130 -124
  62. package/src/payment/paypal-checkout.ts +1 -1
  63. package/src/payment/postfinance-checkout/index.ts +3 -1
  64. package/src/payment/postfinance-checkout/middleware.ts +42 -40
  65. package/src/payment/stripe.ts +82 -74
  66. package/src/pricing/product-price-cryptopay.ts +20 -18
  67. package/src/worker/ZombieKillerWorker.ts +5 -5
  68. package/tsconfig.build.json +13 -5
  69. package/lib/worker/MessageWorker.d.ts +0 -10
@@ -1,4 +1,4 @@
1
- import { useMiddlewareWithCurrentContext } from 'meteor/unchained:api';
1
+ import { useMiddlewareWithCurrentContext } from '@unchainedshop/api';
2
2
  import bodyParser from 'body-parser';
3
3
  import { createLogger } from '@unchainedshop/logger';
4
4
  import { Context } from '@unchainedshop/types/api';
@@ -17,131 +17,137 @@ const logger = createLogger('unchained:core-payment:datatrans');
17
17
 
18
18
  const { postUrl, cancelUrl, errorUrl, successUrl, returnUrl } = getPaths(true);
19
19
 
20
- useMiddlewareWithCurrentContext(
21
- postUrl,
22
- bodyParser.text({
23
- type: 'application/json',
24
- }),
25
- );
26
-
27
- useMiddlewareWithCurrentContext(cancelUrl, bodyParser.urlencoded({ extended: false }));
28
-
29
- useMiddlewareWithCurrentContext(errorUrl, bodyParser.urlencoded({ extended: false }));
30
-
31
- useMiddlewareWithCurrentContext(successUrl, bodyParser.urlencoded({ extended: false }));
32
-
33
- useMiddlewareWithCurrentContext(returnUrl, bodyParser.urlencoded({ extended: false }));
34
-
35
- useMiddlewareWithCurrentContext(postUrl, async (req, res) => {
36
- const resolvedContext = req.unchainedContext as Context;
37
- const { services, modules } = resolvedContext;
38
- const signature = req.headers['datatrans-signature'];
39
- if (req.method === 'POST' && signature) {
40
- const [rawTimestamp, rawHash] = signature.split(',');
41
- const [, hash] = rawHash.split('=');
42
- const [, timestamp] = rawTimestamp.split('=');
43
-
44
- const comparableSignature = generateSignature({
45
- security: DATATRANS_SECURITY,
46
- signKey: DATATRANS_SIGN2_KEY || DATATRANS_SIGN_KEY,
47
- })(timestamp, req.body);
48
-
49
- if (hash !== comparableSignature) {
50
- logger.error(`Datatrans Plugin: Hash mismatch: ${signature} / ${comparableSignature}`, req.body);
51
- res.writeHead(403);
52
- res.end('Hash mismatch');
53
- return;
54
- }
20
+ export default (app) => {
21
+ useMiddlewareWithCurrentContext(
22
+ app,
23
+ postUrl,
24
+ bodyParser.text({
25
+ type: 'application/json',
26
+ }),
27
+ );
28
+
29
+ useMiddlewareWithCurrentContext(app, cancelUrl, bodyParser.urlencoded({ extended: false }));
30
+
31
+ useMiddlewareWithCurrentContext(app, errorUrl, bodyParser.urlencoded({ extended: false }));
32
+
33
+ useMiddlewareWithCurrentContext(app, successUrl, bodyParser.urlencoded({ extended: false }));
34
+
35
+ useMiddlewareWithCurrentContext(app, returnUrl, bodyParser.urlencoded({ extended: false }));
36
+
37
+ useMiddlewareWithCurrentContext(app, postUrl, async (req, res) => {
38
+ const resolvedContext = req.unchainedContext as Context;
39
+ const { services, modules } = resolvedContext;
40
+ const signature = req.headers['datatrans-signature'];
41
+ if (req.method === 'POST' && signature) {
42
+ const [rawTimestamp, rawHash] = signature.split(',');
43
+ const [, hash] = rawHash.split('=');
44
+ const [, timestamp] = rawTimestamp.split('=');
45
+
46
+ const comparableSignature = generateSignature({
47
+ security: DATATRANS_SECURITY,
48
+ signKey: DATATRANS_SIGN2_KEY || DATATRANS_SIGN_KEY,
49
+ })(timestamp, req.body);
50
+
51
+ if (hash !== comparableSignature) {
52
+ logger.error(`Datatrans Plugin: Hash mismatch: ${signature} / ${comparableSignature}`, req.body);
53
+ res.writeHead(403);
54
+ res.end('Hash mismatch');
55
+ return;
56
+ }
55
57
 
56
- const transaction: StatusResponseSuccess = JSON.parse(req.body) as StatusResponseSuccess;
57
-
58
- if (transaction.status === 'authorized') {
59
- const userId = transaction.refno2;
60
- const referenceId = Buffer.from(transaction.refno, 'base64').toString('hex');
61
-
62
- try {
63
- if (transaction.type === 'card_check') {
64
- const paymentProviderId = referenceId;
65
- const paymentCredentials = await services.payment.registerPaymentCredentials(
66
- paymentProviderId,
67
- { transactionContext: { transactionId: transaction.transactionId } },
68
- { ...resolvedContext, userId },
69
- );
70
- logger.info(`Datatrans Webhook: Unchained registered payment credentials for ${userId}`, {
71
- userId,
72
- });
73
- res.writeHead(200);
74
- res.end(JSON.stringify(paymentCredentials));
58
+ const transaction: StatusResponseSuccess = JSON.parse(req.body) as StatusResponseSuccess;
59
+
60
+ if (transaction.status === 'authorized') {
61
+ const userId = transaction.refno2;
62
+ const referenceId = Buffer.from(transaction.refno, 'base64').toString('hex');
63
+
64
+ try {
65
+ if (transaction.type === 'card_check') {
66
+ const paymentProviderId = referenceId;
67
+ const paymentCredentials = await services.payment.registerPaymentCredentials(
68
+ paymentProviderId,
69
+ { transactionContext: { transactionId: transaction.transactionId } },
70
+ { ...resolvedContext, userId },
71
+ );
72
+ logger.info(`Datatrans Webhook: Unchained registered payment credentials for ${userId}`, {
73
+ userId,
74
+ });
75
+ res.writeHead(200);
76
+ res.end(JSON.stringify(paymentCredentials));
77
+ return;
78
+ }
79
+ if (transaction.type === 'payment') {
80
+ const orderPaymentId = referenceId;
81
+ const orderPayment = await modules.orders.payments.findOrderPayment({
82
+ orderPaymentId,
83
+ });
84
+ if (!orderPayment) throw new Error(`Order Payment with id ${orderPaymentId} not found`);
85
+
86
+ const order = await modules.orders.checkout(
87
+ orderPayment.orderId,
88
+ { paymentContext: { transactionId: transaction.transactionId } },
89
+ resolvedContext,
90
+ );
91
+ res.writeHead(200);
92
+ logger.info(
93
+ `Datatrans Webhook: Unchained confirmed checkout for order ${order.orderNumber}`,
94
+ {
95
+ orderId: order._id,
96
+ },
97
+ );
98
+ res.end(JSON.stringify(order));
99
+ return;
100
+ }
101
+ } catch (e) {
102
+ logger.error(`Datatrans Webhook: Unchained rejected to checkout with message`, e);
103
+ res.writeHead(500);
104
+ res.end(JSON.stringify(e));
75
105
  return;
76
106
  }
77
- if (transaction.type === 'payment') {
78
- const orderPaymentId = referenceId;
79
- const orderPayment = await modules.orders.payments.findOrderPayment({
80
- orderPaymentId,
81
- });
82
- if (!orderPayment) throw new Error(`Order Payment with id ${orderPaymentId} not found`);
83
-
84
- const order = await modules.orders.checkout(
85
- orderPayment.orderId,
86
- { paymentContext: { transactionId: transaction.transactionId } },
87
- resolvedContext,
88
- );
89
- res.writeHead(200);
90
- logger.info(`Datatrans Webhook: Unchained confirmed checkout for order ${order.orderNumber}`, {
91
- orderId: order._id,
92
- });
93
- res.end(JSON.stringify(order));
94
- return;
95
- }
96
- } catch (e) {
97
- logger.error(`Datatrans Webhook: Unchained rejected to checkout with message`, e);
98
- res.writeHead(500);
99
- res.end(JSON.stringify(e));
100
- return;
101
107
  }
102
108
  }
103
- }
104
- res.writeHead(404);
105
- res.end();
106
- });
107
-
108
- useMiddlewareWithCurrentContext(successUrl, async (req, res) => {
109
- if (req.method === 'GET') {
110
- const { datatransTrxId } = req.query;
111
- res.end(`Payment successful\nTransaction ID: ${datatransTrxId}`);
112
- return;
113
- }
114
- res.writeHead(404);
115
- res.end();
116
- });
117
-
118
- useMiddlewareWithCurrentContext(errorUrl, async (req, res) => {
119
- if (req.method === 'GET') {
120
- const { datatransTrxId } = req.query;
121
- res.end(`Payment error\nTransaction ID: ${datatransTrxId}`);
122
- return;
123
- }
124
- res.writeHead(404);
125
- res.end();
126
- });
127
-
128
- useMiddlewareWithCurrentContext(cancelUrl, async (req, res) => {
129
- if (req.method === 'GET') {
130
- const { datatransTrxId } = req.query;
131
- res.end(`Payment cancelled\nTransaction ID: ${datatransTrxId}`);
132
- return;
133
- }
134
- res.writeHead(404);
135
- res.end();
136
- });
137
-
138
- useMiddlewareWithCurrentContext(returnUrl, async (req, res) => {
139
- if (req.method === 'GET') {
140
- const { datatransTrxId } = req.query;
141
- res.end(
142
- `Secure Fields Payment authenticated\nTransaction ID: ${datatransTrxId}\nNeeds authorization`,
143
- );
144
- }
145
- res.writeHead(404);
146
- res.end();
147
- });
109
+ res.writeHead(404);
110
+ res.end();
111
+ });
112
+
113
+ useMiddlewareWithCurrentContext(app, successUrl, async (req, res) => {
114
+ if (req.method === 'GET') {
115
+ const { datatransTrxId } = req.query;
116
+ res.end(`Payment successful\nTransaction ID: ${datatransTrxId}`);
117
+ return;
118
+ }
119
+ res.writeHead(404);
120
+ res.end();
121
+ });
122
+
123
+ useMiddlewareWithCurrentContext(app, errorUrl, async (req, res) => {
124
+ if (req.method === 'GET') {
125
+ const { datatransTrxId } = req.query;
126
+ res.end(`Payment error\nTransaction ID: ${datatransTrxId}`);
127
+ return;
128
+ }
129
+ res.writeHead(404);
130
+ res.end();
131
+ });
132
+
133
+ useMiddlewareWithCurrentContext(app, cancelUrl, async (req, res) => {
134
+ if (req.method === 'GET') {
135
+ const { datatransTrxId } = req.query;
136
+ res.end(`Payment cancelled\nTransaction ID: ${datatransTrxId}`);
137
+ return;
138
+ }
139
+ res.writeHead(404);
140
+ res.end();
141
+ });
142
+
143
+ useMiddlewareWithCurrentContext(app, returnUrl, async (req, res) => {
144
+ if (req.method === 'GET') {
145
+ const { datatransTrxId } = req.query;
146
+ res.end(
147
+ `Secure Fields Payment authenticated\nTransaction ID: ${datatransTrxId}\nNeeds authorization`,
148
+ );
149
+ }
150
+ res.writeHead(404);
151
+ res.end();
152
+ });
153
+ };
@@ -2,7 +2,7 @@ import { IPaymentAdapter } from '@unchainedshop/types/payments';
2
2
  import { PaymentDirector, PaymentAdapter, PaymentError } from '@unchainedshop/core-payment';
3
3
  import { createLogger } from '@unchainedshop/logger';
4
4
 
5
- const checkoutNodeJssdk = require('@paypal/checkout-server-sdk'); // eslint-disable-line
5
+ import checkoutNodeJssdk from '@paypal/checkout-server-sdk'; // eslint-disable-line
6
6
 
7
7
  const logger = createLogger('unchained:core-payment');
8
8
 
@@ -17,9 +17,11 @@ import {
17
17
  voidTransaction,
18
18
  } from './api';
19
19
  import { orderIsPaid } from './utils';
20
- import './middleware';
20
+ import setupPostfinance from './middleware';
21
21
  import { CompletionModes, IntegrationModes, SignResponse } from './types';
22
22
 
23
+ export default setupPostfinance;
24
+
23
25
  const {
24
26
  PFCHECKOUT_SPACE_ID,
25
27
  PFCHECKOUT_USER_ID,
@@ -1,5 +1,5 @@
1
1
  import bodyParser from 'body-parser';
2
- import { useMiddlewareWithCurrentContext } from 'meteor/unchained:api';
2
+ import { useMiddlewareWithCurrentContext } from '@unchainedshop/api';
3
3
  import { Context } from '@unchainedshop/types/api';
4
4
  import { createLogger } from '@unchainedshop/logger';
5
5
  import { WebhookData } from './types';
@@ -9,46 +9,48 @@ const { PFCHECKOUT_WEBHOOK_PATH = '/graphql/postfinance-checkout' } = process.en
9
9
 
10
10
  const logger = createLogger('unchained:core-payment:postfinance-checkout');
11
11
 
12
- useMiddlewareWithCurrentContext(PFCHECKOUT_WEBHOOK_PATH, bodyParser.json());
12
+ export default (app) => {
13
+ useMiddlewareWithCurrentContext(app, PFCHECKOUT_WEBHOOK_PATH, bodyParser.json());
13
14
 
14
- useMiddlewareWithCurrentContext(PFCHECKOUT_WEBHOOK_PATH, async (req, res) => {
15
- const context = req.unchainedContext as Context;
16
- const data = req.body as WebhookData;
17
- if (data.listenerEntityTechnicalName === 'TransactionCompletion') {
18
- try {
19
- const transactionCompletion = await getTransactionCompletion(data.entityId as unknown as string);
20
- const transaction = await getTransaction(
21
- transactionCompletion.linkedTransaction as unknown as string,
22
- );
23
- const { orderPaymentId } = transaction.metaData as { orderPaymentId: string };
24
- const orderPayment = await context.modules.orders.payments.findOrderPayment({
25
- orderPaymentId,
26
- });
27
- if (!orderPayment) throw new Error('Order Payment not found');
28
- const order = await context.modules.orders.checkout(
29
- orderPayment.orderId,
30
- {
31
- paymentContext: {
32
- transactionId: transactionCompletion.linkedTransaction,
15
+ useMiddlewareWithCurrentContext(app, PFCHECKOUT_WEBHOOK_PATH, async (req, res) => {
16
+ const context = req.unchainedContext as Context;
17
+ const data = req.body as WebhookData;
18
+ if (data.listenerEntityTechnicalName === 'TransactionCompletion') {
19
+ try {
20
+ const transactionCompletion = await getTransactionCompletion(data.entityId as unknown as string);
21
+ const transaction = await getTransaction(
22
+ transactionCompletion.linkedTransaction as unknown as string,
23
+ );
24
+ const { orderPaymentId } = transaction.metaData as { orderPaymentId: string };
25
+ const orderPayment = await context.modules.orders.payments.findOrderPayment({
26
+ orderPaymentId,
27
+ });
28
+ if (!orderPayment) throw new Error('Order Payment not found');
29
+ const order = await context.modules.orders.checkout(
30
+ orderPayment.orderId,
31
+ {
32
+ paymentContext: {
33
+ transactionId: transactionCompletion.linkedTransaction,
34
+ },
33
35
  },
34
- },
35
- context,
36
- );
37
- logger.info(
38
- `PostFinance Checkout Webhook: Transaction ${transactionCompletion.linkedTransaction} marked order payment ID ${transaction.metaData.orderPaymentId} as paid`,
36
+ context,
37
+ );
38
+ logger.info(
39
+ `PostFinance Checkout Webhook: Transaction ${transactionCompletion.linkedTransaction} marked order payment ID ${transaction.metaData.orderPaymentId} as paid`,
40
+ );
41
+ res.writeHead(200);
42
+ res.end(`Order marked as paid: ${order.orderNumber}`);
43
+ } catch (e) {
44
+ logger.error(`PostFinance Checkout Webhook: Unchained rejected to checkout with message`, e);
45
+ res.writeHead(500);
46
+ res.end(JSON.stringify(e));
47
+ }
48
+ } else {
49
+ logger.error(
50
+ `PostFinance Checkout Webhook: Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`,
39
51
  );
40
- res.writeHead(200);
41
- res.end(`Order marked as paid: ${order.orderNumber}`);
42
- } catch (e) {
43
- logger.error(`PostFinance Checkout Webhook: Unchained rejected to checkout with message`, e);
44
- res.writeHead(500);
45
- res.end(JSON.stringify(e));
52
+ res.writeHead(404);
53
+ res.end();
46
54
  }
47
- } else {
48
- logger.error(
49
- `PostFinance Checkout Webhook: Received unknown listenerEntityTechnicalName ${data.listenerEntityTechnicalName}`,
50
- );
51
- res.writeHead(404);
52
- res.end();
53
- }
54
- });
55
+ });
56
+ };
@@ -1,19 +1,10 @@
1
1
  import { Context } from '@unchainedshop/types/api';
2
2
  import { IPaymentAdapter } from '@unchainedshop/types/payments';
3
3
  import bodyParser from 'body-parser';
4
- import { useMiddlewareWithCurrentContext } from 'meteor/unchained:api';
4
+ import { useMiddlewareWithCurrentContext } from '@unchainedshop/api';
5
5
  import { PaymentAdapter, PaymentDirector, PaymentError } from '@unchainedshop/core-payment';
6
6
  import { createLogger } from '@unchainedshop/logger';
7
7
 
8
- const logger = createLogger('unchained:core-payment:stripe');
9
-
10
- const {
11
- STRIPE_SECRET,
12
- STRIPE_ENDPOINT_SECRET,
13
- EMAIL_WEBSITE_NAME,
14
- STRIPE_WEBHOOK_PATH = '/graphql/stripe',
15
- } = process.env;
16
-
17
8
  /*
18
9
  Test Webhooks:
19
10
 
@@ -23,82 +14,99 @@ stripe listen --forward-to http://localhost:3000/graphql/stripe
23
14
  stripe trigger payment_intent.succeeded
24
15
  */
25
16
 
26
- const stripe = require('stripe')(STRIPE_SECRET); // eslint-disable-line
17
+ import createStripeClient from 'stripe';
18
+
19
+ const logger = createLogger('unchained:core-payment:stripe');
20
+
21
+ const {
22
+ STRIPE_SECRET,
23
+ STRIPE_ENDPOINT_SECRET,
24
+ EMAIL_WEBSITE_NAME,
25
+ STRIPE_WEBHOOK_PATH = '/graphql/stripe',
26
+ } = process.env;
27
+
28
+ const stripe = createStripeClient(STRIPE_SECRET);
27
29
 
28
- useMiddlewareWithCurrentContext(STRIPE_WEBHOOK_PATH, bodyParser.raw({ type: 'application/json' }));
30
+ export default (app) => {
31
+ useMiddlewareWithCurrentContext(
32
+ app,
33
+ STRIPE_WEBHOOK_PATH,
34
+ bodyParser.raw({ type: 'application/json' }),
35
+ );
29
36
 
30
- useMiddlewareWithCurrentContext(STRIPE_WEBHOOK_PATH, async (request, response) => {
31
- const sig = request.headers['stripe-signature'];
32
- const resolvedContext = request.unchainedContext as Context;
33
- const { modules, services } = resolvedContext;
37
+ useMiddlewareWithCurrentContext(app, STRIPE_WEBHOOK_PATH, async (request, response) => {
38
+ const sig = request.headers['stripe-signature'];
39
+ const resolvedContext = request.unchainedContext as Context;
40
+ const { modules, services } = resolvedContext;
34
41
 
35
- let event;
42
+ let event;
36
43
 
37
- try {
38
- event = stripe.webhooks.constructEvent(request.body, sig, STRIPE_ENDPOINT_SECRET);
39
- } catch (err) {
40
- response.writeHead(400);
41
- response.end(`Webhook Error: ${err.message}`);
42
- return;
43
- }
44
+ try {
45
+ event = stripe.webhooks.constructEvent(request.body, sig, STRIPE_ENDPOINT_SECRET);
46
+ } catch (err) {
47
+ response.writeHead(400);
48
+ response.end(`Webhook Error: ${err.message}`);
49
+ return;
50
+ }
44
51
 
45
- try {
46
- if (event.type === 'payment_intent.succeeded') {
47
- const paymentIntent = event.data.object;
48
- const orderPaymentId = paymentIntent.metadata?.orderPaymentId;
52
+ try {
53
+ if (event.type === 'payment_intent.succeeded') {
54
+ const paymentIntent = event.data.object;
55
+ const orderPaymentId = paymentIntent.metadata?.orderPaymentId;
49
56
 
50
- await modules.orders.payments.logEvent(orderPaymentId, event, resolvedContext.userId);
57
+ await modules.orders.payments.logEvent(orderPaymentId, event, resolvedContext.userId);
51
58
 
52
- const orderPayment = await modules.orders.payments.findOrderPayment({
53
- orderPaymentId,
54
- });
59
+ const orderPayment = await modules.orders.payments.findOrderPayment({
60
+ orderPaymentId,
61
+ });
55
62
 
56
- const order = await modules.orders.checkout(
57
- orderPayment.orderId,
58
- {
59
- transactionContext: {
60
- paymentIntentId: paymentIntent.id,
61
- },
62
- paymentContext: {
63
- paymentIntentId: paymentIntent.id,
63
+ const order = await modules.orders.checkout(
64
+ orderPayment.orderId,
65
+ {
66
+ transactionContext: {
67
+ paymentIntentId: paymentIntent.id,
68
+ },
69
+ paymentContext: {
70
+ paymentIntentId: paymentIntent.id,
71
+ },
64
72
  },
65
- },
66
- resolvedContext,
67
- );
68
-
69
- logger.info(`Stripe Webhook: Unchained confirmed checkout for order ${order.orderNumber}`, {
70
- orderId: order._id,
71
- });
72
- } else if (event.type === 'setup_intent.succeeded') {
73
- const setupIntent = event.data.object;
74
- const { paymentProviderId, userId } = setupIntent.metadata;
75
-
76
- await services.payment.registerPaymentCredentials(
77
- paymentProviderId,
78
- {
79
- transactionContext: {
80
- setupIntentId: setupIntent.id,
73
+ resolvedContext,
74
+ );
75
+
76
+ logger.info(`Stripe Webhook: Unchained confirmed checkout for order ${order.orderNumber}`, {
77
+ orderId: order._id,
78
+ });
79
+ } else if (event.type === 'setup_intent.succeeded') {
80
+ const setupIntent = event.data.object;
81
+ const { paymentProviderId, userId } = setupIntent.metadata;
82
+
83
+ await services.payment.registerPaymentCredentials(
84
+ paymentProviderId,
85
+ {
86
+ transactionContext: {
87
+ setupIntentId: setupIntent.id,
88
+ },
81
89
  },
82
- },
83
- resolvedContext,
84
- );
85
-
86
- logger.info(`Stripe Webhook: Unchained registered payment credentials for ${userId}`, {
87
- userId,
88
- });
89
- } else {
90
- response.writeHead(404);
91
- response.end();
90
+ resolvedContext,
91
+ );
92
+
93
+ logger.info(`Stripe Webhook: Unchained registered payment credentials for ${userId}`, {
94
+ userId,
95
+ });
96
+ } else {
97
+ response.writeHead(404);
98
+ response.end();
99
+ return;
100
+ }
101
+ } catch (err) {
102
+ response.writeHead(400);
103
+ response.end(`Webhook Error: ${err.message}`);
92
104
  return;
93
105
  }
94
- } catch (err) {
95
- response.writeHead(400);
96
- response.end(`Webhook Error: ${err.message}`);
97
- return;
98
- }
99
- // Return a 200 response to acknowledge receipt of the event
100
- response.end(JSON.stringify({ received: true }));
101
- });
106
+ // Return a 200 response to acknowledge receipt of the event
107
+ response.end(JSON.stringify({ received: true }));
108
+ });
109
+ };
102
110
 
103
111
  const createRegistrationIntent = async ({ userId, name, email, paymentProviderId }, options = {}) => {
104
112
  const customer = await stripe.customers.create({
@@ -1,25 +1,27 @@
1
1
  import { Context } from '@unchainedshop/types/api';
2
2
  import { ProductPriceRate } from '@unchainedshop/types/products.pricing';
3
3
  import bodyParser from 'body-parser';
4
- import { useMiddlewareWithCurrentContext } from 'meteor/unchained:api';
4
+ import { useMiddlewareWithCurrentContext } from '@unchainedshop/api';
5
5
 
6
6
  const { CRYPTOPAY_SECRET, CRYPTOPAY_PRICING_WEBHOOK_PATH = '/graphql/cryptopay-pricing' } = process.env;
7
7
 
8
- useMiddlewareWithCurrentContext(CRYPTOPAY_PRICING_WEBHOOK_PATH, bodyParser.json());
8
+ export default (app) => {
9
+ useMiddlewareWithCurrentContext(app, CRYPTOPAY_PRICING_WEBHOOK_PATH, bodyParser.json());
9
10
 
10
- useMiddlewareWithCurrentContext(CRYPTOPAY_PRICING_WEBHOOK_PATH, async (request, response) => {
11
- const resolvedContext = request.unchainedContext as Context;
12
- const { baseCurrency, token, rate, timestamp, secret } = request.body;
13
- if (secret !== CRYPTOPAY_SECRET) {
14
- response.end(JSON.stringify({ success: false }));
15
- return;
16
- }
17
- const rateData: ProductPriceRate = {
18
- baseCurrency,
19
- quoteCurrency: token,
20
- rate,
21
- timestamp,
22
- };
23
- const success = await resolvedContext.modules.products.prices.rates.updateRate(rateData);
24
- response.end(JSON.stringify({ success }));
25
- });
11
+ useMiddlewareWithCurrentContext(app, CRYPTOPAY_PRICING_WEBHOOK_PATH, async (request, response) => {
12
+ const resolvedContext = request.unchainedContext as Context;
13
+ const { baseCurrency, token, rate, timestamp, secret } = request.body;
14
+ if (secret !== CRYPTOPAY_SECRET) {
15
+ response.end(JSON.stringify({ success: false }));
16
+ return;
17
+ }
18
+ const rateData: ProductPriceRate = {
19
+ baseCurrency,
20
+ quoteCurrency: token,
21
+ rate,
22
+ timestamp,
23
+ };
24
+ const success = await resolvedContext.modules.products.prices.rates.updateRate(rateData);
25
+ response.end(JSON.stringify({ success }));
26
+ });
27
+ };
@@ -70,11 +70,11 @@ export const ZombieKillerWorker: IWorkerAdapter<
70
70
  const deletedFilesCount =
71
71
  fileIdsToRemove.length > 0
72
72
  ? await services.files.removeFiles(
73
- {
74
- fileIds: fileIdsToRemove,
75
- },
76
- unchainedAPI,
77
- )
73
+ {
74
+ fileIds: fileIdsToRemove,
75
+ },
76
+ unchainedAPI,
77
+ )
78
78
  : 0;
79
79
 
80
80
  // Return delete count