payment-kit 1.20.14 → 1.20.15
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/libs/vendor-util/adapters/launcher-adapter.ts +1 -1
- package/api/src/libs/vendor-util/adapters/types.ts +2 -3
- package/api/src/libs/vendor-util/fulfillment.ts +16 -30
- package/api/src/queues/vendors/commission.ts +32 -42
- package/api/src/queues/vendors/fulfillment-coordinator.ts +68 -60
- package/api/src/queues/vendors/fulfillment.ts +5 -5
- package/api/src/queues/vendors/return-processor.ts +0 -1
- package/api/src/queues/vendors/status-check.ts +2 -2
- package/api/src/routes/vendor.ts +13 -4
- package/api/src/store/models/checkout-session.ts +23 -0
- package/blocklet.yml +1 -1
- package/package.json +5 -5
- package/doc/vendor_fulfillment_system.md +0 -929
|
@@ -7,7 +7,7 @@ import { updateVendorFulfillmentStatus } from './fulfillment-coordinator';
|
|
|
7
7
|
|
|
8
8
|
type VendorFulfillmentJob = {
|
|
9
9
|
checkoutSessionId: string;
|
|
10
|
-
|
|
10
|
+
invoiceId: string;
|
|
11
11
|
vendorId: string;
|
|
12
12
|
vendorConfig: any;
|
|
13
13
|
retryOnError?: boolean;
|
|
@@ -19,7 +19,7 @@ export const handleVendorFulfillment = async (job: VendorFulfillmentJob) => {
|
|
|
19
19
|
jobKeys: Object.keys(job),
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
const { checkoutSessionId,
|
|
22
|
+
const { checkoutSessionId, invoiceId, vendorId, vendorConfig } = job;
|
|
23
23
|
|
|
24
24
|
try {
|
|
25
25
|
const checkoutSession = await CheckoutSession.findByPk(checkoutSessionId);
|
|
@@ -31,7 +31,7 @@ export const handleVendorFulfillment = async (job: VendorFulfillmentJob) => {
|
|
|
31
31
|
checkoutSessionId,
|
|
32
32
|
amount_total: checkoutSession.amount_total,
|
|
33
33
|
customer_id: checkoutSession.customer_id || '',
|
|
34
|
-
|
|
34
|
+
invoiceId,
|
|
35
35
|
currency_id: checkoutSession.currency_id,
|
|
36
36
|
customer_did: checkoutSession.customer_did || '',
|
|
37
37
|
};
|
|
@@ -43,7 +43,7 @@ export const handleVendorFulfillment = async (job: VendorFulfillmentJob) => {
|
|
|
43
43
|
status: fulfillmentResult.status,
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
await updateVendorFulfillmentStatus(checkoutSessionId,
|
|
46
|
+
await updateVendorFulfillmentStatus(checkoutSessionId, invoiceId, vendorId, 'sent', {
|
|
47
47
|
orderId: fulfillmentResult.orderId,
|
|
48
48
|
commissionAmount: fulfillmentResult.commissionAmount,
|
|
49
49
|
serviceUrl: fulfillmentResult.serviceUrl,
|
|
@@ -55,7 +55,7 @@ export const handleVendorFulfillment = async (job: VendorFulfillmentJob) => {
|
|
|
55
55
|
error,
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
await updateVendorFulfillmentStatus(checkoutSessionId,
|
|
58
|
+
await updateVendorFulfillmentStatus(checkoutSessionId, invoiceId, vendorId, 'failed', {
|
|
59
59
|
lastError: error.message,
|
|
60
60
|
});
|
|
61
61
|
|
|
@@ -157,7 +157,6 @@ async function callVendorReturn(
|
|
|
157
157
|
const returnResult = await vendorAdapter.requestReturn({
|
|
158
158
|
orderId: vendor.order_id,
|
|
159
159
|
reason: 'Subscription canceled',
|
|
160
|
-
paymentIntentId: checkoutSession.payment_intent_id || '',
|
|
161
160
|
customParams: {
|
|
162
161
|
checkoutSessionId: checkoutSession.id,
|
|
163
162
|
subscriptionId: checkoutSession.subscription_id,
|
|
@@ -83,7 +83,7 @@ export const handleVendorStatusCheck = async (job: VendorStatusCheckJob) => {
|
|
|
83
83
|
id: `fulfillment-coordinator-${checkoutSessionId}-${vendorId}`,
|
|
84
84
|
job: {
|
|
85
85
|
checkoutSessionId,
|
|
86
|
-
|
|
86
|
+
invoiceId: checkoutSession?.invoice_id || '',
|
|
87
87
|
triggeredBy: 'vendor-status-check-timeout',
|
|
88
88
|
},
|
|
89
89
|
});
|
|
@@ -158,7 +158,7 @@ export const handleVendorStatusCheck = async (job: VendorStatusCheckJob) => {
|
|
|
158
158
|
id: `fulfillment-coordinator-${checkoutSessionId}-${vendorId}`,
|
|
159
159
|
job: {
|
|
160
160
|
checkoutSessionId,
|
|
161
|
-
|
|
161
|
+
invoiceId: checkoutSession?.invoice_id || '',
|
|
162
162
|
triggeredBy: 'vendor-status-check',
|
|
163
163
|
},
|
|
164
164
|
});
|
package/api/src/routes/vendor.ts
CHANGED
|
@@ -355,9 +355,12 @@ async function getVendorStatus(sessionId: string, isDetail = false) {
|
|
|
355
355
|
};
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
+
// FIXME: will remove payment_status @pengfei
|
|
359
|
+
const paymentStatus = doc.status === 'complete' ? 'paid' : 'unpaid';
|
|
360
|
+
|
|
358
361
|
if (doc.status !== 'complete') {
|
|
359
362
|
return {
|
|
360
|
-
payment_status:
|
|
363
|
+
payment_status: paymentStatus,
|
|
361
364
|
session_status: doc.status,
|
|
362
365
|
error: 'CheckoutSession not complete',
|
|
363
366
|
vendors: [],
|
|
@@ -365,7 +368,7 @@ async function getVendorStatus(sessionId: string, isDetail = false) {
|
|
|
365
368
|
}
|
|
366
369
|
if (!doc.vendor_info) {
|
|
367
370
|
return {
|
|
368
|
-
payment_status:
|
|
371
|
+
payment_status: paymentStatus,
|
|
369
372
|
session_status: doc.status,
|
|
370
373
|
error: 'Vendor info not found',
|
|
371
374
|
vendors: [],
|
|
@@ -373,7 +376,13 @@ async function getVendorStatus(sessionId: string, isDetail = false) {
|
|
|
373
376
|
}
|
|
374
377
|
|
|
375
378
|
const vendors = doc.vendor_info.map((item) => {
|
|
376
|
-
return getVendorStatusByVendorId(item.vendor_id, item.order_id, isDetail)
|
|
379
|
+
return getVendorStatusByVendorId(item.vendor_id, item.order_id, isDetail).then((status) => {
|
|
380
|
+
return {
|
|
381
|
+
error_message: item.error_message,
|
|
382
|
+
status: item.status,
|
|
383
|
+
...status,
|
|
384
|
+
};
|
|
385
|
+
});
|
|
377
386
|
});
|
|
378
387
|
|
|
379
388
|
const subscriptionId = doc.subscription_id;
|
|
@@ -390,7 +399,7 @@ async function getVendorStatus(sessionId: string, isDetail = false) {
|
|
|
390
399
|
}
|
|
391
400
|
|
|
392
401
|
return {
|
|
393
|
-
payment_status:
|
|
402
|
+
payment_status: paymentStatus,
|
|
394
403
|
session_status: doc.status,
|
|
395
404
|
subscriptionUrl: shortSubscriptionUrl,
|
|
396
405
|
vendors: await Promise.all(vendors),
|
|
@@ -623,6 +623,29 @@ export class CheckoutSession extends Model<InferAttributes<CheckoutSession>, Inf
|
|
|
623
623
|
return null;
|
|
624
624
|
}
|
|
625
625
|
}
|
|
626
|
+
|
|
627
|
+
public static async findByInvoiceId(invoiceId: string): Promise<CheckoutSession | null> {
|
|
628
|
+
try {
|
|
629
|
+
const invoice = await Invoice.findByPk(invoiceId);
|
|
630
|
+
if (!invoice) {
|
|
631
|
+
return null;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
if (invoice.checkout_session_id) {
|
|
635
|
+
return await CheckoutSession.findByPk(invoice.checkout_session_id);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
if (!invoice.subscription_id) {
|
|
639
|
+
return null;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// Find original CheckoutSession through subscription
|
|
643
|
+
const checkoutSession = await CheckoutSession.findBySubscriptionId(invoice.subscription_id);
|
|
644
|
+
return checkoutSession;
|
|
645
|
+
} catch (error: any) {
|
|
646
|
+
return null;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
626
649
|
}
|
|
627
650
|
|
|
628
651
|
export type TCheckoutSession = InferAttributes<CheckoutSession>;
|
package/blocklet.yml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-kit",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.15",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "blocklet dev --open",
|
|
6
6
|
"lint": "tsc --noEmit && eslint src api/src --ext .mjs,.js,.jsx,.ts,.tsx",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"@blocklet/error": "^0.2.5",
|
|
57
57
|
"@blocklet/js-sdk": "^1.16.52-beta-20250912-112002-e3499e9c",
|
|
58
58
|
"@blocklet/logger": "^1.16.52-beta-20250912-112002-e3499e9c",
|
|
59
|
-
"@blocklet/payment-react": "1.20.
|
|
60
|
-
"@blocklet/payment-vendor": "1.20.
|
|
59
|
+
"@blocklet/payment-react": "1.20.15",
|
|
60
|
+
"@blocklet/payment-vendor": "1.20.15",
|
|
61
61
|
"@blocklet/sdk": "^1.16.52-beta-20250912-112002-e3499e9c",
|
|
62
62
|
"@blocklet/ui-react": "^3.1.41",
|
|
63
63
|
"@blocklet/uploader": "^0.2.11",
|
|
@@ -126,7 +126,7 @@
|
|
|
126
126
|
"devDependencies": {
|
|
127
127
|
"@abtnode/types": "^1.16.52-beta-20250912-112002-e3499e9c",
|
|
128
128
|
"@arcblock/eslint-config-ts": "^0.3.3",
|
|
129
|
-
"@blocklet/payment-types": "1.20.
|
|
129
|
+
"@blocklet/payment-types": "1.20.15",
|
|
130
130
|
"@types/cookie-parser": "^1.4.9",
|
|
131
131
|
"@types/cors": "^2.8.19",
|
|
132
132
|
"@types/debug": "^4.1.12",
|
|
@@ -173,5 +173,5 @@
|
|
|
173
173
|
"parser": "typescript"
|
|
174
174
|
}
|
|
175
175
|
},
|
|
176
|
-
"gitHead": "
|
|
176
|
+
"gitHead": "d205c3b1ec7d2b819e375ed2eb8b70c9d48f0bcb"
|
|
177
177
|
}
|