payment-kit 1.15.11 → 1.15.12
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.
|
@@ -12,6 +12,7 @@ import { handleStripeInvoiceCreated } from './invoice';
|
|
|
12
12
|
import { events } from '../../../libs/event';
|
|
13
13
|
|
|
14
14
|
export async function handleStripePaymentSucceed(paymentIntent: PaymentIntent, event?: TEventExpanded) {
|
|
15
|
+
const triggerRenew = paymentIntent.status !== 'succeeded';
|
|
15
16
|
await paymentIntent.update({
|
|
16
17
|
status: 'succeeded',
|
|
17
18
|
last_payment_error: null,
|
|
@@ -28,7 +29,7 @@ export async function handleStripePaymentSucceed(paymentIntent: PaymentIntent, e
|
|
|
28
29
|
events.emit('checkout.session.pending_invoice', { checkoutSessionId, paymentIntentId: paymentIntent.id });
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
await handlePaymentSucceed(paymentIntent);
|
|
32
|
+
await handlePaymentSucceed(paymentIntent, triggerRenew);
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
export async function syncStripePayment(paymentIntent: PaymentIntent) {
|
|
@@ -41,6 +42,7 @@ export async function syncStripePayment(paymentIntent: PaymentIntent) {
|
|
|
41
42
|
return;
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
const triggerRenew = paymentIntent.status !== 'succeeded';
|
|
44
46
|
const client = await method.getStripeClient();
|
|
45
47
|
const stripeIntent = await client.paymentIntents.retrieve(paymentIntent.metadata.stripe_id);
|
|
46
48
|
if (stripeIntent) {
|
|
@@ -55,7 +57,7 @@ export async function syncStripePayment(paymentIntent: PaymentIntent) {
|
|
|
55
57
|
logger.info('stripe payment intent synced', { locale: paymentIntent.id, remote: stripeIntent.id });
|
|
56
58
|
|
|
57
59
|
if (stripeIntent.status === 'succeeded') {
|
|
58
|
-
await handlePaymentSucceed(paymentIntent);
|
|
60
|
+
await handlePaymentSucceed(paymentIntent, triggerRenew);
|
|
59
61
|
}
|
|
60
62
|
}
|
|
61
63
|
}
|
|
@@ -126,14 +126,14 @@ export default function createQueue<T = any>({ name, onJob, options = defaults }
|
|
|
126
126
|
|
|
127
127
|
const onJobComplete = async (err: any, result: any) => {
|
|
128
128
|
if (result === CANCELLED) {
|
|
129
|
+
await clearJob(jobId);
|
|
129
130
|
emit('cancelled', { id: jobId, job });
|
|
130
|
-
clearJob(jobId);
|
|
131
131
|
return;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
if (!err) {
|
|
135
|
+
await clearJob(jobId);
|
|
135
136
|
emit('finished', { id: jobId, job, result });
|
|
136
|
-
clearJob(jobId);
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
139
139
|
logger.error('job errored', { queue: name, id: jobId, job, result, error: err });
|
|
@@ -56,7 +56,11 @@ async function updateQuantitySold(checkoutSession: CheckoutSession) {
|
|
|
56
56
|
await Promise.all(updatePromises);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
export const handlePaymentSucceed = async (
|
|
59
|
+
export const handlePaymentSucceed = async (
|
|
60
|
+
paymentIntent: PaymentIntent,
|
|
61
|
+
triggerRenew: boolean = true,
|
|
62
|
+
slashStake: boolean = false
|
|
63
|
+
) => {
|
|
60
64
|
// FIXME: @wangshijun we should check stripe payment here before
|
|
61
65
|
|
|
62
66
|
if (paymentIntent.beneficiaries?.length && !slashStake) {
|
|
@@ -206,8 +210,10 @@ export const handlePaymentSucceed = async (paymentIntent: PaymentIntent, slashSt
|
|
|
206
210
|
}
|
|
207
211
|
}
|
|
208
212
|
|
|
209
|
-
if (
|
|
210
|
-
|
|
213
|
+
if (triggerRenew) {
|
|
214
|
+
if (invoice.billing_reason === 'subscription_cycle' || paymentIntent.capture_method === 'manual') {
|
|
215
|
+
createEvent('Subscription', 'customer.subscription.renewed', subscription).catch(console.error);
|
|
216
|
+
}
|
|
211
217
|
}
|
|
212
218
|
if (invoice.billing_reason === 'subscription_update') {
|
|
213
219
|
createEvent('Subscription', 'customer.subscription.upgraded', subscription).catch(console.error);
|
|
@@ -474,7 +480,7 @@ const handleStakeSlash = async (
|
|
|
474
480
|
},
|
|
475
481
|
},
|
|
476
482
|
});
|
|
477
|
-
await handlePaymentSucceed(paymentIntent, true);
|
|
483
|
+
await handlePaymentSucceed(paymentIntent, true, true);
|
|
478
484
|
const jobId = `${paymentIntent.id}-${subscription.id}`;
|
|
479
485
|
const job = await notificationQueue.get(jobId);
|
|
480
486
|
if (job) {
|
|
@@ -674,7 +680,7 @@ export const handlePayment = async (job: PaymentJob) => {
|
|
|
674
680
|
},
|
|
675
681
|
});
|
|
676
682
|
|
|
677
|
-
await handlePaymentSucceed(paymentIntent);
|
|
683
|
+
await handlePaymentSucceed(paymentIntent, true);
|
|
678
684
|
}
|
|
679
685
|
} catch (err) {
|
|
680
686
|
logger.error('PaymentIntent capture failed', { error: err, id: paymentIntent.id });
|
package/blocklet.yml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-kit",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.12",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "blocklet dev --open",
|
|
6
6
|
"eject": "vite eject",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@arcblock/validator": "^1.18.135",
|
|
53
53
|
"@blocklet/js-sdk": "^1.16.32",
|
|
54
54
|
"@blocklet/logger": "^1.16.32",
|
|
55
|
-
"@blocklet/payment-react": "1.15.
|
|
55
|
+
"@blocklet/payment-react": "1.15.12",
|
|
56
56
|
"@blocklet/sdk": "^1.16.32",
|
|
57
57
|
"@blocklet/ui-react": "^2.10.39",
|
|
58
58
|
"@blocklet/uploader": "^0.1.40",
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"devDependencies": {
|
|
119
119
|
"@abtnode/types": "^1.16.32",
|
|
120
120
|
"@arcblock/eslint-config-ts": "^0.3.2",
|
|
121
|
-
"@blocklet/payment-types": "1.15.
|
|
121
|
+
"@blocklet/payment-types": "1.15.12",
|
|
122
122
|
"@types/cookie-parser": "^1.4.7",
|
|
123
123
|
"@types/cors": "^2.8.17",
|
|
124
124
|
"@types/debug": "^4.1.12",
|
|
@@ -160,5 +160,5 @@
|
|
|
160
160
|
"parser": "typescript"
|
|
161
161
|
}
|
|
162
162
|
},
|
|
163
|
-
"gitHead": "
|
|
163
|
+
"gitHead": "522f94d0b960bc6e1bfdb3cf6738ecb077183ca1"
|
|
164
164
|
}
|