@chevre/domain 21.35.0-alpha.22 → 21.35.0-alpha.24

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.
@@ -70,16 +70,16 @@ async function main() {
70
70
  // optimize action
71
71
  if (Array.isArray(authorizeAction.object.acceptedOffer)) {
72
72
  let unsetResult: any;
73
- // unsetResult = await actionRepo.unsetUnnecessaryFields({
74
- // filter: { _id: { $eq: authorizeAction.id } },
75
- // $unset: {
76
- // 'object.acceptedOffer': 1
77
- // }
78
- // });
79
- // updateCount += 1;
80
- // console.log(
81
- // 'result unset. unsetResult:', unsetResult,
82
- // authorizeAction.project.id, authorizeAction.id, authorizeAction.startDate, i, updateCount, saveResultCount);
73
+ unsetResult = await actionRepo.unsetUnnecessaryFields({
74
+ filter: { _id: { $eq: authorizeAction.id } },
75
+ $unset: {
76
+ 'object.acceptedOffer': 1
77
+ }
78
+ });
79
+ updateCount += 1;
80
+ console.log(
81
+ 'result unset. unsetResult:', unsetResult,
82
+ authorizeAction.project.id, authorizeAction.id, authorizeAction.startDate, i, updateCount, saveResultCount);
83
83
  }
84
84
  } else {
85
85
  console.log(
@@ -97,7 +97,7 @@ function changeOffers(params) {
97
97
  videoFormatTypes
98
98
  })(repos);
99
99
  // 供給情報と価格を変更してからDB更新
100
- authorizeAction.object.acceptedOffer = acceptedOffers;
100
+ // authorizeAction.object.acceptedOffer = acceptedOffers; // discontinue acceptedOffers(2024-06-21~)
101
101
  // recipe依存へ変更(2024-06-11~)
102
102
  // const updTmpReserveSeatResult = authorizeAction.result?.responseBody;
103
103
  const recipe = yield repos.action.findRecipeByAction({
@@ -23,7 +23,7 @@ function createAuthorizeSeatReservationActionAttributes(params) {
23
23
  const authorizeObject = {
24
24
  typeOf: factory.action.authorize.offer.eventService.ObjectType.SeatReservation,
25
25
  id: params.acceptAction.id,
26
- acceptedOffer: params.acceptedOffers,
26
+ // acceptedOffer: params.acceptedOffers, // discontinue acceptedOffers(2024-06-21~)
27
27
  event: authorizeObjectEvent,
28
28
  pendingTransaction: params.pendingTransaction,
29
29
  useResultAcceptedOffers: false
@@ -12,7 +12,7 @@ export interface IOnPaymentStatusChangedRefundAction {
12
12
  export type IOnPaymentStatusChangedParams = IOnPaymentStatusChangedPayAction | IOnPaymentStatusChangedRefundAction;
13
13
  export declare function creatPayTransactionStartParams(params: {
14
14
  accountId?: string;
15
- object: factory.action.authorize.paymentMethod.any.IObject;
15
+ object: factory.action.authorize.paymentMethod.any.IObjectIncludingPaymentMethodDetails;
16
16
  paymentServiceType: factory.service.paymentService.PaymentServiceType;
17
17
  transaction: Pick<factory.transaction.ITransaction<factory.transactionType.PlaceOrder>, 'expires' | 'seller' | 'project'>;
18
18
  transactionNumber: string;
@@ -8,12 +8,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
23
  exports.publishPaymentUrl = exports.processVoidPayTransaction = exports.person2username = exports.voidPayTransaction = exports.invalidatePaymentUrl = exports.findCheckAction = exports.findAuthorizeAction = exports.findAcceptAction = exports.authorize = exports.onPaymentStatusChanged = void 0;
13
24
  /**
14
25
  * 汎用決済サービス
15
26
  */
16
27
  const factory = require("../../factory");
28
+ const settings_1 = require("../../settings");
17
29
  const PayTransactionService = require("../assetTransaction/pay");
18
30
  const code_1 = require("../code");
19
31
  const publishConfirmationNumberIfNotExist_1 = require("../transaction/placeOrderInProgress/publishConfirmationNumberIfNotExist");
@@ -289,6 +301,19 @@ function publishPaymentUrl(params) {
289
301
  });
290
302
  }
291
303
  exports.publishPaymentUrl = publishPaymentUrl;
304
+ /**
305
+ * 承認アクションオブジェクトから冗長な属性を排除する
306
+ */
307
+ function minimizeObjectIncludingPaymentMethodDetails(authorizeObjectIncludingPaymentMethodDetails) {
308
+ if (settings_1.USE_EXPERIMENTAL_FEATURE) {
309
+ // experimental(2024-06-21~)
310
+ const { creditCard, method, movieTickets } = authorizeObjectIncludingPaymentMethodDetails, authorizeObject = __rest(authorizeObjectIncludingPaymentMethodDetails, ["creditCard", "method", "movieTickets"]);
311
+ return { authorizeObject };
312
+ }
313
+ else {
314
+ return { authorizeObject: authorizeObjectIncludingPaymentMethodDetails };
315
+ }
316
+ }
292
317
  /**
293
318
  * 決済承認
294
319
  */
@@ -345,7 +370,8 @@ function authorize(params) {
345
370
  }
346
371
  const movieTickets = (Array.isArray(params.object.movieTickets)) ? params.object.movieTickets.map(factory_1.createMovieTicket) : undefined;
347
372
  const { accountId } = yield fixAccountIdIfPossible({ object: params.object, project: { id: transaction.project.id } })(repos);
348
- const authorizeObject = Object.assign(Object.assign(Object.assign(Object.assign({}, params.object), { accountId, paymentMethodId: transactionNumber, typeOf: factory.action.authorize.paymentMethod.any.ResultType.Payment }), (creditCard !== undefined) ? { creditCard } : undefined), (Array.isArray(movieTickets)) ? { movieTickets } : undefined);
373
+ const authorizeObjectIncludingPaymentMethodDetails = Object.assign(Object.assign(Object.assign(Object.assign({}, params.object), { accountId, paymentMethodId: transactionNumber, typeOf: factory.action.authorize.paymentMethod.any.ResultType.Payment }), (creditCard !== undefined) ? { creditCard } : undefined), (Array.isArray(movieTickets)) ? { movieTickets } : undefined);
374
+ const { authorizeObject } = minimizeObjectIncludingPaymentMethodDetails(authorizeObjectIncludingPaymentMethodDetails);
349
375
  // 承認アクションを開始する
350
376
  const taskId = (_a = params.sameAs) === null || _a === void 0 ? void 0 : _a.id;
351
377
  const actionAttributes = Object.assign({ project: transaction.project, typeOf: factory.actionType.AuthorizeAction, object: authorizeObject, agent: {
@@ -368,7 +394,7 @@ function authorize(params) {
368
394
  try {
369
395
  const startParams = (0, factory_1.creatPayTransactionStartParams)({
370
396
  accountId,
371
- object: authorizeObject,
397
+ object: authorizeObjectIncludingPaymentMethodDetails,
372
398
  paymentServiceType,
373
399
  transaction: transaction,
374
400
  transactionNumber: transactionNumber,
@@ -228,24 +228,6 @@ function dissolveAuthorizeActions(completedAuthorizeActions) {
228
228
  serialNumbers.push(serialNumber);
229
229
  }
230
230
  });
231
- // authorizeEventServiceOfferActions.forEach(({ result }) => {
232
- // const acceptedOffersByAuthorizeAction = result?.acceptedOffers; // discontinue(2024-06-17~)
233
- // if (Array.isArray(acceptedOffersByAuthorizeAction)) {
234
- // acceptedOffersFromAuthorizeAction.push(...acceptedOffersByAuthorizeAction);
235
- // }
236
- // });
237
- // authorizeProductOfferActions.forEach(({ result }) => {
238
- // const acceptedOffersByAuthorizeAction = result?.acceptedOffers; // discontinue(2024-06-17~)
239
- // if (Array.isArray(acceptedOffersByAuthorizeAction)) {
240
- // acceptedOffersFromAuthorizeAction.push(...acceptedOffersByAuthorizeAction);
241
- // }
242
- // });
243
- // authorizeMoneyTansferActions.forEach(({ result }) => {
244
- // const acceptedOffersByAuthorizeAction = result?.acceptedOffers; // discontinue(2024-06-17~)
245
- // if (Array.isArray(acceptedOffersByAuthorizeAction)) {
246
- // acceptedOffersFromAuthorizeAction.push(...acceptedOffersByAuthorizeAction);
247
- // }
248
- // });
249
231
  debug('authorizeActions dissolved', serialNumbers, authorizeEventServiceOfferActions.length, 'authorizeEventServiceOfferActions', authorizePaymentActions.length, 'authorizePaymentActions');
250
232
  return {
251
233
  authorizePaymentActions,
@@ -3,7 +3,9 @@ import { placeOrder as PlaceOrderFactory } from '../../../factory/transaction';
3
3
  export type IAuthorizeEventServiceOffer = factory.action.authorize.offer.eventService.IAction<factory.service.webAPI.Identifier>;
4
4
  export type IAuthorizeProductOffer = factory.action.authorize.offer.product.IAction;
5
5
  export type IAuthorizeMoneyTransferOffer = factory.action.authorize.offer.moneyTransfer.IAction;
6
- export type IAuthorizePaymentAction = Pick<factory.action.authorize.paymentMethod.any.IAction, 'id' | 'object' | 'result' | 'endDate' | 'instrument'>;
6
+ export type IAuthorizePaymentAction = Pick<factory.action.authorize.paymentMethod.any.IAction, 'id' | 'result' | 'endDate' | 'instrument'> & {
7
+ object: Pick<factory.action.authorize.paymentMethod.any.IObject, 'typeOf'>;
8
+ };
7
9
  export type IPayTransaction = Pick<factory.assetTransaction.pay.ITransaction, 'object'>;
8
10
  /**
9
11
  * 取引が確定可能な状態かどうかをチェックする
@@ -194,14 +194,16 @@ function validateMonetaryAmount(authorizePaymentActions, authorizeEventServiceOf
194
194
  const requiredMonetaryAmount = requiredMonetaryAmountByCurrencyType
195
195
  .filter((m) => m.currency === currencyType)
196
196
  .reduce((a, b) => a + b.value, 0);
197
- const authorizedMonetaryAmount = authorizeMonetaryAmountActions.filter(({ result }) => {
197
+ let authorizedMonetaryAmount = 0;
198
+ authorizeMonetaryAmountActions.forEach(({ result }) => {
198
199
  var _a;
199
200
  const resultAsInvoice = (Array.isArray(result))
200
201
  ? result.find(({ typeOf }) => typeOf === factory.action.authorize.paymentMethod.any.ResultType.Payment)
201
202
  : undefined;
202
- return ((_a = resultAsInvoice === null || resultAsInvoice === void 0 ? void 0 : resultAsInvoice.totalPaymentDue) === null || _a === void 0 ? void 0 : _a.currency) === currencyType;
203
- })
204
- .reduce((a, b) => a + b.object.amount, 0);
203
+ if (((_a = resultAsInvoice === null || resultAsInvoice === void 0 ? void 0 : resultAsInvoice.totalPaymentDue) === null || _a === void 0 ? void 0 : _a.currency) === currencyType) {
204
+ authorizedMonetaryAmount += resultAsInvoice.totalPaymentDue.value;
205
+ }
206
+ });
205
207
  return requiredMonetaryAmount === authorizedMonetaryAmount;
206
208
  });
207
209
  if (!requireMonetaryAmountSatisfied) {
@@ -385,65 +387,6 @@ function validateEventOffers(params) {
385
387
  }
386
388
  });
387
389
  }
388
- else {
389
- if (a.instrument.identifier === factory.service.webAPI.Identifier.Chevre) {
390
- if (!Array.isArray(a.object.acceptedOffer)) {
391
- throw new factory.errors.ServiceUnavailable('authorizeAction.object.acceptedOffer must be an array');
392
- }
393
- // オファーIDごとにオファー適用条件を確認
394
- const offerIds = [...new Set(a.object.acceptedOffer.map((o) => o.id))];
395
- offerIds.forEach((offerId) => {
396
- var _a, _b, _c, _d, _e;
397
- let unitPriceSpec;
398
- const acceptedOffer = (_a = a.object.acceptedOffer) === null || _a === void 0 ? void 0 : _a.find((o) => o.id === offerId);
399
- if (acceptedOffer === undefined) {
400
- throw new factory.errors.ServiceUnavailable(`authorizeEventServiceOfferAction.object.acceptedOffer not found. [id:${offerId}]`);
401
- }
402
- // Chevre予約の場合、priceSpecificationに複合価格仕様が含まれるので、そこから単価仕様を取り出す
403
- unitPriceSpec = acceptedOffer.priceSpecification.priceComponent.find((spec) => spec.typeOf === factory.priceSpecificationType.UnitPriceSpecification
404
- && (!Array.isArray(spec.appliesToAddOn)) // アドオン単価ではない
405
- );
406
- // 適用金額要件を満たしていなければエラー
407
- const eligibleTransactionVolumePrice = (_b = unitPriceSpec === null || unitPriceSpec === void 0 ? void 0 : unitPriceSpec.eligibleTransactionVolume) === null || _b === void 0 ? void 0 : _b.price;
408
- const eligibleTransactionVolumePriceCurrency = (_c = unitPriceSpec === null || unitPriceSpec === void 0 ? void 0 : unitPriceSpec.eligibleTransactionVolume) === null || _c === void 0 ? void 0 : _c.priceCurrency;
409
- if (typeof eligibleTransactionVolumePrice === 'number') {
410
- if (params.order.price < eligibleTransactionVolumePrice) {
411
- throw new factory.errors.Argument('Transaction', (0, util_1.format)('Transaction volume must be more than or equal to %s %s for offer:%s', eligibleTransactionVolumePrice, eligibleTransactionVolumePriceCurrency, offerId));
412
- }
413
- }
414
- // 適用数量検証(全興行オファー承認アクションについて)(2023-11-15~)
415
- // 適用数量要件を満たしていなければエラー
416
- const numAcceptedOffersByOfferId = params.authorizeEventServiceOfferActions.reduce((previousNumOffer, currentAction) => {
417
- if (!Array.isArray(currentAction.object.acceptedOffer)) {
418
- throw new factory.errors.ServiceUnavailable('currentAuthorizeAction.object.acceptedOffer must be an array');
419
- }
420
- return previousNumOffer + currentAction.object.acceptedOffer.filter((o) => o.id === offerId).length;
421
- }, 0);
422
- const eligibleQuantityMaxValue = (_d = unitPriceSpec === null || unitPriceSpec === void 0 ? void 0 : unitPriceSpec.eligibleQuantity) === null || _d === void 0 ? void 0 : _d.maxValue;
423
- if (typeof eligibleQuantityMaxValue === 'number') {
424
- if (numAcceptedOffersByOfferId > eligibleQuantityMaxValue) {
425
- throw new factory.errors.Argument('Transaction', `Number of offer:${offerId} must be less than or equal to ${eligibleQuantityMaxValue}`);
426
- }
427
- }
428
- const eligibleQuantityMinValue = (_e = unitPriceSpec === null || unitPriceSpec === void 0 ? void 0 : unitPriceSpec.eligibleQuantity) === null || _e === void 0 ? void 0 : _e.minValue;
429
- if (typeof eligibleQuantityMinValue === 'number') {
430
- if (numAcceptedOffersByOfferId < eligibleQuantityMinValue) {
431
- throw new factory.errors.Argument('Transaction', `Number of offer:${offerId} must be more than or equal to ${eligibleQuantityMinValue}`);
432
- }
433
- }
434
- // 利用可能決済方法検証(2023-11-15~)
435
- if (Array.isArray(acceptedOffer.acceptedPaymentMethod)) {
436
- const acceptedPaymentMethodTypes = acceptedOffer.acceptedPaymentMethod.map(({ identifier }) => identifier);
437
- const satisfyAcceptedPaymentMethod = numCreditCardOrFaceToFacePaymentMethod === 1
438
- && typeof firstCreditCardPaymentMethodIdentifier === 'string'
439
- && acceptedPaymentMethodTypes.includes(firstCreditCardPaymentMethodIdentifier);
440
- if (!satisfyAcceptedPaymentMethod) {
441
- throw new factory.errors.Argument('Transaction', `acceptedPaymentMethod requirement not satisfied`);
442
- }
443
- }
444
- });
445
- }
446
- }
447
390
  });
448
391
  }
449
392
  exports.validateEventOffers = validateEventOffers;
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@aws-sdk/credential-providers": "3.433.0",
13
- "@chevre/factory": "4.375.0-alpha.14",
13
+ "@chevre/factory": "4.375.0-alpha.15",
14
14
  "@cinerino/sdk": "7.3.0-alpha.2",
15
15
  "@motionpicture/coa-service": "9.4.0",
16
16
  "@motionpicture/gmo-service": "5.3.0",
@@ -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.35.0-alpha.22"
113
+ "version": "21.35.0-alpha.24"
114
114
  }