@chevre/domain 21.30.0-alpha.20 → 21.30.0-alpha.21

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.
@@ -350,9 +350,9 @@ function payActionParams2seatInfoSyncIn(params) {
350
350
  * MovieTicket着券取消
351
351
  */
352
352
  function refundMovieTicket(params) {
353
- // tslint:disable-next-line:max-func-body-length
353
+ // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
354
354
  return (repos) => __awaiter(this, void 0, void 0, function* () {
355
- var _a, _b, _c, _d, _e, _f;
355
+ var _a, _b, _c, _d, _e, _f, _g;
356
356
  const paymentMethodId = (_a = params.object[0]) === null || _a === void 0 ? void 0 : _a.paymentMethod.paymentMethodId;
357
357
  const paymentServiceId = (_b = params.object[0]) === null || _b === void 0 ? void 0 : _b.id;
358
358
  const availableChannel = yield repos.paymentService.findAvailableChannel({
@@ -368,66 +368,133 @@ function refundMovieTicket(params) {
368
368
  state: ''
369
369
  });
370
370
  const movieTicketSeatService = new surfrock.service.seat.SeatService({ endpoint: String(availableChannel.serviceUrl), auth: mvtkReserveAuthClient }, { timeout: credentials_1.credentials.movieticketReserve.timeout });
371
+ let seatInfoSyncCancelIn;
372
+ let seatInfoSyncIn;
373
+ const useSeatInfoSyncCancel = ((_f = availableChannel.credentials) === null || _f === void 0 ? void 0 : _f.useSeatInfoSyncCancel) === true;
374
+ if (useSeatInfoSyncCancel) {
375
+ seatInfoSyncCancelIn = yield createSeatInfoSyncCancelInOnRefund({
376
+ project: { id: params.project.id },
377
+ paymentMethodId
378
+ })({ action: repos.action });
379
+ }
380
+ else {
381
+ seatInfoSyncIn = yield createSeatInfoSyncInOnRefund({
382
+ project: { id: params.project.id },
383
+ paymentMethodId
384
+ })({ action: repos.action });
385
+ }
371
386
  // アクション開始
372
- let action = yield repos.action.start(Object.assign(Object.assign({}, params), (typeof ((_f = params.sameAs) === null || _f === void 0 ? void 0 : _f.id) === 'string')
387
+ // instrumentをセット(2024-04-30~)
388
+ const instrument = Object.assign(Object.assign({ typeOf: factory.service.paymentService.PaymentServiceType.MovieTicket }, (seatInfoSyncIn !== undefined) ? { seatInfoSyncIn } : undefined), (seatInfoSyncCancelIn !== undefined) ? { seatInfoSyncCancelIn } : undefined);
389
+ let action = yield repos.action.start(Object.assign(Object.assign(Object.assign({}, params), (typeof ((_g = params.sameAs) === null || _g === void 0 ? void 0 : _g.id) === 'string')
373
390
  ? {
374
391
  sameAs: {
375
392
  id: params.sameAs.id,
376
393
  typeOf: 'Task'
377
394
  }
378
395
  }
379
- : undefined));
380
- let seatInfoSyncIn;
396
+ : undefined), { instrument }));
397
+ let seatInfoSyncCancelResult;
381
398
  let seatInfoSyncResult;
382
399
  let seatInfoSyncResultAsError;
383
- try {
384
- seatInfoSyncIn = yield createSeatInfoSyncInOnRefund({
385
- project: { id: params.project.id },
386
- paymentMethodId
387
- })({ action: repos.action });
388
- seatInfoSyncResult = yield movieTicketSeatService.seatInfoSync(seatInfoSyncIn);
389
- }
390
- catch (error) {
391
- let throwsError = true;
392
- // 「存在しない興行会社システム座席予約番号が入力されました」の場合、取消済なのでok
393
- if (error.name === errorHandler_1.MOVIE_TICKET_RESERVE_REQUEST_ERROR_NAME) {
394
- if (error.code === http_status_1.BAD_REQUEST && error.message === MovieticketReserveRequestErrorMessage.NotFound) {
395
- seatInfoSyncResult = error;
396
- throwsError = false;
397
- }
398
- // ReservationResult 19の内容が不明だがリトライする意味はおそらくないパターン
399
- if (error.code === http_status_1.BAD_REQUEST && error.message === MovieticketReserveRequestErrorMessage.ReservationResult19) {
400
- seatInfoSyncResult = error;
401
- throwsError = false;
402
- }
403
- // surfrock: bookingNoが存在しないケースをハンドル(2024-03-13~)
404
- const expectedMessage4surfrockNotFound = JSON.stringify({ message: `bookingNo:"${paymentMethodId}" が見つかりません。` });
405
- if (error.code === http_status_1.BAD_REQUEST && error.message === expectedMessage4surfrockNotFound) {
406
- seatInfoSyncResult = error;
407
- throwsError = false;
400
+ if (useSeatInfoSyncCancel) {
401
+ try {
402
+ if (seatInfoSyncCancelIn === undefined) {
403
+ throw new factory.errors.ServiceUnavailable('seatInfoSyncCancelIn must be set');
408
404
  }
409
- // 着券取消可能期間超過を認識した上でのあえての返金の場合(注文からしばらく経って返品など)(2024-03-19~)
410
- if (error.code === http_status_1.BAD_REQUEST && error.message === MovieticketReserveRequestErrorMessage.CancellationPeriodPassed) {
411
- if (params.purpose.typeOf === factory.actionType.ReturnAction) {
412
- // seatInfoSyncResult = error;
413
- seatInfoSyncResultAsError = error;
405
+ seatInfoSyncCancelResult = yield movieTicketSeatService.seatInfoSyncCancel(seatInfoSyncCancelIn);
406
+ }
407
+ catch (error) {
408
+ let throwsError = true;
409
+ // 「存在しない興行会社システム座席予約番号が入力されました」の場合、取消済なのでok
410
+ if (error.name === errorHandler_1.MOVIE_TICKET_RESERVE_REQUEST_ERROR_NAME) {
411
+ if (error.code === http_status_1.BAD_REQUEST && error.message === MovieticketReserveRequestErrorMessage.NotFound) {
412
+ seatInfoSyncCancelResult = error;
414
413
  throwsError = false;
415
414
  }
415
+ // ReservationResult 19の内容が不明だがリトライする意味はおそらくないパターン
416
+ if (error.code === http_status_1.BAD_REQUEST && error.message === MovieticketReserveRequestErrorMessage.ReservationResult19) {
417
+ seatInfoSyncCancelResult = error;
418
+ throwsError = false;
419
+ }
420
+ // surfrock: bookingNoが存在しないケースをハンドル(2024-03-13~)
421
+ const expectedMessage4surfrockNotFound = JSON.stringify({ message: `bookingNo:"${paymentMethodId}" が見つかりません。` });
422
+ if (error.code === http_status_1.BAD_REQUEST && error.message === expectedMessage4surfrockNotFound) {
423
+ seatInfoSyncCancelResult = error;
424
+ throwsError = false;
425
+ }
426
+ // 着券取消可能期間超過を認識した上でのあえての返金の場合(注文からしばらく経って返品など)(2024-03-19~)
427
+ if (error.code === http_status_1.BAD_REQUEST && error.message === MovieticketReserveRequestErrorMessage.CancellationPeriodPassed) {
428
+ if (params.purpose.typeOf === factory.actionType.ReturnAction) {
429
+ seatInfoSyncResultAsError = error;
430
+ throwsError = false;
431
+ }
432
+ }
433
+ }
434
+ if (throwsError) {
435
+ let message = String(error.message);
436
+ // エラー通知先で情報を読み取りやすくするために、messageに情報付加
437
+ message += `決済ID:${paymentMethodId}`;
438
+ try {
439
+ const actionError = Object.assign(Object.assign({}, error), { message: message, name: error.name });
440
+ yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
441
+ }
442
+ catch (__) {
443
+ // 失敗したら仕方ない
444
+ }
445
+ error = (0, errorHandler_1.handleMvtkReserveError)(Object.assign(Object.assign({}, error), { message: message }));
446
+ throw error;
416
447
  }
417
448
  }
418
- if (throwsError) {
419
- let message = String(error.message);
420
- // エラー通知先で情報を読み取りやすくするために、messageに情報付加
421
- message += `決済ID:${paymentMethodId}`;
422
- try {
423
- const actionError = Object.assign(Object.assign({}, error), { message: message, name: error.name });
424
- yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
449
+ }
450
+ else {
451
+ try {
452
+ if (seatInfoSyncIn === undefined) {
453
+ throw new factory.errors.ServiceUnavailable('seatInfoSyncIn must be set');
425
454
  }
426
- catch (__) {
427
- // 失敗したら仕方ない
455
+ seatInfoSyncResult = yield movieTicketSeatService.seatInfoSync(seatInfoSyncIn);
456
+ }
457
+ catch (error) {
458
+ let throwsError = true;
459
+ // 「存在しない興行会社システム座席予約番号が入力されました」の場合、取消済なのでok
460
+ if (error.name === errorHandler_1.MOVIE_TICKET_RESERVE_REQUEST_ERROR_NAME) {
461
+ if (error.code === http_status_1.BAD_REQUEST && error.message === MovieticketReserveRequestErrorMessage.NotFound) {
462
+ seatInfoSyncResult = error;
463
+ throwsError = false;
464
+ }
465
+ // ReservationResult 19の内容が不明だがリトライする意味はおそらくないパターン
466
+ if (error.code === http_status_1.BAD_REQUEST && error.message === MovieticketReserveRequestErrorMessage.ReservationResult19) {
467
+ seatInfoSyncResult = error;
468
+ throwsError = false;
469
+ }
470
+ // surfrock: bookingNoが存在しないケースをハンドル(2024-03-13~)
471
+ const expectedMessage4surfrockNotFound = JSON.stringify({ message: `bookingNo:"${paymentMethodId}" が見つかりません。` });
472
+ if (error.code === http_status_1.BAD_REQUEST && error.message === expectedMessage4surfrockNotFound) {
473
+ seatInfoSyncResult = error;
474
+ throwsError = false;
475
+ }
476
+ // 着券取消可能期間超過を認識した上でのあえての返金の場合(注文からしばらく経って返品など)(2024-03-19~)
477
+ if (error.code === http_status_1.BAD_REQUEST && error.message === MovieticketReserveRequestErrorMessage.CancellationPeriodPassed) {
478
+ if (params.purpose.typeOf === factory.actionType.ReturnAction) {
479
+ seatInfoSyncResultAsError = error;
480
+ throwsError = false;
481
+ }
482
+ }
483
+ }
484
+ if (throwsError) {
485
+ let message = String(error.message);
486
+ // エラー通知先で情報を読み取りやすくするために、messageに情報付加
487
+ message += `決済ID:${paymentMethodId}`;
488
+ try {
489
+ const actionError = Object.assign(Object.assign({}, error), { message: message, name: error.name });
490
+ yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
491
+ }
492
+ catch (__) {
493
+ // 失敗したら仕方ない
494
+ }
495
+ error = (0, errorHandler_1.handleMvtkReserveError)(Object.assign(Object.assign({}, error), { message: message }));
496
+ throw error;
428
497
  }
429
- error = (0, errorHandler_1.handleMvtkReserveError)(Object.assign(Object.assign({}, error), { message: message }));
430
- throw error;
431
498
  }
432
499
  }
433
500
  // アクションとしてはFailedだが後続処理を実行するケースに対応(2024-03-21~)
@@ -435,11 +502,10 @@ function refundMovieTicket(params) {
435
502
  action = (yield repos.action.giveUpWithObject({ typeOf: action.typeOf, id: action.id, error: seatInfoSyncResultAsError }));
436
503
  }
437
504
  else {
438
- const actionResult = Object.assign(Object.assign({}, (seatInfoSyncIn !== undefined) ? { seatInfoSyncIn } : undefined), (seatInfoSyncResult !== undefined) ? { seatInfoSyncResult } : undefined);
505
+ const actionResult = Object.assign(Object.assign({}, (seatInfoSyncResult !== undefined) ? { seatInfoSyncResult } : undefined), (seatInfoSyncCancelResult !== undefined) ? { seatInfoSyncCancelResult } : undefined);
439
506
  action = (yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult }));
440
507
  }
441
508
  yield (0, onRefund_1.onRefund)(action)(repos);
442
- // return action;
443
509
  });
444
510
  }
445
511
  exports.refundMovieTicket = refundMovieTicket;
@@ -468,9 +534,43 @@ function createSeatInfoSyncInOnRefund(params) {
468
534
  }
469
535
  let seatInfoSyncIn;
470
536
  // 着券時のseatInfoSyncInに対してtrkshFlgだけ変更してリクエストする
471
- // instrument参照に統一(2022-05-02~)
472
537
  seatInfoSyncIn = Object.assign(Object.assign({}, seatInfoSyncInOnPay), { trkshFlg: surfrock.service.seat.factory.DeleteFlag.True // 取消フラグ
473
538
  });
474
539
  return seatInfoSyncIn;
475
540
  });
476
541
  }
542
+ function createSeatInfoSyncCancelInOnRefund(params) {
543
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
544
+ var _a;
545
+ // 本アクションに対応するPayActionを取り出す
546
+ // 例えばtimeoutが原因でCompletedActionStatusでない場合、外部サービス側では着券済の可能性もあるので、そこを考慮する
547
+ const payAction = yield repos.action.findPayAction({
548
+ project: { id: params.project.id },
549
+ paymentMethodId: params.paymentMethodId,
550
+ actionStatus: {
551
+ $in: [
552
+ factory.actionStatusType.ActiveActionStatus,
553
+ factory.actionStatusType.CompletedActionStatus,
554
+ factory.actionStatusType.FailedActionStatus
555
+ ]
556
+ }
557
+ });
558
+ if (payAction === undefined) {
559
+ throw new factory.errors.NotFound('PayAction');
560
+ }
561
+ const seatInfoSyncInOnPay = (_a = payAction.instrument) === null || _a === void 0 ? void 0 : _a.seatInfoSyncIn;
562
+ if (seatInfoSyncInOnPay === undefined) {
563
+ throw new factory.errors.NotFound('PayAction.instrument?.seatInfoSyncIn');
564
+ }
565
+ let seatInfoSyncCancelIn;
566
+ seatInfoSyncCancelIn = {
567
+ kgygishCd: seatInfoSyncInOnPay.kgygishCd,
568
+ kgysystmzskyykNo: seatInfoSyncInOnPay.kgysystmzskyykNo,
569
+ kgysystmzskyykNoIkktsCnclFlg: '1',
570
+ jyuTyp: surfrock.service.seat.factory.seatInfoSyncCancel.IJyuTyp.IJyuTyp05,
571
+ jyuTypRmk: ''
572
+ // knyknrNoInfoIn: [],
573
+ };
574
+ return seatInfoSyncCancelIn;
575
+ });
576
+ }
package/package.json CHANGED
@@ -10,12 +10,12 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@aws-sdk/credential-providers": "3.433.0",
13
- "@chevre/factory": "4.369.0-alpha.1",
13
+ "@chevre/factory": "4.369.0-alpha.2",
14
14
  "@cinerino/sdk": "5.17.1",
15
15
  "@motionpicture/coa-service": "9.4.0",
16
16
  "@motionpicture/gmo-service": "5.3.0",
17
17
  "@sendgrid/mail": "6.4.0",
18
- "@surfrock/sdk": "1.2.0",
18
+ "@surfrock/sdk": "1.3.0-alpha.0",
19
19
  "cdigit": "2.6.7",
20
20
  "debug": "^3.2.7",
21
21
  "google-libphonenumber": "^3.2.18",
@@ -110,5 +110,5 @@
110
110
  "postversion": "git push origin --tags",
111
111
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
112
112
  },
113
- "version": "21.30.0-alpha.20"
113
+ "version": "21.30.0-alpha.21"
114
114
  }