payment-kit 1.22.2 → 1.22.3

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.
@@ -1,5 +1,6 @@
1
1
  import { Auth as VendorAuth } from '@blocklet/payment-vendor';
2
2
 
3
+ import { joinURL } from 'ufo';
3
4
  import { ProductVendor } from '../../../store/models';
4
5
  import dayjs from '../../dayjs';
5
6
  import logger from '../../logger';
@@ -236,19 +237,21 @@ export class LauncherAdapter implements VendorAdapter {
236
237
  }
237
238
 
238
239
  async checkOrderStatus(params: CheckOrderStatusParams): Promise<CheckOrderStatusResult> {
239
- const url = `${params.appUrl}/__blocklet__.js?type=json&noCache=1`;
240
+ const url = joinURL(params.appUrl, '__blocklet__.js?type=json&noCache=1');
240
241
  try {
241
- const blocklet = await api.get(url, {
242
- headers: { 'Content-Type': 'application/json' },
243
- });
242
+ const blocklet = await api.get(url, { headers: { 'Content-Type': 'application/json' } });
244
243
  const blockletInfo = blocklet.data;
244
+
245
245
  let status: 'processing' | 'completed' | 'failed' = 'processing';
246
246
  if (blockletInfo.status === 'running') {
247
- status = 'completed';
247
+ if (blockletInfo.componentMountPoints.every((x: any) => x.status === 'running')) {
248
+ status = 'completed';
249
+ } else if (blockletInfo.componentMountPoints.some((x: any) => x.status === 'failed')) {
250
+ status = 'failed';
251
+ }
248
252
  } else if (blockletInfo.status === 'failed') {
249
253
  status = 'failed';
250
254
  }
251
-
252
255
  return { status };
253
256
  } catch (error: any) {
254
257
  logger.error('Failed to check order status', {
@@ -267,8 +270,34 @@ export class LauncherAdapter implements VendorAdapter {
267
270
  return doRequestVendorData(vendor, orderId, url, options);
268
271
  }
269
272
 
270
- getOrder(vendor: ProductVendor, orderId: string, options: { shortUrl: boolean }): Promise<any> {
271
- const url = formatVendorUrl(vendor, `/api/vendor/orders/${orderId}`);
273
+ async getOrder(
274
+ vendor: ProductVendor,
275
+ orderId: string,
276
+ options: { shortUrl: boolean; appUrl?: string }
277
+ ): Promise<any> {
278
+ const { appUrl } = options;
279
+ let ownerDid = '';
280
+ let appDid = '';
281
+ if (appUrl) {
282
+ const blockletInfoUrl = joinURL(appUrl, '__blocklet__.js?type=json&noCache=1&owner=1');
283
+ try {
284
+ const blocklet = await api.get(blockletInfoUrl, { headers: { 'Content-Type': 'application/json' } });
285
+ const blockletInfo = blocklet.data;
286
+
287
+ ownerDid = blockletInfo.ownerDid;
288
+ appDid = blockletInfo.appId;
289
+ } catch (error: any) {
290
+ logger.error('Failed to get blocklet info', {
291
+ url: blockletInfoUrl,
292
+ error,
293
+ });
294
+ }
295
+ }
296
+
297
+ const url = formatVendorUrl(
298
+ vendor,
299
+ `/api/vendor/orders/${orderId}?ownerDid=${ownerDid || ''}&appDid=${appDid || ''}`
300
+ );
272
301
 
273
302
  return doRequestVendorData(vendor, orderId, url, options);
274
303
  }
@@ -338,13 +338,20 @@ async function testVendorConnection(req: any, res: any) {
338
338
  }
339
339
  }
340
340
 
341
- async function executeVendorOperation(
342
- vendorId: string,
343
- orderId: string,
344
- operation: 'getOrder' | 'getOrderStatus',
345
- shortUrl: boolean
346
- ) {
347
- if (!vendorId || !orderId) {
341
+ async function executeVendorOperation({
342
+ vendorId,
343
+ orderId,
344
+ operation,
345
+ shortUrl,
346
+ appUrl,
347
+ }: {
348
+ vendorId: string;
349
+ orderId: string;
350
+ operation: 'getOrder' | 'getOrderStatus';
351
+ shortUrl: boolean;
352
+ appUrl?: string;
353
+ }) {
354
+ if (!vendorId || !orderId || !appUrl) {
348
355
  return {
349
356
  error: 'Bad Request',
350
357
  message: `vendorId or orderId is required, vendorId: ${vendorId}, orderId: ${orderId}`,
@@ -363,7 +370,7 @@ async function executeVendorOperation(
363
370
 
364
371
  try {
365
372
  const vendorAdapter = await VendorFulfillmentService.getVendorAdapter(vendor.vendor_key);
366
- const data = await vendorAdapter[operation](vendor, orderId, { shortUrl });
373
+ const data = await vendorAdapter[operation](vendor, orderId, { shortUrl, appUrl });
367
374
 
368
375
  return { data: { ...data, vendorType: vendor.vendor_type }, code: 200 };
369
376
  } catch (error: any) {
@@ -424,7 +431,13 @@ async function processVendorOrders(sessionId: string, operation: 'getOrder' | 'g
424
431
  };
425
432
  }
426
433
 
427
- const result = await executeVendorOperation(item.vendor_id, item.order_id, operation, shortUrl);
434
+ const result = await executeVendorOperation({
435
+ vendorId: item.vendor_id,
436
+ orderId: item.order_id,
437
+ operation,
438
+ shortUrl,
439
+ appUrl: item.app_url,
440
+ });
428
441
 
429
442
  // Handle error responses from vendor functions
430
443
  if (result.error) {
@@ -533,7 +546,13 @@ async function redirectToVendor(req: any, res: any) {
533
546
  return res.redirect('/404');
534
547
  }
535
548
 
536
- const result = await executeVendorOperation(vendorId, order.order_id || '', 'getOrder', false);
549
+ const result = await executeVendorOperation({
550
+ vendorId,
551
+ orderId: order.order_id || '',
552
+ operation: 'getOrder',
553
+ shortUrl: false,
554
+ appUrl: order.app_url,
555
+ });
537
556
  if (result.error || !result.data) {
538
557
  logger.warn('Vendor status detail not found', {
539
558
  subscriptionId,
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.22.2
17
+ version: 1.22.3
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.22.2",
3
+ "version": "1.22.3",
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,9 +56,9 @@
56
56
  "@blocklet/error": "^0.2.5",
57
57
  "@blocklet/js-sdk": "^1.16.54-beta-20251029-055649-a9143beb",
58
58
  "@blocklet/logger": "^1.16.54-beta-20251029-055649-a9143beb",
59
- "@blocklet/payment-broker-client": "1.22.2",
60
- "@blocklet/payment-react": "1.22.2",
61
- "@blocklet/payment-vendor": "1.22.2",
59
+ "@blocklet/payment-broker-client": "1.22.3",
60
+ "@blocklet/payment-react": "1.22.3",
61
+ "@blocklet/payment-vendor": "1.22.3",
62
62
  "@blocklet/sdk": "^1.16.54-beta-20251029-055649-a9143beb",
63
63
  "@blocklet/ui-react": "^3.1.53",
64
64
  "@blocklet/uploader": "^0.3.2",
@@ -128,7 +128,7 @@
128
128
  "devDependencies": {
129
129
  "@abtnode/types": "^1.16.54-beta-20251029-055649-a9143beb",
130
130
  "@arcblock/eslint-config-ts": "^0.3.3",
131
- "@blocklet/payment-types": "1.22.2",
131
+ "@blocklet/payment-types": "1.22.3",
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": "13ea906cf090d7069a970d97d9a3f06426b27092"
178
+ "gitHead": "d5967646cdb253d7508a84ccc2dc0e96f4ae25ea"
179
179
  }