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.
@@ -7,7 +7,7 @@ import { updateVendorFulfillmentStatus } from './fulfillment-coordinator';
7
7
 
8
8
  type VendorFulfillmentJob = {
9
9
  checkoutSessionId: string;
10
- paymentIntentId: string;
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, paymentIntentId, vendorId, vendorConfig } = job;
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
- payment_intent_id: checkoutSession.payment_intent_id || '',
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, paymentIntentId, vendorId, 'sent', {
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, paymentIntentId, vendorId, 'failed', {
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
- paymentIntentId: checkoutSession?.payment_intent_id || '',
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
- paymentIntentId: checkoutSession?.payment_intent_id || '',
161
+ invoiceId: checkoutSession?.invoice_id || '',
162
162
  triggeredBy: 'vendor-status-check',
163
163
  },
164
164
  });
@@ -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: doc.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: doc.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: doc.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
@@ -14,7 +14,7 @@ repository:
14
14
  type: git
15
15
  url: git+https://github.com/blocklet/payment-kit.git
16
16
  specVersion: 1.2.8
17
- version: 1.20.14
17
+ version: 1.20.15
18
18
  logo: logo.png
19
19
  files:
20
20
  - dist
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payment-kit",
3
- "version": "1.20.14",
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.14",
60
- "@blocklet/payment-vendor": "1.20.14",
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.14",
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": "365b60721b7f3a372c472f774cda290d56dad365"
176
+ "gitHead": "d205c3b1ec7d2b819e375ed2eb8b70c9d48f0bcb"
177
177
  }