@chevre/domain 21.33.0-alpha.28 → 21.33.0-alpha.29

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.
@@ -1,16 +1,16 @@
1
1
  import * as GMO from '@motionpicture/gmo-service';
2
2
  import * as factory from '../../../factory';
3
3
  interface IProcessAlterTranResult {
4
- searchTradeArgs: GMO.factory.credit.ISearchTradeArgs & GMO.factory.credit.IOptionalSiteArgs;
5
- searchTradeResult: GMO.factory.credit.ISearchTradeResult;
4
+ searchTradeArgs?: GMO.factory.credit.ISearchTradeArgs & GMO.factory.credit.IOptionalSiteArgs;
5
+ searchTradeResult?: GMO.factory.credit.ISearchTradeResult;
6
6
  alterTranArgs?: GMO.factory.credit.IAlterTranArgs & GMO.factory.credit.IOptionalSiteArgs;
7
- alterTranResult: GMO.factory.credit.IAlterTranResult;
7
+ alterTranResult?: GMO.factory.credit.IAlterTranResult;
8
8
  }
9
9
  interface IProcessAlterTranResult4refund {
10
- searchTradeArgs: GMO.factory.credit.ISearchTradeArgs & GMO.factory.credit.IOptionalSiteArgs;
11
- searchTradeResult: GMO.factory.credit.ISearchTradeResult;
10
+ searchTradeArgs?: GMO.factory.credit.ISearchTradeArgs & GMO.factory.credit.IOptionalSiteArgs;
11
+ searchTradeResult?: GMO.factory.credit.ISearchTradeResult;
12
12
  alterTranArgs?: GMO.factory.credit.IAlterTranArgs & GMO.factory.credit.IOptionalSiteArgs;
13
- alterTranResult: GMO.factory.credit.IAlterTranResult | factory.action.trade.refund.IAlterTranResultAsError;
13
+ alterTranResult?: GMO.factory.credit.IAlterTranResult | factory.action.trade.refund.IAlterTranResultAsError;
14
14
  }
