@chevre/domain 21.8.0-alpha.22 → 21.8.0-alpha.23

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.
@@ -8,7 +8,7 @@ const factory = require("../../../factory");
8
8
  const settings_1 = require("../../../settings");
9
9
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
10
10
  function createStartParams(params) {
11
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
11
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
12
12
  const paymentServiceId = (params.paymentService !== undefined)
13
13
  ? String(params.paymentService.id)
14
14
  : '';
@@ -68,10 +68,16 @@ function createStartParams(params) {
68
68
  }
69
69
  }
70
70
  else if (params.paymentServiceType === factory.service.paymentService.PaymentServiceType.CreditCard) {
71
+ const creditCardPaymentServiceOutput = (_l = params.paymentService) === null || _l === void 0 ? void 0 : _l.serviceOutput;
72
+ const invoiceAsServiceOutput = (Array.isArray(creditCardPaymentServiceOutput))
73
+ ? creditCardPaymentServiceOutput.find((output) => output.typeOf === 'Invoice')
74
+ : creditCardPaymentServiceOutput;
71
75
  // カード通貨区分が存在すれば適用
72
- const creditCardAsPaymentServiceOutputCurrency = (_p = (_o = (_m = (_l = params.paymentService) === null || _l === void 0 ? void 0 : _l.serviceOutput) === null || _m === void 0 ? void 0 : _m.paymentMethod) === null || _o === void 0 ? void 0 : _o.amount) === null || _p === void 0 ? void 0 : _p.currency;
73
- if (typeof creditCardAsPaymentServiceOutputCurrency === 'string') {
74
- paymentMethodCurrency = creditCardAsPaymentServiceOutputCurrency;
76
+ if ((invoiceAsServiceOutput === null || invoiceAsServiceOutput === void 0 ? void 0 : invoiceAsServiceOutput.typeOf) === 'Invoice') {
77
+ const creditCardAsPaymentServiceOutputCurrency = (_o = (_m = invoiceAsServiceOutput.paymentMethod) === null || _m === void 0 ? void 0 : _m.amount) === null || _o === void 0 ? void 0 : _o.currency;
78
+ if (typeof creditCardAsPaymentServiceOutputCurrency === 'string') {
79
+ paymentMethodCurrency = creditCardAsPaymentServiceOutputCurrency;
80
+ }
75
81
  }
76
82
  }
77
83
  const paymentMethodAmount = {
@@ -79,24 +85,24 @@ function createStartParams(params) {
79
85
  currency: paymentMethodCurrency,
80
86
  value: params.amount
81
87
  };
82
- const paymentMethod = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ additionalProperty: (Array.isArray((_q = params.object.paymentMethod) === null || _q === void 0 ? void 0 : _q.additionalProperty))
83
- ? (_r = params.object.paymentMethod) === null || _r === void 0 ? void 0 : _r.additionalProperty
84
- : [], name: (typeof ((_s = params.object.paymentMethod) === null || _s === void 0 ? void 0 : _s.name) === 'string')
88
+ const paymentMethod = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ additionalProperty: (Array.isArray((_p = params.object.paymentMethod) === null || _p === void 0 ? void 0 : _p.additionalProperty))
89
+ ? (_q = params.object.paymentMethod) === null || _q === void 0 ? void 0 : _q.additionalProperty
90
+ : [], name: (typeof ((_r = params.object.paymentMethod) === null || _r === void 0 ? void 0 : _r.name) === 'string')
85
91
  ? params.object.paymentMethod.name
86
92
  : paymentMethodType,
87
93
  // MonetaryAmount対応(2023-08-14~)
88
94
  amount: (settings_1.USE_OBJECT_AS_PAY_TRANSACTION_AMOUNT) ? paymentMethodAmount : params.amount,
89
95
  // paymentMethodId: params.transactionNumber, // object.paymentMethodIdへ完全移行(2023-08-30~)
90
- identifier: paymentMethodType }, (typeof ((_t = params.object.paymentMethod) === null || _t === void 0 ? void 0 : _t.description) === 'string')
91
- ? { description: (_u = params.object.paymentMethod) === null || _u === void 0 ? void 0 : _u.description }
96
+ identifier: paymentMethodType }, (typeof ((_s = params.object.paymentMethod) === null || _s === void 0 ? void 0 : _s.description) === 'string')
97
+ ? { description: (_t = params.object.paymentMethod) === null || _t === void 0 ? void 0 : _t.description }
92
98
  : undefined), (totalPaymentDue !== undefined)
93
99
  ? { totalPaymentDue: totalPaymentDue }
