payment-kit 1.13.71 → 1.13.72
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/jobs/payment.ts +15 -17
- package/api/src/libs/util.ts +1 -0
- package/api/src/locales/en.ts +1 -0
- package/api/src/locales/zh.ts +1 -0
- package/blocklet.yml +1 -1
- package/package.json +3 -3
package/api/src/jobs/payment.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { events } from '../libs/event';
|
|
|
6
6
|
import logger from '../libs/logger';
|
|
7
7
|
import { getGasPayerExtra, isDelegationSufficientForPayment } from '../libs/payment';
|
|
8
8
|
import createQueue from '../libs/queue';
|
|
9
|
-
import { MAX_RETRY_COUNT, getNextRetry } from '../libs/util';
|
|
9
|
+
import { MAX_RETRY_COUNT, MIN_RETRY_MAIL, getNextRetry } from '../libs/util';
|
|
10
10
|
import { CheckoutSession } from '../store/models/checkout-session';
|
|
11
11
|
import { Invoice } from '../store/models/invoice';
|
|
12
12
|
import { PaymentCurrency } from '../store/models/payment-currency';
|
|
@@ -66,13 +66,7 @@ export const handlePaymentSucceed = async (paymentIntent: PaymentIntent) => {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
where: {
|
|
71
|
-
subscription_id: invoice.subscription_id,
|
|
72
|
-
status: 'paid',
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
if (count >= 2) {
|
|
69
|
+
if (invoice.billing_reason === 'subscription_cycle') {
|
|
76
70
|
events.emit('customer.subscription.renewed', subscription, invoice);
|
|
77
71
|
}
|
|
78
72
|
}
|
|
@@ -131,6 +125,7 @@ export const handlePayment = async (job: PaymentJob) => {
|
|
|
131
125
|
|
|
132
126
|
// try payment capture and reschedule on error
|
|
133
127
|
logger.info(`PaymentIntent capture attempt: ${paymentIntent.id}`);
|
|
128
|
+
let result;
|
|
134
129
|
try {
|
|
135
130
|
await paymentIntent.update({ status: 'processing', last_payment_error: null });
|
|
136
131
|
|
|
@@ -138,7 +133,7 @@ export const handlePayment = async (job: PaymentJob) => {
|
|
|
138
133
|
const payer = paymentSettings?.payment_method_options.arcblock?.payer;
|
|
139
134
|
|
|
140
135
|
// check balance before capture
|
|
141
|
-
|
|
136
|
+
result = await isDelegationSufficientForPayment({
|
|
142
137
|
paymentMethod,
|
|
143
138
|
paymentCurrency,
|
|
144
139
|
userDid: payer as string,
|
|
@@ -146,11 +141,6 @@ export const handlePayment = async (job: PaymentJob) => {
|
|
|
146
141
|
});
|
|
147
142
|
if (result.sufficient === false) {
|
|
148
143
|
logger.error('PaymentIntent capture aborted on preCheck', { id: paymentIntent.id, result });
|
|
149
|
-
events.emit('customer.subscription.renew_failed', {
|
|
150
|
-
invoice,
|
|
151
|
-
result,
|
|
152
|
-
});
|
|
153
|
-
// FIXME: send email to customer, pause subscription
|
|
154
144
|
throw new CustomError(result.reason, 'payer balance or delegation not sufficient for this payment');
|
|
155
145
|
}
|
|
156
146
|
|
|
@@ -218,11 +208,19 @@ export const handlePayment = async (job: PaymentJob) => {
|
|
|
218
208
|
});
|
|
219
209
|
}
|
|
220
210
|
} else if (invoice) {
|
|
211
|
+
const attemptCount = invoice.attempt_count + 1;
|
|
212
|
+
if (attemptCount >= MIN_RETRY_MAIL && invoice.billing_reason === 'subscription_cycle') {
|
|
213
|
+
events.emit('customer.subscription.renew_failed', {
|
|
214
|
+
invoice,
|
|
215
|
+
result: result || { sufficient: false, reason: 'TX_SEND_FAILED' },
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
221
219
|
if (invoice.attempt_count > MAX_RETRY_COUNT) {
|
|
222
220
|
await paymentIntent.update({ status: 'requires_action', last_payment_error: error });
|
|
223
221
|
await invoice.update({
|
|
224
222
|
status: 'uncollectible',
|
|
225
|
-
attempt_count:
|
|
223
|
+
attempt_count: attemptCount,
|
|
226
224
|
attempted: true,
|
|
227
225
|
status_transitions: { ...invoice.status_transitions, marked_uncollectible_at: dayjs().unix() },
|
|
228
226
|
});
|
|
@@ -230,11 +228,11 @@ export const handlePayment = async (job: PaymentJob) => {
|
|
|
230
228
|
// FIXME: send email to customer, pause subscription
|
|
231
229
|
logger.error('PaymentIntent capture failed after max retry', { id: paymentIntent.id });
|
|
232
230
|
} else {
|
|
233
|
-
const retryAt = getNextRetry(
|
|
231
|
+
const retryAt = getNextRetry(attemptCount);
|
|
234
232
|
|
|
235
233
|
await paymentIntent.update({ status: 'requires_capture', last_payment_error: error });
|
|
236
234
|
await invoice.update({
|
|
237
|
-
attempt_count:
|
|
235
|
+
attempt_count: attemptCount,
|
|
238
236
|
attempted: true,
|
|
239
237
|
next_payment_attempt: retryAt,
|
|
240
238
|
});
|
package/api/src/libs/util.ts
CHANGED
|
@@ -10,6 +10,7 @@ import dayjs from './dayjs';
|
|
|
10
10
|
export const OCAP_PAYMENT_TX_TYPE = 'fg:t:transfer_v2';
|
|
11
11
|
|
|
12
12
|
export const MAX_RETRY_COUNT = 18; // 2^18 seconds ~~ 3 days, total retry time: 6 days
|
|
13
|
+
export const MIN_RETRY_MAIL = 13; // total retry time before sending first mail: 6 hours
|
|
13
14
|
export const STRIPE_API_VERSION = '2023-08-16';
|
|
14
15
|
export const STRIPE_ENDPOINT: string = getUrl('/api/integrations/stripe/webhook');
|
|
15
16
|
export const STRIPE_EVENTS: any[] = [
|
package/api/src/locales/en.ts
CHANGED
|
@@ -77,6 +77,7 @@ export default flat({
|
|
|
77
77
|
noEnoughToken:
|
|
78
78
|
'Your account token balance is {balance}, not enough for {price}, please replenish your tokens and renew your account',
|
|
79
79
|
noSupported: 'Token renewal is not supported, please check your subscription',
|
|
80
|
+
txSendFailed: 'Failed to send transaction when try to collect payment.',
|
|
80
81
|
},
|
|
81
82
|
},
|
|
82
83
|
},
|
package/api/src/locales/zh.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.72",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "COMPONENT_STORE_URL=https://test.store.blocklet.dev blocklet dev",
|
|
6
6
|
"eject": "vite eject",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"@abtnode/types": "^1.16.19",
|
|
107
107
|
"@arcblock/eslint-config": "^0.2.4",
|
|
108
108
|
"@arcblock/eslint-config-ts": "^0.2.4",
|
|
109
|
-
"@did-pay/types": "1.13.
|
|
109
|
+
"@did-pay/types": "1.13.72",
|
|
110
110
|
"@types/cookie-parser": "^1.4.6",
|
|
111
111
|
"@types/cors": "^2.8.17",
|
|
112
112
|
"@types/dotenv-flow": "^3.3.3",
|
|
@@ -143,5 +143,5 @@
|
|
|
143
143
|
"parser": "typescript"
|
|
144
144
|
}
|
|
145
145
|
},
|
|
146
|
-
"gitHead": "
|
|
146
|
+
"gitHead": "bbd67e67e0e6154506b12d7ce30b314e895382c0"
|
|
147
147
|
}
|