15
15
  declare function processAlterTranResult2payRecipe(params: {
16
16
  processAlterTranResults: IProcessAlterTranResult[];
@@ -16,19 +16,12 @@ function processAlterTranResult2payRecipe(params) {
16
16
  {
17
17
  typeOf: 'HowToStep',
18
18
  identifier: factory.recipe.StepIdentifier.searchTrade,
19
- itemListElement: [{
20
- typeOf: 'HowToDirection',
21
- beforeMedia: searchTradeArgs,
22
- afterMedia: searchTradeResult
23
- // text: 'entryTran'
24
- }]
19
+ itemListElement: [Object.assign(Object.assign({ typeOf: 'HowToDirection' }, (searchTradeArgs !== undefined) ? { beforeMedia: searchTradeArgs } : undefined), (searchTradeResult !== undefined) ? { afterMedia: searchTradeResult } : undefined)]
25
20
  },
26
21
  {
27
22
  typeOf: 'HowToStep',
28
23
  identifier: factory.recipe.StepIdentifier.alterTran,
29
- itemListElement: [Object.assign({ typeOf: 'HowToDirection', afterMedia: alterTranResult }, (alterTranArgs !== undefined) ? { beforeMedia: alterTranArgs } : undefined
30
- // text: 'execTran'
31
- )]
24
+ itemListElement: [Object.assign(Object.assign({ typeOf: 'HowToDirection' }, (alterTranResult !== undefined) ? { afterMedia: alterTranResult } : undefined), (alterTranArgs !== undefined) ? { beforeMedia: alterTranArgs } : undefined)]
32
25
  }
33
26
  ]
34
27
  };
@@ -38,6 +31,7 @@ function processAlterTranResult2payRecipe(params) {
38
31
  exports.processAlterTranResult2payRecipe = processAlterTranResult2payRecipe;
39
32
  function processAlterTranResult2refundRecipe(params) {
40
33
  const { processAlterTranResult, project, action } = params;
34
+ const { searchTradeArgs, searchTradeResult, alterTranResult, alterTranArgs } = processAlterTranResult;
41
35
  return {
42
36
  project: { id: project.id, typeOf: factory.organizationType.Project },
43
37
  typeOf: 'Recipe',
@@ -49,21 +43,12 @@ function processAlterTranResult2refundRecipe(params) {
49
43
  {
50
44
  typeOf: 'HowToStep',
51
45
  identifier: factory.recipe.StepIdentifier.searchTrade,
52
- itemListElement: [{
53
- typeOf: 'HowToDirection',
54
- beforeMedia: processAlterTranResult.searchTradeArgs,
55
- afterMedia: processAlterTranResult.searchTradeResult
56
- // text: 'entryTran'
57
- }]
46
+ itemListElement: [Object.assign(Object.assign({ typeOf: 'HowToDirection' }, (searchTradeArgs !== undefined) ? { beforeMedia: searchTradeArgs } : undefined), (searchTradeResult !== undefined) ? { afterMedia: searchTradeResult } : undefined)]
58
47
  },
59
48
  {
60
49
  typeOf: 'HowToStep',
61
50
  identifier: factory.recipe.StepIdentifier.alterTran,
62
- itemListElement: [Object.assign({ typeOf: 'HowToDirection', afterMedia: processAlterTranResult.alterTranResult }, (processAlterTranResult.alterTranArgs !== undefined)
63
- ? { beforeMedia: processAlterTranResult.alterTranArgs }
64
- : undefined
65
- // text: 'execTran'
66
- )]
51
+ itemListElement: [Object.assign(Object.assign({ typeOf: 'HowToDirection' }, (alterTranArgs !== undefined) ? { beforeMedia: alterTranArgs } : undefined), (alterTranResult !== undefined) ? { afterMedia: alterTranResult } : undefined)]
67
52
  }
68
53
  ]
69
54
  }]
@@ -1,10 +1,11 @@
1
- import * as factory from '../../../factory';
2
1
  import type { MongoRepository as AccountingReportRepo } from '../../../repo/accountingReport';
3
2
  import type { MongoRepository as ActionRepo } from '../../../repo/action';
4
3
  import type { MongoRepository as PaymentServiceRepo } from '../../../repo/paymentService';
5
4
  import type { MongoRepository as PaymentServiceProviderRepo } from '../../../repo/paymentServiceProvider';
6
5
  import type { MongoRepository as PaymentAcceptedRepo } from '../../../repo/sellerPaymentAccepted';
7
6
  import type { MongoRepository as TaskRepo } from '../../../repo/task';
7
+ import * as factory from '../../../factory';
8
+ type IPayAction = factory.action.trade.pay.IAction;
8
9
  /**
9
10
  * クレジットカード決済
10
11
  */
@@ -15,5 +16,5 @@ declare function payCreditCard(params: factory.action.trade.pay.IAttributes): (r
15
16
  paymentService: PaymentServiceRepo;
16
17
  paymentServiceProvider: PaymentServiceProviderRepo;
17
18
  task: TaskRepo;
18
- }) => Promise<import("@chevre/factory/lib/action/trade/pay").IAction>;
19
+ }) => Promise<IPayAction>;
19
20
  export { payCreditCard };
@@ -14,7 +14,6 @@ const GMO = require("@motionpicture/gmo-service");
14
14
  const createDebug = require("debug");
15
15
  const credentials_1 = require("../../../credentials");
16
16
  const factory = require("../../../factory");
17
- const settings_1 = require("../../../settings");
18
17
  const onPaid_1 = require("../any/onPaid");
19
18
  const factory_1 = require("./factory");
20
19
  const getGMOInfoFromSeller_1 = require("./getGMOInfoFromSeller");