94
- : undefined), (typeof accountId === 'string') ? { accountId: accountId } : undefined), (typeof ((_v = params.object.paymentMethod) === null || _v === void 0 ? void 0 : _v.method) === 'string')
95
- ? { method: (_w = params.object.paymentMethod) === null || _w === void 0 ? void 0 : _w.method }
96
- : undefined), (((_x = params.object.paymentMethod) === null || _x === void 0 ? void 0 : _x.creditCard) !== undefined)
97
- ? { creditCard: (_y = params.object.paymentMethod) === null || _y === void 0 ? void 0 : _y.creditCard }
98
- : undefined), (Array.isArray((_z = params.object.paymentMethod) === null || _z === void 0 ? void 0 : _z.movieTickets))
99
- ? { movieTickets: (_0 = params.object.paymentMethod) === null || _0 === void 0 ? void 0 : _0.movieTickets }
100
+ : undefined), (typeof accountId === 'string') ? { accountId: accountId } : undefined), (typeof ((_u = params.object.paymentMethod) === null || _u === void 0 ? void 0 : _u.method) === 'string')
101
+ ? { method: (_v = params.object.paymentMethod) === null || _v === void 0 ? void 0 : _v.method }
102
+ : undefined), (((_w = params.object.paymentMethod) === null || _w === void 0 ? void 0 : _w.creditCard) !== undefined)
103
+ ? { creditCard: (_x = params.object.paymentMethod) === null || _x === void 0 ? void 0 : _x.creditCard }
104
+ : undefined), (Array.isArray((_y = params.object.paymentMethod) === null || _y === void 0 ? void 0 : _y.movieTickets))
105
+ ? { movieTickets: (_z = params.object.paymentMethod) === null || _z === void 0 ? void 0 : _z.movieTickets }
100
106
  : undefined);
