@vendit-dev/thirdparty-adapters 0.1.2 → 0.2.0

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,3 +1,15 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
1
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,470 +19,775 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
19
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
20
  });
9
21
  };
10
- import fetch from 'node-fetch';
11
- import moment from 'moment';
12
- import MutexLock from '../utils/mutex';
13
- const WINGS_API_ENDPOINT = 'https://wingsapi.sanhait.com';
14
- const WINGS_COMMON_REQUEST_HEADERS = {
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.WingsApiController = void 0;
54
+ var node_fetch_1 = __importDefault(require("node-fetch"));
55
+ var moment_1 = __importDefault(require("moment"));
56
+ var mutex_1 = __importDefault(require("../utils/mutex"));
57
+ var WINGS_API_ENDPOINT = 'https://wingsapi.sanhait.com';
58
+ var WINGS_COMMON_REQUEST_HEADERS = {
15
59
  'Content-Type': 'application/json',
16
60
  'Echo-Token': '',
17
61
  };
18
- const WINGS_COMMON_REQUEST_PARAMS = {
62
+ var WINGS_COMMON_REQUEST_PARAMS = {
19
63
  LANG_TYPE: 'KOR',
20
64
  KIOSK_ID: 'KIOSK',
21
65
  };
22
- export class WingsApiController {
23
- constructor({ contextApi }) {
24
- this.callWingsApi = ({ route, params = {}, auth }) => __awaiter(this, void 0, void 0, function* () {
25
- const requestOptions = {
26
- method: 'POST',
27
- headers: Object.assign(Object.assign({}, WINGS_COMMON_REQUEST_HEADERS), auth.headers),
28
- body: JSON.stringify(Object.assign(Object.assign(Object.assign({}, auth.params), WINGS_COMMON_REQUEST_PARAMS), params)),
29
- };
30
- if (process.env.NODE_ENV === 'development') {
31
- console.log(requestOptions);
32
- }
33
- const response = yield fetch(`${this.URI}/${this.CONTEXT}/${route}`, requestOptions);
34
- return response.json();
35
- });
66
+ var WingsApiController = /** @class */ (function () {
67
+ function WingsApiController(_a) {
68
+ var _this = this;
69
+ var contextApi = _a.contextApi;
70
+ this.callWingsApi = function (_a) {
71
+ var route = _a.route, _b = _a.params, params = _b === void 0 ? {} : _b, auth = _a.auth;
72
+ return __awaiter(_this, void 0, void 0, function () {
73
+ var requestOptions, response;
74
+ return __generator(this, function (_c) {
75
+ switch (_c.label) {
76
+ case 0:
77
+ requestOptions = {
78
+ method: 'POST',
79
+ headers: __assign(__assign({}, WINGS_COMMON_REQUEST_HEADERS), auth.headers),
80
+ body: JSON.stringify(__assign(__assign(__assign({}, auth.params), WINGS_COMMON_REQUEST_PARAMS), params)),
81
+ };
82
+ if (process.env.NODE_ENV === 'development') {
83
+ console.log(requestOptions);
84
+ }
85
+ return [4 /*yield*/, node_fetch_1.default(this.URI + "/" + this.CONTEXT + "/" + route, requestOptions)];
86
+ case 1:
87
+ response = _c.sent();
88
+ return [2 /*return*/, response.json()];
89
+ }
90
+ });
91
+ });
92
+ };
36
93
  this.URI = WINGS_API_ENDPOINT;
37
94
  this.CONTEXT = contextApi;
38
95
  }
39
- }
40
- const apiController = new WingsApiController({
96
+ return WingsApiController;
97
+ }());
98
+ exports.WingsApiController = WingsApiController;
99
+ var apiController = new WingsApiController({
41
100
  contextApi: 'kiosk',
42
101
  });
43
- export default class WingsAdapter {
44
- constructor({ authenticator, redis }) {
102
+ var WingsAdapter = /** @class */ (function () {
103
+ function WingsAdapter(_a) {
104
+ var _this = this;
105
+ var authenticator = _a.authenticator, redis = _a.redis;
45
106
  this.PROVIDER_KEY = 'SanhaWings';
46
- this.checkWingsIntegration = ({ accommodationId }) => __awaiter(this, void 0, void 0, function* () { return !!this.getAccommodationAuthInfo({ accommodationId }); });
47
- this.getAccommodationAuthInfo = ({ accommodationId }) => __awaiter(this, void 0, void 0, function* () {
48
- let existingAuth = yield this.redis.get(WingsAdapter.indexAccommodation({ accommodationId }));
49
- if (existingAuth) {
50
- if (existingAuth === 'NOT_FOUND') {
51
- throw new Error('THIRDPARTY_AUTH_NOT_FOUND');
52
- }
53
- return JSON.parse(existingAuth);
54
- }
55
- const lockId = `WINGS-HKEY|${accommodationId}`;
56
- const lockHash = yield this.mutexLock.getMutexLock(lockId);
57
- existingAuth = yield this.redis.get(WingsAdapter.indexAccommodation({ accommodationId }));
58
- try {
59
- if (existingAuth) {
60
- return JSON.parse(existingAuth);
61
- }
62
- const newAuth = yield this.authenticator.getThirdPartyCredential({ accommodationId, provider: this.PROVIDER_KEY });
63
- if (!newAuth) {
64
- yield this.redis.set(WingsAdapter.indexAccommodation({ accommodationId }), 'NOT_FOUND', 'EX', 60 * 10);
65
- throw new Error('THIRDPARTY_AUTH_NOT_FOUND');
66
- }
67
- newAuth.credential = JSON.parse(newAuth.credential);
68
- yield this.redis.set(WingsAdapter.indexAccommodation({ accommodationId }), JSON.stringify(newAuth), 'EX', 60 * 10);
69
- return newAuth;
70
- }
71
- catch (err) {
72
- console.log(err);
73
- throw err;
74
- }
75
- finally {
76
- yield this.mutexLock.unlockMutexLock(lockId, lockHash);
77
- }
78
- });
79
- this.getHotelInformation = ({ accommodationId }) => __awaiter(this, void 0, void 0, function* () {
80
- const authInfo = yield this.getAccommodationAuthInfo({ accommodationId });
81
- const response = yield apiController.callWingsApi({
82
- route: 'ki00/getHotelInformation',
83
- auth: WingsAdapter.authFromCredentials(authInfo.credential),
107
+ this.checkWingsIntegration = function (_a) {
108
+ var accommodationId = _a.accommodationId;
109
+ return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_b) {
110
+ return [2 /*return*/, !!this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
111
+ }); });
112
+ };
113
+ this.getAccommodationAuthInfo = function (_a) {
114
+ var accommodationId = _a.accommodationId;
115
+ return __awaiter(_this, void 0, void 0, function () {
116
+ var existingAuth, lockId, lockHash, newAuth, err_1;
117
+ return __generator(this, function (_b) {
118
+ switch (_b.label) {
119
+ case 0: return [4 /*yield*/, this.redis.get(WingsAdapter.indexAccommodation({ accommodationId: accommodationId }))];
120
+ case 1:
121
+ existingAuth = _b.sent();
122
+ if (existingAuth) {
123
+ if (existingAuth === 'NOT_FOUND') {
124
+ throw new Error('THIRDPARTY_AUTH_NOT_FOUND');
125
+ }
126
+ return [2 /*return*/, JSON.parse(existingAuth)];
127
+ }
128
+ lockId = "WINGS-HKEY|" + accommodationId;
129
+ return [4 /*yield*/, this.mutexLock.getMutexLock(lockId)];
130
+ case 2:
131
+ lockHash = _b.sent();
132
+ return [4 /*yield*/, this.redis.get(WingsAdapter.indexAccommodation({ accommodationId: accommodationId }))];
133
+ case 3:
134
+ existingAuth = _b.sent();
135
+ _b.label = 4;
136
+ case 4:
137
+ _b.trys.push([4, 9, 10, 12]);
138
+ if (existingAuth) {
139
+ return [2 /*return*/, JSON.parse(existingAuth)];
140
+ }
141
+ return [4 /*yield*/, this.authenticator.getThirdPartyCredential({ accommodationId: accommodationId, provider: this.PROVIDER_KEY })];
142
+ case 5:
143
+ newAuth = _b.sent();
144
+ if (!!newAuth) return [3 /*break*/, 7];
145
+ return [4 /*yield*/, this.redis.set(WingsAdapter.indexAccommodation({ accommodationId: accommodationId }), 'NOT_FOUND', 'EX', 60 * 10)];
146
+ case 6:
147
+ _b.sent();
148
+ throw new Error('THIRDPARTY_AUTH_NOT_FOUND');
149
+ case 7:
150
+ newAuth.credential = JSON.parse(newAuth.credential);
151
+ return [4 /*yield*/, this.redis.set(WingsAdapter.indexAccommodation({ accommodationId: accommodationId }), JSON.stringify(newAuth), 'EX', 60 * 10)];
152
+ case 8:
153
+ _b.sent();
154
+ return [2 /*return*/, newAuth];
155
+ case 9:
156
+ err_1 = _b.sent();
157
+ console.log(err_1);
158
+ throw err_1;
159
+ case 10: return [4 /*yield*/, this.mutexLock.unlockMutexLock(lockId, lockHash)];
160
+ case 11:
161
+ _b.sent();
162
+ return [7 /*endfinally*/];
163
+ case 12: return [2 /*return*/];
164
+ }
165
+ });
84
166
  });
85
- return response.resultData;
86
- });
87
- this.checkInReservation = ({ accommodationId, reservationNumber, sequenceNumber, startDate, endDate, }) => __awaiter(this, void 0, void 0, function* () {
88
- const authInfo = yield this.getAccommodationAuthInfo({ accommodationId });
89
- try {
90
- const response = yield apiController.callWingsApi({
91
- route: 'ki01/kioskCheckIn',
92
- auth: WingsAdapter.authFromCredentials(authInfo.credential),
93
- params: {
94
- RSVN_NO: reservationNumber,
95
- RSVN_SEQ_NO: sequenceNumber,
96
- ARRV_DATE: startDate,
97
- DEPT_DATE: endDate,
98
- BSNS_CODE: authInfo.credential.BSNS_CODE,
99
- },
167
+ };
168
+ this.getHotelInformation = function (_a) {
169
+ var accommodationId = _a.accommodationId;
170
+ return __awaiter(_this, void 0, void 0, function () {
171
+ var authInfo, response;
172
+ return __generator(this, function (_b) {
173
+ switch (_b.label) {
174
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
175
+ case 1:
176
+ authInfo = _b.sent();
177
+ return [4 /*yield*/, apiController.callWingsApi({
178
+ route: 'ki00/getHotelInformation',
179
+ auth: WingsAdapter.authFromCredentials(authInfo.credential),
180
+ })];
181
+ case 2:
182
+ response = _b.sent();
183
+ return [2 /*return*/, response.resultData];
184
+ }
100
185
  });
101
- const { resultData } = response;
102
- if (!resultData) {
103
- throw new Error('FAILED_TO_CHECKIN');
104
- }
105
- return resultData;
106
- }
107
- catch (err) {
108
- console.log(err);
109
- throw err;
110
- }
111
- });
112
- this.cancelCheckInReservation = ({ accommodationId, folioNumber }) => __awaiter(this, void 0, void 0, function* () {
113
- const authInfo = yield this.getAccommodationAuthInfo({ accommodationId });
114
- try {
115
- const response = yield apiController.callWingsApi({
116
- route: 'ki00/kioskCancel',
117
- auth: WingsAdapter.authFromCredentials(authInfo.credential),
118
- params: {
119
- FOLIO_NO: folioNumber,
120
- },
186
+ });
187
+ };
188
+ this.checkInReservation = function (_a) {
189
+ var accommodationId = _a.accommodationId, reservationNumber = _a.reservationNumber, sequenceNumber = _a.sequenceNumber, startDate = _a.startDate, endDate = _a.endDate;
190
+ return __awaiter(_this, void 0, void 0, function () {
191
+ var authInfo, response, resultData, err_2;
192
+ return __generator(this, function (_b) {
193
+ switch (_b.label) {
194
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
195
+ case 1:
196
+ authInfo = _b.sent();
197
+ _b.label = 2;
198
+ case 2:
199
+ _b.trys.push([2, 4, , 5]);
200
+ return [4 /*yield*/, apiController.callWingsApi({
201
+ route: 'ki01/kioskCheckIn',
202
+ auth: WingsAdapter.authFromCredentials(authInfo.credential),
203
+ params: {
204
+ RSVN_NO: reservationNumber,
205
+ RSVN_SEQ_NO: sequenceNumber,
206
+ ARRV_DATE: startDate,
207
+ DEPT_DATE: endDate,
208
+ BSNS_CODE: authInfo.credential.BSNS_CODE,
209
+ },
210
+ })];
211
+ case 3:
212
+ response = _b.sent();
213
+ resultData = response.resultData;
214
+ if (!resultData) {
215
+ throw new Error('FAILED_TO_CHECKIN');
216
+ }
217
+ return [2 /*return*/, resultData];
218
+ case 4:
219
+ err_2 = _b.sent();
220
+ console.log(err_2);
221
+ throw err_2;
222
+ case 5: return [2 /*return*/];
223
+ }
121
224
  });
122
- const { resultData: { RESULT_YN, RESULT_MSG } } = response;
123
- if (RESULT_YN !== 'Y') {
124
- throw new Error(RESULT_MSG || 'DATA_NOT_FOUND');
125
- }
126
- return true;
127
- }
128
- catch (err) {
129
- console.log(err);
130
- throw err;
131
- }
132
- });
133
- this.getReservationByNumber = ({ accommodationId, reservationNumber }) => __awaiter(this, void 0, void 0, function* () {
134
- const authInfo = yield this.getAccommodationAuthInfo({ accommodationId });
135
- try {
136
- const response = yield apiController.callWingsApi({
137
- route: 'ki01/kioskRsvnInfo',
138
- auth: WingsAdapter.authFromCredentials(authInfo.credential),
139
- params: {
140
- RSVN_NO: reservationNumber,
141
- },
225
+ });
226
+ };
227
+ this.cancelCheckInReservation = function (_a) {
228
+ var accommodationId = _a.accommodationId, folioNumber = _a.folioNumber;
229
+ return __awaiter(_this, void 0, void 0, function () {
230
+ var authInfo, response, _b, RESULT_YN, RESULT_MSG, err_3;
231
+ return __generator(this, function (_c) {
232
+ switch (_c.label) {
233
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
234
+ case 1:
235
+ authInfo = _c.sent();
236
+ _c.label = 2;
237
+ case 2:
238
+ _c.trys.push([2, 4, , 5]);
239
+ return [4 /*yield*/, apiController.callWingsApi({
240
+ route: 'ki00/kioskCancel',
241
+ auth: WingsAdapter.authFromCredentials(authInfo.credential),
242
+ params: {
243
+ FOLIO_NO: folioNumber,
244
+ },
245
+ })];
246
+ case 3:
247
+ response = _c.sent();
248
+ _b = response.resultData, RESULT_YN = _b.RESULT_YN, RESULT_MSG = _b.RESULT_MSG;
249
+ if (RESULT_YN !== 'Y') {
250
+ throw new Error(RESULT_MSG || 'DATA_NOT_FOUND');
251
+ }
252
+ return [2 /*return*/, true];
253
+ case 4:
254
+ err_3 = _c.sent();
255
+ console.log(err_3);
256
+ throw err_3;
257
+ case 5: return [2 /*return*/];
258
+ }
142
259
  });
143
- const { resultData: { rsvnInfo } } = response;
144
- if (!rsvnInfo) {
145
- throw new Error('Data not found');
146
- }
147
- return rsvnInfo;
148
- }
149
- catch (err) {
150
- console.log(err);
151
- return null;
152
- }
153
- });
154
- this.getPurchaseAmount = ({ accommodationId, folioNumber }) => __awaiter(this, void 0, void 0, function* () {
155
- const authInfo = yield this.getAccommodationAuthInfo({ accommodationId });
156
- try {
157
- const response = yield apiController.callWingsApi({
158
- route: 'ki01/searchPaymentAmount',
159
- auth: WingsAdapter.authFromCredentials(authInfo.credential),
160
- params: {
161
- FOLIO_NO: folioNumber,
162
- },
260
+ });
261
+ };
262
+ this.getReservationByNumber = function (_a) {
263
+ var accommodationId = _a.accommodationId, reservationNumber = _a.reservationNumber;
264
+ return __awaiter(_this, void 0, void 0, function () {
265
+ var authInfo, response, rsvnInfo, err_4;
266
+ return __generator(this, function (_b) {
267
+ switch (_b.label) {
268
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
269
+ case 1:
270
+ authInfo = _b.sent();
271
+ _b.label = 2;
272
+ case 2:
273
+ _b.trys.push([2, 4, , 5]);
274
+ return [4 /*yield*/, apiController.callWingsApi({
275
+ route: 'ki01/kioskRsvnInfo',
276
+ auth: WingsAdapter.authFromCredentials(authInfo.credential),
277
+ params: {
278
+ RSVN_NO: reservationNumber,
279
+ },
280
+ })];
281
+ case 3:
282
+ response = _b.sent();
283
+ rsvnInfo = response.resultData.rsvnInfo;
284
+ if (!rsvnInfo) {
285
+ throw new Error('Data not found');
286
+ }
287
+ return [2 /*return*/, rsvnInfo];
288
+ case 4:
289
+ err_4 = _b.sent();
290
+ console.log(err_4);
291
+ return [2 /*return*/, null];
292
+ case 5: return [2 /*return*/];
293
+ }
163
294
  });
164
- }
165
- catch (err) {
166
- console.log(err);
167
- return null;
168
- }
169
- });
170
- this.getWalkinInfo = ({ accommodationId, startDate, endDate, adultCount, childCount, langType, }) => __awaiter(this, void 0, void 0, function* () {
171
- const authInfo = yield this.getAccommodationAuthInfo({ accommodationId });
172
- try {
173
- const response = yield apiController.callWingsApi({
174
- route: 'ki02/kioskWalkInInfo',
175
- auth: WingsAdapter.authFromCredentials(authInfo.credential),
176
- params: {
177
- ARRV_DATE: moment(startDate).format('YYYYMMDD'),
178
- DEPT_DATE: moment(endDate).format('YYYYMMDD'),
179
- ADULT_CNT: adultCount,
180
- CHILD_CNT: childCount,
181
- LANG_TYPE: langType,
182
- },
295
+ });
296
+ };
297
+ this.getPurchaseAmount = function (_a) {
298
+ var accommodationId = _a.accommodationId, folioNumber = _a.folioNumber;
299
+ return __awaiter(_this, void 0, void 0, function () {
300
+ var authInfo, response, err_5;
301
+ return __generator(this, function (_b) {
302
+ switch (_b.label) {
303
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
304
+ case 1:
305
+ authInfo = _b.sent();
306
+ _b.label = 2;
307
+ case 2:
308
+ _b.trys.push([2, 4, , 5]);
309
+ return [4 /*yield*/, apiController.callWingsApi({
310
+ route: 'ki01/searchPaymentAmount',
311
+ auth: WingsAdapter.authFromCredentials(authInfo.credential),
312
+ params: {
313
+ FOLIO_NO: folioNumber,
314
+ },
315
+ })];
316
+ case 3:
317
+ response = _b.sent();
318
+ return [3 /*break*/, 5];
319
+ case 4:
320
+ err_5 = _b.sent();
321
+ console.log(err_5);
322
+ return [2 /*return*/, null];
323
+ case 5: return [2 /*return*/];
324
+ }
183
325
  });
184
- const { resultData: { walkinInfo, roomInfo } } = response;
185
- return {
186
- walkinInfo,
187
- roomInfo,
188
- };
189
- }
190
- catch (err) {
191
- console.log(err);
192
- return null;
193
- }
194
- });
195
- this.getWalkInRoomRate = ({ accommodationId, roomTypeCode, startDate, endDate, salesDate, }) => __awaiter(this, void 0, void 0, function* () {
196
- const authInfo = yield this.getAccommodationAuthInfo({ accommodationId });
197
- try {
198
- const response = yield apiController.callWingsApi({
199
- route: 'ki02/kioskWalkInRoomRate',
200
- auth: WingsAdapter.authFromCredentials(authInfo.credential),
201
- params: {
202
- ARRV_DATE: moment(startDate).format('YYYYMMDD'),
203
- DEPT_DATE: moment(endDate).format('YYYYMMDD'),
204
- ROOM_TYPE_CODE: roomTypeCode,
205
- SALES_DATE: moment(salesDate).format('YYYYMMDD'),
206
- BSNS_CODE: authInfo.credential.BSNS_CODE,
207
- },
326
+ });
327
+ };
328
+ this.getWalkinInfo = function (_a) {
329
+ var accommodationId = _a.accommodationId, startDate = _a.startDate, endDate = _a.endDate, adultCount = _a.adultCount, childCount = _a.childCount, langType = _a.langType;
330
+ return __awaiter(_this, void 0, void 0, function () {
331
+ var authInfo, response, _b, walkinInfo, roomInfo, err_6;
332
+ return __generator(this, function (_c) {
333
+ switch (_c.label) {
334
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
335
+ case 1:
336
+ authInfo = _c.sent();
337
+ _c.label = 2;
338
+ case 2:
339
+ _c.trys.push([2, 4, , 5]);
340
+ return [4 /*yield*/, apiController.callWingsApi({
341
+ route: 'ki02/kioskWalkInInfo',
342
+ auth: WingsAdapter.authFromCredentials(authInfo.credential),
343
+ params: {
344
+ ARRV_DATE: moment_1.default(startDate).format('YYYYMMDD'),
345
+ DEPT_DATE: moment_1.default(endDate).format('YYYYMMDD'),
346
+ ADULT_CNT: adultCount,
347
+ CHILD_CNT: childCount,
348
+ LANG_TYPE: langType,
349
+ },
350
+ })];
351
+ case 3:
352
+ response = _c.sent();
353
+ _b = response.resultData, walkinInfo = _b.walkinInfo, roomInfo = _b.roomInfo;
354
+ return [2 /*return*/, {
355
+ walkinInfo: walkinInfo,
356
+ roomInfo: roomInfo,
357
+ }];
358
+ case 4:
359
+ err_6 = _c.sent();
360
+ console.log(err_6);
361
+ return [2 /*return*/, null];
362
+ case 5: return [2 /*return*/];
363
+ }
208
364
  });
209
- const { resultData } = response;
210
- return resultData;
211
- }
212
- catch (err) {
213
- console.log(err);
214
- return null;
215
- }
216
- });
217
- this.queryWalkinRoomTypesWithPrices = ({ accommodationId, startDate, endDate, adultCount, childCount, langType, }) => __awaiter(this, void 0, void 0, function* () {
218
- const authInfo = yield this.getAccommodationAuthInfo({ accommodationId });
219
- try {
220
- const response = yield apiController.callWingsApi({
221
- route: 'ki02/kioskWalkInInfo',
222
- auth: WingsAdapter.authFromCredentials(authInfo.credential),
223
- params: {
224
- ARRV_DATE: moment(startDate).format('YYYYMMDD'),
225
- DEPT_DATE: moment(endDate).format('YYYYMMDD'),
226
- ADULT_CNT: adultCount,
227
- CHILD_CNT: childCount,
228
- LANG_TYPE: langType,
229
- },
365
+ });
366
+ };
367
+ this.getWalkInRoomRate = function (_a) {
368
+ var accommodationId = _a.accommodationId, roomTypeCode = _a.roomTypeCode, startDate = _a.startDate, endDate = _a.endDate, salesDate = _a.salesDate;
369
+ return __awaiter(_this, void 0, void 0, function () {
370
+ var authInfo, response, resultData, err_7;
371
+ return __generator(this, function (_b) {
372
+ switch (_b.label) {
373
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
374
+ case 1:
375
+ authInfo = _b.sent();
376
+ _b.label = 2;
377
+ case 2:
378
+ _b.trys.push([2, 4, , 5]);
379
+ return [4 /*yield*/, apiController.callWingsApi({
380
+ route: 'ki02/kioskWalkInRoomRate',
381
+ auth: WingsAdapter.authFromCredentials(authInfo.credential),
382
+ params: {
383
+ ARRV_DATE: moment_1.default(startDate).format('YYYYMMDD'),
384
+ DEPT_DATE: moment_1.default(endDate).format('YYYYMMDD'),
385
+ ROOM_TYPE_CODE: roomTypeCode,
386
+ SALES_DATE: moment_1.default(salesDate).format('YYYYMMDD'),
387
+ BSNS_CODE: authInfo.credential.BSNS_CODE,
388
+ },
389
+ })];
390
+ case 3:
391
+ response = _b.sent();
392
+ resultData = response.resultData;
393
+ return [2 /*return*/, resultData];
394
+ case 4:
395
+ err_7 = _b.sent();
396
+ console.log(err_7);
397
+ return [2 /*return*/, null];
398
+ case 5: return [2 /*return*/];
399
+ }
230
400
  });
231
- const { resultData: { walkinInfo, roomInfo } } = response;
232
- const roomInfoWithPrices = yield Promise.all(roomInfo.map((roomType) => __awaiter(this, void 0, void 0, function* () {
233
- const { ROOM_TYPE_CODE } = roomType;
234
- const priceData = yield this.getWalkInRoomRate({
235
- accommodationId,
236
- endDate,
237
- startDate,
238
- salesDate: startDate,
239
- roomTypeCode: ROOM_TYPE_CODE,
240
- });
241
- priceData.rawData = JSON.stringify(priceData);
242
- priceData.dailyPrices = priceData.walkinRoomDaily.map((dailyPrice) => ({
243
- rawData: JSON.stringify(dailyPrice),
244
- amount: dailyPrice.ROOM_FEE,
245
- date: dailyPrice.LODG_DATE,
246
- }));
247
- delete priceData.walkinRoomDaily;
248
- return Object.assign(Object.assign({}, roomType), { price: priceData });
249
- })));
250
- return {
251
- walkinInfo,
252
- roomInfo: roomInfoWithPrices,
253
- };
254
- }
255
- catch (err) {
256
- console.log(err);
257
- return null;
258
- }
259
- });
260
- this.processWalkIn = ({ accommodationId, roomTypeCode, startDate, endDate, nights, salesDate, guestName, adultCount, childCount, dailyRoomFees, }) => __awaiter(this, void 0, void 0, function* () {
261
- const authInfo = yield this.getAccommodationAuthInfo({ accommodationId });
262
- try {
263
- const response = yield apiController.callWingsApi({
264
- route: 'ki02/walkinProcess',
265
- auth: WingsAdapter.authFromCredentials(authInfo.credential),
266
- params: {
267
- walkinInfo: {
268
- ARRV_DATE: startDate,
269
- DEPT_DATE: endDate,
270
- NIGHTS: nights,
271
- ROOM_TYPE_CODE: roomTypeCode,
272
- SALES_DATE: salesDate,
273
- ADULT_CNT: adultCount,
274
- CHILD_CNT: childCount,
275
- INHS_GEST_NAME: guestName,
276
- BSNS_CODE: authInfo.credential.BSNS_CODE,
277
- },
278
- walkinRoomDaily: dailyRoomFees === null || dailyRoomFees === void 0 ? void 0 : dailyRoomFees.map(value => JSON.parse(value)),
279
- },
401
+ });
402
+ };
403
+ this.queryWalkinRoomTypesWithPrices = function (_a) {
404
+ var accommodationId = _a.accommodationId, startDate = _a.startDate, endDate = _a.endDate, adultCount = _a.adultCount, childCount = _a.childCount, langType = _a.langType;
405
+ return __awaiter(_this, void 0, void 0, function () {
406
+ var authInfo, response, _b, walkinInfo, roomInfo, roomInfoWithPrices, err_8;
407
+ var _this = this;
408
+ return __generator(this, function (_c) {
409
+ switch (_c.label) {
410
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
411
+ case 1:
412
+ authInfo = _c.sent();
413
+ _c.label = 2;
414
+ case 2:
415
+ _c.trys.push([2, 5, , 6]);
416
+ return [4 /*yield*/, apiController.callWingsApi({
417
+ route: 'ki02/kioskWalkInInfo',
418
+ auth: WingsAdapter.authFromCredentials(authInfo.credential),
419
+ params: {
420
+ ARRV_DATE: moment_1.default(startDate).format('YYYYMMDD'),
421
+ DEPT_DATE: moment_1.default(endDate).format('YYYYMMDD'),
422
+ ADULT_CNT: adultCount,
423
+ CHILD_CNT: childCount,
424
+ LANG_TYPE: langType,
425
+ },
426
+ })];
427
+ case 3:
428
+ response = _c.sent();
429
+ _b = response.resultData, walkinInfo = _b.walkinInfo, roomInfo = _b.roomInfo;
430
+ return [4 /*yield*/, Promise.all(roomInfo.map(function (roomType) { return __awaiter(_this, void 0, void 0, function () {
431
+ var ROOM_TYPE_CODE, priceData;
432
+ return __generator(this, function (_a) {
433
+ switch (_a.label) {
434
+ case 0:
435
+ ROOM_TYPE_CODE = roomType.ROOM_TYPE_CODE;
436
+ return [4 /*yield*/, this.getWalkInRoomRate({
437
+ accommodationId: accommodationId,
438
+ endDate: endDate,
439
+ startDate: startDate,
440
+ salesDate: startDate,
441
+ roomTypeCode: ROOM_TYPE_CODE,
442
+ })];
443
+ case 1:
444
+ priceData = _a.sent();
445
+ priceData.rawData = JSON.stringify(priceData);
446
+ priceData.dailyPrices = priceData.walkinRoomDaily.map(function (dailyPrice) { return ({
447
+ rawData: JSON.stringify(dailyPrice),
448
+ amount: dailyPrice.ROOM_FEE,
449
+ date: dailyPrice.LODG_DATE,
450
+ }); });
451
+ delete priceData.walkinRoomDaily;
452
+ return [2 /*return*/, __assign(__assign({}, roomType), { price: priceData })];
453
+ }
454
+ });
455
+ }); }))];
456
+ case 4:
457
+ roomInfoWithPrices = _c.sent();
458
+ return [2 /*return*/, {
459
+ walkinInfo: walkinInfo,
460
+ roomInfo: roomInfoWithPrices,
461
+ }];
462
+ case 5:
463
+ err_8 = _c.sent();
464
+ console.log(err_8);
465
+ return [2 /*return*/, null];
466
+ case 6: return [2 /*return*/];
467
+ }
280
468
  });
281
- const { resultData } = response;
282
- return resultData;
283
- }
284
- catch (err) {
285
- console.log(err);
286
- return null;
287
- }
288
- });
289
- this.getCheckOutInfo = ({ accommodationId, folioNumber, }) => __awaiter(this, void 0, void 0, function* () {
290
- const authInfo = yield this.getAccommodationAuthInfo({ accommodationId });
291
- try {
292
- const response = yield apiController.callWingsApi({
293
- route: 'ki03/kioskCheckOutInfo',
294
- auth: WingsAdapter.authFromCredentials(authInfo.credential),
295
- params: {
296
- FOLIO_NO: folioNumber,
297
- },
469
+ });
470
+ };
471
+ this.processWalkIn = function (_a) {
472
+ var accommodationId = _a.accommodationId, roomTypeCode = _a.roomTypeCode, startDate = _a.startDate, endDate = _a.endDate, nights = _a.nights, salesDate = _a.salesDate, guestName = _a.guestName, adultCount = _a.adultCount, childCount = _a.childCount, dailyRoomFees = _a.dailyRoomFees;
473
+ return __awaiter(_this, void 0, void 0, function () {
474
+ var authInfo, response, resultData, err_9;
475
+ return __generator(this, function (_b) {
476
+ switch (_b.label) {
477
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
478
+ case 1:
479
+ authInfo = _b.sent();
480
+ _b.label = 2;
481
+ case 2:
482
+ _b.trys.push([2, 4, , 5]);
483
+ return [4 /*yield*/, apiController.callWingsApi({
484
+ route: 'ki02/walkinProcess',
485
+ auth: WingsAdapter.authFromCredentials(authInfo.credential),
486
+ params: {
487
+ walkinInfo: {
488
+ ARRV_DATE: startDate,
489
+ DEPT_DATE: endDate,
490
+ NIGHTS: nights,
491
+ ROOM_TYPE_CODE: roomTypeCode,
492
+ SALES_DATE: salesDate,
493
+ ADULT_CNT: adultCount,
494
+ CHILD_CNT: childCount,
495
+ INHS_GEST_NAME: guestName,
496
+ BSNS_CODE: authInfo.credential.BSNS_CODE,
497
+ },
498
+ walkinRoomDaily: dailyRoomFees === null || dailyRoomFees === void 0 ? void 0 : dailyRoomFees.map(function (value) { return JSON.parse(value); }),
499
+ },
500
+ })];
501
+ case 3:
502
+ response = _b.sent();
503
+ resultData = response.resultData;
504
+ return [2 /*return*/, resultData];
505
+ case 4:
506
+ err_9 = _b.sent();
507
+ console.log(err_9);
508
+ return [2 /*return*/, null];
509
+ case 5: return [2 /*return*/];
510
+ }
298
511
  });
299
- const { resultData } = response;
300
- return resultData;
301
- }
302
- catch (err) {
303
- console.log(err);
304
- return null;
305
- }
306
- });
307
- this.processCheckOut = ({ accommodationId, folioNumber, }) => __awaiter(this, void 0, void 0, function* () {
308
- const authInfo = yield this.getAccommodationAuthInfo({ accommodationId });
309
- try {
310
- const response = yield apiController.callWingsApi({
311
- route: 'ki03/kioskCheckOutProcess',
312
- auth: WingsAdapter.authFromCredentials(authInfo.credential),
313
- params: {
314
- BSNS_CODE: authInfo.credential.BSNS_CODE,
315
- FOLIO_NO: folioNumber,
316
- },
512
+ });
513
+ };
514
+ this.getCheckOutInfo = function (_a) {
515
+ var accommodationId = _a.accommodationId, folioNumber = _a.folioNumber;
516
+ return __awaiter(_this, void 0, void 0, function () {
517
+ var authInfo, response, resultData, err_10;
518
+ return __generator(this, function (_b) {
519
+ switch (_b.label) {
520
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
521
+ case 1:
522
+ authInfo = _b.sent();
523
+ _b.label = 2;
524
+ case 2:
525
+ _b.trys.push([2, 4, , 5]);
526
+ return [4 /*yield*/, apiController.callWingsApi({
527
+ route: 'ki03/kioskCheckOutInfo',
528
+ auth: WingsAdapter.authFromCredentials(authInfo.credential),
529
+ params: {
530
+ FOLIO_NO: folioNumber,
531
+ },
532
+ })];
533
+ case 3:
534
+ response = _b.sent();
535
+ resultData = response.resultData;
536
+ return [2 /*return*/, resultData];
537
+ case 4:
538
+ err_10 = _b.sent();
539
+ console.log(err_10);
540
+ return [2 /*return*/, null];
541
+ case 5: return [2 /*return*/];
542
+ }
317
543
  });
318
- const { resultData } = response;
319
- return resultData;
320
- }
321
- catch (err) {
322
- console.log(err);
323
- return null;
324
- }
325
- });
326
- this.reportKeyIssue = ({ accommodationId, folioNumber, roomNumber, registerDate, issuedCount, resultMessage, }) => __awaiter(this, void 0, void 0, function* () {
327
- const authInfo = yield this.getAccommodationAuthInfo({ accommodationId });
328
- try {
329
- const response = yield apiController.callWingsApi({
330
- route: 'ki01/kioskRoomKeyIssue',
331
- auth: WingsAdapter.authFromCredentials(authInfo.credential),
332
- params: {
333
- FOLIO_NO: folioNumber,
334
- ROOM_NO: roomNumber,
335
- REG_DATE: registerDate,
336
- REG_TIME: moment().format('HHmmSS'),
337
- ISSUE_CNT: issuedCount,
338
- RESULT_MSG: resultMessage,
339
- },
544
+ });
545
+ };
546
+ this.processCheckOut = function (_a) {
547
+ var accommodationId = _a.accommodationId, folioNumber = _a.folioNumber;
548
+ return __awaiter(_this, void 0, void 0, function () {
549
+ var authInfo, response, resultData, err_11;
550
+ return __generator(this, function (_b) {
551
+ switch (_b.label) {
552
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
553
+ case 1:
554
+ authInfo = _b.sent();
555
+ _b.label = 2;
556
+ case 2:
557
+ _b.trys.push([2, 4, , 5]);
558
+ return [4 /*yield*/, apiController.callWingsApi({
559
+ route: 'ki03/kioskCheckOutProcess',
560
+ auth: WingsAdapter.authFromCredentials(authInfo.credential),
561
+ params: {
562
+ BSNS_CODE: authInfo.credential.BSNS_CODE,
563
+ FOLIO_NO: folioNumber,
564
+ },
565
+ })];
566
+ case 3:
567
+ response = _b.sent();
568
+ resultData = response.resultData;
569
+ return [2 /*return*/, resultData];
570
+ case 4:
571
+ err_11 = _b.sent();
572
+ console.log(err_11);
573
+ return [2 /*return*/, null];
574
+ case 5: return [2 /*return*/];
575
+ }
340
576
  });
341
- const { resultData } = response;
342
- if (!resultData) {
343
- throw new Error('Data not found');
344
- }
345
- return resultData;
346
- }
347
- catch (err) {
348
- console.log(err);
349
- return null;
350
- }
351
- });
352
- this.reportKeyRetrieve = ({ accommodationId, folioNumber, }) => __awaiter(this, void 0, void 0, function* () {
353
- const authInfo = yield this.getAccommodationAuthInfo({ accommodationId });
354
- try {
355
- const response = yield apiController.callWingsApi({
356
- route: 'ki03/kioskCheckOutRoomKey',
357
- auth: WingsAdapter.authFromCredentials(authInfo.credential),
358
- params: {
359
- FOLIO_NO: folioNumber,
360
- BSNS_CODE: authInfo.credential.BSNS_CODE,
361
- ROOM_KEY_CHECK_YN: 'Y',
362
- RETURN_KEY_CNT: 1,
363
- },
577
+ });
578
+ };
579
+ this.reportKeyIssue = function (_a) {
580
+ var accommodationId = _a.accommodationId, folioNumber = _a.folioNumber, roomNumber = _a.roomNumber, registerDate = _a.registerDate, issuedCount = _a.issuedCount, resultMessage = _a.resultMessage;
581
+ return __awaiter(_this, void 0, void 0, function () {
582
+ var authInfo, response, resultData, err_12;
583
+ return __generator(this, function (_b) {
584
+ switch (_b.label) {
585
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
586
+ case 1:
587
+ authInfo = _b.sent();
588
+ _b.label = 2;
589
+ case 2:
590
+ _b.trys.push([2, 4, , 5]);
591
+ return [4 /*yield*/, apiController.callWingsApi({
592
+ route: 'ki01/kioskRoomKeyIssue',
593
+ auth: WingsAdapter.authFromCredentials(authInfo.credential),
594
+ params: {
595
+ FOLIO_NO: folioNumber,
596
+ ROOM_NO: roomNumber,
597
+ REG_DATE: registerDate,
598
+ REG_TIME: moment_1.default().format('HHmmSS'),
599
+ ISSUE_CNT: issuedCount,
600
+ RESULT_MSG: resultMessage,
601
+ },
602
+ })];
603
+ case 3:
604
+ response = _b.sent();
605
+ resultData = response.resultData;
606
+ if (!resultData) {
607
+ throw new Error('Data not found');
608
+ }
609
+ return [2 /*return*/, resultData];
610
+ case 4:
611
+ err_12 = _b.sent();
612
+ console.log(err_12);
613
+ return [2 /*return*/, null];
614
+ case 5: return [2 /*return*/];
615
+ }
364
616
  });
365
- const { resultData } = response;
366
- if (!resultData) {
367
- throw new Error('Data not found');
368
- }
369
- return resultData;
370
- }
371
- catch (err) {
372
- console.log(err);
373
- return null;
374
- }
375
- });
376
- this.savePayment = ({ accommodationId, folioNumber, paymentAmount, saleDate, paymentInfo, }) => __awaiter(this, void 0, void 0, function* () {
377
- const authInfo = yield this.getAccommodationAuthInfo({ accommodationId });
378
- const parsedData = JSON.parse(paymentInfo);
379
- let refinedData;
380
- switch (parsedData.vanType) {
381
- case ('KSNET'): {
382
- refinedData = {
383
- // KSNET data
384
- APPR_TYPE_CODE: parsedData.APPR_TYPE_CODE || '11',
385
- COMT: parsedData.NOTICE2.trim(),
386
- PUR_CPNY_NAME: parsedData.PURCHASENAME.trim(),
387
- PUR_CPNY_CODE: parsedData.PURCHASECODE.trim(),
388
- ISSUE_CPMY_NAME: parsedData.MESSAGE1.trim(),
389
- ISSUE_CPMY_CODE: parsedData.ISSUERCODE.trim(),
390
- FRNC_STORE_NO: parsedData.MERCHANTNUMBER.trim(),
391
- CRDT_CARD_NO: parsedData.FILLER.trim(),
392
- RSPNS_CODE: parsedData.CORPRESPCODE.trim(),
393
- TERM_NO: parsedData.TERMID.trim(),
394
- APPR_NO: parsedData.APPROVALNO.trim(),
395
- APPR_DATE: `20${parsedData.TRADETIME.slice(0, 6)}`,
396
- APPR_TIME: parsedData.TRADETIME.slice(6, 10),
397
- CNFM_DATE: `20${parsedData.TRADETIME.slice(0, 6)}`,
398
- CNFM_TYPE: parsedData.TRADETIME.slice(6, 10),
399
- // Generated data
400
- INSTA_MMS_CNT: parsedData.INSTA_MMS_CNT || '00',
401
- APPR_LINE_TYPE_CODE: parsedData.APPR_LINE_TYPE_CODE || 'A',
402
- KEY_IN_TYPE_CODE: parsedData.KEY_IN_TYPE_CODE || 'S',
403
- SPC_UNIQUE_ALIAS: parsedData.SPC_UNIQUE_ALIAS || 'SEND_GB_APP',
404
- CARD_READING_DATA: parsedData.CARD_READING_DATA || '0000000000000000:00000000000000000000',
405
- SPC_TYPE_CODE: parsedData.SPC_TYPE_CODE,
406
- };
407
- break;
408
- }
409
- case ('CASH'): {
410
- refinedData = {
411
- CRDT_CARD_NO: 'KICASH',
412
- COMT: 'KISOK_CASH_PURCHASE',
413
- };
414
- break;
415
- }
416
- default: {
417
- throw new Error('NOT_REGISTERED_VAN');
418
- }
419
- }
420
- try {
421
- const response = yield apiController.callWingsApi({
422
- route: 'ki00/payment',
423
- auth: WingsAdapter.authFromCredentials(authInfo.credential),
424
- params: {
425
- FOLIO_NO: folioNumber,
426
- PAY_AMT: paymentAmount,
427
- SALE_DATE: saleDate,
428
- CREDIT_RESULT: Object.assign({ APPR_AMT: paymentAmount, FOLIO_NO: folioNumber }, refinedData),
429
- BSNS_CODE: authInfo.credential.BSNS_CODE,
430
- },
617
+ });
618
+ };
619
+ this.reportKeyRetrieve = function (_a) {
620
+ var accommodationId = _a.accommodationId, folioNumber = _a.folioNumber;
621
+ return __awaiter(_this, void 0, void 0, function () {
622
+ var authInfo, response, resultData, err_13;
623
+ return __generator(this, function (_b) {
624
+ switch (_b.label) {
625
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
626
+ case 1:
627
+ authInfo = _b.sent();
628
+ _b.label = 2;
629
+ case 2:
630
+ _b.trys.push([2, 4, , 5]);
631
+ return [4 /*yield*/, apiController.callWingsApi({
632
+ route: 'ki03/kioskCheckOutRoomKey',
633
+ auth: WingsAdapter.authFromCredentials(authInfo.credential),
634
+ params: {
635
+ FOLIO_NO: folioNumber,
636
+ BSNS_CODE: authInfo.credential.BSNS_CODE,
637
+ ROOM_KEY_CHECK_YN: 'Y',
638
+ RETURN_KEY_CNT: 1,
639
+ },
640
+ })];
641
+ case 3:
642
+ response = _b.sent();
643
+ resultData = response.resultData;
644
+ if (!resultData) {
645
+ throw new Error('Data not found');
646
+ }
647
+ return [2 /*return*/, resultData];
648
+ case 4:
649
+ err_13 = _b.sent();
650
+ console.log(err_13);
651
+ return [2 /*return*/, null];
652
+ case 5: return [2 /*return*/];
653
+ }
431
654
  });
432
- const { resultData } = response;
433
- console.log(response);
434
- console.log(resultData);
435
- return resultData;
436
- }
437
- catch (err) {
438
- console.log(err);
439
- return false;
440
- }
441
- });
442
- this.savePaymentWithPaymentId = ({ paymentId, folioNumber, }) => __awaiter(this, void 0, void 0, function* () {
443
- const foundPaymentInfo = yield this.redis.get(`SanhaWings|${paymentId}`);
444
- if (!foundPaymentInfo)
445
- return null;
446
- try {
447
- const parsedPayment = JSON.parse(foundPaymentInfo);
448
- yield this.savePayment({
449
- accommodationId: parsedPayment.accommodationId,
450
- folioNumber,
451
- paymentAmount: parsedPayment.amount.toString(),
452
- paymentInfo: parsedPayment.data,
453
- saleDate: moment(parsedPayment.createdAt).format('YYYYMMDD'),
655
+ });
656
+ };
657
+ this.savePayment = function (_a) {
658
+ var accommodationId = _a.accommodationId, folioNumber = _a.folioNumber, paymentAmount = _a.paymentAmount, saleDate = _a.saleDate, paymentInfo = _a.paymentInfo;
659
+ return __awaiter(_this, void 0, void 0, function () {
660
+ var authInfo, parsedData, refinedData, response, resultData, err_14;
661
+ return __generator(this, function (_b) {
662
+ switch (_b.label) {
663
+ case 0: return [4 /*yield*/, this.getAccommodationAuthInfo({ accommodationId: accommodationId })];
664
+ case 1:
665
+ authInfo = _b.sent();
666
+ parsedData = JSON.parse(paymentInfo);
667
+ switch (parsedData.vanType) {
668
+ case ('KSNET'): {
669
+ refinedData = {
670
+ // KSNET data
671
+ APPR_TYPE_CODE: parsedData.APPR_TYPE_CODE || '11',
672
+ COMT: parsedData.NOTICE2.trim(),
673
+ PUR_CPNY_NAME: parsedData.PURCHASENAME.trim(),
674
+ PUR_CPNY_CODE: parsedData.PURCHASECODE.trim(),
675
+ ISSUE_CPMY_NAME: parsedData.MESSAGE1.trim(),
676
+ ISSUE_CPMY_CODE: parsedData.ISSUERCODE.trim(),
677
+ FRNC_STORE_NO: parsedData.MERCHANTNUMBER.trim(),
678
+ CRDT_CARD_NO: parsedData.FILLER.trim(),
679
+ RSPNS_CODE: parsedData.CORPRESPCODE.trim(),
680
+ TERM_NO: parsedData.TERMID.trim(),
681
+ APPR_NO: parsedData.APPROVALNO.trim(),
682
+ APPR_DATE: "20" + parsedData.TRADETIME.slice(0, 6),
683
+ APPR_TIME: parsedData.TRADETIME.slice(6, 10),
684
+ CNFM_DATE: "20" + parsedData.TRADETIME.slice(0, 6),
685
+ CNFM_TYPE: parsedData.TRADETIME.slice(6, 10),
686
+ // Generated data
687
+ INSTA_MMS_CNT: parsedData.INSTA_MMS_CNT || '00',
688
+ APPR_LINE_TYPE_CODE: parsedData.APPR_LINE_TYPE_CODE || 'A',
689
+ KEY_IN_TYPE_CODE: parsedData.KEY_IN_TYPE_CODE || 'S',
690
+ SPC_UNIQUE_ALIAS: parsedData.SPC_UNIQUE_ALIAS || 'SEND_GB_APP',
691
+ CARD_READING_DATA: parsedData.CARD_READING_DATA || '0000000000000000:00000000000000000000',
692
+ SPC_TYPE_CODE: parsedData.SPC_TYPE_CODE,
693
+ };
694
+ break;
695
+ }
696
+ case ('CASH'): {
697
+ refinedData = {
698
+ CRDT_CARD_NO: 'KICASH',
699
+ COMT: 'KISOK_CASH_PURCHASE',
700
+ };
701
+ break;
702
+ }
703
+ default: {
704
+ throw new Error('NOT_REGISTERED_VAN');
705
+ }
706
+ }
707
+ _b.label = 2;
708
+ case 2:
709
+ _b.trys.push([2, 4, , 5]);
710
+ return [4 /*yield*/, apiController.callWingsApi({
711
+ route: 'ki00/payment',
712
+ auth: WingsAdapter.authFromCredentials(authInfo.credential),
713
+ params: {
714
+ FOLIO_NO: folioNumber,
715
+ PAY_AMT: paymentAmount,
716
+ SALE_DATE: saleDate,
717
+ CREDIT_RESULT: __assign({ APPR_AMT: paymentAmount, FOLIO_NO: folioNumber }, refinedData),
718
+ BSNS_CODE: authInfo.credential.BSNS_CODE,
719
+ },
720
+ })];
721
+ case 3:
722
+ response = _b.sent();
723
+ resultData = response.resultData;
724
+ console.log(response);
725
+ console.log(resultData);
726
+ return [2 /*return*/, resultData];
727
+ case 4:
728
+ err_14 = _b.sent();
729
+ console.log(err_14);
730
+ return [2 /*return*/, false];
731
+ case 5: return [2 /*return*/];
732
+ }
454
733
  });
455
- }
456
- catch (err) {
457
- console.log(err);
458
- throw new Error('FAILED_TO_SAVE_PAYMENT');
459
- }
460
- });
734
+ });
735
+ };
736
+ this.savePaymentWithPaymentId = function (_a) {
737
+ var paymentId = _a.paymentId, folioNumber = _a.folioNumber;
738
+ return __awaiter(_this, void 0, void 0, function () {
739
+ var foundPaymentInfo, parsedPayment, err_15;
740
+ return __generator(this, function (_b) {
741
+ switch (_b.label) {
742
+ case 0: return [4 /*yield*/, this.redis.get("SanhaWings|" + paymentId)];
743
+ case 1:
744
+ foundPaymentInfo = _b.sent();
745
+ if (!foundPaymentInfo)
746
+ return [2 /*return*/, null];
747
+ _b.label = 2;
748
+ case 2:
749
+ _b.trys.push([2, 4, , 5]);
750
+ parsedPayment = JSON.parse(foundPaymentInfo);
751
+ return [4 /*yield*/, this.savePayment({
752
+ accommodationId: parsedPayment.accommodationId,
753
+ folioNumber: folioNumber,
754
+ paymentAmount: parsedPayment.amount.toString(),
755
+ paymentInfo: parsedPayment.data,
756
+ saleDate: moment_1.default(parsedPayment.createdAt).format('YYYYMMDD'),
757
+ })];
758
+ case 3:
759
+ _b.sent();
760
+ return [3 /*break*/, 5];
761
+ case 4:
762
+ err_15 = _b.sent();
763
+ console.log(err_15);
764
+ throw new Error('FAILED_TO_SAVE_PAYMENT');
765
+ case 5: return [2 /*return*/];
766
+ }
767
+ });
768
+ });
769
+ };
461
770
  this.authenticator = authenticator;
462
771
  this.redis = redis;
463
- this.mutexLock = new MutexLock({ hashPrefix: 'RES_WINGS_MUTEX_', mutexLockInterval: 50, redis });
772
+ this.mutexLock = new mutex_1.default({ hashPrefix: 'RES_WINGS_MUTEX_', mutexLockInterval: 50, redis: redis });
464
773
  }
465
- }
466
- WingsAdapter.indexAccommodation = ({ accommodationId }) => `AUTH|WINGS-API|${accommodationId}`;
467
- WingsAdapter.authFromCredentials = ({ vendorId, companyId, apiKey, kioskIp, }) => ({
468
- headers: {
469
- 'API-KEY': apiKey,
470
- VENDOR_ID: vendorId,
471
- 'API-COMPANY': companyId,
472
- },
473
- params: {
474
- KIOSK_IP: kioskIp,
475
- },
476
- });
774
+ WingsAdapter.indexAccommodation = function (_a) {
775
+ var accommodationId = _a.accommodationId;
776
+ return "AUTH|WINGS-API|" + accommodationId;
777
+ };
778
+ WingsAdapter.authFromCredentials = function (_a) {
779
+ var vendorId = _a.vendorId, companyId = _a.companyId, apiKey = _a.apiKey, kioskIp = _a.kioskIp;
780
+ return ({
781
+ headers: {
782
+ 'API-KEY': apiKey,
783
+ VENDOR_ID: vendorId,
784
+ 'API-COMPANY': companyId,
785
+ },
786
+ params: {
787
+ KIOSK_IP: kioskIp,
788
+ },
789
+ });
790
+ };
791
+ return WingsAdapter;
792
+ }());
793
+ exports.default = WingsAdapter;