payment-kit 1.21.9 → 1.21.11
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.
|
@@ -4,14 +4,18 @@ import { events } from '../../libs/event';
|
|
|
4
4
|
import { getLock } from '../../libs/lock';
|
|
5
5
|
import logger from '../../libs/logger';
|
|
6
6
|
import createQueue from '../../libs/queue';
|
|
7
|
+
import dayjs from '../../libs/dayjs';
|
|
7
8
|
import { VendorFulfillmentService } from '../../libs/vendor-util/fulfillment';
|
|
8
9
|
import { CheckoutSession } from '../../store/models/checkout-session';
|
|
9
10
|
import { PaymentIntent } from '../../store/models/payment-intent';
|
|
10
11
|
import { Price } from '../../store/models/price';
|
|
11
12
|
import { Product } from '../../store/models/product';
|
|
12
13
|
import { Refund } from '../../store/models/refund';
|
|
14
|
+
import { Subscription } from '../../store/models/subscription';
|
|
13
15
|
import { sequelize } from '../../store/sequelize';
|
|
14
16
|
import { depositVaultQueue } from '../payment';
|
|
17
|
+
import { addSubscriptionJob } from '../subscription';
|
|
18
|
+
import { SubscriptionWillCanceledSchedule } from '../../crons/subscription-will-canceled';
|
|
15
19
|
import { Invoice } from '../../store/models';
|
|
16
20
|
|
|
17
21
|
export type VendorInfo = NonNullable<CheckoutSession['vendor_info']>[number];
|
|
@@ -634,6 +638,11 @@ export async function initiateFullRefund(invoiceId: string, reason: string): Pro
|
|
|
634
638
|
await checkoutSession.update({ fulfillment_status: 'cancelled' });
|
|
635
639
|
await requestReturnsFromCompletedVendors(checkoutSession, reason);
|
|
636
640
|
|
|
641
|
+
// Cancel subscription if this refund is for a subscription
|
|
642
|
+
if (checkoutSession.subscription_id) {
|
|
643
|
+
await cancelSubscriptionForRefund(checkoutSession.subscription_id, reason);
|
|
644
|
+
}
|
|
645
|
+
|
|
637
646
|
// Calculate remaining amount using the same logic as subscription createProration
|
|
638
647
|
const refunds = await Refund.findAll({
|
|
639
648
|
where: {
|
|
@@ -707,6 +716,66 @@ export async function initiateFullRefund(invoiceId: string, reason: string): Pro
|
|
|
707
716
|
}
|
|
708
717
|
}
|
|
709
718
|
|
|
719
|
+
/**
|
|
720
|
+
* Cancel subscription when full refund is initiated due to vendor fulfillment failure
|
|
721
|
+
*/
|
|
722
|
+
async function cancelSubscriptionForRefund(subscriptionId: string, reason: string): Promise<void> {
|
|
723
|
+
try {
|
|
724
|
+
const subscription = await Subscription.findByPk(subscriptionId);
|
|
725
|
+
if (!subscription) {
|
|
726
|
+
logger.warn('Subscription not found for cancellation', { subscriptionId });
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
// Check if subscription is already canceled
|
|
731
|
+
if (subscription.status === 'canceled') {
|
|
732
|
+
logger.info('Subscription already canceled, skipping', { subscriptionId });
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
const now = dayjs().unix() + 3;
|
|
737
|
+
const haveStake = !!subscription.payment_details?.arcblock?.staking?.tx_hash;
|
|
738
|
+
|
|
739
|
+
// Prepare cancellation details
|
|
740
|
+
const updates: Partial<Subscription> = {
|
|
741
|
+
status: 'canceled',
|
|
742
|
+
cancel_at: now,
|
|
743
|
+
canceled_at: now,
|
|
744
|
+
cancelation_details: {
|
|
745
|
+
comment: `Canceled due to vendor fulfillment failure: ${reason}`,
|
|
746
|
+
reason: 'vendor_fulfillment_failed',
|
|
747
|
+
feedback: 'vendor_issue',
|
|
748
|
+
return_stake: haveStake, // Return stake when canceled due to vendor failure
|
|
749
|
+
slash_stake: false,
|
|
750
|
+
slash_reason: '',
|
|
751
|
+
},
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
// Update subscription
|
|
755
|
+
await subscription.update(updates);
|
|
756
|
+
|
|
757
|
+
// Schedule cancellation job
|
|
758
|
+
await addSubscriptionJob(subscription, 'cancel', true, updates.cancel_at);
|
|
759
|
+
|
|
760
|
+
// Update scheduled tasks
|
|
761
|
+
await new SubscriptionWillCanceledSchedule().reScheduleSubscriptionTasks([subscription]);
|
|
762
|
+
|
|
763
|
+
logger.info('Subscription canceled due to vendor fulfillment failure', {
|
|
764
|
+
subscriptionId: subscription.id,
|
|
765
|
+
customerId: subscription.customer_id,
|
|
766
|
+
reason,
|
|
767
|
+
cancelAt: subscription.cancel_at,
|
|
768
|
+
returnStake: haveStake,
|
|
769
|
+
});
|
|
770
|
+
} catch (error: any) {
|
|
771
|
+
logger.error('Failed to cancel subscription for refund', {
|
|
772
|
+
subscriptionId,
|
|
773
|
+
reason,
|
|
774
|
+
error,
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
710
779
|
async function requestReturnsFromCompletedVendors(checkoutSession: CheckoutSession, reason: string): Promise<void> {
|
|
711
780
|
logger.info('Starting return request process', {
|
|
712
781
|
checkoutSessionId: checkoutSession.id,
|
|
@@ -1329,6 +1329,49 @@ router.get('/retrieve/:id', user, async (req, res) => {
|
|
|
1329
1329
|
});
|
|
1330
1330
|
});
|
|
1331
1331
|
|
|
1332
|
+
// for checkout page
|
|
1333
|
+
router.get('/broker-status/:id', user, async (req, res) => {
|
|
1334
|
+
const { needShortUrl = false } = req.query;
|
|
1335
|
+
const doc = await CheckoutSession.findByPk(req.params.id);
|
|
1336
|
+
|
|
1337
|
+
if (!doc) {
|
|
1338
|
+
res.json({
|
|
1339
|
+
checkoutSession: {},
|
|
1340
|
+
paymentLink: null,
|
|
1341
|
+
});
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
// @ts-ignore
|
|
1346
|
+
doc.line_items = await Price.expand(doc.line_items, { upsell: true });
|
|
1347
|
+
|
|
1348
|
+
const hasVendorConfig = doc.line_items?.some((item: any) => !!item?.price?.product?.vendor_config?.length);
|
|
1349
|
+
|
|
1350
|
+
if (!hasVendorConfig || doc.payment_status === 'unpaid' || doc.fulfillment_status === 'cancelled') {
|
|
1351
|
+
res.json({
|
|
1352
|
+
checkoutSession: {},
|
|
1353
|
+
paymentLink: null,
|
|
1354
|
+
});
|
|
1355
|
+
return;
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
const paymentUrl = getUrl(`/checkout/pay/${doc.id}`);
|
|
1359
|
+
const paymentLink = needShortUrl
|
|
1360
|
+
? await formatToShortUrl({
|
|
1361
|
+
url: paymentUrl,
|
|
1362
|
+
validUntil: dayjs().add(20, 'minutes').format('YYYY-MM-DDTHH:mm:ss+00:00'),
|
|
1363
|
+
maxVisits: 5,
|
|
1364
|
+
})
|
|
1365
|
+
: paymentUrl;
|
|
1366
|
+
|
|
1367
|
+
res.json({
|
|
1368
|
+
checkoutSession: {
|
|
1369
|
+
...doc.toJSON(),
|
|
1370
|
+
},
|
|
1371
|
+
paymentLink,
|
|
1372
|
+
});
|
|
1373
|
+
});
|
|
1374
|
+
|
|
1332
1375
|
async function checkVendorConfig(items: TLineItemExpanded[]) {
|
|
1333
1376
|
const lineItems = await Price.expand(items, { upsell: true });
|
|
1334
1377
|
return lineItems?.some((item: TLineItemExpanded) => !!item?.price?.product?.vendor_config?.length);
|
package/blocklet.yml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-kit",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.11",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "blocklet dev --open",
|
|
6
6
|
"lint": "tsc --noEmit && eslint src api/src --ext .mjs,.js,.jsx,.ts,.tsx",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
]
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@abtnode/cron": "^1.16.
|
|
47
|
+
"@abtnode/cron": "^1.16.53-beta-20251011-054719-4ed2f6b7",
|
|
48
48
|
"@arcblock/did": "^1.25.6",
|
|
49
49
|
"@arcblock/did-connect-react": "^3.1.46",
|
|
50
50
|
"@arcblock/did-connect-storage-nedb": "^1.8.0",
|
|
@@ -54,15 +54,15 @@
|
|
|
54
54
|
"@arcblock/validator": "^1.25.6",
|
|
55
55
|
"@blocklet/did-space-js": "^1.1.32",
|
|
56
56
|
"@blocklet/error": "^0.2.5",
|
|
57
|
-
"@blocklet/js-sdk": "^1.16.
|
|
58
|
-
"@blocklet/logger": "^1.16.
|
|
59
|
-
"@blocklet/payment-broker-client": "1.21.
|
|
60
|
-
"@blocklet/payment-react": "1.21.
|
|
61
|
-
"@blocklet/payment-vendor": "1.21.
|
|
62
|
-
"@blocklet/sdk": "^1.16.
|
|
57
|
+
"@blocklet/js-sdk": "^1.16.53-beta-20251011-054719-4ed2f6b7",
|
|
58
|
+
"@blocklet/logger": "^1.16.53-beta-20251011-054719-4ed2f6b7",
|
|
59
|
+
"@blocklet/payment-broker-client": "1.21.11",
|
|
60
|
+
"@blocklet/payment-react": "1.21.11",
|
|
61
|
+
"@blocklet/payment-vendor": "1.21.11",
|
|
62
|
+
"@blocklet/sdk": "^1.16.53-beta-20251011-054719-4ed2f6b7",
|
|
63
63
|
"@blocklet/ui-react": "^3.1.46",
|
|
64
|
-
"@blocklet/uploader": "^0.2.
|
|
65
|
-
"@blocklet/xss": "^0.2.
|
|
64
|
+
"@blocklet/uploader": "^0.2.15",
|
|
65
|
+
"@blocklet/xss": "^0.2.12",
|
|
66
66
|
"@mui/icons-material": "^7.1.2",
|
|
67
67
|
"@mui/lab": "7.0.0-beta.14",
|
|
68
68
|
"@mui/material": "^7.1.2",
|
|
@@ -126,9 +126,9 @@
|
|
|
126
126
|
"web3": "^4.16.0"
|
|
127
127
|
},
|
|
128
128
|
"devDependencies": {
|
|
129
|
-
"@abtnode/types": "^1.16.
|
|
129
|
+
"@abtnode/types": "^1.16.53-beta-20251011-054719-4ed2f6b7",
|
|
130
130
|
"@arcblock/eslint-config-ts": "^0.3.3",
|
|
131
|
-
"@blocklet/payment-types": "1.21.
|
|
131
|
+
"@blocklet/payment-types": "1.21.11",
|
|
132
132
|
"@types/cookie-parser": "^1.4.9",
|
|
133
133
|
"@types/cors": "^2.8.19",
|
|
134
134
|
"@types/debug": "^4.1.12",
|
|
@@ -175,5 +175,5 @@
|
|
|
175
175
|
"parser": "typescript"
|
|
176
176
|
}
|
|
177
177
|
},
|
|
178
|
-
"gitHead": "
|
|
178
|
+
"gitHead": "8a8bfd7810c58143314585fd31bad3c97637a761"
|
|
179
179
|
}
|
|
@@ -82,7 +82,7 @@ export default function VendorServiceList({
|
|
|
82
82
|
{vendor.name || vendor.vendor_key}
|
|
83
83
|
</Typography>
|
|
84
84
|
</Stack>
|
|
85
|
-
{isLauncher && (
|
|
85
|
+
{isLauncher && !isCanceled && (
|
|
86
86
|
<Box>
|
|
87
87
|
<Stack direction="row" spacing={0.5}>
|
|
88
88
|
<Tooltip title={t('admin.subscription.serviceHome')} placement="top">
|