payment-kit 1.13.80 → 1.13.81
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/api/src/crons/index.ts +25 -20
- package/api/src/index.ts +3 -2
- package/api/src/integrations/stripe/handlers/payment-intent.ts +1 -1
- package/api/src/queues/event.ts +20 -9
- package/api/src/store/models/payment-intent.ts +2 -2
- package/api/third.d.ts +2 -0
- package/blocklet.yml +1 -1
- package/package.json +3 -3
- package/src/components/webhook/attempts.tsx +2 -2
- package/src/libs/util.ts +4 -0
package/api/src/crons/index.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
1
|
import Cron from '@abtnode/cron';
|
|
3
2
|
|
|
4
3
|
import { notificationCronTime } from '../libs/env';
|
|
@@ -6,23 +5,29 @@ import logger from '../libs/logger';
|
|
|
6
5
|
import { SubscriptionTrailWillEndSchedule } from './subscription-trail-will-end';
|
|
7
6
|
import { SubscriptionWillRenewSchedule } from './subscription-will-renew';
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
function init() {
|
|
9
|
+
Cron.init({
|
|
10
|
+
context: {},
|
|
11
|
+
jobs: [
|
|
12
|
+
{
|
|
13
|
+
name: 'subscription.will.renew',
|
|
14
|
+
time: notificationCronTime,
|
|
15
|
+
fn: () => new SubscriptionWillRenewSchedule().run(),
|
|
16
|
+
options: { runOnInit: true },
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'subscription.trial.will.end',
|
|
20
|
+
time: notificationCronTime,
|
|
21
|
+
fn: () => new SubscriptionTrailWillEndSchedule().run(),
|
|
22
|
+
options: { runOnInit: true },
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
onError: (error: Error, name: string) => {
|
|
26
|
+
logger.error('run job failed', { name, error: error.message, stack: error.stack });
|
|
17
27
|
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
],
|
|
25
|
-
onError: (error: Error, name: string) => {
|
|
26
|
-
logger.error('run job failed', { name, error: error.message, stack: error.stack });
|
|
27
|
-
},
|
|
28
|
-
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default {
|
|
32
|
+
init,
|
|
33
|
+
};
|
package/api/src/index.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import 'express-async-errors';
|
|
2
2
|
|
|
3
|
-
import './crons';
|
|
4
|
-
|
|
5
3
|
import path from 'path';
|
|
6
4
|
|
|
7
5
|
import fallback from '@blocklet/sdk/lib/middlewares/fallback';
|
|
@@ -11,6 +9,7 @@ import dotenv from 'dotenv-flow';
|
|
|
11
9
|
import express, { ErrorRequestHandler, Request, Response } from 'express';
|
|
12
10
|
import morgan from 'morgan';
|
|
13
11
|
|
|
12
|
+
import crons from './crons/index';
|
|
14
13
|
import { ensureStakedForGas } from './integrations/blockchain/stake';
|
|
15
14
|
import { ensureWebhookRegistered } from './integrations/stripe/setup';
|
|
16
15
|
import { handlers } from './libs/auth';
|
|
@@ -111,4 +110,6 @@ export const server = app.listen(port, (err?: any) => {
|
|
|
111
110
|
}
|
|
112
111
|
|
|
113
112
|
ensureStakedForGas().catch(console.error);
|
|
113
|
+
|
|
114
|
+
crons.init();
|
|
114
115
|
});
|
|
@@ -78,6 +78,7 @@ export async function handleStripePaymentCreated(event: TEventExpanded, client:
|
|
|
78
78
|
amount_received: String(stripeIntent.amount_received),
|
|
79
79
|
amount_capturable: String(stripeIntent.amount_capturable),
|
|
80
80
|
amount_details: stripeIntent.amount_details,
|
|
81
|
+
setup_future_usage: stripeIntent.setup_future_usage || 'on_session',
|
|
81
82
|
|
|
82
83
|
...pick(stripeIntent, [
|
|
83
84
|
'livemode',
|
|
@@ -88,7 +89,6 @@ export async function handleStripePaymentCreated(event: TEventExpanded, client:
|
|
|
88
89
|
'receipt_email',
|
|
89
90
|
'statement_descriptor',
|
|
90
91
|
'statement_descriptor_suffix',
|
|
91
|
-
'setup_future_usage',
|
|
92
92
|
'last_payment_error',
|
|
93
93
|
]),
|
|
94
94
|
|
package/api/src/queues/event.ts
CHANGED
|
@@ -37,17 +37,28 @@ export const handleEvent = async (job: EventJob) => {
|
|
|
37
37
|
|
|
38
38
|
await event.update({ pending_webhooks: eventWebhooks.length });
|
|
39
39
|
eventWebhooks.forEach(async (webhook) => {
|
|
40
|
-
const
|
|
41
|
-
where: {
|
|
40
|
+
const attemptCount = await WebhookAttempt.count({
|
|
41
|
+
where: {
|
|
42
|
+
event_id: event.id,
|
|
43
|
+
webhook_endpoint_id: webhook.id,
|
|
44
|
+
response_status: {
|
|
45
|
+
[Op.gte]: 200,
|
|
46
|
+
[Op.lt]: 300,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
42
49
|
});
|
|
43
50
|
|
|
44
|
-
// we should only push webhook if it's not attempted before
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
webhookQueue.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
// we should only push webhook if it's not successfully attempted before
|
|
52
|
+
if (attemptCount === 0) {
|
|
53
|
+
const jobId = getWebhookJobId(event.id, webhook.id);
|
|
54
|
+
const exist = await webhookQueue.get(jobId);
|
|
55
|
+
if (!exist) {
|
|
56
|
+
logger.info('schedule attempt for event', job);
|
|
57
|
+
webhookQueue.push({
|
|
58
|
+
id: jobId,
|
|
59
|
+
job: { eventId: event.id, webhookId: webhook.id },
|
|
60
|
+
});
|
|
61
|
+
}
|
|
51
62
|
}
|
|
52
63
|
});
|
|
53
64
|
};
|
|
@@ -77,7 +77,7 @@ export class PaymentIntent extends Model<InferAttributes<PaymentIntent>, InferCr
|
|
|
77
77
|
// 3rd party payment tx hash
|
|
78
78
|
declare payment_details?: PaymentDetails;
|
|
79
79
|
|
|
80
|
-
declare setup_future_usage
|
|
80
|
+
declare setup_future_usage?: LiteralUnion<'off_session' | 'on_session', string>;
|
|
81
81
|
|
|
82
82
|
// TODO: following fields not supported yet
|
|
83
83
|
// automatic_payment_methods
|
|
@@ -216,7 +216,7 @@ export class PaymentIntent extends Model<InferAttributes<PaymentIntent>, InferCr
|
|
|
216
216
|
},
|
|
217
217
|
setup_future_usage: {
|
|
218
218
|
type: DataTypes.ENUM('on_session', 'off_session'),
|
|
219
|
-
allowNull:
|
|
219
|
+
allowNull: true,
|
|
220
220
|
},
|
|
221
221
|
created_at: {
|
|
222
222
|
type: DataTypes.DATE,
|
package/api/third.d.ts
CHANGED
package/blocklet.yml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-kit",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.81",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "COMPONENT_STORE_URL=https://test.store.blocklet.dev blocklet dev",
|
|
6
6
|
"eject": "vite eject",
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
"@abtnode/types": "^1.16.20",
|
|
110
110
|
"@arcblock/eslint-config": "^0.2.4",
|
|
111
111
|
"@arcblock/eslint-config-ts": "^0.2.4",
|
|
112
|
-
"@did-pay/types": "1.13.
|
|
112
|
+
"@did-pay/types": "1.13.81",
|
|
113
113
|
"@types/cookie-parser": "^1.4.6",
|
|
114
114
|
"@types/cors": "^2.8.17",
|
|
115
115
|
"@types/dotenv-flow": "^3.3.3",
|
|
@@ -148,5 +148,5 @@
|
|
|
148
148
|
"parser": "typescript"
|
|
149
149
|
}
|
|
150
150
|
},
|
|
151
|
-
"gitHead": "
|
|
151
|
+
"gitHead": "ccdd4c815330b40a748619132db7bb3332850749"
|
|
152
152
|
}
|
|
@@ -19,7 +19,7 @@ import { useInfiniteScroll } from 'ahooks';
|
|
|
19
19
|
import React, { useEffect, useState } from 'react';
|
|
20
20
|
|
|
21
21
|
import api from '../../libs/api';
|
|
22
|
-
import { formatTime } from '../../libs/util';
|
|
22
|
+
import { formatTime, isSuccessAttempt } from '../../libs/util';
|
|
23
23
|
|
|
24
24
|
const fetchData = (params: Record<string, any> = {}): Promise<Paginated<TWebhookAttemptExpanded>> => {
|
|
25
25
|
const search = new URLSearchParams();
|
|
@@ -104,7 +104,7 @@ export default function WebhookAttempts({ event_id, webhook_endpoint_id, event }
|
|
|
104
104
|
<Typography color="text.secondary">{formatTime(attempt.created_at, 'HH:mm:ss A')}</Typography>
|
|
105
105
|
}>
|
|
106
106
|
<ListItemIcon>
|
|
107
|
-
{attempt.response_status
|
|
107
|
+
{isSuccessAttempt(attempt.response_status) === false ? (
|
|
108
108
|
<ErrorOutlined color="error" />
|
|
109
109
|
) : (
|
|
110
110
|
<CheckCircleOutlined color="success" />
|