@@ -45,27 +44,33 @@ function payCreditCard(params) {
45
44
  // アクション開始
46
45
  let action = yield repos.action.start(params);
47
46
  const alterTranResults = [];
47
+ const processAlterTranResults = [];
48
48
  try {
49
49
  const creditCardService = new GMO.service.Credit({
50
50
  endpoint: String(availableChannel.serviceUrl),
51
51
  useFetch: credentials_1.credentials.gmo.useFetch
52
52
  }, { timeout: credentials_1.credentials.gmo.timeout });
53
- const processAlterTranResults = [];
54
53
  yield Promise.all(payObject.map((paymentMethod) => __awaiter(this, void 0, void 0, function* () {
55
54
  const processAlterTranResult = yield processAlterTran({
56
55
  shopId, shopPass, availableChannel, paymentMethod
57
56
  })({ creditCardService });
58
- alterTranResults.push(processAlterTranResult.alterTranResult);
59
57
  processAlterTranResults.push(processAlterTranResult);
58
+ if (processAlterTranResult.processAlterTranError === undefined) {
59
+ if (processAlterTranResult.alterTranResult !== undefined) {
60
+ alterTranResults.push(processAlterTranResult.alterTranResult);
61
+ }
62
+ }
63
+ else {
64
+ // 代行決済連携中にエラーがあればそのままthrow
65
+ throw processAlterTranResult.processAlterTranError;
66
+ }
60
67
  })));
61
68
  // add recipe(2024-06-03~)
62
- if (settings_1.USE_EXPERIMENTAL_FEATURE) {
63
- yield repos.action.saveOneRecipe((0, factory_1.processAlterTranResult2payRecipe)({
64
- processAlterTranResults,
65
- project: { id: params.project.id },
66
- action: { id: action.id, typeOf: action.typeOf }
67
- }));
68
- }
69
+ yield repos.action.saveOneRecipe((0, factory_1.processAlterTranResult2payRecipe)({
70
+ processAlterTranResults,
71
+ project: { id: params.project.id },
72
+ action: { id: action.id, typeOf: action.typeOf }
73
+ }));
69
74
  }
70
75
  catch (error) {
71
76
  try {
@@ -76,10 +81,7 @@ function payCreditCard(params) {
76
81
  }
77
82
  throw error;
78
83
  }
79
- // アクション完了
80
- const actionResult = {
81
- creditCardSales: alterTranResults
82
- };
84
+ const actionResult = { creditCardSales: alterTranResults };
83
85
  action = (yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult }));
84
86
  yield (0, onPaid_1.onPaid)(action)(repos);
85
87
  return action;
