@chevre/domain 21.20.0-alpha.2 → 21.20.0-alpha.3

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.
@@ -11,6 +11,13 @@ const paymentMethodType = 'CreditCard';
11
11
  const paymentServiceId = '5f9a4fed4f3709000abe6415';
12
12
  // const paymentMethodType = 'PayPay';
13
13
  // const paymentServiceId = '60e9560176a391000b23e20b';
14
+ const AMOUNT: number = 1;
15
+ const creditCard: chevre.factory.paymentMethod.paymentCard.creditCard.IUncheckedCardRaw = {
16
+ cardNo: '4100000000000100',
17
+ expire: '2812',
18
+ cardPass: '123',
19
+ holderName: 'AA AA'
20
+ };
14
21
 
15
22
  // tslint:disable-next-line:max-func-body-length
16
23
  async function main() {
@@ -43,16 +50,13 @@ async function main() {
43
50
  agent: { id: CLIENT_ID },
44
51
  object: {
45
52
  typeOf: chevre.factory.action.authorize.paymentMethod.any.ResultType.Payment,
46
- amount: 1,
53
+ amount: AMOUNT,
47
54
  paymentMethod: paymentMethodType,
48
55
  issuedThrough: { id: paymentServiceId },
49
56
  method: '1',
50
57
  creditCard: {
51
- retUrl: String(process.env.SECURE_TRAN_RET_URL),
52
- cardNo: '4100000000000100',
53
- expire: '2812',
54
- cardPass: '123',
55
- holderName: 'AA AA'
58
+ ...creditCard,
59
+ retUrl: String(process.env.SECURE_TRAN_RET_URL)
56
60
  }
57
61
  },
58
62
  purpose: { id: transaction.id, typeOf: transaction.typeOf },
@@ -61,9 +65,6 @@ async function main() {
61
65
  typeOf: chevre.factory.creativeWorkType.WebApplication,
62
66
  id: CLIENT_ID
63
67
  }
64
- // options: {
65
- // use3DS: true
66
- // }
67
68
  })({
68
69
  assetTransaction: await chevre.repository.AssetTransaction.createInstance(mongoose.connection),
69
70
  paymentAccepted: await chevre.repository.SellerPaymentAccepted.createInstance(mongoose.connection),
@@ -90,17 +91,12 @@ async function main() {
90
91
  agent: { id: CLIENT_ID },
91
92
  object: {
92
93
  typeOf: chevre.factory.action.authorize.paymentMethod.any.ResultType.Payment,
93
- amount: 1,
94
+ amount: AMOUNT,
94
95
  paymentMethodId: publishPaymentUrlResult.paymentMethodId,
95
96
  paymentMethod: paymentMethodType,
96
97
  issuedThrough: { id: paymentServiceId },
97
98
  method: '1',
98
- creditCard: {
99
- cardNo: '4100000000000100',
100
- expire: '2812',
101
- cardPass: '123',
102
- holderName: 'AA AA'
103
- }
99
+ creditCard
104
100
  },
105
101
  purpose: { id: transaction.id, typeOf: transaction.typeOf },
106
102
  paymentServiceType: chevre.factory.service.paymentService.PaymentServiceType.CreditCard,
@@ -129,7 +125,7 @@ async function main() {
129
125
  transactionNumber: await chevre.repository.TransactionNumber.createInstance(client),
130
126
  transaction: await chevre.repository.Transaction.createInstance(mongoose.connection)
131
127
  });
132
- console.log(authorizeResult);
128
+ console.log('payment authorized.', authorizeResult.result);
133
129
 
134
130
  resolve();
135
131
  } catch (error) {
@@ -237,7 +237,8 @@ function publishPaymentUrl(params) {
237
237
  entryTranArgs: result.entryTranArgs,
238
238
  entryTranResult: result.entryTranResult,
239
239
  execTranArgs: result.execTranArgs,
240
- execTranResult: result.execTranResult
240
+ execTranResult: result.execTranResult,
241
+ paymentMethod: startParams.object.paymentMethod // 拡張(2024-01-04~)
241
242
  };
242
243
  yield repos.transaction.findByIdAndUpdateInProgress({
243
244
  id: transaction.id,
@@ -266,6 +267,11 @@ function authorize(params) {
266
267
  if (typeof params.object.paymentMethodId === 'string' && params.object.paymentMethodId.length > 0) {
267
268
  const paymentMethodByTransaction = transaction.object.paymentMethods;
268
269
  if (params.object.paymentMethodId === (paymentMethodByTransaction === null || paymentMethodByTransaction === void 0 ? void 0 : paymentMethodByTransaction.paymentMethodId)) {
270
+ // 検証強化(2024-01-04~)
271
+ validatePaymentMethodByTransaction({
272
+ object: params.object,
273
+ paymentMethodByTransaction
274
+ });
269
275
  transactionNumber = params.object.paymentMethodId;
270
276
  const { entryTranArgs, entryTranResult, execTranArgs, execTranResult } = paymentMethodByTransaction;
271
277
  if (entryTranArgs !== undefined && entryTranResult !== undefined
@@ -368,6 +374,25 @@ function authorize(params) {
368
374
  });
369
375
  }
370
376
  exports.authorize = authorize;
377
+ function validatePaymentMethodByTransaction(params) {
378
+ var _a;
379
+ const paymentServiceIdByObject = params.object.issuedThrough.id;
380
+ const amountByObject = params.object.amount;
381
+ const paymentServiceIdByTransaction = params.paymentMethodByTransaction.issuedThrough.id;
382
+ const amountByTransaction = (_a = params.paymentMethodByTransaction.entryTranArgs) === null || _a === void 0 ? void 0 : _a.amount;
383
+ // 決済サービスID検証
384
+ if (paymentServiceIdByObject !== paymentServiceIdByTransaction) {
385
+ throw new factory.errors.Argument('object.issuedThrough.id', 'issuedThrough.id must match the target of the paymentUrl');
386
+ }
387
+ // 金額検証
388
+ if (amountByObject !== amountByTransaction) {
389
+ throw new factory.errors.Argument('object.amount', 'amount must match the target of the paymentUrl');
390
+ }
391
+ if (params.paymentMethodByTransaction.paymentMethod !== undefined) {
392
+ // tslint:disable-next-line:no-suspicious-comment
393
+ // TODO params.objectを上書きするか?
394
+ }
395
+ }
371
396
  function validateFromLocation(params) {
372
397
  return (repos) => __awaiter(this, void 0, void 0, function* () {
373
398
  var _a, _b;
@@ -7,8 +7,6 @@ import type { MongoRepository as AccountingReportRepo } from '../../repo/account
7
7
  import type { MongoRepository as ActionRepo } from '../../repo/action';
8
8
  import type { MongoRepository as PaymentServiceRepo } from '../../repo/paymentService';
9
9
  import type { MongoRepository as PaymentServiceProviderRepo } from '../../repo/paymentServiceProvider';
10
- import type { CognitoRepository as PersonRepo } from '../../repo/person';
11
- import type { MongoRepository as ProjectRepo } from '../../repo/project';
12
10
  import type { MongoRepository as PaymentAcceptedRepo } from '../../repo/sellerPaymentAccepted';
13
11
  import type { MongoRepository as TaskRepo } from '../../repo/task';
14
12
  interface IPaymentAgencyTransaction {
@@ -32,8 +30,6 @@ declare function authorize(params: factory.assetTransaction.pay.IStartParamsWith
32
30
  paymentAccepted: PaymentAcceptedRepo;
33
31
  paymentService: PaymentServiceRepo;
34
32
  paymentServiceProvider: PaymentServiceProviderRepo;
35
- person: PersonRepo;
36
- project: ProjectRepo;
37
33
  }) => Promise<IAuthorizeResult>;
38
34
  /**
39
35
  * クレジットカード決済中止
@@ -42,7 +38,6 @@ declare function voidTransaction(params: factory.task.voidPayment.IData): (repos
42
38
  paymentAccepted: PaymentAcceptedRepo;
43
39
  paymentService: PaymentServiceRepo;
44
40
  paymentServiceProvider: PaymentServiceProviderRepo;
45
- project: ProjectRepo;
46
41
  }) => Promise<void>;
47
42
  /**
48
43
  * クレジットカード決済
@@ -53,7 +48,6 @@ declare function payCreditCard(params: factory.task.pay.IData): (repos: {
53
48
  paymentAccepted: PaymentAcceptedRepo;
54
49
  paymentService: PaymentServiceRepo;
55
50
  paymentServiceProvider: PaymentServiceProviderRepo;
56
- project: ProjectRepo;
57
51
  task: TaskRepo;
58
52
  }) => Promise<import("@chevre/factory/lib/action/trade/pay").IAction>;
59
53
  /**
@@ -65,7 +59,6 @@ declare function refundCreditCard(params: factory.task.refund.IData, requirePayA
65
59
  paymentAccepted: PaymentAcceptedRepo;
66
60
  paymentService: PaymentServiceRepo;
67
61
  paymentServiceProvider: PaymentServiceProviderRepo;
68
- project: ProjectRepo;
69
62
  task: TaskRepo;
70
63
  }) => Promise<import("@chevre/factory/lib/action/trade/refund").IAction>;
71
64
  interface IGMOInfo {
@@ -20,7 +20,7 @@ const credentials_1 = require("../../credentials");
20
20
  const factory = require("../../factory");
21
21
  const onPaid_1 = require("./any/onPaid");
22
22
  const onRefund_1 = require("./any/onRefund");
23
- const person2username_1 = require("./any/person2username");
23
+ // import { person2username } from './any/person2username';
24
24
  const debug = createDebug('chevre-domain:service:payment');
25
25
  /**
26
26
  * クレジットカード決済承認
@@ -28,12 +28,12 @@ const debug = createDebug('chevre-domain:service:payment');
28
28
  function authorize(params, paymentServiceId, options) {
29
29
  // tslint:disable-next-line:max-func-body-length
30
30
  return (repos) => __awaiter(this, void 0, void 0, function* () {
31
+ // const project = <Pick<factory.project.IProject, 'settings'>>await repos.project.findById({
32
+ // id: params.project.id,
33
+ // inclusion: ['settings'],
34
+ // exclusion: []
35
+ // });
31
36
  var _a, _b, _c, _d, _e;
32
- const project = yield repos.project.findById({
33
- id: params.project.id,
34
- inclusion: ['settings'],
35
- exclusion: []
36
- });
37
37
  // CreditCard系統の決済方法タイプは動的
38
38
  const paymentMethodType = (_a = params.object.paymentMethod) === null || _a === void 0 ? void 0 : _a.identifier;
39
39
  if (typeof paymentMethodType !== 'string') {
@@ -69,13 +69,13 @@ function authorize(params, paymentServiceId, options) {
69
69
  }
70
70
  else {
71
71
  authorizeResult = yield processAuthorizeCreditCard({
72
- projectSettings: project.settings,
72
+ // projectSettings: project.settings,
73
73
  shopId: shopId,
74
74
  shopPass: shopPass,
75
75
  orderId: orderId,
76
76
  availableChannel: availableChannel,
77
77
  object: params.object.paymentMethod
78
- })(repos);
78
+ })();
79
79
  }
80
80
  }
81
81
  catch (error) {
@@ -108,8 +108,8 @@ function authorize(params, paymentServiceId, options) {
108
108
  exports.authorize = authorize;
109
109
  function processAuthorizeCreditCard(params) {
110
110
  // tslint:disable-next-line:max-func-body-length
111
- return (repos) => __awaiter(this, void 0, void 0, function* () {
112
- var _a, _b, _c, _d, _e;
111
+ return () => __awaiter(this, void 0, void 0, function* () {
112
+ var _a, _b, _c, _d, _e, _f;
113
113
  // GMOオーソリ取得
114
114
  let entryTranArgs;
115
115
  let entryTranResult;
@@ -117,21 +117,21 @@ function processAuthorizeCreditCard(params) {
117
117
  let execTranResult;
118
118
  const creditCardService = new GMO.service.Credit({ endpoint: String(params.availableChannel.serviceUrl) }, { timeout: credentials_1.credentials.gmo.timeout });
119
119
  const creditCard = params.object.creditCard;
120
- let memberId = creditCard.memberId;
120
+ const memberId = creditCard.memberId;
121
121
  const cardSeq = creditCard.cardSeq;
122
122
  if (typeof memberId === 'string' && memberId.length > 0 && typeof cardSeq === 'number') {
123
+ // 決済承認時のuseUsernameAsGMOMemberId判定を廃止(2024-01-04~)
123
124
  // 特殊なプロジェクトのみユーザーネームに自動変換(新旧会員互換性維持対応)
124
125
  // memberIdはPersonIDが指定されてくる想定
125
- const useUsernameAsGMOMemberId = ((_a = params.projectSettings) === null || _a === void 0 ? void 0 : _a.useUsernameAsGMOMemberId) === true;
126
- if (useUsernameAsGMOMemberId) {
127
- try {
128
- const customer = yield repos.person.findById({ userId: memberId });
129
- memberId = yield (0, person2username_1.person2username)(customer);
130
- }
131
- catch (error) {
132
- throw error;
133
- }
134
- }
126
+ // const useUsernameAsGMOMemberId = params.projectSettings?.useUsernameAsGMOMemberId === true;
127
+ // if (useUsernameAsGMOMemberId) {
128
+ // try {
129
+ // const customer = await repos.person.findById({ userId: memberId });
130
+ // memberId = await person2username(customer);
131
+ // } catch (error) {
132
+ // throw error;
133
+ // }
134
+ // }
135
135
  }
136
136
  const retUrl = creditCard === null || creditCard === void 0 ? void 0 : creditCard.retUrl;
137
137
  // 3DS拡張(2024-01-02~)
@@ -156,8 +156,8 @@ function processAuthorizeCreditCard(params) {
156
156
  accessPass: entryTranResult.accessPass,
157
157
  orderId: params.orderId,
158
158
  method: params.object.method,
159
- // siteId: params.availableChannel.credentials?.siteId,
160
- // sitePass: params.availableChannel.credentials?.sitePass,
159
+ siteId: (_a = params.availableChannel.credentials) === null || _a === void 0 ? void 0 : _a.siteId,
160
+ sitePass: (_b = params.availableChannel.credentials) === null || _b === void 0 ? void 0 : _b.sitePass,
161
161
  cardNo: creditCard.cardNo,
162
162
  cardPass: creditCard.cardPass,
163
163
  expire: creditCard.expire,
@@ -179,8 +179,8 @@ function processAuthorizeCreditCard(params) {
179
179
  amount: (typeof params.object.amount === 'number')
180
180
  ? params.object.amount
181
181
  : params.object.amount.value,
182
- siteId: (_b = params.availableChannel.credentials) === null || _b === void 0 ? void 0 : _b.siteId,
183
- sitePass: (_c = params.availableChannel.credentials) === null || _c === void 0 ? void 0 : _c.sitePass
182
+ siteId: (_c = params.availableChannel.credentials) === null || _c === void 0 ? void 0 : _c.siteId,
183
+ sitePass: (_d = params.availableChannel.credentials) === null || _d === void 0 ? void 0 : _d.sitePass
184
184
  };
185
185
  entryTranResult = yield creditCardService.entryTran(entryTranArgs);
186
186
  execTranArgs = {
@@ -188,8 +188,8 @@ function processAuthorizeCreditCard(params) {
188
188
  accessPass: entryTranResult.accessPass,
189
189
  orderId: params.orderId,
190
190
  method: params.object.method,
191
- siteId: (_d = params.availableChannel.credentials) === null || _d === void 0 ? void 0 : _d.siteId,
192
- sitePass: (_e = params.availableChannel.credentials) === null || _e === void 0 ? void 0 : _e.sitePass,
191
+ siteId: (_e = params.availableChannel.credentials) === null || _e === void 0 ? void 0 : _e.siteId,
192
+ sitePass: (_f = params.availableChannel.credentials) === null || _f === void 0 ? void 0 : _f.sitePass,
193
193
  cardNo: creditCard.cardNo,
194
194
  cardPass: creditCard.cardPass,
195
195
  expire: creditCard.expire,
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.351.0-alpha.2",
13
+ "@chevre/factory": "4.351.0-alpha.3",
14
14
  "@cinerino/sdk": "5.6.0",
15
15
  "@motionpicture/coa-service": "9.2.0",
16
16
  "@motionpicture/gmo-service": "5.3.0-alpha.0",
@@ -115,5 +115,5 @@
115
115
  "postversion": "git push origin --tags",
116
116
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
117
117
  },
118
- "version": "21.20.0-alpha.2"
118
+ "version": "21.20.0-alpha.3"
119
119
  }