@vendit-dev/thirdparty-adapters 0.3.31 → 0.4.0-beta.2

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