payment-kit 1.13.272 → 1.13.274
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/README.md
CHANGED
|
@@ -19,3 +19,13 @@ The decentralized stripe for blocklet platform.
|
|
|
19
19
|
### Test Stripe
|
|
20
20
|
|
|
21
21
|
Invoices for subscriptions are not finalized automatically. You can use stripe postman collection to finalize it and then confirm the payment.
|
|
22
|
+
|
|
23
|
+
### Easter Eggs
|
|
24
|
+
|
|
25
|
+
None public environment variables used in the code, can change the behavior of the payment-kit.
|
|
26
|
+
|
|
27
|
+
- PAYMENT_CHANGE_LOCKED_PRICE: allow change locked price, must be set to "1" to work
|
|
28
|
+
- PAYMENT_RELOAD_SUBSCRIPTION_JOBS: reload subscription jobs on start, must be set to "1" to work
|
|
29
|
+
- PAYMENT_BILLING_THRESHOLD: global default billing threshold, must be a number
|
|
30
|
+
- PAYMENT_DAYS_UNTIL_DUE: global default days until due, must be a number
|
|
31
|
+
- PAYMENT_DAYS_UNTIL_CANCEL: global default days until cancel, must be a number
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
TLineItemExpanded,
|
|
22
22
|
UsageRecord,
|
|
23
23
|
} from '../store/models';
|
|
24
|
+
import { createEvent } from './audit';
|
|
24
25
|
import dayjs from './dayjs';
|
|
25
26
|
import env from './env';
|
|
26
27
|
import logger from './logger';
|
|
@@ -563,7 +564,7 @@ export async function finalizeStripeSubscriptionUpdate({
|
|
|
563
564
|
// remote item not associated with local item
|
|
564
565
|
const created = await SubscriptionItem.create({
|
|
565
566
|
price_id: item.price_id as string,
|
|
566
|
-
quantity: item.quantity as number,
|
|
567
|
+
quantity: (item.quantity || 1) as number,
|
|
567
568
|
livemode: subscription.livemode,
|
|
568
569
|
subscription_id: subscription.id,
|
|
569
570
|
metadata: {
|
|
@@ -584,6 +585,8 @@ export async function finalizeStripeSubscriptionUpdate({
|
|
|
584
585
|
const releaseAt = subscription.current_period_end;
|
|
585
586
|
await Lock.acquire(`${subscription.id}-change-plan`, releaseAt);
|
|
586
587
|
logger.info('subscription plan change lock acquired on finalize', { subscription: subscription.id, releaseAt });
|
|
588
|
+
|
|
589
|
+
createEvent('Subscription', 'customer.subscription.upgraded', subscription).catch(console.error);
|
|
587
590
|
}
|
|
588
591
|
|
|
589
592
|
logger.info('subscription update finalized', { subscription: subscription.id, updates, items });
|
|
@@ -501,7 +501,7 @@ export const startSubscriptionQueue = async () => {
|
|
|
501
501
|
if (supportAutoCharge === false) {
|
|
502
502
|
return;
|
|
503
503
|
}
|
|
504
|
-
await addSubscriptionJob(x, 'cycle');
|
|
504
|
+
await addSubscriptionJob(x, 'cycle', process.env.PAYMENT_RELOAD_SUBSCRIPTION_JOBS === '1');
|
|
505
505
|
});
|
|
506
506
|
|
|
507
507
|
await batchHandleStripeSubscriptions();
|
|
@@ -568,6 +568,15 @@ events.on('customer.subscription.deleted', (subscription: Subscription) => {
|
|
|
568
568
|
// FIXME: ensure invoices that are open or uncollectible are voided
|
|
569
569
|
});
|
|
570
570
|
|
|
571
|
+
events.on('customer.subscription.upgraded', async (subscription: Subscription) => {
|
|
572
|
+
await subscriptionQueue.delete(subscription.id);
|
|
573
|
+
await addSubscriptionJob(subscription, 'cancel', true, subscription.current_period_end);
|
|
574
|
+
logger.info('subscription cycle job rescheduled after upgrade', {
|
|
575
|
+
subscription: subscription.id,
|
|
576
|
+
runAt: subscription.current_period_end,
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
|
|
571
580
|
events.on('customer.stake.revoked', async ({ subscriptionId, tx }: { subscriptionId: string; tx: any }) => {
|
|
572
581
|
const subscription = await Subscription.findByPk(subscriptionId);
|
|
573
582
|
if (!subscription) {
|
|
@@ -703,7 +703,9 @@ router.put('/:id', authPortal, async (req, res) => {
|
|
|
703
703
|
addedItems.map(async (x) => {
|
|
704
704
|
const price = await Price.findByPk(x.price_id);
|
|
705
705
|
const stripePrice = await ensureStripePrice(price!, paymentMethod, paymentCurrency);
|
|
706
|
-
return
|
|
706
|
+
return price!.recurring?.usage_type === 'metered'
|
|
707
|
+
? { price: stripePrice.id }
|
|
708
|
+
: { price: stripePrice.id, quantity: x.quantity };
|
|
707
709
|
})
|
|
708
710
|
);
|
|
709
711
|
const updatedStripeItems = await Promise.all(
|
|
@@ -716,7 +718,12 @@ router.put('/:id', authPortal, async (req, res) => {
|
|
|
716
718
|
const deletedStripeItems = await Promise.all(
|
|
717
719
|
deletedItems.map(async (x) => {
|
|
718
720
|
const item = await SubscriptionItem.findByPk(x.id);
|
|
719
|
-
|
|
721
|
+
const price = await Price.findByPk(item!.price_id);
|
|
722
|
+
return {
|
|
723
|
+
id: item!.metadata.stripe_id,
|
|
724
|
+
deleted: true,
|
|
725
|
+
clear_usage: price!.recurring?.usage_type === 'metered',
|
|
726
|
+
};
|
|
720
727
|
})
|
|
721
728
|
);
|
|
722
729
|
|
|
@@ -987,9 +994,7 @@ router.put('/:id', authPortal, async (req, res) => {
|
|
|
987
994
|
}
|
|
988
995
|
if (shouldCycle) {
|
|
989
996
|
await addSubscriptionJob(subscription, 'cycle', true, now);
|
|
990
|
-
logger.info('subscription job rescheduled on period end', {
|
|
991
|
-
subscription: subscription.id,
|
|
992
|
-
});
|
|
997
|
+
logger.info('subscription job rescheduled on period end', { subscription: subscription.id });
|
|
993
998
|
}
|
|
994
999
|
}
|
|
995
1000
|
}
|
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.274",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "blocklet dev --open",
|
|
6
6
|
"eject": "vite eject",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@arcblock/ux": "^2.9.90",
|
|
52
52
|
"@arcblock/validator": "^1.18.123",
|
|
53
53
|
"@blocklet/logger": "1.16.26",
|
|
54
|
-
"@blocklet/payment-react": "1.13.
|
|
54
|
+
"@blocklet/payment-react": "1.13.274",
|
|
55
55
|
"@blocklet/sdk": "1.16.26",
|
|
56
56
|
"@blocklet/ui-react": "^2.9.90",
|
|
57
57
|
"@blocklet/uploader": "^0.1.6",
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"devDependencies": {
|
|
117
117
|
"@abtnode/types": "1.16.26",
|
|
118
118
|
"@arcblock/eslint-config-ts": "^0.3.0",
|
|
119
|
-
"@blocklet/payment-types": "1.13.
|
|
119
|
+
"@blocklet/payment-types": "1.13.274",
|
|
120
120
|
"@types/cookie-parser": "^1.4.7",
|
|
121
121
|
"@types/cors": "^2.8.17",
|
|
122
122
|
"@types/dotenv-flow": "^3.3.3",
|
|
@@ -155,5 +155,5 @@
|
|
|
155
155
|
"parser": "typescript"
|
|
156
156
|
}
|
|
157
157
|
},
|
|
158
|
-
"gitHead": "
|
|
158
|
+
"gitHead": "e16c193a6fe497c78f6d1b1ccb7627e1ff0224f2"
|
|
159
159
|
}
|