@chevre/domain 22.5.0-alpha.27 → 22.5.0-alpha.28

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.
@@ -71,7 +71,7 @@ export async function aggregateScreeningEvent() {
71
71
  abortedTasksWithoutReport: [],
72
72
  coa: { timeout: 1000 },
73
73
  gmo: { timeout: 1000, timeoutBackground: 1000, useFetch: true },
74
- movieticketReserve: { timeout: 1000, timeoutCheck: 1000 },
74
+ movieticketReserve: { timeout: 1000, timeoutCheck: 1000, minIntervalBetweenPayAndRefund: 0 },
75
75
  numTryConfirmReserveTransaction: 10,
76
76
  useAssetTransactionSyncProcessing: true,
77
77
  useExperimentalFeature: false
@@ -12,10 +12,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.refundMovieTicket = void 0;
13
13
  const surfrock = require("@surfrock/sdk");
14
14
  const http_status_1 = require("http-status");
15
+ const moment = require("moment");
15
16
  const errorHandler_1 = require("../../../errorHandler");
16
17
  const factory = require("../../../factory");
17
18
  const onRefund_1 = require("../any/onRefund");
18
19
  const factory_1 = require("./factory");
20
+ function wait4payActionDelayIfNeeded(params) {
21
+ return (settings) => __awaiter(this, void 0, void 0, function* () {
22
+ const { payAction } = params;
23
+ const minIntervalBetweenPayAndRefund = settings.movieticketReserve.minIntervalBetweenPayAndRefund;
24
+ let waitingNecessary = false;
25
+ if (typeof minIntervalBetweenPayAndRefund === 'number' && minIntervalBetweenPayAndRefund > 0) {
26
+ if (payAction.actionStatus !== factory.actionStatusType.CompletedActionStatus) {
27
+ const payStartExpected = moment()
28
+ .add(-minIntervalBetweenPayAndRefund, 'milliseconds');
29
+ waitingNecessary = moment(payAction.startDate)
30
+ .isAfter(payStartExpected);
31
+ }
32
+ }
33
+ if (waitingNecessary) {
34
+ // tslint:disable-next-line:no-console
35
+ console.log('wait4payActionDelayIfNeeded: waiting... minIntervalBetweenPayAndRefund:', minIntervalBetweenPayAndRefund);
36
+ yield new Promise((resolve) => {
37
+ setTimeout(() => {
38
+ resolve();
39
+ }, minIntervalBetweenPayAndRefund);
40
+ });
41
+ }
42
+ });
43
+ }
19
44
  /**
20
45
  * 決済カード返金
21
46
  */
@@ -25,6 +50,24 @@ function refundMovieTicket(params) {
25
50
  var _a, _b, _c, _d, _e, _f;
26
51
  const paymentMethodId = (_a = params.object[0]) === null || _a === void 0 ? void 0 : _a.paymentMethod.paymentMethodId;
27
52
  const paymentServiceId = (_b = params.object[0]) === null || _b === void 0 ? void 0 : _b.id;
53
+ // 本アクションに対応するPayActionを取り出す
54
+ // 例えばtimeoutが原因でCompletedActionStatusでない場合、外部サービス側では着券済の可能性もあるので、そこを考慮する
55
+ const payAction = yield repos.action.findPayAction({
56
+ project: { id: params.project.id },
57
+ paymentMethodId,
58
+ actionStatus: {
59
+ $in: [
60
+ factory.actionStatusType.ActiveActionStatus,
61
+ factory.actionStatusType.CompletedActionStatus,
62
+ factory.actionStatusType.FailedActionStatus
63
+ ]
64
+ }
65
+ });
66
+ if (payAction === undefined) {
67
+ throw new factory.errors.NotFound(factory.actionType.PayAction);
68
+ }
69
+ // handle delays in the side of payment service(2024-10-23~)
70
+ yield wait4payActionDelayIfNeeded({ payAction })(settings);
28
71
  const availableChannel = yield repos.paymentService.findAvailableChannel({
29
72
  project: params.project,
30
73
  typeOf: factory.service.paymentService.PaymentServiceType.MovieTicket,
@@ -44,13 +87,15 @@ function refundMovieTicket(params) {
44
87
  if (useSeatInfoSyncCancel) {
45
88
  seatInfoSyncCancelIn = yield createSeatInfoSyncCancelInOnRefund({
46
89
  project: { id: params.project.id },
47
- paymentMethodId
90
+ paymentMethodId,
91
+ payAction: { id: payAction.id }
48
92
  })({ action: repos.action });
49
93
  }
50
94
  else {
51
95
  seatInfoSyncIn = yield createSeatInfoSyncInOnRefund({
52
96
  project: { id: params.project.id },
53
- paymentMethodId
97
+ paymentMethodId,
98
+ payAction: { id: payAction.id }
54
99
  })({ action: repos.action });
55
100
  }
56
101
  let recipe = (0, factory_1.processSeatInfoSyncResult2refundRecipe)(Object.assign(Object.assign({ project: { id: params.project.id } }, (seatInfoSyncIn !== undefined) ? { processSeatInfoSyncResult: { seatInfoSyncIn } } : undefined), (seatInfoSyncCancelIn !== undefined) ? { processSeatInfoSyncCancelResult: { seatInfoSyncCancelIn } } : undefined));
@@ -100,15 +145,7 @@ function refundMovieTicket(params) {
100
145
  else {
101
146
  // add recipe(2024-06-04~)
102
147
  recipe = (0, factory_1.processSeatInfoSyncResult2refundRecipe)(Object.assign(Object.assign({ project: { id: params.project.id } }, (processSeatInfoSyncResult !== undefined) ? { processSeatInfoSyncResult } : undefined), (processSeatInfoSyncCancelResult !== undefined) ? { processSeatInfoSyncCancelResult } : undefined));
103
- const actionResult = {
104
- // ...(seatInfoSyncIn !== undefined) ? { seatInfoSyncIn } : undefined, // instrumentへ移行(2024-04-30~)
105
- // ...(processSeatInfoSyncResult?.seatInfoSyncResult !== undefined) // discontinue(2024-06-10~)
106
- // ? { seatInfoSyncResult: processSeatInfoSyncResult.seatInfoSyncResult }
107
- // : undefined,
108
- // ...(processSeatInfoSyncCancelResult?.seatInfoSyncCancelResult !== undefined) // discontinue(2024-06-10~)
109
- // ? { seatInfoSyncCancelResult: processSeatInfoSyncCancelResult.seatInfoSyncCancelResult }
110
- // : undefined
111
- };
148
+ const actionResult = {};
112
149
  yield repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: actionResult, recipe });
113
150
  actionStatus = factory.actionStatusType.CompletedActionStatus;
114
151
  }
@@ -127,34 +164,12 @@ exports.refundMovieTicket = refundMovieTicket;
127
164
  function createSeatInfoSyncInOnRefund(params) {
128
165
  return (repos) => __awaiter(this, void 0, void 0, function* () {
129
166
  var _a, _b, _c;
130
- // 本アクションに対応するPayActionを取り出す
131
- // 例えばtimeoutが原因でCompletedActionStatusでない場合、外部サービス側では着券済の可能性もあるので、そこを考慮する
132
- const payAction = yield repos.action.findPayAction({
133
- project: { id: params.project.id },
134
- paymentMethodId: params.paymentMethodId,
135
- actionStatus: {
136
- $in: [
137
- factory.actionStatusType.ActiveActionStatus,
138
- factory.actionStatusType.CompletedActionStatus,
139
- factory.actionStatusType.FailedActionStatus
140
- ]
141
- }
142
- });
143
- if (payAction === undefined) {
144
- throw new factory.errors.NotFound('PayAction');
145
- }
146
167
  const recipe = yield repos.action.findRecipeByAction({
147
168
  project: { id: params.project.id },
148
- recipeFor: { id: payAction.id }
169
+ recipeFor: { id: params.payAction.id }
149
170
  });
150
- // const seatInfoSyncInOnPay: surfrock.factory.service.seat.seatInfoSync.ISeatInfoSyncIn | undefined =
151
- // payAction.instrument?.seatInfoSyncIn;
152
171
  const seatInfoSyncInOnPay = (_c = (_b = (_a = recipe === null || recipe === void 0 ? void 0 : recipe.step[0]) === null || _a === void 0 ? void 0 : _a.itemListElement[0]) === null || _b === void 0 ? void 0 : _b.itemListElement[0]) === null || _c === void 0 ? void 0 : _c.beforeMedia;
153
- // if (seatInfoSyncInOnPay === undefined && payAction.instrument?.seatInfoSyncIn !== undefined) {
154
- // seatInfoSyncInOnPay = payAction.instrument.seatInfoSyncIn; // compatibility
155
- // }
156
172
  if (seatInfoSyncInOnPay === undefined) {
157
- // throw new factory.errors.NotFound('PayAction.instrument?.seatInfoSyncIn');
158
173
  throw new factory.errors.NotFound('PayAction.recipe.step.itemListElement.itemListElement.beforeMedia');
159
174
  }
160
175
  let seatInfoSyncIn;
@@ -167,34 +182,12 @@ function createSeatInfoSyncInOnRefund(params) {
167
182
  function createSeatInfoSyncCancelInOnRefund(params) {
168
183
  return (repos) => __awaiter(this, void 0, void 0, function* () {
169
184
  var _a, _b, _c;
170
- // 本アクションに対応するPayActionを取り出す
171
- // 例えばtimeoutが原因でCompletedActionStatusでない場合、外部サービス側では着券済の可能性もあるので、そこを考慮する
172
- const payAction = yield repos.action.findPayAction({
173
- project: { id: params.project.id },
174
- paymentMethodId: params.paymentMethodId,
175
- actionStatus: {
176
- $in: [
177
- factory.actionStatusType.ActiveActionStatus,
178
- factory.actionStatusType.CompletedActionStatus,
179
- factory.actionStatusType.FailedActionStatus
180
- ]
181
- }
182
- });
183
- if (payAction === undefined) {
184
- throw new factory.errors.NotFound('PayAction');
185
- }
186
185
  const recipe = yield repos.action.findRecipeByAction({
187
186
  project: { id: params.project.id },
188
- recipeFor: { id: payAction.id }
187
+ recipeFor: { id: params.payAction.id }
189
188
  });
190
- // const seatInfoSyncInOnPay: surfrock.factory.service.seat.seatInfoSync.ISeatInfoSyncIn | undefined =
191
- // payAction.instrument?.seatInfoSyncIn;
192
189
  const seatInfoSyncInOnPay = (_c = (_b = (_a = recipe === null || recipe === void 0 ? void 0 : recipe.step[0]) === null || _a === void 0 ? void 0 : _a.itemListElement[0]) === null || _b === void 0 ? void 0 : _b.itemListElement[0]) === null || _c === void 0 ? void 0 : _c.beforeMedia;
193
- // if (seatInfoSyncInOnPay === undefined && payAction.instrument?.seatInfoSyncIn !== undefined) {
194
- // seatInfoSyncInOnPay = payAction.instrument.seatInfoSyncIn; // compatibility
195
- // }
196
190
  if (seatInfoSyncInOnPay === undefined) {
197
- // throw new factory.errors.NotFound('PayAction.instrument?.seatInfoSyncIn');
198
191
  throw new factory.errors.NotFound('PayAction.recipe.step.itemListElement.itemListElement.beforeMedia');
199
192
  }
200
193
  let seatInfoSyncCancelIn;
@@ -52,6 +52,10 @@ interface IOptions {
52
52
  * 認証時タイムアウト
53
53
  */
54
54
  timeoutCheck: number;
55
+ /**
56
+ * 決済と返金の最小間隔(ms)
57
+ */
58
+ minIntervalBetweenPayAndRefund: number;
55
59
  };
56
60
  useAssetTransactionSyncProcessing: boolean;
57
61
  useExperimentalFeature: boolean;
@@ -119,6 +123,10 @@ declare class Settings {
119
123
  * 認証時タイムアウト
120
124
  */
121
125
  timeoutCheck: number;
126
+ /**
127
+ * 決済と返金の最小間隔(ms)
128
+ */
129
+ minIntervalBetweenPayAndRefund: number;
122
130
  };
123
131
  readonly useAssetTransactionSyncProcessing: boolean;
124
132
  readonly useExperimentalFeature: boolean;
package/package.json CHANGED
@@ -108,5 +108,5 @@
108
108
  "postversion": "git push origin --tags",
109
109
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
110
110
  },
111
- "version": "22.5.0-alpha.27"
111
+ "version": "22.5.0-alpha.28"
112
112
  }