@chevre/domain 25.2.0-alpha.18 → 25.2.0-alpha.19

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.
@@ -7,6 +7,10 @@ type IDocType = Omit<factory.order.IOrder, 'id'> & {
7
7
  * 注文取引IDとして再定義(2026-06-22~)
8
8
  */
9
9
  identifier?: string;
10
+ /**
11
+ * 外部URL決済の場合に発行される決済方法IDとして定義(2026-07-12~)
12
+ */
13
+ paymentMethodId?: string;
10
14
  };
11
15
  type IModel = Model<IDocType, Record<string, never>, Record<string, never>, IVirtuals>;
12
16
  type ISchemaDefinition = SchemaDefinition<IDocType>;
@@ -27,6 +27,7 @@ const schemaDefinition = {
27
27
  dateReturned: Date,
28
28
  orderedItem: [mongoose_1.SchemaTypes.Mixed],
29
29
  identifier: { type: String, required: true }, // 注文取引IDとして再定義(2026-06-22~)
30
+ paymentMethodId: { type: String, required: false }, // 注文取引から移行(2026-07-12~)
30
31
  // 以下廃止(2026-06-13~)
31
32
  // identifier: SchemaTypes.Mixed, // 廃止するためにMixed化(2026-06-12~)
32
33
  // isGift: Boolean,
@@ -135,6 +135,7 @@ export declare class OrderRepo {
135
135
  getCursor(conditions: any, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Omit<factory.order.IOrder, "id"> & {
136
136
  acceptedOffers?: factory.order.IAcceptedOffer[];
137
137
  identifier?: string;
138
+ paymentMethodId?: string;
138
139
  } & {
139
140
  _id: import("mongoose").Types.ObjectId;
140
141
  } & {
@@ -142,6 +143,7 @@ export declare class OrderRepo {
142
143
  }, import("mongoose").QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Omit<factory.order.IOrder, "id"> & {
143
144
  acceptedOffers?: factory.order.IAcceptedOffer[];
144
145
  identifier?: string;
146
+ paymentMethodId?: string;
145
147
  } & {
146
148
  _id: import("mongoose").Types.ObjectId;
147
149
  } & {
@@ -298,7 +298,20 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
298
298
  .exec()
299
299
  .then((doc) => {
300
300
  if (doc === null) {
301
- throw new factory_1.factory.errors.ArgumentNull(factory_1.factory.transactionType.PlaceOrder);
301
+ throw new factory_1.factory.errors.NotFound(factory_1.factory.transactionType.PlaceOrder);
302
+ }
303
+ });
304
+ // 注文ドキュメントにも保管する(2026-07-12~)
305
+ await this.orderModel.findOneAndUpdate({
306
+ identifier: { $eq: params.id },
307
+ paymentMethodId: { $exists: false },
308
+ typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder }
309
+ }, { $set: { paymentMethodId: params.paymentMethod } }, { projection: { _id: 1 } })
310
+ .lean()
311
+ .exec()
312
+ .then((doc) => {
313
+ if (doc === null) {
314
+ throw new factory_1.factory.errors.NotFound('orderInTransaction');
302
315
  }
303
316
  });
304
317
  }
@@ -331,7 +344,24 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
331
344
  if (doc === null) {
332
345
  throw new factory_1.factory.errors.NotFound(this.transactionModel.modelName, `${factory_1.factory.transactionType.PlaceOrder} ${factory_1.factory.transactionStatusType.InProgress} not found`);
333
346
  }
334
- return (typeof doc.object.paymentMethods?.paymentMethodId === 'string') ? doc.object.paymentMethods.paymentMethodId : undefined;
347
+ const paymentMethodId = doc.object.paymentMethods?.paymentMethodId;
348
+ if (typeof paymentMethodId === 'string') {
349
+ // 注文ドキュメントにも発行済の場合、同一性を検証(2026-07-12~)
350
+ const orderDoc = await this.orderModel.findOne({ identifier: { $eq: params.id } }, { paymentMethodId: 1 })
351
+ .lean()
352
+ .exec();
353
+ if (orderDoc === null) {
354
+ throw new factory_1.factory.errors.NotFound('orderInTransaction');
355
+ }
356
+ const paymentMethodIdByOrder = orderDoc.paymentMethodId;
357
+ if (typeof paymentMethodIdByOrder === 'string') {
358
+ console.log('paymentMethodId matched?', JSON.stringify(doc), JSON.stringify(orderDoc));
359
+ if (paymentMethodId !== paymentMethodIdByOrder) {
360
+ throw new factory_1.factory.errors.Internal('paymentMethodId not matched unexpectedly');
361
+ }
362
+ }
363
+ }
364
+ return (typeof paymentMethodId === 'string') ? paymentMethodId : undefined;
335
365
  }
336
366
  async deleteByIdentifier(params) {
337
367
  return this.orderModel.deleteOne({
@@ -6,7 +6,11 @@ export { IAcceptPayAction, IAuthorizeEventServiceOffer, IAuthorizePaymentAction,
6
6
  /**
7
7
  * 取引が確定可能な状態かどうかをチェックする
8
8
  */
9
- export declare function validateTransaction(transaction: Pick<factory.transaction.placeOrder.ITransaction, 'id' | 'object'>, acceptPayActions: IAcceptPayAction[], authorizePaymentActions: IAuthorizePaymentAction[], authorizeEventServiceOfferActions: Pick<IAuthorizeEventServiceOffer, 'id' | 'result'>[], eventReservationAcceptedOffers: Pick<factory.order.IAcceptedOffer, 'itemOffered' | 'priceSpecification'>[], payTransactions: IPayTransaction[], customer: factory.order.ICustomer): void;
9
+ export declare function validateTransaction(transaction: {
10
+ id: string;
11
+ }, acceptPayActions: IAcceptPayAction[], authorizePaymentActions: IAuthorizePaymentAction[], authorizeEventServiceOfferActions: Pick<IAuthorizeEventServiceOffer, 'id' | 'result'>[], eventReservationAcceptedOffers: Pick<factory.order.IAcceptedOffer, 'itemOffered' | 'priceSpecification'>[], payTransactions: IPayTransaction[], customer: factory.order.ICustomer, options: {
12
+ paymentMethodIdByTransaction?: string;
13
+ }): void;
10
14
  /**
11
15
  * 注文オファー数検証
12
16
  */
@@ -21,8 +21,8 @@ const debug = (0, debug_1.default)('chevre-domain:service:transaction:placeOrder
21
21
  /**
22
22
  * 取引が確定可能な状態かどうかをチェックする
23
23
  */
24
- function validateTransaction(transaction, acceptPayActions, authorizePaymentActions, authorizeEventServiceOfferActions, eventReservationAcceptedOffers, payTransactions, customer) {
25
- // validateProfile(transaction);
24
+ function validateTransaction(transaction, acceptPayActions, authorizePaymentActions, authorizeEventServiceOfferActions, eventReservationAcceptedOffers, payTransactions, customer, options) {
25
+ const { paymentMethodIdByTransaction } = options;
26
26
  validateProfile({ customer });
27
27
  (0, validatePrice_1.validatePrice)(authorizePaymentActions, authorizeEventServiceOfferActions);
28
28
  // 請求のreferencesOrder検証(2025-11-23~)
@@ -61,7 +61,7 @@ function validateTransaction(transaction, acceptPayActions, authorizePaymentActi
61
61
  });
62
62
  }
63
63
  // 決済URLが発行されている場合、検証
64
- validatePaymentUrl(transaction, acceptPayActions, authorizePaymentActions);
64
+ validatePaymentUrl({ paymentMethodIdByTransaction, acceptPayActions, authorizePaymentActions });
65
65
  }
66
66
  function findMovieTicketPaymentMethodTypesFromTransaction(authorizePaymentActions, eventReservationAcceptedOffers) {
67
67
  const paymentMethodTypes = [];
@@ -106,9 +106,11 @@ function validateProfile(params) {
106
106
  throw new factory_1.factory.errors.Argument('Transaction', 'customer name required');
107
107
  }
108
108
  }
109
- function validatePaymentUrl(transaction, acceptPayActions, authorizePaymentActions) {
109
+ function validatePaymentUrl(params) {
110
+ const { paymentMethodIdByTransaction, acceptPayActions, authorizePaymentActions } = params;
110
111
  // 決済URLが発行されている場合、検証
111
- const paymentMethodId = transaction.object.paymentMethods?.paymentMethodId;
112
+ const paymentMethodId = paymentMethodIdByTransaction;
113
+ debug('validatePaymentUrl: paymentMethodIdByTransaction:', paymentMethodIdByTransaction);
112
114
  if (typeof paymentMethodId === 'string' && paymentMethodId.length > 0) {
113
115
  // check existing accept action(2025-02-26~)
114
116
  const acceptActionExists = acceptPayActions.some(({ object, result }) => {
@@ -116,6 +118,7 @@ function validatePaymentUrl(transaction, acceptPayActions, authorizePaymentActio
116
118
  && result?.paymentMethodId === paymentMethodId
117
119
  && typeof result?.paymentUrl === 'string';
118
120
  });
121
+ debug('validatePaymentUrl: acceptActionExists:', acceptActionExists);
119
122
  if (!acceptActionExists) {
120
123
  throw new factory_1.factory.errors.NotFound(factory_1.factory.actionType.AcceptAction);
121
124
  }
@@ -127,6 +130,7 @@ function validatePaymentUrl(transaction, acceptPayActions, authorizePaymentActio
127
130
  : undefined;
128
131
  return resultAsInvoice?.paymentMethodId === paymentMethodId;
129
132
  });
133
+ debug('validatePaymentUrl: authorizePaymentAction4paymentUrlExists:', authorizePaymentAction4paymentUrlExists);
130
134
  if (!authorizePaymentAction4paymentUrlExists) {
131
135
  throw new factory_1.factory.errors.Argument('Transaction', 'Payment for published payment URL required');
132
136
  }
@@ -82,10 +82,12 @@ function confirm(params, options) {
82
82
  // if (typeof orderNumber !== 'string' || orderNumber === '') {
83
83
  // throw new factory.errors.Argument('transactionId', 'orderNumber not issued');
84
84
  // }
85
+ // 注文に決済方法IDが発行済か確認(2026-07-12)
86
+ const paymentMethodIdByTransaction = await repos.orderInTransaction.findPaymentMethodId({ id: params.id });
85
87
  // 取引に対する全ての承認アクションをマージ
86
88
  const completedAuthorizeActions = await searchAuthorizeActions(params)(repos);
87
89
  let acceptPayActions = [];
88
- if (typeof transaction.object.paymentMethods?.paymentMethodId === 'string') {
90
+ if (typeof paymentMethodIdByTransaction === 'string') {
89
91
  acceptPayActions = await searchAcceptPayActions(params)(repos);
90
92
  }
91
93
  // 必要あらば注文コード発行(2024-02-05~)
@@ -149,7 +151,8 @@ function confirm(params, options) {
149
151
  authorizePaymentActions, authorizeEventServiceOfferActions,
150
152
  acceptedOffers, payTransactions, customer,
151
153
  ...(typeof code === 'string') ? { code } : undefined,
152
- ...((Array.isArray(unitPriceOfferConditions)) && { unitPriceOfferConditions })
154
+ ...((Array.isArray(unitPriceOfferConditions)) && { unitPriceOfferConditions }),
155
+ paymentMethodIdByTransaction
153
156
  }, options);
154
157
  // ポストアクションを作成
155
158
  const setting = await repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['defaultSenderEmail']);
@@ -321,7 +324,10 @@ function createResult(params, options) {
321
324
  }
322
325
  });
323
326
  // 取引の確定条件が全て整っているかどうか確認
324
- (0, validation_1.validateTransaction)(transaction, params.acceptPayActions, params.authorizePaymentActions, params.authorizeEventServiceOfferActions, eventReservationAcceptedOffers, params.payTransactions, params.customer);
327
+ const { paymentMethodIdByTransaction } = params;
328
+ (0, validation_1.validateTransaction)({ id: transaction.id }, params.acceptPayActions, params.authorizePaymentActions, params.authorizeEventServiceOfferActions, eventReservationAcceptedOffers, params.payTransactions, params.customer, {
329
+ ...((typeof paymentMethodIdByTransaction === 'string') && { paymentMethodIdByTransaction })
330
+ });
325
331
  const { paymentMethods, price } = (0, factory_2.createPaymentMethods)({ authorizePaymentActions: params.authorizePaymentActions });
326
332
  const orderedItem = (0, orderedItem_1.acceptedOffers2orderedItem)({
327
333
  eventReservationAcceptedOffers
package/package.json CHANGED
@@ -91,5 +91,5 @@
91
91
  "postversion": "git push origin --tags",
92
92
  "prepublishOnly": "npm run clean && npm run build"
93
93
  },
94
- "version": "25.2.0-alpha.18"
94
+ "version": "25.2.0-alpha.19"
95
95
  }