101
107
  const object = {
102
108
  // パラメータから必要なもののみ取り込む
@@ -107,7 +113,7 @@ function createStartParams(params) {
107
113
  onPaymentStatusChanged: { informPayment: informPaymentParams },
108
114
  paymentMethod
109
115
  };
110
- return Object.assign({ project: { typeOf: factory.organizationType.Project, id: params.project.id }, transactionNumber: params.transactionNumber, typeOf: factory.assetTransactionType.Pay, agent: params.agent, recipient: params.recipient, object, expires: params.expires }, (typeof ((_1 = params.location) === null || _1 === void 0 ? void 0 : _1.typeOf) === 'string')
116
+ return Object.assign({ project: { typeOf: factory.organizationType.Project, id: params.project.id }, transactionNumber: params.transactionNumber, typeOf: factory.assetTransactionType.Pay, agent: params.agent, recipient: params.recipient, object, expires: params.expires }, (typeof ((_0 = params.location) === null || _0 === void 0 ? void 0 : _0.typeOf) === 'string')
111
117
  ? { location: params.location }
112
118
  : undefined);
113
119
  }
@@ -6,7 +6,7 @@ exports.createStartParams = void 0;
6
6
  */
7
7
  const factory = require("../../../factory");
8
8
  function createStartParams(params) {
9
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
9
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
10
10
  const paymentMethodType = (_a = params.object.paymentMethod) === null || _a === void 0 ? void 0 : _a.typeOf;
11
11
  if (typeof paymentMethodType !== 'string') {
12
12
  throw new factory.errors.ArgumentNull('object.paymentMethod.typeOf');
@@ -23,7 +23,13 @@ function createStartParams(params) {
23
23
  let refundFee;
24
24
  if (((_g = params.paymentService) === null || _g === void 0 ? void 0 : _g.typeOf) === factory.service.paymentService.PaymentServiceType.CreditCard) {
25
25
  // カード通貨区分の存在する決済サービスを考慮(2023-08-09~)
26
- const paymentServiceOutputAmountCurrency = (_k = (_j = (_h = params.paymentService.serviceOutput) === null || _h === void 0 ? void 0 : _h.paymentMethod) === null || _j === void 0 ? void 0 : _j.amount) === null || _k === void 0 ? void 0 : _k.currency;
26
+ const invoiceAsServiceOutput = (Array.isArray(params.paymentService.serviceOutput))
27
+ ? params.paymentService.serviceOutput.find((output) => output.typeOf === 'Invoice')
28
+ : params.paymentService.serviceOutput;
29
+ let paymentServiceOutputAmountCurrency;
30
+ if ((invoiceAsServiceOutput === null || invoiceAsServiceOutput === void 0 ? void 0 : invoiceAsServiceOutput.typeOf) === 'Invoice') {
31
+ paymentServiceOutputAmountCurrency = (_j = (_h = invoiceAsServiceOutput === null || invoiceAsServiceOutput === void 0 ? void 0 : invoiceAsServiceOutput.paymentMethod) === null || _h === void 0 ? void 0 : _h.amount) === null || _j === void 0 ? void 0 : _j.currency;
32
+ }
27
33
  if (typeof paymentServiceOutputAmountCurrency !== 'string') {
28
34
  if (typeof params.object.refundFee === 'number') {
29
35
  refundFee = params.object.refundFee;
@@ -571,31 +571,64 @@ function validateProgramMembershipUsed(params) {
571
571
  if (typeof issuedThroughId !== 'string' || issuedThroughId.length === 0) {
572
572
  throw new factory.errors.ArgumentNull('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed.issuedThrough.id');
573
573
  }
574
- // requestedProgramMembershipUsedの発行サービスIDから外部連携設定を取得する
575
- const permitService = yield createPermitService({ issuedThrough: { id: issuedThroughId } })(repos);
576
- // メンバーシップの存在確認
577
- const serviceOutput = yield permitService.findByIdentifier({
578
- project: { id: params.project.id },
579
- identifier: programMembershipUsedIdentifier,
580
- issuedThrough: { typeOf: factory.product.ProductType.MembershipService }
581
- });
582
- // 有効期間のチェック
583
- if (serviceOutput.validFrom === undefined || serviceOutput.validFrom === null
584
- || serviceOutput.validUntil === undefined || serviceOutput.validUntil === null) {
585
- throw new factory.errors.Argument('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed', 'not valid programMembership');
586
- }
587
- if (moment(serviceOutput.validFrom)
588
- .isAfter(moment(now))
589
- || moment(serviceOutput.validUntil)
590
- .isBefore(moment(now))) {
591
- throw new factory.errors.Argument('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed', 'unavailable programMembership');
574
+ const permitIssuedThrough = yield repos.product.findById({ id: issuedThroughId }, ['_id', 'typeOf', 'project', 'serviceType', 'serviceOutput'], []);
575
+ switch (permitIssuedThrough.typeOf) {
576
+ // 発行サービスがCreditCardのケースに対応(2023-09-01~)
577
+ case factory.service.paymentService.PaymentServiceType.CreditCard:
578
+ // 決済サービスのserviceOutputにPermitが存在すれば、設定されたメンバーシップ区分のPermitをprogramMembershipUsedとして適用する
579
+ let issuedThroughServiceType;
580
+ if (Array.isArray(permitIssuedThrough.serviceOutput)) {
581
+ const serviceOutputAsPermit = permitIssuedThrough.serviceOutput.find((output) => output.typeOf === factory.permit.PermitType.Permit);
582
+ if ((serviceOutputAsPermit === null || serviceOutputAsPermit === void 0 ? void 0 : serviceOutputAsPermit.typeOf) === factory.permit.PermitType.Permit) {
583
+ issuedThroughServiceType = serviceOutputAsPermit.issuedThrough.serviceType;
584
+ }
585
+ }
586
+ if ((issuedThroughServiceType === null || issuedThroughServiceType === void 0 ? void 0 : issuedThroughServiceType.typeOf) === 'CategoryCode') {
587
+ programMembershipUsed = {
588
+ project: permitIssuedThrough.project,
589
+ typeOf: factory.permit.PermitType.Permit,
590
+ identifier: programMembershipUsedIdentifier,
591
+ issuedThrough: {
592
+ id: permitIssuedThrough.id,
593
+ serviceType: issuedThroughServiceType,
594
+ typeOf: permitIssuedThrough.typeOf
595
+ }
596
+ };
597
+ }
598
+ else {
599
+ throw new factory.errors.Argument('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed', 'issuedThrough has no serviceOutput as Permit');
600
+ }
601
+ break;
602
+ case factory.product.ProductType.MembershipService:
603
+ // requestedProgramMembershipUsedの発行サービスIDから外部連携設定を取得する
604
+ const permitService = yield createPermitService({ issuedThrough: { id: issuedThroughId } })(repos);
605
+ // メンバーシップの存在確認
606
+ const serviceOutput = yield permitService.findByIdentifier({
607
+ project: { id: params.project.id },
608
+ identifier: programMembershipUsedIdentifier,
609
+ issuedThrough: { typeOf: factory.product.ProductType.MembershipService }
610
+ });
611
+ // 有効期間のチェック
612
+ if (serviceOutput.validFrom === undefined || serviceOutput.validFrom === null
613
+ || serviceOutput.validUntil === undefined || serviceOutput.validUntil === null) {
614
+ throw new factory.errors.Argument('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed', 'not valid programMembership');
615
+ }
616
+ if (moment(serviceOutput.validFrom)
617
+ .isAfter(moment(now))
618
+ || moment(serviceOutput.validUntil)
619
+ .isBefore(moment(now))) {
620
+ throw new factory.errors.Argument('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed', 'unavailable programMembership');
621
+ }
622
+ programMembershipUsed = {
623
+ project: serviceOutput.project,
624
+ typeOf: serviceOutput.typeOf,
625
+ identifier: serviceOutput.identifier,
626
+ issuedThrough: serviceOutput.issuedThrough
627
+ };
628
+ break;
629
+ default:
630
+ throw new factory.errors.Argument('acceptedOffer.itemOffered.serviceOutput.programMembershipUsed', `${permitIssuedThrough.typeOf} not implemented`);
592
631
  }
593
- programMembershipUsed = {
594
- project: serviceOutput.project,
595
- typeOf: serviceOutput.typeOf,
596
- identifier: serviceOutput.identifier,
597
- issuedThrough: serviceOutput.issuedThrough
598
- };
599
632
  }
600
633
  return programMembershipUsed;
601
634
  });
package/package.json CHANGED
@@ -9,8 +9,8 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.329.0-alpha.0",
13
- "@cinerino/sdk": "3.166.0-alpha.3",
12
+ "@chevre/factory": "4.329.0-alpha.1",
13
+ "@cinerino/sdk": "3.166.0-alpha.4",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
16
16
  "@sendgrid/mail": "6.4.0",
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.8.0-alpha.22"
120
+ "version": "21.8.0-alpha.23"
121
121
  }