@xsolla/payment-client-core 0.0.10 → 0.0.12

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.
Files changed (65) hide show
  1. package/esm2020/lib/core/payment/actions/action-factory-value.interface.mjs +1 -1
  2. package/esm2020/lib/core/payment/actions/check-status/check-status.action.token.mjs +5 -2
  3. package/esm2020/lib/core/payment/actions/next-action.interface.mjs +1 -1
  4. package/esm2020/lib/core/payment/actions/next-action.service.mjs +11 -10
  5. package/esm2020/lib/core/payment/actions/next-actions.mjs +3 -1
  6. package/esm2020/lib/core/payment/actions/redirect/redirect.action.class.mjs +20 -0
  7. package/esm2020/lib/core/payment/actions/redirect/redirect.action.token.mjs +16 -0
  8. package/esm2020/lib/core/payment/actions/redirect/redirect.action.type.mjs +2 -0
  9. package/esm2020/lib/core/payment/actions/show-fields/show-fields.action.class.mjs +2 -2
  10. package/esm2020/lib/core/payment/actions/show-fields/show-fields.action.token.mjs +5 -2
  11. package/esm2020/lib/core/payment/actions/status-updated/status-updated.action.token.mjs +2 -2
  12. package/esm2020/lib/core/payment/finance-details/cart-item.interface.mjs +1 -1
  13. package/esm2020/lib/core/payment/finance-details/cart-line.interface.mjs +1 -1
  14. package/esm2020/lib/core/payment/finance-details/{cart-pricing.interface.mjs → cart-summary.interface.mjs} +1 -1
  15. package/esm2020/lib/core/payment/finance-details/finance-details.class.mjs +35 -12
  16. package/esm2020/lib/core/payment/form/converters/converter.abstract.mjs +5 -7
  17. package/esm2020/lib/core/payment/form/converters/zip.converter.mjs +9 -5
  18. package/esm2020/lib/core/payment/form/mask-config.interface.mjs +2 -0
  19. package/esm2020/lib/core/payment/form/masks-functions.map.mjs +7 -0
  20. package/esm2020/lib/core/payment/form/validators/convert.function.mjs +3 -2
  21. package/esm2020/lib/core/payment/form/validators/email-validator.mjs +3 -2
  22. package/esm2020/lib/core/payment/form/validators/errors-codes.enum.mjs +8 -0
  23. package/esm2020/lib/core/payment/form/validators/required-validator.mjs +3 -2
  24. package/esm2020/lib/core/payment/form/validators/validation-error.interface.mjs +1 -1
  25. package/esm2020/lib/core/payment/payment.interface.mjs +1 -1
  26. package/esm2020/lib/core/payment/payment.service.mjs +23 -4
  27. package/esm2020/lib/core/payment/submit/response/is-submit-response.function.mjs +5 -0
  28. package/esm2020/lib/core/payment/sync/field-sync-state.interface.mjs +1 -1
  29. package/esm2020/lib/core/payment/sync/sync.service.mjs +14 -2
  30. package/esm2020/lib/core/payment/xps-purchase.interface.mjs +1 -1
  31. package/esm2020/lib/core-library.service.mjs +7 -2
  32. package/fesm2015/xsolla-payment-client-core.mjs +266 -152
  33. package/fesm2015/xsolla-payment-client-core.mjs.map +1 -1
  34. package/fesm2020/xsolla-payment-client-core.mjs +257 -147
  35. package/fesm2020/xsolla-payment-client-core.mjs.map +1 -1
  36. package/lib/core/payment/actions/action-factory-value.interface.d.ts +2 -1
  37. package/lib/core/payment/actions/next-action.interface.d.ts +2 -1
  38. package/lib/core/payment/actions/next-action.service.d.ts +2 -2
  39. package/lib/core/payment/actions/redirect/redirect.action.class.d.ts +9 -0
  40. package/lib/core/payment/actions/redirect/redirect.action.token.d.ts +4 -0
  41. package/lib/core/payment/actions/redirect/redirect.action.type.d.ts +17 -0
  42. package/lib/core/payment/finance-details/cart-item.interface.d.ts +1 -0
  43. package/lib/core/payment/finance-details/cart-line.interface.d.ts +1 -0
  44. package/lib/core/payment/finance-details/finance-details.class.d.ts +8 -4
  45. package/lib/core/payment/form/converters/converter.abstract.d.ts +1 -2
  46. package/lib/core/payment/form/mask-config.interface.d.ts +6 -0
  47. package/lib/core/payment/form/masks-functions.map.d.ts +3 -0
  48. package/lib/core/payment/form/validators/convert.function.d.ts +1 -1
  49. package/lib/core/payment/form/validators/errors-codes.enum.d.ts +6 -0
  50. package/lib/core/payment/form/validators/validation-error.interface.d.ts +1 -0
  51. package/lib/core/payment/payment.interface.d.ts +1 -2
  52. package/lib/core/payment/payment.service.d.ts +4 -5
  53. package/lib/core/payment/submit/response/is-submit-response.function.d.ts +2 -0
  54. package/lib/core/payment/sync/field-sync-state.interface.d.ts +2 -2
  55. package/lib/core/payment/sync/sync.service.d.ts +1 -0
  56. package/lib/core/payment/xps-purchase.interface.d.ts +0 -2
  57. package/lib/core-library.service.d.ts +2 -0
  58. package/package.json +1 -1
  59. package/xsolla-payment-client-core-0.0.12.tgz +0 -0
  60. package/esm2020/lib/core/payment/actions/action-type-command.map.mjs +0 -6
  61. package/esm2020/lib/core/payment/xps-subscription-item.interface.mjs +0 -2
  62. package/lib/core/payment/actions/action-type-command.map.d.ts +0 -4
  63. package/lib/core/payment/xps-subscription-item.interface.d.ts +0 -20
  64. package/xsolla-payment-client-core-0.0.10.tgz +0 -0
  65. /package/lib/core/payment/finance-details/{cart-pricing.interface.d.ts → cart-summary.interface.d.ts} +0 -0