@@ -89,74 +91,77 @@ exports.payCreditCard = payCreditCard;
89
91
  function processAlterTran(params) {
90
92
  return (repos) => __awaiter(this, void 0, void 0, function* () {
91
93
  var _a, _b, _c, _d, _e, _f, _g;
94
+ let searchTradeArgs;
95
+ let searchTradeResult;
92
96
  let alterTranArgs;
93
97
  let alterTranResult;
94
- const paymentMethod = params.paymentMethod;
95
- const orderId = paymentMethod.paymentMethod.paymentMethodId;
96
- // 取引状態参照
97
- const searchTradeArgs = {
98
- shopId: params.shopId,
99
- shopPass: params.shopPass,
100
- orderId: orderId,
101
- siteId: (_a = params.availableChannel.credentials) === null || _a === void 0 ? void 0 : _a.siteId,
102
- sitePass: (_b = params.availableChannel.credentials) === null || _b === void 0 ? void 0 : _b.sitePass
103
- };
104
- const searchTradeResult = yield repos.creditCardService.searchTrade(searchTradeArgs);
105
- const amount = (_c = paymentMethod.paymentMethod.totalPaymentDue) === null || _c === void 0 ? void 0 : _c.value;
106
- if (typeof amount !== 'number') {
107
- throw new factory.errors.ArgumentNull('object.paymentMethod.totalPaymentDue?.value');
98
+ let processAlterTranError;
99
+ try {
100
+ const { shopId, shopPass } = params;
101
+ const paymentMethod = params.paymentMethod;
102
+ const orderId = paymentMethod.paymentMethod.paymentMethodId;
103
+ // 取引状態参照
104
+ searchTradeArgs = {
105
+ shopId, shopPass, orderId,
106
+ siteId: (_a = params.availableChannel.credentials) === null || _a === void 0 ? void 0 : _a.siteId,
107
+ sitePass: (_b = params.availableChannel.credentials) === null || _b === void 0 ? void 0 : _b.sitePass
108
+ };
109
+ searchTradeResult = yield repos.creditCardService.searchTrade(searchTradeArgs);
110
+ const { accessId, accessPass } = searchTradeResult;
111
+ const amount = (_c = paymentMethod.paymentMethod.totalPaymentDue) === null || _c === void 0 ? void 0 : _c.value;
112
+ if (typeof amount !== 'number') {
113
+ throw new factory.errors.ArgumentNull('object.paymentMethod.totalPaymentDue?.value');
114
+ }
115
+ switch (searchTradeResult.jobCd) {
116
+ case GMO.utils.util.JobCd.Capture:
117
+ case GMO.utils.util.JobCd.Sales:
118
+ debug('already in SALES');
119
+ // すでに即時売上済み
120
+ alterTranResult = {
121
+ accessId, accessPass,
122
+ forward: searchTradeResult.forward,
123
+ approve: searchTradeResult.approve,
124
+ tranId: searchTradeResult.tranId,
125
+ tranDate: ''
126
+ };
127
+ break;
128
+ case GMO.utils.util.JobCd.Void:
129
+ // 返品手数料決済の場合を追加(状態が取消であれば即時売上)
130
+ debug('calling alterTran...');
131
+ alterTranArgs = {
132
+ shopId, shopPass,
133
+ accessId, accessPass,
134
+ jobCd: GMO.utils.util.JobCd.Capture,
135
+ amount: amount,
136
+ siteId: (_d = params.availableChannel.credentials) === null || _d === void 0 ? void 0 : _d.siteId,
137
+ sitePass: (_e = params.availableChannel.credentials) === null || _e === void 0 ? void 0 : _e.sitePass,
138
+ method: GMO.utils.util.Method.Lump // 再オーソリの場合、支払方法指定は必須
139
+ };
140
+ alterTranResult = yield repos.creditCardService.alterTran(alterTranArgs);
141
+ debug('alterTran processed.');
142
+ break;
143
+ case GMO.utils.util.JobCd.Auth:
144
+ debug('calling alterTran...');
145
+ alterTranArgs = {
146
+ shopId, shopPass,
147
+ accessId, accessPass,
148
+ jobCd: GMO.utils.util.JobCd.Sales,
149
+ amount: amount,
150
+ siteId: (_f = params.availableChannel.credentials) === null || _f === void 0 ? void 0 : _f.siteId,
151
+ sitePass: (_g = params.availableChannel.credentials) === null || _g === void 0 ? void 0 : _g.sitePass
152
+ };
153
+ alterTranResult = yield repos.creditCardService.alterTran(alterTranArgs);
154
+ // 失敗したら取引状態確認してどうこう、という処理も考えうるが、
155
+ // GMOはapiのコール制限が厳しく、下手にコールするとすぐにクライアントサイドにも影響をあたえてしまう
156
+ // リトライはタスクの仕組みに含まれているので失敗してもここでは何もしない
157
+ break;
158
+ default:
159
+ throw new factory.errors.NotImplemented(`jobCd '${searchTradeResult.jobCd}' not implemented`);
160
+ }
108
161
  }
109
- switch (searchTradeResult.jobCd) {
110
- case GMO.utils.util.JobCd.Capture:
111
- case GMO.utils.util.JobCd.Sales:
112
- debug('already in SALES');
113
- // すでに即時売上済み
114
- alterTranResult = {
115
- accessId: searchTradeResult.accessId,
116
- accessPass: searchTradeResult.accessPass,
117
- forward: searchTradeResult.forward,
118
- approve: searchTradeResult.approve,
119
- tranId: searchTradeResult.tranId,
120
- tranDate: ''
121
- };
122
- break;
123
- case GMO.utils.util.JobCd.Void:
124
- // 返品手数料決済の場合を追加(状態が取消であれば即時売上)
125
- debug('calling alterTran...');
126
- alterTranArgs = {
127
- shopId: params.shopId,
128
- shopPass: params.shopPass,
129
- accessId: searchTradeResult.accessId,
130
- accessPass: searchTradeResult.accessPass,
131
- jobCd: GMO.utils.util.JobCd.Capture,
132
- amount: amount,
133
- siteId: (_d = params.availableChannel.credentials) === null || _d === void 0 ? void 0 : _d.siteId,
134
- sitePass: (_e = params.availableChannel.credentials) === null || _e === void 0 ? void 0 : _e.sitePass,
135
- method: GMO.utils.util.Method.Lump // 再オーソリの場合、支払方法指定は必須
136
- };
137
- alterTranResult = yield repos.creditCardService.alterTran(alterTranArgs);
138
- debug('alterTran processed.');
139
- break;
140
- case GMO.utils.util.JobCd.Auth:
141
- debug('calling alterTran...');
142
- alterTranArgs = {
143
- shopId: params.shopId,
144
- shopPass: params.shopPass,
145
- accessId: searchTradeResult.accessId,
146
- accessPass: searchTradeResult.accessPass,
147
- jobCd: GMO.utils.util.JobCd.Sales,
148
- amount: amount,
149
- siteId: (_f = params.availableChannel.credentials) === null || _f === void 0 ? void 0 : _f.siteId,
150
- sitePass: (_g = params.availableChannel.credentials) === null || _g === void 0 ? void 0 : _g.sitePass
151
- };
152
- alterTranResult = yield repos.creditCardService.alterTran(alterTranArgs);
153
- // 失敗したら取引状態確認してどうこう、という処理も考えうるが、
154
- // GMOはapiのコール制限が厳しく、下手にコールするとすぐにクライアントサイドにも影響をあたえてしまう
155
- // リトライはタスクの仕組みに含まれているので失敗してもここでは何もしない
156
- break;
157
- default:
158
- throw new factory.errors.NotImplemented(`jobCd '${searchTradeResult.jobCd}' not implemented`);
162
+ catch (error) {
163
+ processAlterTranError = error;
159
164
  }
160
- return { searchTradeArgs, searchTradeResult, alterTranArgs, alterTranResult };
165
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (searchTradeArgs !== undefined) ? { searchTradeArgs } : undefined), (searchTradeResult !== undefined) ? { searchTradeResult } : undefined), (alterTranArgs !== undefined) ? { alterTranArgs } : undefined), (alterTranResult !== undefined) ? { alterTranResult } : undefined), (processAlterTranError !== undefined) ? { processAlterTranError } : undefined);
161
166
  });
