playttm 0.0.6 → 0.0.8

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.
package/dist/lib.js CHANGED
@@ -177,45 +177,169 @@ class ThaiTicketMajor {
177
177
  /**
178
178
  * Setup declarativeNetRequest session rules in Chrome Extension to set Referer header for API requests only.
179
179
  */
180
+ /**
181
+ * Setup declarativeNetRequest session rules in Chrome Extension to set Referer headers accurately for each endpoint.
182
+ */
180
183
  static setupExtensionRules() {
181
184
  return __awaiter(this, void 0, void 0, function* () {
182
- var _a, _b, _c, _d, _e, _f, _g;
185
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3;
183
186
  if (typeof chrome === "undefined" || !((_a = chrome === null || chrome === void 0 ? void 0 : chrome.declarativeNetRequest) === null || _a === void 0 ? void 0 : _a.updateSessionRules)) {
184
187
  return;
185
188
  }
186
189
  try {
190
+ const ruleIdsToRemove = [1001, 1002, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019];
187
191
  yield chrome.declarativeNetRequest.updateSessionRules({
188
- removeRuleIds: [1001, 1002],
192
+ removeRuleIds: ruleIdsToRemove,
189
193
  addRules: [
190
194
  {
191
- id: 1001,
192
- priority: 1,
195
+ id: 1010,
196
+ priority: 20,
193
197
  action: {
194
198
  type: ((_b = chrome.declarativeNetRequest.RuleActionType) === null || _b === void 0 ? void 0 : _b.MODIFY_HEADERS) || "modifyHeaders",
195
199
  requestHeaders: [
196
200
  {
197
201
  header: "Referer",
198
202
  operation: ((_c = chrome.declarativeNetRequest.HeaderOperation) === null || _c === void 0 ? void 0 : _c.SET) || "set",
199
- value: "https://booking.thaiticketmajor.com",
203
+ value: "https://booking.thaiticketmajor.com/booking/3m/orderenc_kbankqr.php",
200
204
  },
201
205
  ],
202
206
  },
203
207
  condition: {
204
- urlFilter: "thaiticketmajor.com",
208
+ urlFilter: "getkbankqr.php",
205
209
  resourceTypes: [
206
210
  ((_d = chrome.declarativeNetRequest.ResourceType) === null || _d === void 0 ? void 0 : _d.XMLHTTPREQUEST) || "xmlhttprequest",
207
211
  ],
208
212
  },
209
213
  },
210
214
  {
211
- id: 1002,
212
- priority: 1,
215
+ id: 1011,
216
+ priority: 20,
213
217
  action: {
214
218
  type: ((_e = chrome.declarativeNetRequest.RuleActionType) === null || _e === void 0 ? void 0 : _e.MODIFY_HEADERS) || "modifyHeaders",
215
219
  requestHeaders: [
216
220
  {
217
221
  header: "Referer",
218
222
  operation: ((_f = chrome.declarativeNetRequest.HeaderOperation) === null || _f === void 0 ? void 0 : _f.SET) || "set",
223
+ value: "https://booking.thaiticketmajor.com/booking/3m/orderenc_kbankqr.php",
224
+ },
225
+ ],
226
+ },
227
+ condition: {
228
+ urlFilter: "payment_kbankqr.php",
229
+ resourceTypes: [
230
+ ((_g = chrome.declarativeNetRequest.ResourceType) === null || _g === void 0 ? void 0 : _g.XMLHTTPREQUEST) || "xmlhttprequest",
231
+ ],
232
+ },
233
+ },
234
+ {
235
+ id: 1012,
236
+ priority: 20,
237
+ action: {
238
+ type: ((_h = chrome.declarativeNetRequest.RuleActionType) === null || _h === void 0 ? void 0 : _h.MODIFY_HEADERS) || "modifyHeaders",
239
+ requestHeaders: [
240
+ {
241
+ header: "Referer",
242
+ operation: ((_j = chrome.declarativeNetRequest.HeaderOperation) === null || _j === void 0 ? void 0 : _j.SET) || "set",
243
+ value: "https://booking.thaiticketmajor.com/booking/3m/paycfmall.php",
244
+ },
245
+ ],
246
+ },
247
+ condition: {
248
+ urlFilter: "orderenc_kbankqr.php",
249
+ resourceTypes: [
250
+ ((_k = chrome.declarativeNetRequest.ResourceType) === null || _k === void 0 ? void 0 : _k.XMLHTTPREQUEST) || "xmlhttprequest",
251
+ ],
252
+ },
253
+ },
254
+ {
255
+ id: 1013,
256
+ priority: 20,
257
+ action: {
258
+ type: ((_l = chrome.declarativeNetRequest.RuleActionType) === null || _l === void 0 ? void 0 : _l.MODIFY_HEADERS) || "modifyHeaders",
259
+ requestHeaders: [
260
+ {
261
+ header: "Referer",
262
+ operation: ((_m = chrome.declarativeNetRequest.HeaderOperation) === null || _m === void 0 ? void 0 : _m.SET) || "set",
263
+ value: "https://booking.thaiticketmajor.com/booking/3m/paymentall.php",
264
+ },
265
+ ],
266
+ },
267
+ condition: {
268
+ urlFilter: "paycfmall.php",
269
+ resourceTypes: [
270
+ ((_o = chrome.declarativeNetRequest.ResourceType) === null || _o === void 0 ? void 0 : _o.XMLHTTPREQUEST) || "xmlhttprequest",
271
+ ],
272
+ },
273
+ },
274
+ {
275
+ id: 1014,
276
+ priority: 20,
277
+ action: {
278
+ type: ((_p = chrome.declarativeNetRequest.RuleActionType) === null || _p === void 0 ? void 0 : _p.MODIFY_HEADERS) || "modifyHeaders",
279
+ requestHeaders: [
280
+ {
281
+ header: "Referer",
282
+ operation: ((_q = chrome.declarativeNetRequest.HeaderOperation) === null || _q === void 0 ? void 0 : _q.SET) || "set",
283
+ value: "https://booking.thaiticketmajor.com/booking/3m/fixed.php",
284
+ },
285
+ ],
286
+ },
287
+ condition: {
288
+ urlFilter: "paymentall.php",
289
+ resourceTypes: [
290
+ ((_r = chrome.declarativeNetRequest.ResourceType) === null || _r === void 0 ? void 0 : _r.XMLHTTPREQUEST) || "xmlhttprequest",
291
+ ],
292
+ },
293
+ },
294
+ {
295
+ id: 1015,
296
+ priority: 20,
297
+ action: {
298
+ type: ((_s = chrome.declarativeNetRequest.RuleActionType) === null || _s === void 0 ? void 0 : _s.MODIFY_HEADERS) || "modifyHeaders",
299
+ requestHeaders: [
300
+ {
301
+ header: "Referer",
302
+ operation: ((_t = chrome.declarativeNetRequest.HeaderOperation) === null || _t === void 0 ? void 0 : _t.SET) || "set",
303
+ value: "https://booking.thaiticketmajor.com/booking/3m/fixed.php",
304
+ },
305
+ ],
306
+ },
307
+ condition: {
308
+ urlFilter: "enroll",
309
+ resourceTypes: [
310
+ ((_u = chrome.declarativeNetRequest.ResourceType) === null || _u === void 0 ? void 0 : _u.XMLHTTPREQUEST) || "xmlhttprequest",
311
+ ],
312
+ },
313
+ },
314
+ {
315
+ id: 1018,
316
+ priority: 20,
317
+ action: {
318
+ type: ((_v = chrome.declarativeNetRequest.RuleActionType) === null || _v === void 0 ? void 0 : _v.MODIFY_HEADERS) || "modifyHeaders",
319
+ requestHeaders: [
320
+ {
321
+ header: "Referer",
322
+ operation: ((_w = chrome.declarativeNetRequest.HeaderOperation) === null || _w === void 0 ? void 0 : _w.SET) || "set",
323
+ value: "https://booking.thaiticketmajor.com/booking/3m/zones.php",
324
+ },
325
+ ],
326
+ },
327
+ condition: {
328
+ urlFilter: "zonesavail.php",
329
+ resourceTypes: [
330
+ ((_x = chrome.declarativeNetRequest.ResourceType) === null || _x === void 0 ? void 0 : _x.XMLHTTPREQUEST) || "xmlhttprequest",
331
+ ],
332
+ },
333
+ },
334
+ {
335
+ id: 1002,
336
+ priority: 20,
337
+ action: {
338
+ type: ((_y = chrome.declarativeNetRequest.RuleActionType) === null || _y === void 0 ? void 0 : _y.MODIFY_HEADERS) || "modifyHeaders",
339
+ requestHeaders: [
340
+ {
341
+ header: "Referer",
342
+ operation: ((_z = chrome.declarativeNetRequest.HeaderOperation) === null || _z === void 0 ? void 0 : _z.SET) || "set",
219
343
  value: "https://kpaymentgateway.kasikornbank.com/",
220
344
  },
221
345
  ],
@@ -223,7 +347,27 @@ class ThaiTicketMajor {
223
347
  condition: {
224
348
  urlFilter: "kasikornbank.com",
225
349
  resourceTypes: [
226
- ((_g = chrome.declarativeNetRequest.ResourceType) === null || _g === void 0 ? void 0 : _g.XMLHTTPREQUEST) || "xmlhttprequest",
350
+ ((_0 = chrome.declarativeNetRequest.ResourceType) === null || _0 === void 0 ? void 0 : _0.XMLHTTPREQUEST) || "xmlhttprequest",
351
+ ],
352
+ },
353
+ },
354
+ {
355
+ id: 1001,
356
+ priority: 1,
357
+ action: {
358
+ type: ((_1 = chrome.declarativeNetRequest.RuleActionType) === null || _1 === void 0 ? void 0 : _1.MODIFY_HEADERS) || "modifyHeaders",
359
+ requestHeaders: [
360
+ {
361
+ header: "Referer",
362
+ operation: ((_2 = chrome.declarativeNetRequest.HeaderOperation) === null || _2 === void 0 ? void 0 : _2.SET) || "set",
363
+ value: "https://booking.thaiticketmajor.com/booking/3m/",
364
+ },
365
+ ],
366
+ },
367
+ condition: {
368
+ urlFilter: "thaiticketmajor.com",
369
+ resourceTypes: [
370
+ ((_3 = chrome.declarativeNetRequest.ResourceType) === null || _3 === void 0 ? void 0 : _3.XMLHTTPREQUEST) || "xmlhttprequest",
227
371
  ],
228
372
  },
229
373
  },
@@ -255,36 +399,57 @@ class ThaiTicketMajor {
255
399
  */
256
400
  getRounds(eventUrl) {
257
401
  return __awaiter(this, void 0, void 0, function* () {
258
- this.emitProgress("GET_ROUNDS", `Fetching rounds from ${eventUrl}`);
259
- const response = yield this.client.get(eventUrl, {
260
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: "https://www.thaiticketmajor.com/all-event/" }),
402
+ var _a, _b;
403
+ this.emitProgress("GET_ROUNDS", `Fetching rounds from ${eventUrl}`, {
404
+ url: eventUrl,
405
+ requestPayload: null,
261
406
  });
262
- const $ = cheerio.load(response.data);
263
- const rounds = [];
264
- $("a[data-button]").each((_, el) => {
265
- var _a, _b, _c, _d;
266
- const link = $(el);
267
- const href = (_a = link.attr("href")) !== null && _a !== void 0 ? _a : "";
268
- const onclick = (_b = link.attr("onclick")) !== null && _b !== void 0 ? _b : "";
269
- const dataUrl = (_c = link.attr("data-url")) !== null && _c !== void 0 ? _c : "";
270
- const dataHref = (_d = link.attr("data-href")) !== null && _d !== void 0 ? _d : "";
271
- const allLinkAttrs = `${href} ${onclick} ${dataUrl} ${dataHref}`;
272
- const queryMatch = allLinkAttrs.match(/query=([0-9a-zA-Z_-]+)/);
273
- const query = queryMatch ? queryMatch[1] : "";
274
- const time = link.find(".item-show").text().trim();
275
- const date = link.closest(".row").find(".date").text().trim();
276
- const isDisabled = link.is(":disabled") || link.attr("disabled") !== undefined || !query;
277
- rounds.push({
278
- id: query || link.attr("data-button") || "",
279
- label: `${date} ${time}`.trim(),
280
- date,
281
- time,
282
- url: href,
283
- query,
284
- isDisabled,
407
+ try {
408
+ const response = yield this.client.get(eventUrl, {
409
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: "https://www.thaiticketmajor.com/all-event/" }),
285
410
  });
286
- });
287
- return rounds;
411
+ const $ = cheerio.load(response.data);
412
+ const rounds = [];
413
+ $("a[data-button]").each((_, el) => {
414
+ var _a, _b, _c, _d;
415
+ const link = $(el);
416
+ const href = (_a = link.attr("href")) !== null && _a !== void 0 ? _a : "";
417
+ const onclick = (_b = link.attr("onclick")) !== null && _b !== void 0 ? _b : "";
418
+ const dataUrl = (_c = link.attr("data-url")) !== null && _c !== void 0 ? _c : "";
419
+ const dataHref = (_d = link.attr("data-href")) !== null && _d !== void 0 ? _d : "";
420
+ const allLinkAttrs = `${href} ${onclick} ${dataUrl} ${dataHref}`;
421
+ const queryMatch = allLinkAttrs.match(/query=([0-9a-zA-Z_-]+)/);
422
+ const query = queryMatch ? queryMatch[1] : "";
423
+ const time = link.find(".item-show").text().trim();
424
+ const date = link.closest(".row").find(".date").text().trim();
425
+ const isDisabled = link.is(":disabled") || link.attr("disabled") !== undefined || !query;
426
+ rounds.push({
427
+ id: query || link.attr("data-button") || "",
428
+ label: `${date} ${time}`.trim(),
429
+ date,
430
+ time,
431
+ url: href,
432
+ query,
433
+ isDisabled,
434
+ });
435
+ });
436
+ this.emitProgress("GET_ROUNDS_RES", `Found ${rounds.length} rounds`, {
437
+ url: eventUrl,
438
+ requestPayload: null,
439
+ responseStatus: response.status,
440
+ responseData: rounds,
441
+ });
442
+ return rounds;
443
+ }
444
+ catch (err) {
445
+ this.emitProgress("GET_ROUNDS_ERR", `Failed to fetch rounds: ${err.message}`, {
446
+ url: eventUrl,
447
+ requestPayload: null,
448
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
449
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
450
+ });
451
+ throw err;
452
+ }
288
453
  });
289
454
  }
290
455
  /**
@@ -292,17 +457,40 @@ class ThaiTicketMajor {
292
457
  */
293
458
  verifyCheckCondition(query) {
294
459
  return __awaiter(this, void 0, void 0, function* () {
460
+ var _a, _b, _c;
295
461
  if (!query) {
296
462
  throw new Error("Query ID is missing. The selected round might be disabled or not open for sale yet.");
297
463
  }
298
- this.emitProgress("VERIFY_CONDITION", `Verifying condition for query ${query}`);
299
- const response = yield this.client.post(`${this.endpoint}/verify_checkcondition.php`, new URLSearchParams({
464
+ const url = `${this.endpoint}/verify_checkcondition.php`;
465
+ const payload = {
300
466
  rdagree: "1",
301
467
  rdId: "",
302
468
  autopopup: "",
303
469
  query: query,
304
- }), { headers: this.defaultHeaders });
305
- return response.data;
470
+ };
471
+ this.emitProgress("VERIFY_CONDITION", `Verifying condition for query ${query}`, {
472
+ url,
473
+ requestPayload: payload,
474
+ });
475
+ try {
476
+ const response = yield this.client.post(url, new URLSearchParams(payload), { headers: this.defaultHeaders });
477
+ this.emitProgress("VERIFY_CONDITION_RES", `Condition check: ${((_a = response.data) === null || _a === void 0 ? void 0 : _a.result) ? "PASS" : "FAIL"}`, {
478
+ url,
479
+ requestPayload: payload,
480
+ responseStatus: response.status,
481
+ responseData: response.data,
482
+ });
483
+ return response.data;
484
+ }
485
+ catch (err) {
486
+ this.emitProgress("VERIFY_CONDITION_ERR", `Condition check error: ${err.message}`, {
487
+ url,
488
+ requestPayload: payload,
489
+ responseStatus: (_b = err.response) === null || _b === void 0 ? void 0 : _b.status,
490
+ responseData: ((_c = err.response) === null || _c === void 0 ? void 0 : _c.data) || err.message,
491
+ });
492
+ throw err;
493
+ }
306
494
  });
307
495
  }
308
496
  /**
@@ -310,38 +498,61 @@ class ThaiTicketMajor {
310
498
  */
311
499
  getZones(query) {
312
500
  return __awaiter(this, void 0, void 0, function* () {
313
- this.emitProgress("GET_ZONES", `Fetching zone data and tokens for query ${query}`);
314
- const response = yield this.client.get(`${this.endpoint}/zones.php?query=${query}`, {
315
- headers: this.defaultHeaders,
316
- });
317
- const $ = cheerio.load(response.data);
318
- const rawInputs = {};
319
- $("#frm input[type='hidden']").each((_, el) => {
320
- var _a;
321
- const name = $(el).attr("name");
322
- const value = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
323
- if (name) {
324
- rawInputs[name] = value;
325
- }
501
+ var _a, _b;
502
+ const url = `${this.endpoint}/zones.php?query=${query}`;
503
+ this.emitProgress("GET_ZONES", `Fetching zone data and tokens for query ${query}`, {
504
+ url,
505
+ requestPayload: { query },
326
506
  });
327
- const rounds = $("#rdId option")
328
- .filter((_, el) => !!$(el).attr("value"))
329
- .map((_, el) => {
330
- var _a;
331
- const opt = $(el);
332
- return {
333
- id: (_a = opt.attr("value")) !== null && _a !== void 0 ? _a : "",
334
- label: opt.text().trim(),
507
+ try {
508
+ const response = yield this.client.get(url, {
509
+ headers: this.defaultHeaders,
510
+ });
511
+ const $ = cheerio.load(response.data);
512
+ const rawInputs = {};
513
+ $("#frm input[type='hidden']").each((_, el) => {
514
+ var _a;
515
+ const name = $(el).attr("name");
516
+ const value = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
517
+ if (name) {
518
+ rawInputs[name] = value;
519
+ }
520
+ });
521
+ const rounds = $("#rdId option")
522
+ .filter((_, el) => !!$(el).attr("value"))
523
+ .map((_, el) => {
524
+ var _a;
525
+ const opt = $(el);
526
+ return {
527
+ id: (_a = opt.attr("value")) !== null && _a !== void 0 ? _a : "",
528
+ label: opt.text().trim(),
529
+ };
530
+ })
531
+ .get();
532
+ const result = {
533
+ k: rawInputs["k"] || "",
534
+ tk: rawInputs["tk"] || "",
535
+ query,
536
+ rounds,
537
+ rawInputs,
335
538
  };
336
- })
337
- .get();
338
- return {
339
- k: rawInputs["k"] || "",
340
- tk: rawInputs["tk"] || "",
341
- query,
342
- rounds,
343
- rawInputs,
344
- };
539
+ this.emitProgress("GET_ZONES_RES", `Extracted tokens k=${result.k ? result.k.slice(0, 10) + '...' : 'none'} and ${rounds.length} rounds`, {
540
+ url,
541
+ requestPayload: { query },
542
+ responseStatus: response.status,
543
+ responseData: result,
544
+ });
545
+ return result;
546
+ }
547
+ catch (err) {
548
+ this.emitProgress("GET_ZONES_ERR", `Failed to get zones: ${err.message}`, {
549
+ url,
550
+ requestPayload: { query },
551
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
552
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
553
+ });
554
+ throw err;
555
+ }
345
556
  });
346
557
  }
347
558
  /**
@@ -349,43 +560,65 @@ class ThaiTicketMajor {
349
560
  */
350
561
  getZoneAvailability(roundId, tk, k, query) {
351
562
  return __awaiter(this, void 0, void 0, function* () {
352
- this.emitProgress("GET_ZONE_AVAIL", `Checking zone availability for round ${roundId}`);
353
- const response = yield this.client.get(`${this.endpoint}/zonesavail.php?round=${roundId}&tk=${tk}`, {
354
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: `${this.endpoint}/zones.php?query=${query}` }),
563
+ var _a, _b;
564
+ const url = `${this.endpoint}/zonesavail.php?round=${roundId}&tk=${tk}`;
565
+ this.emitProgress("GET_ZONE_AVAIL", `Checking zone availability for round ${roundId}`, {
566
+ url,
567
+ requestPayload: { roundId, tk, query },
355
568
  });
356
- const $ = cheerio.load(response.data);
357
- const zones = [];
358
- $(".table tbody tr").each((_, el) => {
359
- var _a, _b, _c, _d;
360
- const row = $(el);
361
- const zoneId = (_a = row.find("td:nth-child(1) a").attr("id")) !== null && _a !== void 0 ? _a : "";
362
- const onclick = (_b = row.attr("onclick")) !== null && _b !== void 0 ? _b : "";
363
- const match = onclick.match(/gonextstep\('([^']+)','([^']+)'/);
364
- const page = ((_c = match === null || match === void 0 ? void 0 : match[1]) !== null && _c !== void 0 ? _c : "");
365
- const zoneValue = (_d = match === null || match === void 0 ? void 0 : match[2]) !== null && _d !== void 0 ? _d : "";
366
- const statusText = row.find("td:nth-child(2) a").text().trim();
367
- let available = 0;
368
- let isAvailable = false;
369
- if (statusText.toLowerCase() === "available") {
370
- available = 1;
371
- isAvailable = true;
372
- }
373
- else {
374
- const num = Number(statusText);
375
- if (!Number.isNaN(num) && num > 0) {
376
- available = num;
569
+ try {
570
+ const response = yield this.client.get(url, {
571
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: `${this.endpoint}/zones.php?query=${query}` }),
572
+ });
573
+ const $ = cheerio.load(response.data);
574
+ const zones = [];
575
+ $(".table tbody tr").each((_, el) => {
576
+ var _a, _b, _c, _d;
577
+ const row = $(el);
578
+ const zoneId = (_a = row.find("td:nth-child(1) a").attr("id")) !== null && _a !== void 0 ? _a : "";
579
+ const onclick = (_b = row.attr("onclick")) !== null && _b !== void 0 ? _b : "";
580
+ const match = onclick.match(/gonextstep\('([^']+)','([^']+)'/);
581
+ const page = ((_c = match === null || match === void 0 ? void 0 : match[1]) !== null && _c !== void 0 ? _c : "");
582
+ const zoneValue = (_d = match === null || match === void 0 ? void 0 : match[2]) !== null && _d !== void 0 ? _d : "";
583
+ const statusText = row.find("td:nth-child(2) a").text().trim();
584
+ let available = 0;
585
+ let isAvailable = false;
586
+ if (statusText.toLowerCase() === "available") {
587
+ available = 1;
377
588
  isAvailable = true;
378
589
  }
379
- }
380
- zones.push({
381
- id: zoneId,
382
- value: zoneValue,
383
- available,
384
- page,
385
- isAvailable,
590
+ else {
591
+ const num = Number(statusText);
592
+ if (!Number.isNaN(num) && num > 0) {
593
+ available = num;
594
+ isAvailable = true;
595
+ }
596
+ }
597
+ zones.push({
598
+ id: zoneId,
599
+ value: zoneValue,
600
+ available,
601
+ page,
602
+ isAvailable,
603
+ });
386
604
  });
387
- });
388
- return zones;
605
+ this.emitProgress("GET_ZONE_AVAIL_RES", `Found ${zones.length} zones (${zones.filter(z => z.isAvailable).length} available)`, {
606
+ url,
607
+ requestPayload: { roundId, tk, query },
608
+ responseStatus: response.status,
609
+ responseData: zones,
610
+ });
611
+ return zones;
612
+ }
613
+ catch (err) {
614
+ this.emitProgress("GET_ZONE_AVAIL_ERR", `Failed to check zone availability: ${err.message}`, {
615
+ url,
616
+ requestPayload: { roundId, tk, query },
617
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
618
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
619
+ });
620
+ throw err;
621
+ }
389
622
  });
390
623
  }
391
624
  // --- Flow บัตรนั่ง (Fixed Seats) ---
@@ -394,31 +627,57 @@ class ThaiTicketMajor {
394
627
  */
395
628
  getFixedSeats(k, zone, roundId) {
396
629
  return __awaiter(this, void 0, void 0, function* () {
397
- this.emitProgress("GET_FIXED_SEATS", `Fetching seat layout for zone ${zone}`);
398
- const response = yield this.client.get(`${this.endpoint}/fixed.php?k=${k}&zone=${zone}&round=${roundId}`, {
399
- headers: this.defaultHeaders,
400
- });
401
- const $ = cheerio.load(response.data);
402
- const seats = $("#tableseats .seatuncheck")
403
- .map((_, el) => {
404
- var _a, _b, _c;
405
- const seat = $(el);
406
- return {
407
- id: (_a = seat.attr("id")) !== null && _a !== void 0 ? _a : "",
408
- seat: (_b = seat.attr("data-seat")) !== null && _b !== void 0 ? _b : "",
409
- seatk: (_c = seat.attr("data-seatk")) !== null && _c !== void 0 ? _c : "",
410
- };
411
- })
412
- .get();
413
- const form = {};
414
- $("#frmPayment input").each((_, el) => {
415
- var _a;
416
- const name = $(el).attr("name");
417
- if (name) {
418
- form[name] = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
419
- }
630
+ var _a, _b;
631
+ const url = `${this.endpoint}/fixed.php?k=${k}&zone=${zone}&round=${roundId}`;
632
+ this.emitProgress("GET_FIXED_SEATS", `Fetching seat layout for zone ${zone}`, {
633
+ url,
634
+ requestPayload: { k, zone, roundId },
420
635
  });
421
- return { seats, form };
636
+ try {
637
+ const response = yield this.client.get(url, {
638
+ headers: this.defaultHeaders,
639
+ });
640
+ const $ = cheerio.load(response.data);
641
+ const seats = $("#tableseats .seatuncheck")
642
+ .map((_, el) => {
643
+ var _a, _b, _c;
644
+ const seat = $(el);
645
+ return {
646
+ id: (_a = seat.attr("id")) !== null && _a !== void 0 ? _a : "",
647
+ seat: (_b = seat.attr("data-seat")) !== null && _b !== void 0 ? _b : "",
648
+ seatk: (_c = seat.attr("data-seatk")) !== null && _c !== void 0 ? _c : "",
649
+ };
650
+ })
651
+ .get();
652
+ const form = {};
653
+ $("#frmPayment input").each((_, el) => {
654
+ var _a;
655
+ const name = $(el).attr("name");
656
+ if (name) {
657
+ form[name] = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
658
+ }
659
+ });
660
+ this.emitProgress("GET_FIXED_SEATS_RES", `Found ${seats.length} available seats in zone ${zone}`, {
661
+ url,
662
+ requestPayload: { k, zone, roundId },
663
+ responseStatus: response.status,
664
+ responseData: {
665
+ seatsCount: seats.length,
666
+ seatsSample: seats.slice(0, 10),
667
+ form,
668
+ },
669
+ });
670
+ return { seats, form };
671
+ }
672
+ catch (err) {
673
+ this.emitProgress("GET_FIXED_SEATS_ERR", `Failed to get fixed seats: ${err.message}`, {
674
+ url,
675
+ requestPayload: { k, zone, roundId },
676
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
677
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
678
+ });
679
+ throw err;
680
+ }
422
681
  });
423
682
  }
424
683
  /**
@@ -426,7 +685,8 @@ class ThaiTicketMajor {
426
685
  */
427
686
  validateFixedSeats(k_1, zone_1, payload_1, chkSeats_1) {
428
687
  return __awaiter(this, arguments, void 0, function* (k, zone, payload, chkSeats, bookType = "fix") {
429
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
688
+ var _a, _b;
689
+ var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
430
690
  this.emitProgress("VALIDATE_FIXED_SEATS", `Validating ${chkSeats.length} fixed seats`);
431
691
  let lastResponse = null;
432
692
  const accumulatedSeats = [];
@@ -439,27 +699,27 @@ class ThaiTicketMajor {
439
699
  for (const seat of accumulatedSeats) {
440
700
  formData.append("chkSeats[]", seat);
441
701
  }
442
- formData.append("ehId", (_a = payload.ehId) !== null && _a !== void 0 ? _a : "");
443
- formData.append("curentdate", (_b = payload.curentdate) !== null && _b !== void 0 ? _b : "");
444
- formData.append("max_payment", (_c = payload.max_payment) !== null && _c !== void 0 ? _c : "6");
445
- formData.append("payment_cnt", (_d = payload.payment_cnt) !== null && _d !== void 0 ? _d : "0");
446
- formData.append("paytype", (_e = payload.paytype) !== null && _e !== void 0 ? _e : "BOAI");
447
- formData.append("performance", (_f = payload.performance) !== null && _f !== void 0 ? _f : "");
702
+ formData.append("ehId", (_c = payload.ehId) !== null && _c !== void 0 ? _c : "");
703
+ formData.append("curentdate", (_d = payload.curentdate) !== null && _d !== void 0 ? _d : "");
704
+ formData.append("max_payment", (_e = payload.max_payment) !== null && _e !== void 0 ? _e : "6");
705
+ formData.append("payment_cnt", (_f = payload.payment_cnt) !== null && _f !== void 0 ? _f : "0");
706
+ formData.append("paytype", (_g = payload.paytype) !== null && _g !== void 0 ? _g : "BOAI");
707
+ formData.append("performance", (_h = payload.performance) !== null && _h !== void 0 ? _h : "");
448
708
  formData.append("pricelist", "");
449
- formData.append("rdId", (_g = payload.rdId) !== null && _g !== void 0 ? _g : "");
709
+ formData.append("rdId", (_j = payload.rdId) !== null && _j !== void 0 ? _j : "");
450
710
  formData.append("seatlist", "");
451
- formData.append("showdate", (_h = payload.showdate) !== null && _h !== void 0 ? _h : "");
452
- formData.append("showtime", (_j = payload.showtime) !== null && _j !== void 0 ? _j : "");
453
- formData.append("venue", (_k = payload.venue) !== null && _k !== void 0 ? _k : "");
454
- formData.append("zone", (_l = payload.zone) !== null && _l !== void 0 ? _l : "");
455
- formData.append("zoneDesc", (_m = payload.zoneDesc) !== null && _m !== void 0 ? _m : "");
711
+ formData.append("showdate", (_k = payload.showdate) !== null && _k !== void 0 ? _k : "");
712
+ formData.append("showtime", (_l = payload.showtime) !== null && _l !== void 0 ? _l : "");
713
+ formData.append("venue", (_m = payload.venue) !== null && _m !== void 0 ? _m : "");
714
+ formData.append("zone", (_o = payload.zone) !== null && _o !== void 0 ? _o : "");
715
+ formData.append("zoneDesc", (_p = payload.zoneDesc) !== null && _p !== void 0 ? _p : "");
456
716
  formData.append("travelChild1", "");
457
717
  formData.append("travelChild2", "");
458
718
  formData.append("travelChild2", "");
459
- formData.append("enroll_val", (_o = payload.enroll_val) !== null && _o !== void 0 ? _o : "");
460
- formData.append("dval", (_p = payload.dval) !== null && _p !== void 0 ? _p : "");
461
- formData.append("companyid", (_q = payload.companyid) !== null && _q !== void 0 ? _q : "");
462
- formData.append("ks", (_r = payload.ks) !== null && _r !== void 0 ? _r : "");
719
+ formData.append("enroll_val", (_q = payload.enroll_val) !== null && _q !== void 0 ? _q : "");
720
+ formData.append("dval", (_r = payload.dval) !== null && _r !== void 0 ? _r : "");
721
+ formData.append("companyid", (_s = payload.companyid) !== null && _s !== void 0 ? _s : "");
722
+ formData.append("ks", (_t = payload.ks) !== null && _t !== void 0 ? _t : "");
463
723
  formData.append("inclvat", "");
464
724
  const seatParts = currentSeat.seat.split("-");
465
725
  const row = seatParts[0];
@@ -467,12 +727,31 @@ class ThaiTicketMajor {
467
727
  formData.append("row", row);
468
728
  formData.append("seat", seatNo);
469
729
  formData.append("book_type", bookType);
470
- const response = yield this.client.post(`${this.endpoint}/validateseat.php?k=${k}&zw=${zone}`, formData.toString(), {
471
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/fixed.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}` }),
472
- });
473
- lastResponse = response.data;
474
- if (!lastResponse.result) {
475
- throw new Error(`Validate seat failed (${currentSeat.seat}): ${lastResponse.message || "Unknown error"}`);
730
+ const url = `${this.endpoint}/validateseat.php?k=${k}&zw=${zone}`;
731
+ const reqPayloadObj = Object.fromEntries(formData.entries());
732
+ try {
733
+ const response = yield this.client.post(url, formData.toString(), {
734
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/fixed.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}` }),
735
+ });
736
+ lastResponse = response.data;
737
+ this.emitProgress("VALIDATE_FIXED_SEATS_RES", `Seat validated (${currentSeat.seat}): ${(lastResponse === null || lastResponse === void 0 ? void 0 : lastResponse.result) ? "SUCCESS" : "FAIL"}`, {
738
+ url,
739
+ requestPayload: reqPayloadObj,
740
+ responseStatus: response.status,
741
+ responseData: lastResponse,
742
+ });
743
+ if (!lastResponse.result) {
744
+ throw new Error(`Validate seat failed (${currentSeat.seat}): ${lastResponse.message || "Unknown error"}`);
745
+ }
746
+ }
747
+ catch (err) {
748
+ this.emitProgress("VALIDATE_FIXED_SEATS_ERR", `Validate seat failed (${currentSeat.seat}): ${err.message}`, {
749
+ url,
750
+ requestPayload: reqPayloadObj,
751
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
752
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
753
+ });
754
+ throw err;
476
755
  }
477
756
  }
478
757
  return lastResponse;
@@ -483,6 +762,7 @@ class ThaiTicketMajor {
483
762
  */
484
763
  bookFixedSeats(k, payload, seats) {
485
764
  return __awaiter(this, void 0, void 0, function* () {
765
+ var _a, _b;
486
766
  this.emitProgress("BOOK_FIXED_SEATS", `Booking fixed seats`);
487
767
  let pricelistvalue = "";
488
768
  let seatlistvalue = "";
@@ -517,13 +797,32 @@ class ThaiTicketMajor {
517
797
  bodyParams.set("ks", "");
518
798
  bodyParams.set("inclvat", "");
519
799
  bodyParams.set("seatklist", seatklistvalue);
520
- const response = yield this.client.post(`${this.endpoint}/bookingseats.php?k=${k}`, bodyParams.toString(), {
521
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { accept: "application/json, text/javascript, */*; q=0.01", "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/fixed.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}`, origin: "https://booking.thaiticketmajor.com" }),
522
- });
523
- return {
524
- data: response.data,
525
- nextPayload: bodyParams,
526
- };
800
+ const url = `${this.endpoint}/bookingseats.php?k=${k}`;
801
+ const reqPayloadObj = Object.fromEntries(bodyParams.entries());
802
+ try {
803
+ const response = yield this.client.post(url, bodyParams.toString(), {
804
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { accept: "application/json, text/javascript, */*; q=0.01", "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/fixed.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}`, origin: "https://booking.thaiticketmajor.com" }),
805
+ });
806
+ this.emitProgress("BOOK_FIXED_SEATS_RES", `Book fixed seats completed`, {
807
+ url,
808
+ requestPayload: reqPayloadObj,
809
+ responseStatus: response.status,
810
+ responseData: response.data,
811
+ });
812
+ return {
813
+ data: response.data,
814
+ nextPayload: bodyParams,
815
+ };
816
+ }
817
+ catch (err) {
818
+ this.emitProgress("BOOK_FIXED_SEATS_ERR", `Booking seats error: ${err.message}`, {
819
+ url,
820
+ requestPayload: reqPayloadObj,
821
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
822
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
823
+ });
824
+ throw err;
825
+ }
527
826
  });
528
827
  }
529
828
  // --- Flow บัตรยืน (Festival / Standing) ---
@@ -532,20 +831,42 @@ class ThaiTicketMajor {
532
831
  */
533
832
  getFestival(k, tk, query, zone, roundId) {
534
833
  return __awaiter(this, void 0, void 0, function* () {
535
- this.emitProgress("GET_FESTIVAL", `Fetching festival zone ${zone}`);
536
- const response = yield this.client.get(`${this.endpoint}/festival.php?k=${k}&zone=${zone}&round=${roundId}`, {
537
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: `${this.endpoint}/zones.php?rdId=${roundId}&k=${k}&tk=${tk}&query=${query}` }),
538
- });
539
- const $ = cheerio.load(response.data);
540
- const formData = {};
541
- $("#frm input").each((_, el) => {
542
- var _a;
543
- const name = $(el).attr("name");
544
- if (name) {
545
- formData[name] = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
546
- }
834
+ var _a, _b;
835
+ const url = `${this.endpoint}/festival.php?k=${k}&zone=${zone}&round=${roundId}`;
836
+ this.emitProgress("GET_FESTIVAL", `Fetching festival zone ${zone}`, {
837
+ url,
838
+ requestPayload: { k, tk, query, zone, roundId },
547
839
  });
548
- return formData;
840
+ try {
841
+ const response = yield this.client.get(url, {
842
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: `${this.endpoint}/zones.php?rdId=${roundId}&k=${k}&tk=${tk}&query=${query}` }),
843
+ });
844
+ const $ = cheerio.load(response.data);
845
+ const formData = {};
846
+ $("#frm input").each((_, el) => {
847
+ var _a;
848
+ const name = $(el).attr("name");
849
+ if (name) {
850
+ formData[name] = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
851
+ }
852
+ });
853
+ this.emitProgress("GET_FESTIVAL_RES", `Loaded festival form (${Object.keys(formData).length} fields)`, {
854
+ url,
855
+ requestPayload: { k, tk, query, zone, roundId },
856
+ responseStatus: response.status,
857
+ responseData: formData,
858
+ });
859
+ return formData;
860
+ }
861
+ catch (err) {
862
+ this.emitProgress("GET_FESTIVAL_ERR", `Failed to get festival page: ${err.message}`, {
863
+ url,
864
+ requestPayload: { k, tk, query, zone, roundId },
865
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
866
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
867
+ });
868
+ throw err;
869
+ }
549
870
  });
550
871
  }
551
872
  /**
@@ -553,13 +874,32 @@ class ThaiTicketMajor {
553
874
  */
554
875
  validateFestivalSeats(k, payload, ticketCount) {
555
876
  return __awaiter(this, void 0, void 0, function* () {
877
+ var _a, _b, _c;
556
878
  this.emitProgress("VALIDATE_FESTIVAL", `Validating ${ticketCount} festival tickets`);
557
879
  const preparePayload = Object.assign(Object.assign({}, payload), { book_cnt: ticketCount.toString(), book_type: "fest" });
558
880
  const formData = new URLSearchParams(preparePayload);
559
- const response = yield this.client.post(`${this.endpoint}/validateseat.php?k=${k}&zw=${payload.zone}`, formData.toString(), {
560
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/festival.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}` }),
561
- });
562
- return response.data;
881
+ const url = `${this.endpoint}/validateseat.php?k=${k}&zw=${payload.zone}`;
882
+ try {
883
+ const response = yield this.client.post(url, formData.toString(), {
884
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/festival.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}` }),
885
+ });
886
+ this.emitProgress("VALIDATE_FESTIVAL_RES", `Validate festival tickets: ${((_a = response.data) === null || _a === void 0 ? void 0 : _a.result) ? "SUCCESS" : "FAIL"}`, {
887
+ url,
888
+ requestPayload: preparePayload,
889
+ responseStatus: response.status,
890
+ responseData: response.data,
891
+ });
892
+ return response.data;
893
+ }
894
+ catch (err) {
895
+ this.emitProgress("VALIDATE_FESTIVAL_ERR", `Validate festival error: ${err.message}`, {
896
+ url,
897
+ requestPayload: preparePayload,
898
+ responseStatus: (_b = err.response) === null || _b === void 0 ? void 0 : _b.status,
899
+ responseData: ((_c = err.response) === null || _c === void 0 ? void 0 : _c.data) || err.message,
900
+ });
901
+ throw err;
902
+ }
563
903
  });
564
904
  }
565
905
  /**
@@ -567,13 +907,32 @@ class ThaiTicketMajor {
567
907
  */
568
908
  bookFestivalSeats(k, payload, ticketCount) {
569
909
  return __awaiter(this, void 0, void 0, function* () {
910
+ var _a, _b;
570
911
  this.emitProgress("BOOK_FESTIVAL", `Booking ${ticketCount} festival tickets`);
571
912
  const preparePayload = Object.assign(Object.assign({}, payload), { book_cnt: ticketCount.toString() });
572
913
  const formData = new URLSearchParams(preparePayload);
573
- const response = yield this.client.post(`${this.endpoint}/bookingfestival.php?k=${k}`, formData.toString(), {
574
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/festival.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}` }),
575
- });
576
- return response.data;
914
+ const url = `${this.endpoint}/bookingfestival.php?k=${k}`;
915
+ try {
916
+ const response = yield this.client.post(url, formData.toString(), {
917
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/festival.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}` }),
918
+ });
919
+ this.emitProgress("BOOK_FESTIVAL_RES", `Book festival tickets completed`, {
920
+ url,
921
+ requestPayload: preparePayload,
922
+ responseStatus: response.status,
923
+ responseData: response.data,
924
+ });
925
+ return response.data;
926
+ }
927
+ catch (err) {
928
+ this.emitProgress("BOOK_FESTIVAL_ERR", `Book festival error: ${err.message}`, {
929
+ url,
930
+ requestPayload: preparePayload,
931
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
932
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
933
+ });
934
+ throw err;
935
+ }
577
936
  });
578
937
  }
579
938
  // --- Flow การลงทะเบียนผู้เข้าชม (Enrollment) ---
@@ -582,20 +941,42 @@ class ThaiTicketMajor {
582
941
  */
583
942
  enroll(k, zone, roundId, payload) {
584
943
  return __awaiter(this, void 0, void 0, function* () {
585
- this.emitProgress("GET_ENROLL", `Fetching enrollment form`);
586
- const response = yield this.client.post(`${this.endpoint}/enroll.php?k=${k}&zone=${zone}&round=${roundId}`, payload.toString(), {
587
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: `${this.endpoint}/fixed.php?k=${k}&zone=${zone}&round=${roundId}` }),
588
- });
589
- const $ = cheerio.load(response.data);
590
- const formData = {};
591
- $("#form input, #form select").each((_, el) => {
592
- var _a, _b;
593
- const name = $(el).attr("name");
594
- if (name) {
595
- formData[name] = (_b = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : $(el).find("option:selected").attr("value")) !== null && _b !== void 0 ? _b : "";
596
- }
944
+ var _a, _b;
945
+ const url = `${this.endpoint}/enroll.php?k=${k}&zone=${zone}&round=${roundId}`;
946
+ this.emitProgress("GET_ENROLL", `Fetching enrollment form`, {
947
+ url,
948
+ requestPayload: payload.toString(),
597
949
  });
598
- return formData;
950
+ try {
951
+ const response = yield this.client.post(url, payload.toString(), {
952
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: `${this.endpoint}/fixed.php?k=${k}&zone=${zone}&round=${roundId}` }),
953
+ });
954
+ const $ = cheerio.load(response.data);
955
+ const formData = {};
956
+ $("#form input, #form select").each((_, el) => {
957
+ var _a, _b;
958
+ const name = $(el).attr("name");
959
+ if (name) {
960
+ formData[name] = (_b = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : $(el).find("option:selected").attr("value")) !== null && _b !== void 0 ? _b : "";
961
+ }
962
+ });
963
+ this.emitProgress("GET_ENROLL_RES", `Loaded enrollment form (${Object.keys(formData).length} fields)`, {
964
+ url,
965
+ requestPayload: payload.toString(),
966
+ responseStatus: response.status,
967
+ responseData: formData,
968
+ });
969
+ return formData;
970
+ }
971
+ catch (err) {
972
+ this.emitProgress("GET_ENROLL_ERR", `Enroll form error: ${err.message}`, {
973
+ url,
974
+ requestPayload: payload.toString(),
975
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
976
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
977
+ });
978
+ throw err;
979
+ }
599
980
  });
600
981
  }
601
982
  /**
@@ -603,8 +984,13 @@ class ThaiTicketMajor {
603
984
  */
604
985
  enrollProcess(k, payload, attendees) {
605
986
  return __awaiter(this, void 0, void 0, function* () {
606
- var _a;
607
- this.emitProgress("ENROLL_PROCESS", `Submitting info for ${attendees.length} attendees`);
987
+ var _a, _b;
988
+ var _c;
989
+ const url = `${this.endpoint}/enroll_process.php?k=${k}`;
990
+ this.emitProgress("ENROLL_PROCESS", `Submitting info for ${attendees.length} attendees`, {
991
+ url,
992
+ requestPayload: { attendeesCount: attendees.length, attendees },
993
+ });
608
994
  const formData = new URLSearchParams();
609
995
  for (const user of attendees) {
610
996
  formData.append("txt_fullname[]", user.fullname || "");
@@ -613,7 +999,7 @@ class ThaiTicketMajor {
613
999
  formData.append("txt_lastname[]", user.lastname || "");
614
1000
  formData.append("txt_phone[]", user.phone || "");
615
1001
  formData.append("sel_options[]", user.options || "");
616
- formData.append("zones[]", (_a = payload.zone) !== null && _a !== void 0 ? _a : "");
1002
+ formData.append("zones[]", (_c = payload.zone) !== null && _c !== void 0 ? _c : "");
617
1003
  }
618
1004
  const excludedKeys = new Set([
619
1005
  "txt_fullname[]",
@@ -629,13 +1015,31 @@ class ThaiTicketMajor {
629
1015
  formData.append(key, value !== undefined && value !== null ? String(value) : "");
630
1016
  }
631
1017
  }
632
- const response = yield this.client.post(`${this.endpoint}/enroll_process.php?k=${k}`, formData.toString(), {
633
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/enroll.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}` }),
634
- });
635
- return {
636
- data: response.data,
637
- nextPayload: formData,
638
- };
1018
+ const reqPayloadObj = Object.fromEntries(formData.entries());
1019
+ try {
1020
+ const response = yield this.client.post(url, formData.toString(), {
1021
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/enroll.php?k=${k}&zone=${payload.zone}&round=${payload.rdId}` }),
1022
+ });
1023
+ this.emitProgress("ENROLL_PROCESS_RES", `Enrollment processed successfully`, {
1024
+ url,
1025
+ requestPayload: reqPayloadObj,
1026
+ responseStatus: response.status,
1027
+ responseData: response.data,
1028
+ });
1029
+ return {
1030
+ data: response.data,
1031
+ nextPayload: formData,
1032
+ };
1033
+ }
1034
+ catch (err) {
1035
+ this.emitProgress("ENROLL_PROCESS_ERR", `Enrollment error: ${err.message}`, {
1036
+ url,
1037
+ requestPayload: reqPayloadObj,
1038
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
1039
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
1040
+ });
1041
+ throw err;
1042
+ }
639
1043
  });
640
1044
  }
641
1045
  // --- Flow การชำระเงิน (Payment) ---
@@ -644,51 +1048,73 @@ class ThaiTicketMajor {
644
1048
  */
645
1049
  getPaymentDetails(k_1, formData_1, zone_1, roundId_1) {
646
1050
  return __awaiter(this, arguments, void 0, function* (k, formData, zone, roundId, delayMs = 1000) {
647
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
648
- var _k, _l, _m, _o, _p, _q, _r, _s, _t;
649
- this.emitProgress("GET_PAYMENT_DETAILS", `Loading payment confirmation page`);
1051
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
1052
+ var _m, _o, _p, _q, _r, _s, _t, _u, _v;
1053
+ const url = `${this.endpoint}/paymentall.php?k=${k}`;
650
1054
  const body = formData instanceof URLSearchParams ? formData.toString() : new URLSearchParams(formData).toString();
651
- const response = yield this.client.post(`${this.endpoint}/paymentall.php?k=${k}`, body, {
652
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/enroll.php?k=${k}&zone=${zone}&round=${roundId}` }),
1055
+ const reqPayloadObj = formData instanceof URLSearchParams ? Object.fromEntries(formData.entries()) : formData;
1056
+ this.emitProgress("GET_PAYMENT_DETAILS", `Loading payment confirmation page`, {
1057
+ url,
1058
+ requestPayload: reqPayloadObj,
653
1059
  });
654
- const $ = cheerio.load(response.data);
655
- const hiddenInputs = {};
656
- $("#frm-confirm input").each((_, el) => {
657
- var _a;
658
- var _b, _c;
659
- const key = (_b = $(el).attr("name")) !== null && _b !== void 0 ? _b : $(el).attr("id");
660
- if (key) {
661
- hiddenInputs[key] = (_c = (_a = $(el).val()) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _c !== void 0 ? _c : "";
1060
+ try {
1061
+ const response = yield this.client.post(url, body, {
1062
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/enroll.php?k=${k}&zone=${zone}&round=${roundId}` }),
1063
+ });
1064
+ const $ = cheerio.load(response.data);
1065
+ const hiddenInputs = {};
1066
+ $("#frm-confirm input").each((_, el) => {
1067
+ var _a;
1068
+ var _b, _c;
1069
+ const key = (_b = $(el).attr("name")) !== null && _b !== void 0 ? _b : $(el).attr("id");
1070
+ if (key) {
1071
+ hiddenInputs[key] = (_c = (_a = $(el).val()) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _c !== void 0 ? _c : "";
1072
+ }
1073
+ });
1074
+ const addressForm = $("#frm-address");
1075
+ if (addressForm.length > 0) {
1076
+ const fname = (_m = (_a = addressForm.find("input[name='c_fname_m']").val()) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _m !== void 0 ? _m : "";
1077
+ const lname = (_o = (_b = addressForm.find("input[name='c_lname_m']").val()) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _o !== void 0 ? _o : "";
1078
+ const address = (_p = (_c = addressForm.find("textarea[name='c_address_m']").val()) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _p !== void 0 ? _p : "";
1079
+ const ctId = (_q = (_d = addressForm.find("select[name='c_ctCode'] option:selected").val()) === null || _d === void 0 ? void 0 : _d.toString()) !== null && _q !== void 0 ? _q : "";
1080
+ const pvId = (_r = (_e = addressForm.find("select[name='c_pvId'] option:selected").val()) === null || _e === void 0 ? void 0 : _e.toString()) !== null && _r !== void 0 ? _r : "";
1081
+ const amId = (_s = (_f = addressForm.find("select[name='c_amId'] option:selected").val()) === null || _f === void 0 ? void 0 : _f.toString()) !== null && _s !== void 0 ? _s : "";
1082
+ const zipcode = (_t = (_g = addressForm.find("input[name='c_PostCode']").val()) === null || _g === void 0 ? void 0 : _g.toString()) !== null && _t !== void 0 ? _t : "";
1083
+ let rawPhone = (_u = (_h = addressForm.find("input[name='c_ContactRecipient']").val()) === null || _h === void 0 ? void 0 : _h.toString()) !== null && _u !== void 0 ? _u : "";
1084
+ if (rawPhone.startsWith("66")) {
1085
+ rawPhone = rawPhone.slice(2);
1086
+ }
1087
+ const phoneArea = (_v = (_j = addressForm.find("input[name='telephoneArea']").val()) === null || _j === void 0 ? void 0 : _j.toString()) !== null && _v !== void 0 ? _v : "66";
1088
+ hiddenInputs["adr_fname"] = fname;
1089
+ hiddenInputs["adr_lname"] = lname;
1090
+ hiddenInputs["adr_address"] = address;
1091
+ hiddenInputs["adr_ctId"] = ctId;
1092
+ hiddenInputs["adr_pvId"] = pvId;
1093
+ hiddenInputs["adr_amId"] = amId;
1094
+ hiddenInputs["adr_zipcode"] = zipcode;
1095
+ hiddenInputs["adr_mobile"] = rawPhone.replace(/(\d{2})(\d{3})(\d{4})/, "$1 $2 $3");
1096
+ hiddenInputs["adr_mobilearea"] = phoneArea;
662
1097
  }
663
- });
664
- const addressForm = $("#frm-address");
665
- if (addressForm.length > 0) {
666
- const fname = (_k = (_a = addressForm.find("input[name='c_fname_m']").val()) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _k !== void 0 ? _k : "";
667
- const lname = (_l = (_b = addressForm.find("input[name='c_lname_m']").val()) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _l !== void 0 ? _l : "";
668
- const address = (_m = (_c = addressForm.find("textarea[name='c_address_m']").val()) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _m !== void 0 ? _m : "";
669
- const ctId = (_o = (_d = addressForm.find("select[name='c_ctCode'] option:selected").val()) === null || _d === void 0 ? void 0 : _d.toString()) !== null && _o !== void 0 ? _o : "";
670
- const pvId = (_p = (_e = addressForm.find("select[name='c_pvId'] option:selected").val()) === null || _e === void 0 ? void 0 : _e.toString()) !== null && _p !== void 0 ? _p : "";
671
- const amId = (_q = (_f = addressForm.find("select[name='c_amId'] option:selected").val()) === null || _f === void 0 ? void 0 : _f.toString()) !== null && _q !== void 0 ? _q : "";
672
- const zipcode = (_r = (_g = addressForm.find("input[name='c_PostCode']").val()) === null || _g === void 0 ? void 0 : _g.toString()) !== null && _r !== void 0 ? _r : "";
673
- let rawPhone = (_s = (_h = addressForm.find("input[name='c_ContactRecipient']").val()) === null || _h === void 0 ? void 0 : _h.toString()) !== null && _s !== void 0 ? _s : "";
674
- if (rawPhone.startsWith("66")) {
675
- rawPhone = rawPhone.slice(2);
1098
+ this.emitProgress("GET_PAYMENT_DETAILS_RES", `Loaded payment confirmation details (${Object.keys(hiddenInputs).length} fields)`, {
1099
+ url,
1100
+ requestPayload: reqPayloadObj,
1101
+ responseStatus: response.status,
1102
+ responseData: hiddenInputs,
1103
+ });
1104
+ if (delayMs > 0) {
1105
+ yield new Promise((resolve) => setTimeout(resolve, delayMs));
676
1106
  }
677
- const phoneArea = (_t = (_j = addressForm.find("input[name='telephoneArea']").val()) === null || _j === void 0 ? void 0 : _j.toString()) !== null && _t !== void 0 ? _t : "66";
678
- hiddenInputs["adr_fname"] = fname;
679
- hiddenInputs["adr_lname"] = lname;
680
- hiddenInputs["adr_address"] = address;
681
- hiddenInputs["adr_ctId"] = ctId;
682
- hiddenInputs["adr_pvId"] = pvId;
683
- hiddenInputs["adr_amId"] = amId;
684
- hiddenInputs["adr_zipcode"] = zipcode;
685
- hiddenInputs["adr_mobile"] = rawPhone.replace(/(\d{2})(\d{3})(\d{4})/, "$1 $2 $3");
686
- hiddenInputs["adr_mobilearea"] = phoneArea;
1107
+ return hiddenInputs;
687
1108
  }
688
- if (delayMs > 0) {
689
- yield new Promise((resolve) => setTimeout(resolve, delayMs));
1109
+ catch (err) {
1110
+ this.emitProgress("GET_PAYMENT_DETAILS_ERR", `Payment details error: ${err.message}`, {
1111
+ url,
1112
+ requestPayload: reqPayloadObj,
1113
+ responseStatus: (_k = err.response) === null || _k === void 0 ? void 0 : _k.status,
1114
+ responseData: ((_l = err.response) === null || _l === void 0 ? void 0 : _l.data) || err.message,
1115
+ });
1116
+ throw err;
690
1117
  }
691
- return hiddenInputs;
692
1118
  });
693
1119
  }
694
1120
  /**
@@ -696,7 +1122,8 @@ class ThaiTicketMajor {
696
1122
  */
697
1123
  confirmPayment(k_1, payload_1) {
698
1124
  return __awaiter(this, arguments, void 0, function* (k, payload, deliver = "1", payType = "KBQR") {
699
- this.emitProgress("CONFIRM_PAYMENT", `Calculating total and confirming payment (${payType})`);
1125
+ var _a, _b;
1126
+ const url = `${this.endpoint}/paycfmall.php?k=${k}`;
700
1127
  const cntTicket = parseInt(payload.cal_cntticket || "0", 10);
701
1128
  const amountCode = parseFloat(payload.amountcode || "0");
702
1129
  const deliverFee = parseFloat(payload.cal_deliverfee || payload.val_deliverfee || "80");
@@ -706,26 +1133,47 @@ class ThaiTicketMajor {
706
1133
  const ticketFee = cntTicket * 191; // Ticket Fee 191 THB per ticket
707
1134
  const totalAmount = amountCode + deliverFee + ticketFee + addCharge - discount - voucher;
708
1135
  const computedPayload = Object.assign(Object.assign({}, payload), { paytype: payType, deliver: deliver, cal_ticketfee: ticketFee.toString(), cal_totalamount: Math.round(totalAmount).toString() });
1136
+ this.emitProgress("CONFIRM_PAYMENT", `Calculating total and confirming payment (${payType})`, {
1137
+ url,
1138
+ requestPayload: computedPayload,
1139
+ });
709
1140
  const formData = new URLSearchParams();
710
1141
  for (const [key, value] of Object.entries(computedPayload)) {
711
1142
  if (key !== "check-protect") {
712
1143
  formData.append(key, value !== undefined && value !== null ? String(value) : "");
713
1144
  }
714
1145
  }
715
- const response = yield this.client.post(`${this.endpoint}/paycfmall.php?k=${k}`, formData.toString(), {
716
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/paymentall.php?k=${k}` }),
717
- });
718
- const $ = cheerio.load(response.data);
719
- const nextJsonData = {};
720
- $("#payallfrm input[type='hidden']").each((_, el) => {
721
- var _a;
722
- const name = $(el).attr("name");
723
- const value = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
724
- if (name) {
725
- nextJsonData[name] = value;
726
- }
727
- });
728
- return nextJsonData;
1146
+ try {
1147
+ const response = yield this.client.post(url, formData.toString(), {
1148
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/paymentall.php?k=${k}` }),
1149
+ });
1150
+ const $ = cheerio.load(response.data);
1151
+ const nextJsonData = {};
1152
+ $("#payallfrm input[type='hidden']").each((_, el) => {
1153
+ var _a;
1154
+ const name = $(el).attr("name");
1155
+ const value = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
1156
+ if (name) {
1157
+ nextJsonData[name] = value;
1158
+ }
1159
+ });
1160
+ this.emitProgress("CONFIRM_PAYMENT_RES", `Confirmed payment (Total: ฿${computedPayload.cal_totalamount})`, {
1161
+ url,
1162
+ requestPayload: computedPayload,
1163
+ responseStatus: response.status,
1164
+ responseData: nextJsonData,
1165
+ });
1166
+ return nextJsonData;
1167
+ }
1168
+ catch (err) {
1169
+ this.emitProgress("CONFIRM_PAYMENT_ERR", `Payment confirmation error: ${err.message}`, {
1170
+ url,
1171
+ requestPayload: computedPayload,
1172
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
1173
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
1174
+ });
1175
+ throw err;
1176
+ }
729
1177
  });
730
1178
  }
731
1179
  /**
@@ -733,22 +1181,44 @@ class ThaiTicketMajor {
733
1181
  */
734
1182
  orderEncKBankQR(k, payCfmData) {
735
1183
  return __awaiter(this, void 0, void 0, function* () {
736
- this.emitProgress("ORDER_ENC_KBANK", `Encrypting order payload for KBank`);
737
- const formData = new URLSearchParams(payCfmData);
738
- const response = yield this.client.post(`${this.endpoint}/orderenc_kbankqr.php`, formData.toString(), {
739
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/paycfmall.php?k=${k}` }),
740
- });
741
- const $ = cheerio.load(response.data);
742
- const kbankqrData = {};
743
- $("#kbankqr input[type='hidden']").each((_, el) => {
744
- var _a;
745
- const name = $(el).attr("name");
746
- const value = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
747
- if (name) {
748
- kbankqrData[name] = value;
749
- }
1184
+ var _a, _b;
1185
+ const url = `${this.endpoint}/orderenc_kbankqr.php`;
1186
+ this.emitProgress("ORDER_ENC_KBANK", `Encrypting order payload for KBank`, {
1187
+ url,
1188
+ requestPayload: payCfmData,
750
1189
  });
751
- return kbankqrData;
1190
+ const formData = new URLSearchParams(payCfmData);
1191
+ try {
1192
+ const response = yield this.client.post(url, formData.toString(), {
1193
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/paycfmall.php?k=${k}` }),
1194
+ });
1195
+ const $ = cheerio.load(response.data);
1196
+ const kbankqrData = {};
1197
+ $("#kbankqr input[type='hidden']").each((_, el) => {
1198
+ var _a;
1199
+ const name = $(el).attr("name");
1200
+ const value = (_a = $(el).attr("value")) !== null && _a !== void 0 ? _a : "";
1201
+ if (name) {
1202
+ kbankqrData[name] = value;
1203
+ }
1204
+ });
1205
+ this.emitProgress("ORDER_ENC_KBANK_RES", `Received orderenc_kbankqr.php response`, {
1206
+ url,
1207
+ requestPayload: payCfmData,
1208
+ responseStatus: response.status,
1209
+ responseData: Object.keys(kbankqrData).length > 0 ? kbankqrData : response.data,
1210
+ });
1211
+ return kbankqrData;
1212
+ }
1213
+ catch (err) {
1214
+ this.emitProgress("ORDER_ENC_KBANK_ERR", `Order encrypt error: ${err.message}`, {
1215
+ url,
1216
+ requestPayload: payCfmData,
1217
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
1218
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
1219
+ });
1220
+ throw err;
1221
+ }
752
1222
  });
753
1223
  }
754
1224
  /**
@@ -756,12 +1226,34 @@ class ThaiTicketMajor {
756
1226
  */
757
1227
  getKBankQR(orderEncData) {
758
1228
  return __awaiter(this, void 0, void 0, function* () {
759
- this.emitProgress("GET_KBANK_QR", `Calling KBank Gateway info`);
760
- const formData = new URLSearchParams(orderEncData);
761
- const response = yield this.client.post(`${this.endpoint}/getkbankqr.php`, formData.toString(), {
762
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/orderenc_kbankqr.php` }),
1229
+ var _a, _b;
1230
+ const url = `${this.endpoint}/getkbankqr.php`;
1231
+ this.emitProgress("GET_KBANK_QR", `Calling KBank Gateway info`, {
1232
+ url,
1233
+ requestPayload: orderEncData,
763
1234
  });
764
- return response.data;
1235
+ const formData = new URLSearchParams(orderEncData);
1236
+ try {
1237
+ const response = yield this.client.post(url, formData.toString(), {
1238
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/orderenc_kbankqr.php` }),
1239
+ });
1240
+ this.emitProgress("GET_KBANK_QR_RES", `Received getkbankqr.php response`, {
1241
+ url,
1242
+ requestPayload: orderEncData,
1243
+ responseStatus: response.status,
1244
+ responseData: response.data,
1245
+ });
1246
+ return response.data;
1247
+ }
1248
+ catch (err) {
1249
+ this.emitProgress("GET_KBANK_QR_ERR", `Get KBank QR error: ${err.message}`, {
1250
+ url,
1251
+ requestPayload: orderEncData,
1252
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
1253
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
1254
+ });
1255
+ throw err;
1256
+ }
765
1257
  });
766
1258
  }
767
1259
  /**
@@ -770,20 +1262,42 @@ class ThaiTicketMajor {
770
1262
  paymentKBankQR(orderEncData, kbankPayload) {
771
1263
  return __awaiter(this, void 0, void 0, function* () {
772
1264
  var _a, _b;
773
- this.emitProgress("PAYMENT_KBANK_QR", `Extracting KBank OrderID and API Key`);
774
- const preparePayload = Object.assign(Object.assign({}, orderEncData), { reasoncode: kbankPayload.reasoncode, eventname: kbankPayload.eventname, rounddetail: kbankPayload.rounddetail, totalamount: kbankPayload.totalamount, orderstatus: kbankPayload.orderstatus, kbankqr_txExpiry: kbankPayload.kbankqr_txExpiry });
775
- const formData = new URLSearchParams(preparePayload);
776
- const response = yield this.client.post(`${this.endpoint}/payment_kbankqr.php`, formData.toString(), {
777
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/orderenc_kbankqr.php` }),
1265
+ var _c, _d;
1266
+ const preparePayload = Object.assign(Object.assign({}, orderEncData), { reasoncode: kbankPayload === null || kbankPayload === void 0 ? void 0 : kbankPayload.reasoncode, eventname: kbankPayload === null || kbankPayload === void 0 ? void 0 : kbankPayload.eventname, rounddetail: kbankPayload === null || kbankPayload === void 0 ? void 0 : kbankPayload.rounddetail, totalamount: kbankPayload === null || kbankPayload === void 0 ? void 0 : kbankPayload.totalamount, orderstatus: kbankPayload === null || kbankPayload === void 0 ? void 0 : kbankPayload.orderstatus, kbankqr_txExpiry: kbankPayload === null || kbankPayload === void 0 ? void 0 : kbankPayload.kbankqr_txExpiry });
1267
+ const url = `${this.endpoint}/payment_kbankqr.php`;
1268
+ this.emitProgress("PAYMENT_KBANK_QR", `Extracting KBank OrderID and API Key`, {
1269
+ url,
1270
+ requestPayload: preparePayload,
778
1271
  });
779
- const $ = cheerio.load(response.data);
780
- const script = $("#kbankpost script[data-order-id]");
781
- const orderId = (_a = script.attr("data-order-id")) !== null && _a !== void 0 ? _a : "";
782
- const apiKey = (_b = script.attr("data-apikey")) !== null && _b !== void 0 ? _b : "";
783
- if (!orderId || !apiKey) {
784
- throw new Error("Unable to extract KBank orderId or apiKey from response");
1272
+ const formData = new URLSearchParams(preparePayload);
1273
+ try {
1274
+ const response = yield this.client.post(url, formData.toString(), {
1275
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { "content-type": "application/x-www-form-urlencoded; charset=UTF-8", "x-requested-with": "XMLHttpRequest", referer: `${this.endpoint}/orderenc_kbankqr.php` }),
1276
+ });
1277
+ const $ = cheerio.load(response.data);
1278
+ const script = $("#kbankpost script[data-order-id]");
1279
+ const orderId = (_c = script.attr("data-order-id")) !== null && _c !== void 0 ? _c : "";
1280
+ const apiKey = (_d = script.attr("data-apikey")) !== null && _d !== void 0 ? _d : "";
1281
+ this.emitProgress("PAYMENT_KBANK_QR_RES", `Received payment_kbankqr.php response (OrderID: ${orderId || "N/A"})`, {
1282
+ url,
1283
+ requestPayload: preparePayload,
1284
+ responseStatus: response.status,
1285
+ responseData: orderId && apiKey ? { orderId, apiKey, htmlSnippet: $("#kbankpost").html() } : response.data,
1286
+ });
1287
+ if (!orderId || !apiKey) {
1288
+ throw new Error("Unable to extract KBank orderId or apiKey from response");
1289
+ }
1290
+ return { orderId, apiKey };
1291
+ }
1292
+ catch (err) {
1293
+ this.emitProgress("PAYMENT_KBANK_QR_ERR", `Payment KBank QR error: ${err.message}`, {
1294
+ url,
1295
+ requestPayload: preparePayload,
1296
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
1297
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
1298
+ });
1299
+ throw err;
785
1300
  }
786
- return { orderId, apiKey };
787
1301
  });
788
1302
  }
789
1303
  /**
@@ -791,7 +1305,8 @@ class ThaiTicketMajor {
791
1305
  */
792
1306
  generateThaiQR(orderId, apiKey, amount) {
793
1307
  return __awaiter(this, void 0, void 0, function* () {
794
- this.emitProgress("GENERATE_THAI_QR", `Requesting ThaiQR code from Kasikorn Bank`);
1308
+ var _a, _b;
1309
+ const url = "https://kpaymentgateway-services.kasikornbank.com/qr/v2/qr";
795
1310
  const payload = {
796
1311
  amount: amount,
797
1312
  currency: "THB",
@@ -799,10 +1314,31 @@ class ThaiTicketMajor {
799
1314
  order_id: orderId,
800
1315
  sof: "ThaiQR",
801
1316
  };
802
- const response = yield this.client.post("https://kpaymentgateway-services.kasikornbank.com/qr/v2/qr", payload, {
803
- headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: "https://kpaymentgateway.kasikornbank.com/", "x-api-key": apiKey }),
1317
+ this.emitProgress("GENERATE_THAI_QR", `Requesting ThaiQR code from Kasikorn Bank`, {
1318
+ url,
1319
+ requestPayload: payload,
804
1320
  });
805
- return response.data;
1321
+ try {
1322
+ const response = yield this.client.post(url, payload, {
1323
+ headers: Object.assign(Object.assign({}, this.defaultHeaders), { referer: "https://kpaymentgateway.kasikornbank.com/", "x-api-key": apiKey }),
1324
+ });
1325
+ this.emitProgress("GENERATE_THAI_QR_RES", `Received ThaiQR from Kasikorn Bank`, {
1326
+ url,
1327
+ requestPayload: payload,
1328
+ responseStatus: response.status,
1329
+ responseData: response.data,
1330
+ });
1331
+ return response.data;
1332
+ }
1333
+ catch (err) {
1334
+ this.emitProgress("GENERATE_THAI_QR_ERR", `Kasikorn ThaiQR error: ${err.message}`, {
1335
+ url,
1336
+ requestPayload: payload,
1337
+ responseStatus: (_a = err.response) === null || _a === void 0 ? void 0 : _a.status,
1338
+ responseData: ((_b = err.response) === null || _b === void 0 ? void 0 : _b.data) || err.message,
1339
+ });
1340
+ throw err;
1341
+ }
806
1342
  });
807
1343
  }
808
1344
  // ==========================================