@@ -8,6 +8,13 @@ import { UntypedFormGroup, Validators, UntypedFormControl, ReactiveFormsModule }
8
8
  import { filter, map as map$1, catchError } from 'rxjs/operators';
9
9
  import * as i1$1 from '@angular/router';
10
10
 
11
+ const masksFunctionsMap = {
12
+ zip: () => {
13
+ const zipLength = 5;
14
+ return new Array(zipLength).fill('9').join('');
15
+ },
16
+ };
17
+
11
18
  class AppError extends Error {
12
19
  constructor(message) {
13
20
  super(message);
@@ -425,6 +432,114 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
425
432
  }] }, { type: SettingsService }, { type: SecureApiClient }];
426
433
  } });
427
434
 
435
+ var XpsCommand;
436
+ (function (XpsCommand) {
437
+ XpsCommand["form"] = "form";
438
+ XpsCommand["check"] = "check";
439
+ XpsCommand["status"] = "status";
440
+ XpsCommand["checkout"] = "checkout";
441
+ XpsCommand["account"] = "account";
442
+ XpsCommand["create"] = "create";
443
+ })(XpsCommand || (XpsCommand = {}));
444
+
445
+ var FieldNames;
446
+ (function (FieldNames) {
447
+ FieldNames["address1"] = "address1";
448
+ FieldNames["address2"] = "address2";
449
+ FieldNames["address"] = "address";
450
+ FieldNames["allowRecurrentSubscription"] = "allowRecurrentSubscription";
451
+ FieldNames["allowSubscription"] = "allowSubscription";
452
+ FieldNames["apt"] = "apt";
453
+ FieldNames["availableCardTypes"] = "available_card_types";
454
+ FieldNames["bank"] = "bank";
455
+ FieldNames["birthDate"] = "birth_date";
456
+ FieldNames["cardMonth"] = "card_month";
457
+ FieldNames["cardYear"] = "card_year";
458
+ FieldNames["cardNumber"] = "card_number";
459
+ FieldNames["cardholdername"] = "cardholdername";
460
+ FieldNames["city"] = "city";
461
+ FieldNames["couponCode"] = "couponCode";
462
+ FieldNames["cpfName"] = "cpf_name";
463
+ FieldNames["cpfNumber"] = "cpf_number";
464
+ FieldNames["cvv"] = "cvv";
465
+ FieldNames["description"] = "description";
466
+ FieldNames["email"] = "email";
467
+ FieldNames["psEmail"] = "psEmail";
468
+ FieldNames["euCheck"] = "eu_check";
469
+ FieldNames["extraCvv"] = "extra_cvv";
470
+ FieldNames["extraCardNumber"] = "extra_card_number";
471
+ FieldNames["extraCardType"] = "extra_card_type";
472
+ FieldNames["fName"] = "f_name";
473
+ FieldNames["installments"] = "installments";
474
+ FieldNames["lName"] = "l_name";
475
+ FieldNames["needInstallments"] = "needInstallments";
476
+ FieldNames["personId"] = "person_id";
477
+ FieldNames["personIdAr"] = "person_id_ar";
478
+ FieldNames["personIdCo"] = "person_id_co";
479
+ FieldNames["phone"] = "phone";
480
+ FieldNames["purchaseDescription"] = "purchaseDescription";
481
+ FieldNames["recurrentType"] = "recurrent_type";
482
+ FieldNames["rockstarTaxes"] = "rockstar_taxes";
483
+ FieldNames["state"] = "state";
484
+ FieldNames["street"] = "street";
485
+ FieldNames["streetNumber"] = "street_number";
486
+ FieldNames["take2Taxes"] = "take2_taxes";
487
+ FieldNames["termsAndConditions"] = "termsAndConditions";
488
+ FieldNames["termsAndConditionsAtariPp"] = "termsAndConditionsAtariPP";
489
+ FieldNames["termsAndConditionsAtariTc"] = "termsAndConditionsAtariTC";
490
+ FieldNames["termsAndConditionsHtcEula"] = "termsAndConditionsHtcEula";
491
+ FieldNames["termsAndConditionsRobloxEula"] = "termsAndConditionsRobloxEula";
492
+ FieldNames["termsAndConditionsRolandEula"] = "termsAndConditionsRolandEula";
493
+ FieldNames["termsAndConditionsDeusLoVultEula"] = "termsAndConditionsDeusLoVultEula";
494
+ FieldNames["termsAndConditionsOnzenga"] = "termsAndConditionsOnzenga";
495
+ FieldNames["xsollaTipsAmount"] = "xsollaTipsAmount";
496
+ FieldNames["zip"] = "zip";
497
+ FieldNames["allowSave"] = "allowSave";
498
+ FieldNames["koreaLimitsInstruction"] = "korea_limits_instruction";
499
+ FieldNames["tokenApplePay"] = "token_applepay";
500
+ FieldNames["fixInvoice"] = "fix_invoice";
501
+ FieldNames["fixPid"] = "fix_pid";
502
+ FieldNames["signature"] = "signature";
503
+ FieldNames["qr"] = "qr";
504
+ FieldNames["sum"] = "sum";
505
+ FieldNames["out"] = "out";
506
+ FieldNames["tinkoffDisclaimer"] = "ps.tinkoff.disclaimer";
507
+ })(FieldNames || (FieldNames = {}));
508
+
509
+ class SubmitResponse {
510
+ constructor(parameters, responseNumber = 0) {
511
+ var _a, _b, _c;
512
+ this.responseNumber = responseNumber;
513
+ /* Todo split into properties */
514
+ this.parameters = parameters;
515
+ this.fields = Object.keys(parameters.form).map((key) => parameters.form[key]);
516
+ if (parameters.onlineBanking) {
517
+ this.onlineBanking = {
518
+ url: parameters.onlineBanking.value,
519
+ };
520
+ }
521
+ this.isNeedRedirect =
522
+ parameters.currentCommand === XpsCommand.account ||
523
+ (parameters.currentCommand === XpsCommand.checkout &&
524
+ Boolean(parameters.checkout));
525
+ this.buyData = parameters.buyData;
526
+ this.fixInvoice = (_a = this.fields.find((field) => field.name === FieldNames.fixInvoice)) === null || _a === void 0 ? void 0 : _a.value;
527
+ this.signature = (_b = this.fields.find((field) => field.name === FieldNames.signature)) === null || _b === void 0 ? void 0 : _b.value;
528
+ this.hasFatalErrors = (_c = parameters.textAll) === null || _c === void 0 ? void 0 : _c.fatal;
529
+ this.userSession = parameters.userSession;
530
+ this.pid = parameters.pid;
531
+ this.errors = parameters.errors;
532
+ this.summary = parameters.summary;
533
+ this.title = parameters.title;
534
+ this.currentCommand = parameters.currentCommand;
535
+ this.messages = parameters.messages;
536
+ }
537
+ }
538
+
539
+ const isSubmitResponse = (value) => {
540
+ return value instanceof SubmitResponse;
541
+ };
542
+
428
543
  class InitializeResponse {
429
544
  constructor(response) {
430
545
  this.paymentForm = null;
@@ -561,110 +676,6 @@ const submitRequestFactoryProvider = {
561
676
  useValue: (...args) => new SubmitRequest(...args),
562
677
  };
563
678
 
564
- var XpsCommand;
565
- (function (XpsCommand) {
566
- XpsCommand["form"] = "form";
567
- XpsCommand["check"] = "check";
568
- XpsCommand["status"] = "status";
569
- XpsCommand["checkout"] = "checkout";
570
- XpsCommand["account"] = "account";
571
- XpsCommand["create"] = "create";
572
- })(XpsCommand || (XpsCommand = {}));
573
-
574
- var FieldNames;
575
- (function (FieldNames) {
576
- FieldNames["address1"] = "address1";
577
- FieldNames["address2"] = "address2";
578
- FieldNames["address"] = "address";
579
- FieldNames["allowRecurrentSubscription"] = "allowRecurrentSubscription";
580
- FieldNames["allowSubscription"] = "allowSubscription";
581
- FieldNames["apt"] = "apt";
582
- FieldNames["availableCardTypes"] = "available_card_types";
583
- FieldNames["bank"] = "bank";
584
- FieldNames["birthDate"] = "birth_date";
585
- FieldNames["cardMonth"] = "card_month";
586
- FieldNames["cardYear"] = "card_year";
587
- FieldNames["cardNumber"] = "card_number";
588
- FieldNames["cardholdername"] = "cardholdername";
589
- FieldNames["city"] = "city";
590
- FieldNames["couponCode"] = "couponCode";
591
- FieldNames["cpfName"] = "cpf_name";
592
- FieldNames["cpfNumber"] = "cpf_number";
593
- FieldNames["cvv"] = "cvv";
594
- FieldNames["description"] = "description";
595
- FieldNames["email"] = "email";
596
- FieldNames["psEmail"] = "psEmail";
597
- FieldNames["euCheck"] = "eu_check";
598
- FieldNames["extraCvv"] = "extra_cvv";
599
- FieldNames["extraCardNumber"] = "extra_card_number";
600
- FieldNames["extraCardType"] = "extra_card_type";
601
- FieldNames["fName"] = "f_name";
602
- FieldNames["installments"] = "installments";
603
- FieldNames["lName"] = "l_name";
604
- FieldNames["needInstallments"] = "needInstallments";
605
- FieldNames["personId"] = "person_id";
606
- FieldNames["personIdAr"] = "person_id_ar";
607
- FieldNames["personIdCo"] = "person_id_co";
608
- FieldNames["phone"] = "phone";
609
- FieldNames["purchaseDescription"] = "purchaseDescription";
610
- FieldNames["recurrentType"] = "recurrent_type";
611
- FieldNames["rockstarTaxes"] = "rockstar_taxes";
612
- FieldNames["state"] = "state";
613
- FieldNames["street"] = "street";
614
- FieldNames["streetNumber"] = "street_number";
615
- FieldNames["take2Taxes"] = "take2_taxes";
616
- FieldNames["termsAndConditions"] = "termsAndConditions";
617
- FieldNames["termsAndConditionsAtariPp"] = "termsAndConditionsAtariPP";
618
- FieldNames["termsAndConditionsAtariTc"] = "termsAndConditionsAtariTC";
619
- FieldNames["termsAndConditionsHtcEula"] = "termsAndConditionsHtcEula";
620
- FieldNames["termsAndConditionsRobloxEula"] = "termsAndConditionsRobloxEula";
621
- FieldNames["termsAndConditionsRolandEula"] = "termsAndConditionsRolandEula";
622
- FieldNames["termsAndConditionsDeusLoVultEula"] = "termsAndConditionsDeusLoVultEula";
623
- FieldNames["termsAndConditionsOnzenga"] = "termsAndConditionsOnzenga";
624
- FieldNames["xsollaTipsAmount"] = "xsollaTipsAmount";
625
- FieldNames["zip"] = "zip";
626
- FieldNames["allowSave"] = "allowSave";
627
- FieldNames["koreaLimitsInstruction"] = "korea_limits_instruction";
628
- FieldNames["tokenApplePay"] = "token_applepay";
629
- FieldNames["fixInvoice"] = "fix_invoice";
630
- FieldNames["fixPid"] = "fix_pid";
631
- FieldNames["signature"] = "signature";
632
- FieldNames["qr"] = "qr";
633
- FieldNames["sum"] = "sum";
634
- FieldNames["out"] = "out";
635
- FieldNames["tinkoffDisclaimer"] = "ps.tinkoff.disclaimer";
636
- })(FieldNames || (FieldNames = {}));
637
-
638
- class SubmitResponse {
639
- constructor(parameters, responseNumber = 0) {
640
- var _a, _b, _c;
641
- this.responseNumber = responseNumber;
642
- /* Todo split into properties */
643
- this.parameters = parameters;
644
- this.fields = Object.keys(parameters.form).map((key) => parameters.form[key]);
645
- if (parameters.onlineBanking) {
646
- this.onlineBanking = {
647
- url: parameters.onlineBanking.value,
648
- };
649
- }
650
- this.isNeedRedirect =
651
- parameters.currentCommand === XpsCommand.account ||
652
- (parameters.currentCommand === XpsCommand.checkout &&
653
- Boolean(parameters.checkout));
654
- this.buyData = parameters.buyData;
655
- this.fixInvoice = (_a = this.fields.find((field) => field.name === FieldNames.fixInvoice)) === null || _a === void 0 ? void 0 : _a.value;
656
- this.signature = (_b = this.fields.find((field) => field.name === FieldNames.signature)) === null || _b === void 0 ? void 0 : _b.value;
657
- this.hasFatalErrors = (_c = parameters.textAll) === null || _c === void 0 ? void 0 : _c.fatal;
658
- this.userSession = parameters.userSession;
659
- this.pid = parameters.pid;
660
- this.errors = parameters.errors;
661
- this.summary = parameters.summary;
662
- this.title = parameters.title;
663
- this.currentCommand = parameters.currentCommand;
664
- this.messages = parameters.messages;
665
- }
666
- }
667
-
668
679
  const submitResponseFactoryToken = new InjectionToken('SubmitResponse');
669
680
  const submitResponseFactoryProvider = {
670
681
  provide: submitResponseFactoryToken,
@@ -1021,7 +1032,10 @@ class SyncService extends EmitDataService {
1021
1032
  return Promise.resolve(null);
1022
1033
  }
1023
1034
  if (prevFieldState && value === prevFieldState.value) {
1024
- return Promise.resolve(prevFieldState.result);
1035
+ return Promise.resolve(prevFieldState.result).then((response) => {
1036
+ var _a;
1037
+ return (_a = response === null || response === void 0 ? void 0 : response.rewritableError) !== null && _a !== void 0 ? _a : null;
1038
+ });
1025
1039
  }
1026
1040
  const requestPromise = this.request(field);
1027
1041
  this.setPrevFieldSyncState(field, value, requestPromise);
@@ -1031,6 +1045,17 @@ class SyncService extends EmitDataService {
1031
1045
  });
1032
1046
  });