162
167
  }
@@ -1,10 +1,11 @@
1
- import * as factory from '../../../factory';
2
1
  import type { MongoRepository as AccountingReportRepo } from '../../../repo/accountingReport';
3
2
  import type { MongoRepository as ActionRepo } from '../../../repo/action';
4
3
  import type { MongoRepository as PaymentServiceRepo } from '../../../repo/paymentService';
5
4
  import type { MongoRepository as PaymentServiceProviderRepo } from '../../../repo/paymentServiceProvider';
6
5
  import type { MongoRepository as PaymentAcceptedRepo } from '../../../repo/sellerPaymentAccepted';
7
6
  import type { MongoRepository as TaskRepo } from '../../../repo/task';
7
+ import * as factory from '../../../factory';
8
+ type IRefundAction = factory.action.trade.refund.IAction;
8
9
  /**
9
10
  * クレジットカード返金
10
11
  */
@@ -21,5 +22,5 @@ declare function refundCreditCard(params: factory.task.refund.IData & {
21
22
  paymentService: PaymentServiceRepo;
22
23
  paymentServiceProvider: PaymentServiceProviderRepo;
23
24
  task: TaskRepo;
24
- }) => Promise<import("@chevre/factory/lib/action/trade/refund").IAction>;
25
+ }) => Promise<IRefundAction>;
25
26
  export { refundCreditCard };
@@ -14,7 +14,6 @@ const GMO = require("@motionpicture/gmo-service");
14
14
  const createDebug = require("debug");
15
15
  const credentials_1 = require("../../../credentials");
16
16
  const factory = require("../../../factory");
17
- const settings_1 = require("../../../settings");
18
17
  const onRefund_1 = require("../any/onRefund");
19
18
  const factory_1 = require("./factory");
20
19
  const getGMOInfoFromSeller_1 = require("./getGMOInfoFromSeller");
@@ -48,26 +47,35 @@ function refundCreditCard(params, options) {
48
47
  });
49
48
  let action = yield repos.action.start(Object.assign(Object.assign({}, params), (typeof ((_e = params.sameAs) === null || _e === void 0 ? void 0 : _e.id) === 'string') ? { sameAs: { id: params.sameAs.id, typeOf: 'Task' } } : undefined));
50
49
  const alterTranResult = [];
