@chevre/domain 21.29.0 → 21.30.0-alpha.1

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.
@@ -5,6 +5,7 @@ import * as mongoose from 'mongoose';
5
5
  import { chevre } from '../../../lib/index';
6
6
 
7
7
  // const project = { id: String(process.env.PROJECT_ID) };
8
+ const STORAGE_PERIOD_IN_DAYS = 30;
8
9
 
9
10
  // tslint:disable-next-line:max-func-body-length
10
11
  async function main() {
@@ -16,18 +17,18 @@ async function main() {
16
17
  const cursor = taskRepo.getCursor(
17
18
  {
18
19
  name: { $eq: chevre.factory.taskName.DeleteTransaction },
19
- status: { $eq: chevre.factory.taskStatus.Ready },
20
- runsAt: {
21
- $gte: moment()
22
- // tslint:disable-next-line:no-magic-numbers
23
- .add(329, 'days')
24
- .toDate(),
25
- $lte: moment()
26
- // tslint:disable-next-line:no-magic-numbers
27
- .add(365, 'days')
28
- .toDate()
29
- }
30
- // _id: { $eq: '64aba5f37b8b8ef9eca60be5' }
20
+ status: { $eq: chevre.factory.taskStatus.Ready }
21
+ // runsAt: {
22
+ // $gte: moment()
23
+ // // tslint:disable-next-line:no-magic-numbers
24
+ // .add(29, 'days')
25
+ // .toDate(),
26
+ // $lte: moment()
27
+ // // tslint:disable-next-line:no-magic-numbers
28
+ // .add(365, 'days')
29
+ // .toDate()
30
+ // },
31
+ // _id: { $eq: '6440d8cf9e4983c32ade65de' }
31
32
  },
32
33
  {
33
34
  _id: 1,
@@ -51,7 +52,10 @@ async function main() {
51
52
 
52
53
  let placeOrderTransactionId: string | undefined;
53
54
  if (deleteTransactionTask.data.object.typeOf === chevre.factory.transactionType.PlaceOrder) {
54
- if (deleteTransactionTask.data.object.specifyingMethod === chevre.factory.task.deleteTransaction.SpecifyingMethod.Id) {
55
+ if (
56
+ (typeof deleteTransactionTask.data.object.specifyingMethod !== 'string')
57
+ || (deleteTransactionTask.data.object.specifyingMethod === chevre.factory.task.deleteTransaction.SpecifyingMethod.Id)
58
+ ) {
55
59
  placeOrderTransactionId = deleteTransactionTask.data.object.id;
56
60
  }
57
61
  }
@@ -59,17 +63,26 @@ async function main() {
59
63
  let alreadyMigrated = true;
60
64
  let runsAtExpected: moment.Moment | undefined;
61
65
  if (typeof placeOrderTransactionId === 'string') {
62
- const { endDate, status } = await transactionRepo.findById({
66
+ console.log(
67
+ 'checking transaction...',
68
+ deleteTransactionTask.project.id, deleteTransactionTask.name, deleteTransactionTask.id, deleteTransactionTask.runsAt,
69
+ placeOrderTransactionId
70
+ );
71
+ const placeOrderTransaction = (await transactionRepo.search({
72
+ limit: 1,
73
+ page: 1,
63
74
  typeOf: chevre.factory.transactionType.PlaceOrder,
64
- id: placeOrderTransactionId,
75
+ ids: [placeOrderTransactionId],
65
76
  inclusion: ['endDate', 'status'],
66
77
  exclusion: []
67
- });
68
- runsAtExpected = moment(endDate)
69
- // tslint:disable-next-line:no-magic-numbers
70
- .add(180, 'days');
78
+ })).shift();
79
+ if (placeOrderTransaction !== undefined) {
80
+ const { endDate, status } = placeOrderTransaction;
81
+ runsAtExpected = moment(endDate)
82
+ // tslint:disable-next-line:no-magic-numbers
83
+ .add(STORAGE_PERIOD_IN_DAYS, 'days');
71
84
 
72
- if (status !== chevre.factory.transactionStatusType.Confirmed) {
85
+ // if (status !== chevre.factory.transactionStatusType.Confirmed) {
73
86
  const taskRunsTooLate = moment(deleteTransactionTask.runsAt)
74
87
  .isAfter(runsAtExpected);
75
88
  const diff = moment(deleteTransactionTask.runsAt)
@@ -78,12 +91,13 @@ async function main() {
78
91
  if (taskRunsTooLate) {
79
92
  alreadyMigrated = false;
80
93
  }
94
+ // }
81
95
  }
82
96
  }
83
97
 
84
98
  if (alreadyMigrated) {
85
99
  console.log(
86
- 'already exist.',
100
+ 'already migrated.',
87
101
  deleteTransactionTask.project.id, deleteTransactionTask.name, deleteTransactionTask.id, deleteTransactionTask.runsAt,
88
102
  i, updateCount);
89
103
  } else {
@@ -0,0 +1,119 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ // const project = { id: String(process.env.PROJECT_ID) };
7
+
8
+ // tslint:disable-next-line:max-func-body-length
9
+ async function main() {
10
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
+
12
+ const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
13
+
14
+ const cursor = taskRepo.getCursor(
15
+ {
16
+ name: { $eq: chevre.factory.taskName.DeleteTransaction },
17
+ status: { $eq: chevre.factory.taskStatus.Ready }
18
+ // runsAt: {
19
+ // $gte: moment()
20
+ // // tslint:disable-next-line:no-magic-numbers
21
+ // .add(29, 'days')
22
+ // .toDate(),
23
+ // $lte: moment()
24
+ // // tslint:disable-next-line:no-magic-numbers
25
+ // .add(365, 'days')
26
+ // .toDate()
27
+ // },
28
+ // _id: { $eq: '6441bcf04014af2c7d39f6aa' }
29
+ },
30
+ {
31
+ _id: 1,
32
+ project: 1,
33
+ data: 1,
34
+ status: 1,
35
+ name: 1,
36
+ runsAt: 1
37
+ }
38
+ );
39
+ console.log('tasks found');
40
+
41
+ let i = 0;
42
+ let updateCount = 0;
43
+ await cursor.eachAsync(async (doc) => {
44
+ i += 1;
45
+ const deleteTransactionTask: Pick<
46
+ chevre.factory.task.deleteTransaction.ITask,
47
+ 'id' | 'project' | 'data' | 'status' | 'name' | 'runsAt'
48
+ > = doc.toObject();
49
+
50
+ let dataObject: chevre.factory.task.deleteTransaction.IObjectAsPlaceOrder | undefined;
51
+ if (deleteTransactionTask.data.object.typeOf === chevre.factory.transactionType.PlaceOrder) {
52
+ if (
53
+ (typeof deleteTransactionTask.data.object.specifyingMethod !== 'string')
54
+ || (deleteTransactionTask.data.object.specifyingMethod === chevre.factory.task.deleteTransaction.SpecifyingMethod.Id)
55
+ ) {
56
+ const existingDataObject = deleteTransactionTask.data.object;
57
+ if ((<any>existingDataObject).agent !== undefined) {
58
+ dataObject = {
59
+ specifyingMethod: chevre.factory.task.deleteTransaction.SpecifyingMethod.Id,
60
+ id: existingDataObject.id,
61
+ object: {
62
+ ...(typeof existingDataObject.object.confirmationNumber === 'string')
63
+ ? { confirmationNumber: existingDataObject.object.confirmationNumber }
64
+ : undefined,
65
+ ...(typeof existingDataObject.object.orderNumber === 'string')
66
+ ? { orderNumber: existingDataObject.object.orderNumber }
67
+ : undefined
68
+ },
69
+ project: existingDataObject.project,
70
+ startDate: existingDataObject.startDate,
71
+ typeOf: existingDataObject.typeOf,
72
+ ...(existingDataObject.endDate !== undefined) ? { endDate: existingDataObject.endDate } : undefined
73
+ };
74
+ }
75
+ }
76
+ }
77
+
78
+ let alreadyMigrated = true;
79
+ if (typeof dataObject?.id === 'string') {
80
+ alreadyMigrated = false;
81
+ }
82
+
83
+ if (alreadyMigrated) {
84
+ console.log(
85
+ 'already migrated.',
86
+ deleteTransactionTask.project.id, deleteTransactionTask.name, deleteTransactionTask.id, deleteTransactionTask.runsAt,
87
+ i, updateCount);
88
+ } else {
89
+ console.log(
90
+ 'updating...',
91
+ deleteTransactionTask.project.id, deleteTransactionTask.name, deleteTransactionTask.id, deleteTransactionTask.runsAt,
92
+ i, updateCount, dataObject);
93
+ if (dataObject !== undefined) {
94
+ await taskRepo.taskModel.findByIdAndUpdate(
95
+ deleteTransactionTask.id,
96
+ {
97
+ $set: {
98
+ 'data.object': dataObject
99
+ }
100
+ },
101
+ { timestamps: false }
102
+ )
103
+ .exec();
104
+ }
105
+ updateCount += 1;
106
+ console.log(
107
+ 'updated.',
108
+ deleteTransactionTask.project.id, deleteTransactionTask.name, deleteTransactionTask.id, deleteTransactionTask.runsAt,
109
+ i, updateCount);
110
+ }
111
+ });
112
+
113
+ console.log(i, 'tasks checked');
114
+ console.log(updateCount, 'tasks updated');
115
+ }
116
+
117
+ main()
118
+ .then()
119
+ .catch(console.error);
@@ -115,7 +115,8 @@ async function main() {
115
115
  options: {
116
116
  useCancelPayTransactionOnFailed: false,
117
117
  useCheckMovieTicketBeforePay: false,
118
- useCheckByIdentifierIfNotYet: false
118
+ useCheckByIdentifierIfNotYet: false,
119
+ useUnlockTransactionProcess: false
119
120
  }
120
121
  })({
121
122
  accountingReport: await chevre.repository.AccountingReport.createInstance(mongoose.connection),
@@ -128,6 +129,8 @@ async function main() {
128
129
  product: await chevre.repository.Product.createInstance(mongoose.connection),
129
130
  task: await chevre.repository.Task.createInstance(mongoose.connection),
130
131
  transactionNumber: await chevre.repository.TransactionNumber.createInstance(client),
132
+ transactionProcess:
133
+ await chevre.repository.TransactionProcess.createInstance(client, { lockExpiresInSeconds: 120 }),
131
134
  transaction: await chevre.repository.Transaction.createInstance(mongoose.connection)
132
135
  });
133
136
  console.log('payment authorized.', authorizeResult.id);
@@ -26,7 +26,8 @@ const schemaDefinition = {
26
26
  instrument: mongoose_1.SchemaTypes.Mixed,
27
27
  location: mongoose_1.SchemaTypes.Mixed,
28
28
  replacer: mongoose_1.SchemaTypes.Mixed,
29
- targetCollection: mongoose_1.SchemaTypes.Mixed // add targetCollection(2024-03-19~)
29
+ targetCollection: mongoose_1.SchemaTypes.Mixed,
30
+ sameAs: mongoose_1.SchemaTypes.Mixed // タスク関連付けのために追加(2024-04-20~)
30
31
  };
31
32
  const schemaOptions = {
32
33
  autoIndex: settings_1.MONGO_AUTO_INDEX,
@@ -35,7 +36,6 @@ const schemaOptions = {
35
36
  id: true,
36
37
  read: 'primary',
37
38
  writeConcern: writeConcern_1.writeConcern,
38
- // true化(2022-11-12~)
39
39
  strict: true,
40
40
  strictQuery: false,
41
41
  timestamps: {
@@ -0,0 +1,24 @@
1
+ import type { RedisClientType } from 'redis';
2
+ import * as factory from '../factory';
3
+ interface IProcessKey {
4
+ typeOf: factory.transactionType;
5
+ /**
6
+ * 取引ID
7
+ */
8
+ id: string;
9
+ }
10
+ interface IOptions {
11
+ lockExpiresInSeconds: number;
12
+ }
13
+ /**
14
+ * 取引プロセスリポジトリ
15
+ */
16
+ export declare class TransactionProcessRepository {
17
+ private readonly options;
18
+ private readonly redisClient;
19
+ constructor(redisClient: RedisClientType, options: IOptions);
20
+ static CREATE_REDIS_KEY(params: IProcessKey): string;
21
+ lock(params: IProcessKey): Promise<boolean>;
22
+ unlock(params: IProcessKey): Promise<void>;
23
+ }
24
+ export {};
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TransactionProcessRepository = void 0;
13
+ const createDebug = require("debug");
14
+ const factory = require("../factory");
15
+ const debug = createDebug('chevre-domain:repo:transactionProcess');
16
+ const DEFAULT_LOCK_EXPIRES = 120;
17
+ /**
18
+ * 取引プロセスリポジトリ
19
+ */
20
+ class TransactionProcessRepository {
21
+ constructor(redisClient, options) {
22
+ this.redisClient = redisClient;
23
+ this.options = options;
24
+ }
25
+ static CREATE_REDIS_KEY(params) {
26
+ // 最適化(2024-03-21~)
27
+ // return `chevre-api:${params.project.id}:transactionProcess:${params.typeOf}:${params.id}`;
28
+ return `chvrapi:lockTxn:${params.id}`;
29
+ }
30
+ lock(params) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const key = TransactionProcessRepository.CREATE_REDIS_KEY(params);
33
+ // const ttl = TRANSACTION_RROCESS_LOCK_EXPIRES;
34
+ const ttl = (typeof this.options.lockExpiresInSeconds === 'number') ? this.options.lockExpiresInSeconds : DEFAULT_LOCK_EXPIRES;
35
+ const results = yield this.redisClient.multi()
36
+ .setNX(key, '1')
37
+ .expire(key, ttl)
38
+ .exec();
39
+ debug('locked,', params.id, results);
40
+ if (Array.isArray(results) && (results[0] === 1 || results[0] === true)) {
41
+ return true;
42
+ }
43
+ else {
44
+ throw new factory.errors.AlreadyInUse(params.typeOf, [], 'Another transaction process in progress');
45
+ }
46
+ });
47
+ }
48
+ unlock(params) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ const key = TransactionProcessRepository.CREATE_REDIS_KEY(params);
51
+ yield this.redisClient.del([key]);
52
+ });
53
+ }
54
+ }
55
+ exports.TransactionProcessRepository = TransactionProcessRepository;
@@ -57,6 +57,7 @@ import type { MongoRepository as TaskRepo } from './repo/task';
57
57
  import type { MongoRepository as TelemetryRepo } from './repo/telemetry';
58
58
  import type { MongoRepository as TransactionRepo } from './repo/transaction';
59
59
  import type { RedisRepository as TransactionNumberRepo } from './repo/transactionNumber';
60
+ import type { TransactionProcessRepository } from './repo/transactionProcess';
60
61
  import type { MongoRepository as TripRepo } from './repo/trip';
61
62
  import type { RedisRepository as ConfirmationNumberRepo } from './repo/confirmationNumber';
62
63
  import type { RedisRepository as OrderNumberRepo } from './repo/orderNumber';
@@ -323,6 +324,10 @@ export type TransactionNumber = TransactionNumberRepo;
323
324
  export declare namespace TransactionNumber {
324
325
  function createInstance(...params: ConstructorParameters<typeof TransactionNumberRepo>): Promise<TransactionNumberRepo>;
325
326
  }
327
+ export type TransactionProcess = TransactionProcessRepository;
328
+ export declare namespace TransactionProcess {
329
+ function createInstance(...params: ConstructorParameters<typeof TransactionProcessRepository>): Promise<TransactionProcessRepository>;
330
+ }
326
331
  export type Trip = TripRepo;
327
332
  export declare namespace Trip {
328
333
  function createInstance(...params: ConstructorParameters<typeof TripRepo>): Promise<TripRepo>;
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.StockHolder = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.SellerPaymentAccepted = exports.Seller = exports.Role = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductOffer = exports.ProductModel = exports.Product = exports.PriceSpecification = exports.place = exports.Permit = exports.Person = exports.paymentMethod = exports.PaymentServiceProvider = exports.PaymentService = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.Note = exports.MerchantReturnPolicy = exports.Member = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.CreativeWork = exports.ConfirmationNumber = exports.Comment = exports.Code = exports.CategoryCode = exports.AssetTransaction = exports.Aggregation = exports.AggregateReservation = exports.AggregateOffer = exports.AdditionalProperty = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.Account = exports.AcceptedOffer = void 0;
13
- exports.rateLimit = exports.Trip = exports.TransactionNumber = exports.Transaction = exports.Telemetry = exports.Task = void 0;
13
+ exports.rateLimit = exports.Trip = exports.TransactionProcess = exports.TransactionNumber = exports.Transaction = exports.Telemetry = exports.Task = void 0;
14
14
  var AcceptedOffer;
15
15
  (function (AcceptedOffer) {
16
16
  let repo;
@@ -802,6 +802,19 @@ var TransactionNumber;
802
802
  }
803
803
  TransactionNumber.createInstance = createInstance;
804
804
  })(TransactionNumber = exports.TransactionNumber || (exports.TransactionNumber = {}));
805
+ var TransactionProcess;
806
+ (function (TransactionProcess) {
807
+ let repo;
808
+ function createInstance(...params) {
809
+ return __awaiter(this, void 0, void 0, function* () {
810
+ if (repo === undefined) {
811
+ repo = (yield Promise.resolve().then(() => require('./repo/transactionProcess'))).TransactionProcessRepository;
812
+ }
813
+ return new repo(...params);
814
+ });
815
+ }
816
+ TransactionProcess.createInstance = createInstance;
817
+ })(TransactionProcess = exports.TransactionProcess || (exports.TransactionProcess = {}));
805
818
  var Trip;
806
819
  (function (Trip) {
807
820
  let repo;
@@ -13,6 +13,7 @@ import type { MongoRepository as PaymentAcceptedRepo } from '../../repo/sellerPa
13
13
  import type { MongoRepository as TaskRepo } from '../../repo/task';
14
14
  import type { MongoRepository as TransactionRepo } from '../../repo/transaction';
15
15
  import type { RedisRepository as TransactionNumberRepo } from '../../repo/transactionNumber';
16
+ import type { TransactionProcessRepository } from '../../repo/transactionProcess';
16
17
  import * as PayTransactionService from '../assetTransaction/pay';
17
18
  import { onPaymentStatusChanged } from './any/onPaymentStatusChanged';
18
19
  import { person2username } from './any/person2username';
@@ -63,6 +64,7 @@ interface IAuthorizeRepos {
63
64
  task: TaskRepo;
64
65
  transaction: TransactionRepo;
65
66
  transactionNumber: TransactionNumberRepo;
67
+ transactionProcess: TransactionProcessRepository;
66
68
  }
67
69
  type IAuthorizeOperation<T> = (repos: IAuthorizeRepos) => Promise<T>;
68
70
  interface IPublishPaymentUrlRepos {
@@ -112,6 +114,7 @@ declare function authorize(params: {
112
114
  useCancelPayTransactionOnFailed: boolean;
113
115
  useCheckMovieTicketBeforePay: boolean;
114
116
  useCheckByIdentifierIfNotYet: boolean;
117
+ useUnlockTransactionProcess: boolean;
115
118
  };
116
119
  }): IAuthorizeOperation<{
117
120
  /**
@@ -278,7 +278,7 @@ exports.publishPaymentUrl = publishPaymentUrl;
278
278
  * 決済承認
279
279
  */
280
280
  function authorize(params) {
281
- // tslint:disable-next-line:max-func-body-length
281
+ // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
282
282
  return (repos) => __awaiter(this, void 0, void 0, function* () {
283
283
  var _a, _b;
284
284
  const transaction = yield repos.transaction.findInProgressById({ typeOf: params.purpose.typeOf, id: params.purpose.id });
@@ -406,12 +406,16 @@ function authorize(params) {
406
406
  }
407
407
  const result = (0, factory_1.createAuthorizeResult)({ payTransaction, object: authorizeObject });
408
408
  yield repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: result });
409
+ // 取引プロセスロック解除(2024-04-20~)
410
+ if (params.options.useUnlockTransactionProcess) {
411
+ yield repos.transactionProcess.unlock({ typeOf: transaction.typeOf, id: transaction.id });
412
+ }
409
413
  return { id: action.id };
410
414
  });
411
415
  }
412
416
  exports.authorize = authorize;
413
417
  /**
414
- * 注文取引に保管された決済情報を承認しようとしている決済の整合性をを検証する
418
+ * 注文取引に保管された決済情報を承認しようとしている決済の整合性を検証する
415
419
  */
416
420
  function validatePaymentMethodByTransaction(params) {
417
421
  var _a, _b;
@@ -56,7 +56,11 @@ declare function payCreditCard(params: factory.task.pay.IPayActionData): (repos:
56
56
  /**
57
57
  * クレジットカード返金
58
58
  */
59
- declare function refundCreditCard(params: factory.task.refund.IData, options: {
59
+ declare function refundCreditCard(params: factory.task.refund.IData & {
60
+ sameAs?: {
61
+ id: string;
62
+ };
63
+ }, options: {
60
64
  requirePayAction: boolean;
61
65
  }): (repos: {
62
66
  action: ActionRepo;
@@ -421,7 +421,7 @@ function processAlterTran(params) {
421
421
  */
422
422
  function refundCreditCard(params, options) {
423
423
  return (repos) => __awaiter(this, void 0, void 0, function* () {
424
- var _a, _b, _c, _d, _e;
424
+ var _a, _b, _c, _d, _e, _f;
425
425
  const paymentMethodType = (_a = params.object[0]) === null || _a === void 0 ? void 0 : _a.paymentMethod.typeOf;
426
426
  const paymentMethodId = (_b = params.object[0]) === null || _b === void 0 ? void 0 : _b.paymentMethod.paymentMethodId;
427
427
  const paymentServiceId = (_c = params.object[0]) === null || _c === void 0 ? void 0 : _c.id;
@@ -443,7 +443,14 @@ function refundCreditCard(params, options) {
443
443
  typeOf: factory.service.paymentService.PaymentServiceType.CreditCard,
444
444
  id: paymentServiceId
445
445
  });
446
- let action = yield repos.action.start(params);
446
+ let action = yield repos.action.start(Object.assign(Object.assign({}, params), (typeof ((_e = params.sameAs) === null || _e === void 0 ? void 0 : _e.id) === 'string')
447
+ ? {
448
+ sameAs: {
449
+ id: params.sameAs.id,
450
+ typeOf: 'Task'
451
+ }
452
+ }
453
+ : undefined));
447
454
  let alterTranResult = [];
448
455
  try {
449
456
  alterTranResult = yield processChangeTransaction({
@@ -452,7 +459,7 @@ function refundCreditCard(params, options) {
452
459
  paymentMethodId: paymentMethodId,
453
460
  shopId: shopId,
454
461
  shopPass: shopPass,
455
- refundFee: (_e = params.object[0]) === null || _e === void 0 ? void 0 : _e.refundFee
462
+ refundFee: (_f = params.object[0]) === null || _f === void 0 ? void 0 : _f.refundFee
456
463
  });
457
464
  }
458
465
  catch (error) {
@@ -499,6 +506,12 @@ function processChangeTransaction(params) {
499
506
  if (searchTradeResult.tranId !== creditCardSalesBefore.tranId) {
500
507
  alreadyRefunded = true;
501
508
  }
509
+ // tranIdが空文字のケース(SPSwrapperで発生)に対応(Voidに対してVoidを実行してしまうので)(2024-04-20~)
510
+ if (searchTradeResult.tranId === '' && creditCardSalesBefore.tranId === '') {
511
+ if (searchTradeResult.status === GMO.utils.util.Status.Void) {
512
+ alreadyRefunded = true;
513
+ }
514
+ }
502
515
  }
503
516
  if (alreadyRefunded) {
504
517
  alterTranResult.push({
@@ -70,5 +70,9 @@ declare function payMovieTicket(params: factory.task.pay.IPayActionData): IPayOp
70
70
  /**
71
71
  * MovieTicket着券取消
72
72
  */
73
- declare function refundMovieTicket(params: factory.task.refund.IData): IRefundOperation<void>;
73
+ declare function refundMovieTicket(params: factory.task.refund.IData & {
74
+ sameAs?: {
75
+ id: string;
76
+ };
77
+ }): IRefundOperation<void>;
74
78
  export { ICheckResult, authorize, checkMovieTicket, payMovieTicket, refundMovieTicket, voidTransaction };
@@ -352,7 +352,7 @@ function payActionParams2seatInfoSyncIn(params) {
352
352
  function refundMovieTicket(params) {
353
353
  // tslint:disable-next-line:max-func-body-length
354
354
  return (repos) => __awaiter(this, void 0, void 0, function* () {
355
- var _a, _b, _c, _d, _e;
355
+ var _a, _b, _c, _d, _e, _f;
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({
@@ -369,7 +369,14 @@ function refundMovieTicket(params) {
369
369
  });
370
370
  const movieTicketSeatService = new surfrock.service.seat.SeatService({ endpoint: String(availableChannel.serviceUrl), auth: mvtkReserveAuthClient }, { timeout: credentials_1.credentials.movieticketReserve.timeout });
371
371
  // アクション開始
372
- let action = yield repos.action.start(params);
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')
373
+ ? {
374
+ sameAs: {
375
+ id: params.sameAs.id,
376
+ typeOf: 'Task'
377
+ }
378
+ }
379
+ : undefined));
373
380
  let seatInfoSyncIn;
374
381
  let seatInfoSyncResult;
375
382
  let seatInfoSyncResultAsError;
@@ -45,7 +45,11 @@ export declare function voidPayment(params: factory.task.voidPayment.IData): (re
45
45
  /**
46
46
  * 返金
47
47
  */
48
- export declare function refund(params: factory.task.refund.IData): (repos: {
48
+ export declare function refund(params: factory.task.refund.IData & {
49
+ sameAs?: {
50
+ id: string;
51
+ };
52
+ }): (repos: {
49
53
  action: ActionRepo;
50
54
  accountingReport: AccountingReportRepo;
51
55
  paymentAccepted: PaymentAcceptedRepo;
@@ -3,4 +3,4 @@ import * as factory from '../../factory';
3
3
  /**
4
4
  * タスク実行関数
5
5
  */
6
- export declare function call(data: factory.task.refund.IData): IOperation<void>;
6
+ export declare function call(params: factory.task.refund.IData | factory.task.refund.ITask): IOperation<void>;
@@ -25,11 +25,19 @@ const PaymentService = require("../payment");
25
25
  /**
26
26
  * タスク実行関数
27
27
  */
28
- function call(data) {
28
+ function call(params) {
29
29
  return (settings) => __awaiter(this, void 0, void 0, function* () {
30
30
  if (settings.redisClient === undefined) {
31
31
  throw new factory.errors.Argument('settings', 'redisClient required');
32
32
  }
33
+ let data;
34
+ if (params.name === factory.taskName.Refund) {
35
+ data = Object.assign(Object.assign({}, params.data), { sameAs: { id: params.id } // タスクIDを関連付け(2024-04-20~)
36
+ });
37
+ }
38
+ else {
39
+ data = params;
40
+ }
33
41
  yield PaymentService.refund(data)({
34
42
  accountingReport: new accountingReport_1.MongoRepository(settings.connection),
35
43
  action: new action_1.MongoRepository(settings.connection),
@@ -87,7 +87,13 @@ function execute(task) {
87
87
  try {
88
88
  // タスク名の関数が定義されていなければ、TypeErrorとなる
89
89
  const { call } = yield Promise.resolve(`${`./task/${task.name}`}`).then(s => require(s));
90
- yield call(task.data)(settings);
90
+ switch (task.name) {
91
+ case factory.taskName.Refund:
92
+ yield call(task)(settings);
93
+ break;
94
+ default:
95
+ yield call(task.data)(settings);
96
+ }
91
97
  const result = {
92
98
  executedAt: now,
93
99
  endDate: new Date(),
package/package.json CHANGED
@@ -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.29.0"
113
+ "version": "21.30.0-alpha.1"
114
114
  }