1033
1047
  }
1048
+ getSyncValidationErrors(field) {
1049
+ var _a;
1050
+ const control = this.form.get(field.name);
1051
+ if (!control) {
1052
+ return null;
1053
+ }
1054
+ const rewritableError = (_a = control.errors) === null || _a === void 0 ? void 0 : _a.rewritableError;
1055
+ return rewritableError
1056
+ ? { message: rewritableError.message, code: rewritableError.code }
1057
+ : null;
1058
+ }
1034
1059
  request(field) {
1035
1060
  return __awaiter(this, void 0, void 0, function* () {
1036
1061
  const requestParams = this.requestFactory({
@@ -1091,7 +1116,7 @@ class TextControlConfig extends ControlConfig {
1091
1116
  }
1092
1117
  }
1093
1118
 
1094
- function convert(validator, message) {
1119
+ function convert(validator, message, errorCode) {
1095
1120
  return (control) => {
1096
1121
  const errors = validator(control);
1097
1122
  if (!errors) {
@@ -1102,6 +1127,7 @@ function convert(validator, message) {
1102
1127
  error = typeof error === 'object' && error !== null ? error : {};
1103
1128
  const rewritableError = Object.assign({}, error);
1104
1129
  rewritableError.message = message;
1130
+ rewritableError.code = errorCode;
1105
1131
  if (error[firstErrorKey] != null) {
1106
1132
  rewritableError.value = error[firstErrorKey];
1107
1133
  }
@@ -1113,13 +1139,21 @@ function convert(validator, message) {
1113
1139
  };
1114
1140
  }
1115
1141
 
1142
+ var ErrorsCodes;
1143
+ (function (ErrorsCodes) {
1144
+ ErrorsCodes["minLength"] = "min-length";
1145
+ ErrorsCodes["maxLength"] = "max-length";
1146
+ ErrorsCodes["invalidValue"] = "invalid-value";
1147
+ ErrorsCodes["required"] = "required";
1148
+ })(ErrorsCodes || (ErrorsCodes = {}));
1149
+
1116
1150
  const emailRegexp = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i; // eslint-disable-line
1117
1151
  function emailValidator() {
1118
- return convert(Validators.pattern(emailRegexp), 'Enter a valid email');
1152
+ return convert(Validators.pattern(emailRegexp), 'Enter a valid email', ErrorsCodes.invalidValue);
1119
1153
  }
1120
1154
 
1121
1155
  function requiredValidator() {
1122
- return convert(Validators.required, 'Required');
1156
+ return convert(Validators.required, 'Required', ErrorsCodes.required);
1123
1157
  }
1124
1158
 
1125
1159
  class Converter {
@@ -1134,7 +1168,7 @@ class Converter {
1134
1168
  return config;
1135
1169
  }
1136
1170
  convertToFormControl(field) {
1137
- return new UntypedFormControl(this.getValue(field), this.getValidators(field), this.getAsyncValidators(field));
1171
+ return new UntypedFormControl(this.getValue(field), this.getValidators(field));
1138
1172
  }
1139
1173
  getValidators(field) {
1140
1174
  const validators = [];
@@ -1148,14 +1182,11 @@ class Converter {
1148
1182
  const errorMessage = field.validation_error_msg
1149
1183
  ? field.validation_error_msg
1150
1184
  : 'Enter valid data';
1151
- validators.push(convert(Validators.pattern(pattern), errorMessage));
1185
+ validators.push(convert(Validators.pattern(pattern), errorMessage, ErrorsCodes.invalidValue));
1152
1186
  }
1153
1187
  }
1154
1188
  return validators;
1155
1189
  }
1156
- getAsyncValidators(field) {
1157
- return () => __awaiter(this, void 0, void 0, function* () { return this.syncService.validate(field); });
1158
- }
1159
1190
  createDefaultControlConfig(controlConfigClass, field) {
1160
1191
  const config = new controlConfigClass();
1161
1192
  this.copyCommonOptions(config, field);
@@ -1240,11 +1271,11 @@ class ZipConverter extends Converter {
1240
1271
  const validators = super
1241
1272
  .getValidators(field)
1242
1273
  .concat([
1243
- convert(Validators.minLength(minLength), 'Enter at least ${minLength} characters'),
1244
- convert(Validators.maxLength(maxLength), 'Enter no more than ${maxLength} characters'),
1274
+ convert(Validators.minLength(minLength), `Enter at least ${minLength} characters`, ErrorsCodes.minLength),
1275
+ convert(Validators.maxLength(maxLength), `Enter no more than ${maxLength} characters`, ErrorsCodes.maxLength),
1245
1276
  ]);
1246
1277
  if (this.isUsCountry) {
1247
- validators.push(convert(restrictedValueValidator('00000'), 'Enter a valid ZIP code'));
1278
+ validators.push(convert(restrictedValueValidator('00000'), 'Enter a valid ZIP code', ErrorsCodes.invalidValue));
1248
1279
  }
1249
1280
  return validators;
1250
1281
  }
@@ -1253,12 +1284,14 @@ class ZipConverter extends Converter {
1253
1284
  config.icon = 'location';
1254
1285
  if (this.isUsCountry) {
1255
1286
  config.maskConfig = {
1256
- mask: () => new Array(this.usCountryLength).fill('9').join(''),
1257
1287
  guide: false,
1258
1288
  unmaskModelValue: true,
1259
1289
  showMask: true,
1260
1290
  };
1261
1291
  config.inputMode = 'numeric';
1292
+ if (masksFunctionsMap['zip']) {
1293
+ config.maskConfig.mask = masksFunctionsMap['zip'];
1294
+ }
1262
1295
  }
1263
1296
  else {
1264
1297
  config.maxLength = this.maxLength;
@@ -2372,7 +2405,7 @@ class ShowFieldsAction {
2372
2405
  messages: [],
2373
2406
  order: {},
2374
2407
  };
2375
- this.data.fields = submitResponse.fields;
2408
+ this.data.fields = submitResponse.fields.filter((field) => (field === null || field === void 0 ? void 0 : field.isVisible) === "1" /* XpsBoolean.true */);
2376
2409
  this.data.errors = submitResponse.errors;
2377
2410
  this.data.messages = submitResponse.messages;
2378
2411
  this.data.order = submitResponse.summary;
@@ -2384,7 +2417,9 @@ const showFieldsActionFactoryProvider = {
2384
2417
  provide: showFieldsActionFactoryToken,
2385
2418
  useValue: {
2386
2419
  factory: (...args) => new ShowFieldsAction(...args),
2387
- type: 'show_fields',
2420
+ isSuitable: (response) => {
2421
+ return response.currentCommand === XpsCommand.check;
2422
+ },
2388
2423
  },
2389
2424
  };
2390
2425
 
@@ -2410,7 +2445,9 @@ const checkStatusActionFactoryProvider = {
2410
2445
  provide: checkStatusActionFactoryToken,
2411
2446
  useValue: {
2412
2447
  factory: (...args) => new CheckStatusAction(...args),
2413
- type: 'check_status',
2448
+ isSuitable: (response) => {
2449
+ return response.currentCommand === XpsCommand.status;
2450
+ },
2414
2451
  },
2415
2452
  };
2416
2453
 
@@ -2419,7 +2456,40 @@ const statusUpdatedActionFactoryProvider = {
2419
2456
  provide: statusUpdatedActionFactoryToken,
2420
2457
  useValue: {
2421
2458
  factory: (...args) => new StatusUpdatedAction(...args),
2422
- type: 'status_updated',
2459
+ isSuitable: () => false,
2460
+ },
2461
+ };
2462
+
2463
+ class RedirectAction {
2464
+ constructor(submitResponse) {
2465
+ this.type = 'redirect';
2466
+ this.data = {
2467
+ fields: submitResponse.fields,
2468
+ errors: submitResponse.errors,
2469
+ messages: submitResponse.messages,
2470
+ order: submitResponse.summary,
2471
+ invoiceId: submitResponse.fixInvoice,
2472
+ redirect: this.getRedirect(submitResponse),
2473
+ };
2474
+ }
2475
+ getRedirect(submitResponse) {
2476
+ return {
2477
+ redirectUrl: submitResponse.parameters.checkout.action,
2478
+ data: submitResponse.parameters.checkout.data,
2479
+ };
2480
+ }
2481
+ }
2482
+
2483
+ const redirectActionFactoryToken = new InjectionToken('RedirectAction');
2484
+ const redirectActionFactoryProvider = {
2485
+ provide: redirectActionFactoryToken,
2486
+ useValue: {
2487
+ factory: (...args) => new RedirectAction(...args),
2488
+ isSuitable: (response) => {
2489
+ return (response.currentCommand === XpsCommand.account ||
2490
+ (response.currentCommand === XpsCommand.checkout &&
2491
+ Boolean(response.parameters.checkout)));
2492
+ },
2423
2493
  },
2424
2494
  };
2425
2495
 
@@ -2428,13 +2498,9 @@ const nextActions = [
2428
2498
  showFieldsActionFactoryProvider,
2429
2499
  checkStatusActionFactoryProvider,
2430
2500
  statusUpdatedActionFactoryProvider,
2501
+ redirectActionFactoryProvider,
2431
2502
  ];
2432
2503
 
2433
- const actionTypeCommandMap = {
2434
- [XpsCommand.check]: 'show_fields',
2435
- [XpsCommand.status]: 'check_status',
2436
- };
2437
-
2438
2504
  class NextActionService {
2439
2505
  get flowUpdates$() {
2440
2506
  return this.flowUpdatesSubject.asObservable();
@@ -2443,14 +2509,14 @@ class NextActionService {
2443
2509
  this.nextActionTokens = nextActionTokens;
2444
2510
  this.injector = injector;
2445
2511
  this.flowUpdatesSubject = new Subject();
2446
- this.nextActionsMap = new Map();
2447
- this.fillNextActionsMap();
2512
+ this.nextActionsList = [];
2513
+ this.fillNextActionsList();
2448
2514
  }
2449
2515
  getNextAction(submitResponse) {
2450
2516
  if (!submitResponse.currentCommand) {
2451
2517
  return null;
2452
2518
  }
2453
- const nextActionFactory = this.findNextAction(submitResponse.currentCommand);
2519
+ const nextActionFactory = this.findNextAction(submitResponse);
2454
2520
  if (nextActionFactory) {
2455
2521
  return nextActionFactory(submitResponse);
2456
2522
  }
@@ -2459,18 +2525,20 @@ class NextActionService {
2459
2525
  emitFlowUpdates(action) {
2460
2526
  this.flowUpdatesSubject.next(action);
2461
2527
  }
2462
- fillNextActionsMap() {
2528
+ fillNextActionsList() {
2463
2529
  this.nextActionTokens.forEach((nextAction) => {
2464
2530
  const item = this.injector.get(nextAction.provide);
2465
- this.nextActionsMap.set(item.type, item.factory);
2531
+ this.nextActionsList.push(item);
2466
2532
  });
2467
2533
  }
2468
- findNextAction(command) {
2469
- const actionType = actionTypeCommandMap[command];
2534
+ findNextAction(submitResponse) {
2535
+ const actionType = this.nextActionsList.find((nextAction) => {
2536
+ return nextAction.isSuitable(submitResponse);
2537
+ });
2470
2538
  if (!actionType) {
2471
2539
  return;
2472
2540
  }
2473
- return this.nextActionsMap.get(actionType);
2541
+ return actionType.factory;
2474
2542
  }
2475
2543
  }
2476
2544
  NextActionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: NextActionService, deps: [{ token: nextActionsToken }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
@@ -2558,6 +2626,9 @@ class FinanceDetails {
2558
2626
  constructor(parameters) {
2559
2627
  this.purchase = parameters.purchase;
2560
2628
  this.finance = parameters.finance;
2629
+ this.cartItems = this.getFormattedPurchaseForCart();
2630
+ this.cartSummary = this.getFormattedPricingForCart();
2631
+ this.paymentCountry = this.getPaymentCountry();
2561
2632
  }
2562
2633
  getFormattedPurchaseForCart() {
2563
2634
  var _a, _b, _c, _d;
@@ -2599,9 +2670,8 @@ class FinanceDetails {
2599
2670
  if (this.purchase.checkout) {
2600
2671
  checkoutArray = [
2601
2672
  {
2602
- title: this.purchase.checkout.description
2603
- ? this.purchase.checkout.description
2604
- : 'In-game purchase',
2673
+ key: 'checkout',
2674
+ title: this.purchase.checkout.description,
2605
2675
  price: extractMoneyCurrency(this.purchase.checkout),
2606
2676
  isBonus: (_d = this.purchase.checkout.is_bonus) !== null && _d !== void 0 ? _d : false,
2607
2677
  },
@@ -2619,14 +2689,17 @@ class FinanceDetails {
2619
2689
  const subtotalDetailsSorting = [
2620
2690
  {
2621
2691
  key: 'discount',
2692
+ responseKey: 'discount',
2622
2693
  title: 'Discount',
2623
2694
  },
2624
2695
  {
2625
2696
  key: 'fee',
2697
+ responseKey: 'fee',
2626
2698
  title: 'Payment system fee',
2627
2699
  },
2628
2700
  {
2629
- key: 'user_balance',
2701
+ key: 'user-balance',
2702
+ responseKey: 'user_balance',
2630
2703
  title: 'Balance',
2631
2704
  },
2632
2705
  ];
@@ -2646,14 +2719,18 @@ class FinanceDetails {
2646
2719
  totalDetails: this.getTaxesForTotalDetails(),
2647
2720
  subtotalDetails: [
2648
2721
  ...subtotalDetailsSorting.map((sorting) => {
2649
- const field = this.finance[sorting.key];
2722
+ const field = this.finance[sorting.responseKey];
2650
2723
  if (field) {
2651
- return Object.assign(Object.assign({}, sorting), { money: {
2724
+ return {
2725
+ key: sorting.key,
2726
+ title: sorting.title,
2727
+ money: {
2652
2728
  amount: sorting.key === 'discount' && field.amount
2653
2729
  ? -field.amount
2654
2730
  : field.amount,
2655
2731
  currency: field.currency,
2656
- } });
2732
+ },
2733
+ };
2657
2734
  }
2658
2735
  return sorting;
2659
2736
  }),
@@ -2662,29 +2739,36 @@ class FinanceDetails {
2662
2739
  };
2663
2740
  }
2664
2741
  getPaymentCountry() {
2665
- var _a;
2666
- return (_a = this.finance) === null || _a === void 0 ? void 0 : _a.payment_country.iso;
2742
+ return this.finance.payment_country.iso;
2667
2743
  }
2668
2744
  getTaxForItem(indirectTaxRate) {
2669
2745
  if (indirectTaxRate ||
2670
2746
  (this.shouldShowZeroIndirectTaxRate && indirectTaxRate === 0)) {
2671
2747
  if (this.isSalesTaxes) {
2672
2748
  return {
2749
+ key: 'sales-tax',
2673
2750
  content: `Sales tax ${indirectTaxRate}%`,
2751
+ rate: indirectTaxRate,
2674
2752
  };
2675
2753
  }
2676
2754
  if (this.isIndia()) {
2677
2755
  return {
2756
+ key: 'vat-india',
2678
2757
  content: `GST ${indirectTaxRate}%`,
2758
+ rate: indirectTaxRate,
2679
2759
  };
2680
2760
  }
2681
2761
  if (this.isGhana()) {
2682
2762
  return {
2763
+ key: 'vat-ghana',
2683
2764
  content: 'VAT, NHIL, GETFund Levy, and Covid-19 Levy',
2765
+ rate: indirectTaxRate,
2684
2766
  };
2685
2767
  }
2686
2768
  return {
2769
+ key: 'vat',
2687
2770
  content: `VAT ${indirectTaxRate}%`,
2771
+ rate: indirectTaxRate,
2688
2772
  };
2689
2773
  }
2690
2774
  return null;
@@ -2696,14 +2780,14 @@ class FinanceDetails {
2696
2780
  if (this.finance.vat_user &&
2697
2781
  ((_c = (_b = (_a = this.finance) === null || _a === void 0 ? void 0 : _a.vat_user) === null || _b === void 0 ? void 0 : _b.amount) !== null && _c !== void 0 ? _c : (_e = (_d = this.finance) === null || _d === void 0 ? void 0 : _d.vat_user) === null || _e === void 0 ? void 0 : _e.visible)) {
2698
2782
  ret.push({
2699
- key: 'vat_user',
2783
+ key: this.getVatKeyForDetails(),
2700
2784
  title: this.getVatLabelForSubtotalDetails(),
2701
2785
  money: extractMoneyCurrency(this.finance.vat_user),
2702
2786
  });
2703
2787
  }
2704
2788
  if ((_f = this.finance.sales_tax_user) === null || _f === void 0 ? void 0 : _f.amount) {
2705
2789
  ret.push({
2706
- key: 'sales_tax_user',
2790
+ key: 'sales-tax',
2707
2791
  title: 'Sales tax',
2708
2792
  money: extractMoneyCurrency(this.finance.sales_tax_user),
2709
2793
  });
@@ -2727,7 +2811,7 @@ class FinanceDetails {
2727
2811
  if ((((_b = (_a = this.finance) === null || _a === void 0 ? void 0 : _a.vat) === null || _b === void 0 ? void 0 : _b.amount) || ((_d = (_c = this.finance) === null || _c === void 0 ? void 0 : _c.vat) === null || _d === void 0 ? void 0 : _d.visible)) &&
2728
2812
  !((_f = (_e = this.finance) === null || _e === void 0 ? void 0 : _e.vat_user) === null || _f === void 0 ? void 0 : _f.amount)) {
2729
2813
  ret.push({
2730
- key: 'vat',
2814
+ key: this.getVatKeyForDetails(),
2731
2815
  title: this.getVatLabelForTotalDetails(),
2732
2816
  money: extractMoneyCurrency(this.finance.vat),
2733
2817
  });
@@ -2735,13 +2819,22 @@ class FinanceDetails {
2735
2819
  if (((_h = (_g = this.finance) === null || _g === void 0 ? void 0 : _g.sales_tax) === null || _h === void 0 ? void 0 : _h.amount) &&
2736
2820
  !((_k = (_j = this.finance) === null || _j === void 0 ? void 0 : _j.sales_tax_user) === null || _k === void 0 ? void 0 : _k.amount)) {
2737
2821
  ret.push({
2738
- key: 'sales_tax',
2822
+ key: 'sales-tax',
2739
2823
  title: 'Sales tax included',
2740
2824
  money: extractMoneyCurrency(this.finance.sales_tax),
2741
2825
  });
2742
2826
  }
2743
2827
  return ret;
2744
2828
  }
2829
+ getVatKeyForDetails() {
2830
+ if (this.isIndia()) {
2831
+ return 'vat-india';
2832
+ }
2833
+ if (this.isGhana()) {
2834
+ return 'vat-ghana';
2835
+ }
2836
+ return 'vat';
2837
+ }
2745
2838
  getVatLabelForTotalDetails() {
2746
2839
  if (this.isIndia()) {
2747
2840
  return `Including ${this.finance.vat.percent}% GST`;
@@ -2820,7 +2913,7 @@ class PaymentService {
2820
2913
  this.form = this.formService.createForm(this.fields);
2821
2914
  this.emitFinanceDetails((_a = this.data.paymentForm) === null || _a === void 0 ? void 0 : _a.summary);
2822
2915
  this.setupSyncService(this.form, this.fields);
2823
- return this.fields;
2916
+ return this.fields.filter((field) => (field === null || field === void 0 ? void 0 : field.isVisible) === "1" /* XpsBoolean.true */);
2824
2917
  });
2825
2918
  }
2826
2919
  submit() {
@@ -2829,16 +2922,24 @@ class PaymentService {
2829
2922
  throw new Error('form is empty!');
2830
2923
  }
2831
2924
  const submitResponse = yield this.submitService.request(this.fields, this.form);
2925
+ this.data = submitResponse;
2832
2926
  this.emitFinanceDetails(submitResponse.summary);
2833
2927
  return this.nextActionService.getNextAction(submitResponse);
2834
2928
  });
2835
2929
  }
2836
2930
  getFields() {
2837
- var _a, _b, _c;
2838
- return (_c = (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.paymentForm) === null || _b === void 0 ? void 0 : _b.fields) !== null && _c !== void 0 ? _c : [];
2931
+ var _a, _b, _c, _d;
2932
+ if (this.data instanceof SubmitResponse) {
2933
+ return (_a = this.data.fields) !== null && _a !== void 0 ? _a : [];
2934
+ }
2935
+ return (_d = (_c = (_b = this.data) === null || _b === void 0 ? void 0 : _b.paymentForm) === null || _c === void 0 ? void 0 : _c.fields) !== null && _d !== void 0 ? _d : [];
2839
2936
  }
2840
2937
  validate(field) {
2841
2938
  return __awaiter(this, void 0, void 0, function* () {
2939
+ const syncErrors = this.syncService.getSyncValidationErrors(field);
2940
+ if (syncErrors) {
2941
+ return Promise.resolve(syncErrors);
2942
+ }
2842
2943
  return this.syncService.validate(field);
2843
2944
  });
2844
2945
  }
@@ -2848,8 +2949,17 @@ class PaymentService {
2848
2949
  getFinanceDetails() {
2849
2950
  return this.financeDetails;
2850
2951
  }
2851
- getStatus(params) {
2952
+ getStatus() {
2953
+ var _a, _b, _c, _d;
2852
2954
  return __awaiter(this, void 0, void 0, function* () {
2955
+ if (!isSubmitResponse(this.data)) {
2956
+ throw new Error('Should submit form first');
2957
+ }
2958
+ const params = {
2959
+ invoice: parseInt((_a = this.data.fixInvoice) !== null && _a !== void 0 ? _a : ''),
2960
+ signature: (_b = this.data.signature) !== null && _b !== void 0 ? _b : '',
2961
+ locale: (_d = (_c = this.data.fields.find((field) => field.name === 'locale')) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 'en',
2962
+ };
2853
2963
  return this.statusService.getStatus(Object.assign(Object.assign({}, params), { pid: this.config.paymentMethodId }));
2854
2964
  });
2855
2965
  }
@@ -3033,7 +3143,7 @@ class CoreLibraryService {
3033
3143
  validate: (field) => __awaiter(this, void 0, void 0, function* () { return this.paymentService.validate(field); }),
3034
3144
  getFinanceDetails: () => this.paymentService.getFinanceDetails(),
3035
3145
  runThreeDs: () => this.paymentService.runThreeDs(),
3036
- getStatus: (params) => __awaiter(this, void 0, void 0, function* () { return this.paymentService.getStatus(params); }),
3146
+ getStatus: () => __awaiter(this, void 0, void 0, function* () { return this.paymentService.getStatus(); }),
3037
3147
  flowUpdates$: this.nextActionService.flowUpdates$,
3038
3148
  financeDetailsUpdates$: this.financeDetailsService.data$,
3039
3149
  form: {
@@ -3045,6 +3155,10 @@ class CoreLibraryService {
3045
3155
  getLegalComponentConfig() {
3046
3156
  return this.legalService.getLegalComponentConfig();
3047
3157
  }
3158
+ getFieldMask(field) {
3159
+ const sanitizedName = field.name.replace(/^fix_/i, '');
3160
+ return masksFunctionsMap[sanitizedName];
3161
+ }
3048
3162
  }
3049
3163
  CoreLibraryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, deps: [{ token: SettingsService }, { token: CountryService }, { token: PaymentMethodsService }, { token: SavedMethodsService }, { token: UserBalanceService }, { token: PaymentService }, { token: DeviceFingerPrintService }, { token: FinanceDetailsService }, { token: LegalService }, { token: NextActionService }], target: i0.ɵɵFactoryTarget.Injectable });
3050
3164
  CoreLibraryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, providedIn: 'root' });