50
+ let processAlterTranResult;
51
51
  try {
52
- const processAlterTranResult = yield processChangeTransaction({
52
+ const creditCardService = new GMO.service.Credit({
53
+ endpoint: String(availableChannel.serviceUrl),
54
+ useFetch: credentials_1.credentials.gmo.useFetch
55
+ }, { timeout: credentials_1.credentials.gmo.timeout });
56
+ processAlterTranResult = yield processAlterTran({
53
57
  availableChannel,
54
58
  payAction: payAction,
55
59
  paymentMethodId: paymentMethodId,
56
60
  shopId: shopId,
57
61
  shopPass: shopPass,
58
62
  refundFee: (_f = params.object[0]) === null || _f === void 0 ? void 0 : _f.refundFee
59
- });
60
- if (processAlterTranResult.alterTranResult !== undefined) {
61
- alterTranResult.push(processAlterTranResult.alterTranResult);
63
+ })({ creditCardService });
64
+ if (processAlterTranResult.processAlterTranError === undefined) {
65
+ if (processAlterTranResult.alterTranResult !== undefined) {
66
+ alterTranResult.push(processAlterTranResult.alterTranResult);
67
+ }
62
68
  }
63
- // add recipe(2024-06-04~)
64
- if (settings_1.USE_EXPERIMENTAL_FEATURE) {
65
- yield repos.action.saveOneRecipe((0, factory_1.processAlterTranResult2refundRecipe)({
66
- processAlterTranResult,
67
- project: { id: params.project.id },
68
- action: { id: action.id, typeOf: action.typeOf }
69
- }));
69
+ else {
70
+ // 代行決済連携中にエラーがあればそのままthrow
71
+ throw processAlterTranResult.processAlterTranError;
70
72
  }
73
+ // add recipe(2024-06-04~)
74
+ yield repos.action.saveOneRecipe((0, factory_1.processAlterTranResult2refundRecipe)({
75
+ processAlterTranResult,
76
+ project: { id: params.project.id },
77
+ action: { id: action.id, typeOf: action.typeOf }
78
+ }));
71
79
  }
72
80
  catch (error) {
73
81
  try {
@@ -85,97 +93,99 @@ function refundCreditCard(params, options) {
85
93
  });
86
94
  }
87
95
  exports.refundCreditCard = refundCreditCard;
88
- // tslint:disable-next-line:max-func-body-length
89
- function processChangeTransaction(params) {
90
- var _a, _b, _c, _d, _e, _f, _g, _h;
91
- return __awaiter(this, void 0, void 0, function* () {
96
+ function processAlterTran(params) {
97
+ // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
98
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
99
+ var _a, _b, _c, _d, _e, _f, _g, _h;
100
+ let searchTradeArgs;
101
+ let searchTradeResult;
92
102
  let alterTranArgs;
93
103
  let alterTranResult;
104
+ let processAlterTranError;
94
105
  let alterTranError;
95
- const creditCardService = new GMO.service.Credit({
96
- endpoint: String(params.availableChannel.serviceUrl),
97
- useFetch: credentials_1.credentials.gmo.useFetch
98
- }, { timeout: credentials_1.credentials.gmo.timeout });
99
- // 取引状態参照
100
- const searchTradeArgs = {
101
- shopId: params.shopId,
102
- shopPass: params.shopPass,
103
- orderId: params.paymentMethodId,
104
- siteId: (_a = params.availableChannel.credentials) === null || _a === void 0 ? void 0 : _a.siteId,
105
- sitePass: (_b = params.availableChannel.credentials) === null || _b === void 0 ? void 0 : _b.sitePass
106
- };
107
- const searchTradeResult = yield creditCardService.searchTrade(searchTradeArgs);
108
- // 冪等性の担保をいったん保留
109
- let creditCardSalesBefore;
110
- if (Array.isArray((_d = (_c = params.payAction) === null || _c === void 0 ? void 0 : _c.result) === null || _d === void 0 ? void 0 : _d.creditCardSales)) {
111
- creditCardSalesBefore = (_f = (_e = params.payAction) === null || _e === void 0 ? void 0 : _e.result) === null || _f === void 0 ? void 0 : _f.creditCardSales[0];
112
- }
113
- let alreadyRefunded = false;
114
- // 決済時のGMO取引を確認できれば、既に返金済かどうかを判定
115
- if (typeof (creditCardSalesBefore === null || creditCardSalesBefore === void 0 ? void 0 : creditCardSalesBefore.tranId) === 'string') {
116
- // GMO取引状態に変更がなければ金額変更
117
- if (searchTradeResult.tranId !== creditCardSalesBefore.tranId) {
118
- alreadyRefunded = true;
106
+ try {
107
+ const { shopId, shopPass } = params;
108
+ // 取引状態参照
109
+ searchTradeArgs = {
110
+ shopId, shopPass,
111
+ orderId: params.paymentMethodId,
112
+ siteId: (_a = params.availableChannel.credentials) === null || _a === void 0 ? void 0 : _a.siteId,
113
+ sitePass: (_b = params.availableChannel.credentials) === null || _b === void 0 ? void 0 : _b.sitePass
114
+ };
115
+ searchTradeResult = yield repos.creditCardService.searchTrade(searchTradeArgs);
116
+ const { accessId, accessPass } = searchTradeResult;
117
+ // 冪等性の担保をいったん保留
118
+ let creditCardSalesBefore;
119
+ if (Array.isArray((_d = (_c = params.payAction) === null || _c === void 0 ? void 0 : _c.result) === null || _d === void 0 ? void 0 : _d.creditCardSales)) {
120
+ creditCardSalesBefore = (_f = (_e = params.payAction) === null || _e === void 0 ? void 0 : _e.result) === null || _f === void 0 ? void 0 : _f.creditCardSales[0];
119
121
  }
120
- // tranIdが空文字のケース(SPSwrapperで発生)に対応(Voidに対してVoidを実行してしまうので)(2024-04-20~)
121
- if (searchTradeResult.tranId === '' && creditCardSalesBefore.tranId === '') {
122
- if (searchTradeResult.status === GMO.utils.util.Status.Void) {
122
+ let alreadyRefunded = false;
123
+ // 決済時のGMO取引を確認できれば、既に返金済かどうかを判定
124
+ if (typeof (creditCardSalesBefore === null || creditCardSalesBefore === void 0 ? void 0 : creditCardSalesBefore.tranId) === 'string') {
125
+ // GMO取引状態に変更がなければ金額変更
126
+ if (searchTradeResult.tranId !== creditCardSalesBefore.tranId) {
123
127
  alreadyRefunded = true;
124
128
  }
129
+ // tranIdが空文字のケース(SPSwrapperで発生)に対応(Voidに対してVoidを実行してしまうので)(2024-04-20~)
130
+ if (searchTradeResult.tranId === '' && creditCardSalesBefore.tranId === '') {
131
+ if (searchTradeResult.status === GMO.utils.util.Status.Void) {
132
+ alreadyRefunded = true;
133
+ }
134
+ }
125
135
  }
126
- }
127
- if (alreadyRefunded) {
128
- alterTranResult = {
129
- accessId: searchTradeResult.accessId,
130
- accessPass: searchTradeResult.accessPass,
131
- forward: searchTradeResult.forward,
132
- approve: searchTradeResult.approve,
133
- tranId: searchTradeResult.tranId,
134
- tranDate: ''
135
- };
136
- }
137
- else {
138
- try {
139
- // 手数料決済については、取消→即時売上の流れ
140
- debug('alterTran processing... searchTradeResult:', searchTradeResult);
141
- alterTranArgs = {
142
- shopId: params.shopId,
143
- shopPass: params.shopPass,
144
- accessId: searchTradeResult.accessId,
145
- accessPass: searchTradeResult.accessPass,
146
- jobCd: GMO.utils.util.JobCd.Void,
147
- siteId: (_g = params.availableChannel.credentials) === null || _g === void 0 ? void 0 : _g.siteId,
148
- sitePass: (_h = params.availableChannel.credentials) === null || _h === void 0 ? void 0 : _h.sitePass
136
+ if (alreadyRefunded) {
137
+ alterTranResult = {
138
+ accessId, accessPass,
139
+ forward: searchTradeResult.forward,
140
+ approve: searchTradeResult.approve,
141
+ tranId: searchTradeResult.tranId,
142
+ tranDate: ''
149
143
  };
150
- alterTranResult = yield creditCardService.alterTran(alterTranArgs);
151
- debug('alterTran processed.');
152
144
  }
153
- catch (error) {
154
- let throwsError = true;
155
- // 未決済(3D 登録済)->取消をトライするとE01050004エラーとなるが、この場合何もする必要はない(2024-01-09~)
156
- if (error.name === 'GMOServiceBadRequestError') {
157
- // 会員が存在しない場合このエラーになる
158
- if (Array.isArray(error.errors) && error.errors.length === 1 && error.errors[0].info === 'E01050004') {
159
- debug('creditCardService.alterTran:E01050004:', 'orderId:', searchTradeResult.orderId, 'status:', searchTradeResult.status);
160
- if (searchTradeResult.status === GMO.utils.util.Status.Authenticated
161
- || searchTradeResult.status === GMO.utils.util.Status.Void) {
162
- alterTranError = error;
163
- throwsError = false;
145
+ else {
146
+ try {
147
+ // 手数料決済については、取消→即時売上の流れ
148
+ debug('alterTran processing... searchTradeResult:', searchTradeResult);
149
+ alterTranArgs = {
150
+ shopId, shopPass,
151
+ accessId, accessPass,
152
+ jobCd: GMO.utils.util.JobCd.Void,
153
+ siteId: (_g = params.availableChannel.credentials) === null || _g === void 0 ? void 0 : _g.siteId,
154
+ sitePass: (_h = params.availableChannel.credentials) === null || _h === void 0 ? void 0 : _h.sitePass
155
+ };
156
+ alterTranResult = yield repos.creditCardService.alterTran(alterTranArgs);
157
+ debug('alterTran processed.');
158
+ }
159
+ catch (error) {
160
+ let throwsError = true;
161
+ // 未決済(3D 登録済)->取消をトライするとE01050004エラーとなるが、この場合何もする必要はない(2024-01-09~)
162
+ if (error.name === 'GMOServiceBadRequestError') {
163
+ // 会員が存在しない場合このエラーになる
164
+ if (Array.isArray(error.errors) && error.errors.length === 1 && error.errors[0].info === 'E01050004') {
165
+ debug('creditCardService.alterTran:E01050004:', 'orderId:', searchTradeResult.orderId, 'status:', searchTradeResult.status);
166
+ if (searchTradeResult.status === GMO.utils.util.Status.Authenticated
167
+ || searchTradeResult.status === GMO.utils.util.Status.Void) {
168
+ alterTranError = error;
169
+ throwsError = false;
170
+ }
164
171
  }
165
172
  }
166
- }
167
- if (throwsError) {
168
- throw error;
173
+ if (throwsError) {
174
+ throw error;
175
+ }
169
176
  }
170
177
  }
178
+ if (alterTranResult === undefined && alterTranError !== undefined) {
179
+ alterTranResult = alterTranError;
180
+ }
181
+ if (alterTranResult === undefined) {
182
+ // impossible path
183
+ throw new factory.errors.NotImplemented('alterTranResult undefined not implemented');
184
+ }
171
185
  }
172
- if (alterTranResult === undefined && alterTranError !== undefined) {
173
- alterTranResult = alterTranError;
174
- }
175
- if (alterTranResult === undefined) {
176
- // impossible path
177
- throw new factory.errors.NotImplemented('alterTranResult undefined not implemented');
186
+ catch (error) {
187
+ processAlterTranError = error;
178
188
  }
179
- return { searchTradeArgs, searchTradeResult, alterTranArgs, alterTranResult };
189
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (searchTradeArgs !== undefined) ? { searchTradeArgs } : undefined), (searchTradeResult !== undefined) ? { searchTradeResult } : undefined), (alterTranArgs !== undefined) ? { alterTranArgs } : undefined), (alterTranResult !== undefined) ? { alterTranResult } : undefined), (processAlterTranError !== undefined) ? { processAlterTranError } : undefined);
180
190
  });
181
191
  }
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.374.0-alpha.5",
13
+ "@chevre/factory": "4.374.0-alpha.6",
14
14
  "@cinerino/sdk": "7.1.0",
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.33.0-alpha.28"
113
+ "version": "21.33.0-alpha.29"
114
114
  }