payment-kit 1.18.31 → 1.18.33
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/integrations/stripe/handlers/setup-intent.ts +13 -2
- package/api/src/integrations/stripe/handlers/subscription.ts +20 -2
- package/api/src/libs/notification/template/subscription-succeeded.ts +1 -1
- package/blocklet.yml +1 -1
- package/package.json +16 -16
- package/src/components/price/form.tsx +1 -0
- package/src/pages/customer/subscription/detail.tsx +1 -1
|
@@ -3,6 +3,7 @@ import type Stripe from 'stripe';
|
|
|
3
3
|
import logger from '../../../libs/logger';
|
|
4
4
|
import { CheckoutSession, Lock, SetupIntent, Subscription, TEventExpanded } from '../../../store/models';
|
|
5
5
|
import { updateGroupSubscriptionsPaymentMethod } from '../resource';
|
|
6
|
+
import { getCheckoutSessionSubscriptionIds } from '../../../libs/session';
|
|
6
7
|
|
|
7
8
|
async function handleSubscriptionOnSetupSucceeded(event: TEventExpanded, stripeIntentId: string) {
|
|
8
9
|
const subscription = await Subscription.findOne({
|
|
@@ -22,8 +23,18 @@ async function handleSubscriptionOnSetupSucceeded(event: TEventExpanded, stripeI
|
|
|
22
23
|
|
|
23
24
|
const checkoutSession = await CheckoutSession.findBySubscriptionId(subscription.id);
|
|
24
25
|
if (checkoutSession && checkoutSession.status === 'open') {
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
const subscriptionIds = getCheckoutSessionSubscriptionIds(checkoutSession);
|
|
27
|
+
if (subscriptionIds.length <= 1) {
|
|
28
|
+
const updates: Partial<CheckoutSession> = {
|
|
29
|
+
status: 'complete',
|
|
30
|
+
payment_status: 'no_payment_required',
|
|
31
|
+
};
|
|
32
|
+
if (checkoutSession.subscription_id) {
|
|
33
|
+
updates.success_subscription_count = 1;
|
|
34
|
+
}
|
|
35
|
+
await checkoutSession.update(updates);
|
|
36
|
+
logger.info('checkout session become complete on stripe intent succeeded', checkoutSession.id);
|
|
37
|
+
}
|
|
27
38
|
}
|
|
28
39
|
|
|
29
40
|
return;
|
|
@@ -5,6 +5,7 @@ import logger from '../../../libs/logger';
|
|
|
5
5
|
import { finalizeStripeSubscriptionUpdate } from '../../../libs/subscription';
|
|
6
6
|
import { CheckoutSession, PaymentMethod, Subscription, TEventExpanded } from '../../../store/models';
|
|
7
7
|
import { getCheckoutSessionSubscriptionIds } from '../../../libs/session';
|
|
8
|
+
import { createEvent } from '../../../libs/audit';
|
|
8
9
|
|
|
9
10
|
export async function handleStripeSubscriptionSucceed(subscription: Subscription, status: string) {
|
|
10
11
|
if (!subscription.payment_details?.stripe?.subscription_id) {
|
|
@@ -17,6 +18,20 @@ export async function handleStripeSubscriptionSucceed(subscription: Subscription
|
|
|
17
18
|
const result: any = await client.subscriptions.retrieve(subscription.payment_details.stripe.subscription_id, {
|
|
18
19
|
expand: ['latest_invoice.payment_intent', 'pending_setup_intent'],
|
|
19
20
|
});
|
|
21
|
+
const checkoutSession = await CheckoutSession.findBySubscriptionId(subscription.id);
|
|
22
|
+
let subscriptionIds: string[] = [subscription.id];
|
|
23
|
+
if (checkoutSession) {
|
|
24
|
+
subscriptionIds = getCheckoutSessionSubscriptionIds(checkoutSession);
|
|
25
|
+
}
|
|
26
|
+
const isMultipleSubscriptions = subscriptionIds.length > 1 && checkoutSession?.enable_subscription_grouping;
|
|
27
|
+
// if not multiple subscriptions, check if setup is done
|
|
28
|
+
if (!isMultipleSubscriptions && result.pending_setup_intent && result.pending_setup_intent.status !== 'succeeded') {
|
|
29
|
+
logger.warn('subscription can not active because stripe setup not done', {
|
|
30
|
+
id: subscription.id,
|
|
31
|
+
status: result.pending_setup_intent.status,
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
20
35
|
const paymentIntent = result.latest_invoice?.payment_intent;
|
|
21
36
|
const paymentIntentStatus = typeof paymentIntent === 'string' ? paymentIntent : paymentIntent?.status;
|
|
22
37
|
if (result.latest_invoice?.payment_intent && paymentIntentStatus !== 'succeeded') {
|
|
@@ -28,13 +43,16 @@ export async function handleStripeSubscriptionSucceed(subscription: Subscription
|
|
|
28
43
|
}
|
|
29
44
|
|
|
30
45
|
await subscription.update({ status });
|
|
46
|
+
if (subscription.trial_end && subscription.trial_end > Date.now() / 1000 && subscription.status === 'trialing') {
|
|
47
|
+
createEvent('Subscription', 'customer.subscription.trial_start', subscription).catch(console.error);
|
|
48
|
+
} else if (subscription.status === 'active') {
|
|
49
|
+
createEvent('Subscription', 'customer.subscription.started', subscription).catch(console.error);
|
|
50
|
+
}
|
|
31
51
|
logger.info('subscription become active on stripe event', { id: subscription.id, status: subscription.status });
|
|
32
52
|
|
|
33
|
-
const checkoutSession = await CheckoutSession.findBySubscriptionId(subscription.id);
|
|
34
53
|
if (checkoutSession && checkoutSession.status === 'open') {
|
|
35
54
|
await checkoutSession.increment('success_subscription_count', { by: 1 });
|
|
36
55
|
await checkoutSession.reload();
|
|
37
|
-
const subscriptionIds = getCheckoutSessionSubscriptionIds(checkoutSession);
|
|
38
56
|
if (checkoutSession.success_subscription_count === subscriptionIds.length) {
|
|
39
57
|
await checkoutSession.update({
|
|
40
58
|
status: 'complete',
|
|
@@ -87,7 +87,7 @@ export class SubscriptionSucceededEmailTemplate
|
|
|
87
87
|
|
|
88
88
|
return Boolean(
|
|
89
89
|
['disabled', 'minted', 'sent', 'error'].includes(checkoutSession?.nft_mint_status as string) &&
|
|
90
|
-
(invoice?.payment_intent_id || (invoice && +invoice.
|
|
90
|
+
(invoice?.payment_intent_id || (invoice && +invoice.amount_remaining === 0))
|
|
91
91
|
);
|
|
92
92
|
},
|
|
93
93
|
{ timeout: 1000 * 10, interval: 1000 }
|
package/blocklet.yml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-kit",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.33",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "blocklet dev --open",
|
|
6
6
|
"eject": "vite eject",
|
|
@@ -45,29 +45,29 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@abtnode/cron": "^1.16.42",
|
|
48
|
-
"@arcblock/did": "^1.20.
|
|
48
|
+
"@arcblock/did": "^1.20.2",
|
|
49
49
|
"@arcblock/did-auth-storage-nedb": "^1.7.1",
|
|
50
|
-
"@arcblock/did-connect": "^2.13.
|
|
51
|
-
"@arcblock/did-util": "^1.20.
|
|
52
|
-
"@arcblock/jwt": "^1.20.
|
|
53
|
-
"@arcblock/ux": "^2.13.
|
|
54
|
-
"@arcblock/validator": "^1.20.
|
|
50
|
+
"@arcblock/did-connect": "^2.13.9",
|
|
51
|
+
"@arcblock/did-util": "^1.20.2",
|
|
52
|
+
"@arcblock/jwt": "^1.20.2",
|
|
53
|
+
"@arcblock/ux": "^2.13.9",
|
|
54
|
+
"@arcblock/validator": "^1.20.2",
|
|
55
55
|
"@blocklet/js-sdk": "^1.16.42",
|
|
56
56
|
"@blocklet/logger": "^1.16.42",
|
|
57
|
-
"@blocklet/payment-react": "1.18.
|
|
57
|
+
"@blocklet/payment-react": "1.18.33",
|
|
58
58
|
"@blocklet/sdk": "^1.16.42",
|
|
59
|
-
"@blocklet/ui-react": "^2.13.
|
|
59
|
+
"@blocklet/ui-react": "^2.13.9",
|
|
60
60
|
"@blocklet/uploader": "^0.1.83",
|
|
61
61
|
"@blocklet/xss": "^0.1.32",
|
|
62
62
|
"@mui/icons-material": "^5.16.6",
|
|
63
63
|
"@mui/lab": "^5.0.0-alpha.173",
|
|
64
64
|
"@mui/material": "^5.16.6",
|
|
65
65
|
"@mui/system": "^5.16.6",
|
|
66
|
-
"@ocap/asset": "^1.20.
|
|
67
|
-
"@ocap/client": "^1.20.
|
|
68
|
-
"@ocap/mcrypto": "^1.20.
|
|
69
|
-
"@ocap/util": "^1.20.
|
|
70
|
-
"@ocap/wallet": "^1.20.
|
|
66
|
+
"@ocap/asset": "^1.20.2",
|
|
67
|
+
"@ocap/client": "^1.20.2",
|
|
68
|
+
"@ocap/mcrypto": "^1.20.2",
|
|
69
|
+
"@ocap/util": "^1.20.2",
|
|
70
|
+
"@ocap/wallet": "^1.20.2",
|
|
71
71
|
"@stripe/react-stripe-js": "^2.7.3",
|
|
72
72
|
"@stripe/stripe-js": "^2.4.0",
|
|
73
73
|
"ahooks": "^3.8.0",
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
"devDependencies": {
|
|
123
123
|
"@abtnode/types": "^1.16.42",
|
|
124
124
|
"@arcblock/eslint-config-ts": "^0.3.3",
|
|
125
|
-
"@blocklet/payment-types": "1.18.
|
|
125
|
+
"@blocklet/payment-types": "1.18.33",
|
|
126
126
|
"@types/cookie-parser": "^1.4.7",
|
|
127
127
|
"@types/cors": "^2.8.17",
|
|
128
128
|
"@types/debug": "^4.1.12",
|
|
@@ -168,5 +168,5 @@
|
|
|
168
168
|
"parser": "typescript"
|
|
169
169
|
}
|
|
170
170
|
},
|
|
171
|
-
"gitHead": "
|
|
171
|
+
"gitHead": "91ae6c4dda76b8cc7a8ab5f82ae44874d429439b"
|
|
172
172
|
}
|
|
@@ -467,6 +467,7 @@ export default function PriceForm({ prefix, simple }: PriceFormProps) {
|
|
|
467
467
|
<option value="day">{t('common.days')}</option>
|
|
468
468
|
<option value="week">{t('common.weeks')}</option>
|
|
469
469
|
<option value="month">{t('common.months')}</option>
|
|
470
|
+
<option value="year">{t('common.years')}</option>
|
|
470
471
|
</select>
|
|
471
472
|
</InputAdornment>
|
|
472
473
|
),
|
|
@@ -79,7 +79,7 @@ export default function CustomerSubscriptionDetail() {
|
|
|
79
79
|
loading: overdraftProtectionLoading,
|
|
80
80
|
run: refreshOverdraftProtection,
|
|
81
81
|
} = useRequest(() => fetchOverdraftProtection(id), {
|
|
82
|
-
ready: ['active', 'trialing', 'past_due'].includes(data?.status || ''),
|
|
82
|
+
ready: ['active', 'trialing', 'past_due'].includes(data?.status || '') && data?.paymentMethod?.type === 'arcblock',
|
|
83
83
|
});
|
|
84
84
|
|
|
85
85
|
const {
|