@xsolla/payment-client-core 0.0.10-6 → 0.0.11

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 (49) 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/form/converters/converter.abstract.mjs +4 -3
  13. package/esm2020/lib/core/payment/form/converters/zip.converter.mjs +6 -15
  14. package/esm2020/lib/core/payment/form/mask-config.interface.mjs +2 -0
  15. package/esm2020/lib/core/payment/form/masks-functions.map.mjs +5 -2
  16. package/esm2020/lib/core/payment/form/validators/convert.function.mjs +3 -2
  17. package/esm2020/lib/core/payment/form/validators/email-validator.mjs +3 -2
  18. package/esm2020/lib/core/payment/form/validators/errors-codes.enum.mjs +8 -0
  19. package/esm2020/lib/core/payment/form/validators/required-validator.mjs +3 -2
  20. package/esm2020/lib/core/payment/form/validators/validation-error.interface.mjs +1 -1
  21. package/esm2020/lib/core/payment/payment.interface.mjs +1 -1
  22. package/esm2020/lib/core/payment/payment.service.mjs +19 -4
  23. package/esm2020/lib/core/payment/submit/response/is-submit-response.function.mjs +5 -0
  24. package/esm2020/lib/core/payment/sync/field-sync-state.interface.mjs +1 -1
  25. package/esm2020/lib/core/payment/sync/sync.service.mjs +4 -2
  26. package/esm2020/lib/core-library.service.mjs +3 -3
  27. package/fesm2015/xsolla-payment-client-core.mjs +201 -145
  28. package/fesm2015/xsolla-payment-client-core.mjs.map +1 -1
  29. package/fesm2020/xsolla-payment-client-core.mjs +198 -142
  30. package/fesm2020/xsolla-payment-client-core.mjs.map +1 -1
  31. package/lib/core/payment/actions/action-factory-value.interface.d.ts +2 -1
  32. package/lib/core/payment/actions/next-action.interface.d.ts +2 -1
  33. package/lib/core/payment/actions/next-action.service.d.ts +2 -2
  34. package/lib/core/payment/actions/redirect/redirect.action.class.d.ts +9 -0
  35. package/lib/core/payment/actions/redirect/redirect.action.token.d.ts +4 -0
  36. package/lib/core/payment/actions/redirect/redirect.action.type.d.ts +17 -0
  37. package/lib/core/payment/form/mask-config.interface.d.ts +6 -0
  38. package/lib/core/payment/form/validators/convert.function.d.ts +1 -1
  39. package/lib/core/payment/form/validators/errors-codes.enum.d.ts +6 -0
  40. package/lib/core/payment/form/validators/validation-error.interface.d.ts +1 -0
  41. package/lib/core/payment/payment.interface.d.ts +1 -2
  42. package/lib/core/payment/payment.service.d.ts +4 -5
  43. package/lib/core/payment/submit/response/is-submit-response.function.d.ts +2 -0
  44. package/lib/core/payment/sync/field-sync-state.interface.d.ts +2 -2
  45. package/package.json +1 -1
  46. package/xsolla-payment-client-core-0.0.11.tgz +0 -0
  47. package/esm2020/lib/core/payment/actions/action-type-command.map.mjs +0 -6
  48. package/lib/core/payment/actions/action-type-command.map.d.ts +0 -4
  49. package/xsolla-payment-client-core-0.0.10-6.tgz +0 -0
@@ -8,7 +8,10 @@ import { filter, map as map$1, catchError } from 'rxjs/operators';
8
8
  import * as i1$1 from '@angular/router';
9
9
 
10
10
  const masksFunctionsMap = {
11
- zip: () => new Array(5).fill('9').join(''),
11
+ zip: () => {
12
+ const zipLength = 5;
13
+ return new Array(zipLength).fill('9').join('');
14
+ },
12
15
  };
13
16
 
14
17
  class AppError extends Error {
@@ -402,6 +405,113 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
402
405
  args: [userBalanceResponseFactoryToken]
403
406
  }] }, { type: SettingsService }, { type: SecureApiClient }]; } });
404
407
 
408
+ var XpsCommand;
409
+ (function (XpsCommand) {
410
+ XpsCommand["form"] = "form";
411
+ XpsCommand["check"] = "check";
412
+ XpsCommand["status"] = "status";
413
+ XpsCommand["checkout"] = "checkout";
414
+ XpsCommand["account"] = "account";
415
+ XpsCommand["create"] = "create";
416
+ })(XpsCommand || (XpsCommand = {}));
417
+
418
+ var FieldNames;
419
+ (function (FieldNames) {
420
+ FieldNames["address1"] = "address1";
421
+ FieldNames["address2"] = "address2";
422
+ FieldNames["address"] = "address";
423
+ FieldNames["allowRecurrentSubscription"] = "allowRecurrentSubscription";
424
+ FieldNames["allowSubscription"] = "allowSubscription";
425
+ FieldNames["apt"] = "apt";
426
+ FieldNames["availableCardTypes"] = "available_card_types";
427
+ FieldNames["bank"] = "bank";
428
+ FieldNames["birthDate"] = "birth_date";
429
+ FieldNames["cardMonth"] = "card_month";
430
+ FieldNames["cardYear"] = "card_year";
431
+ FieldNames["cardNumber"] = "card_number";
432
+ FieldNames["cardholdername"] = "cardholdername";
433
+ FieldNames["city"] = "city";
434
+ FieldNames["couponCode"] = "couponCode";
435
+ FieldNames["cpfName"] = "cpf_name";
436
+ FieldNames["cpfNumber"] = "cpf_number";
437
+ FieldNames["cvv"] = "cvv";
438
+ FieldNames["description"] = "description";
439
+ FieldNames["email"] = "email";
440
+ FieldNames["psEmail"] = "psEmail";
441
+ FieldNames["euCheck"] = "eu_check";
442
+ FieldNames["extraCvv"] = "extra_cvv";
443
+ FieldNames["extraCardNumber"] = "extra_card_number";
444
+ FieldNames["extraCardType"] = "extra_card_type";
445
+ FieldNames["fName"] = "f_name";
446
+ FieldNames["installments"] = "installments";
447
+ FieldNames["lName"] = "l_name";
448
+ FieldNames["needInstallments"] = "needInstallments";
449
+ FieldNames["personId"] = "person_id";
450
+ FieldNames["personIdAr"] = "person_id_ar";
451
+ FieldNames["personIdCo"] = "person_id_co";
452
+ FieldNames["phone"] = "phone";
453
+ FieldNames["purchaseDescription"] = "purchaseDescription";
454
+ FieldNames["recurrentType"] = "recurrent_type";
455
+ FieldNames["rockstarTaxes"] = "rockstar_taxes";
456
+ FieldNames["state"] = "state";
457
+ FieldNames["street"] = "street";
458
+ FieldNames["streetNumber"] = "street_number";
459
+ FieldNames["take2Taxes"] = "take2_taxes";
460
+ FieldNames["termsAndConditions"] = "termsAndConditions";
461
+ FieldNames["termsAndConditionsAtariPp"] = "termsAndConditionsAtariPP";
462
+ FieldNames["termsAndConditionsAtariTc"] = "termsAndConditionsAtariTC";
463
+ FieldNames["termsAndConditionsHtcEula"] = "termsAndConditionsHtcEula";
464
+ FieldNames["termsAndConditionsRobloxEula"] = "termsAndConditionsRobloxEula";
465
+ FieldNames["termsAndConditionsRolandEula"] = "termsAndConditionsRolandEula";
466
+ FieldNames["termsAndConditionsDeusLoVultEula"] = "termsAndConditionsDeusLoVultEula";
467
+ FieldNames["termsAndConditionsOnzenga"] = "termsAndConditionsOnzenga";
468
+ FieldNames["xsollaTipsAmount"] = "xsollaTipsAmount";
469
+ FieldNames["zip"] = "zip";
470
+ FieldNames["allowSave"] = "allowSave";
471
+ FieldNames["koreaLimitsInstruction"] = "korea_limits_instruction";
472
+ FieldNames["tokenApplePay"] = "token_applepay";
473
+ FieldNames["fixInvoice"] = "fix_invoice";
474
+ FieldNames["fixPid"] = "fix_pid";
475
+ FieldNames["signature"] = "signature";
476
+ FieldNames["qr"] = "qr";
477
+ FieldNames["sum"] = "sum";
478
+ FieldNames["out"] = "out";
479
+ FieldNames["tinkoffDisclaimer"] = "ps.tinkoff.disclaimer";
480
+ })(FieldNames || (FieldNames = {}));
481
+
482
+ class SubmitResponse {
483
+ constructor(parameters, responseNumber = 0) {
484
+ this.responseNumber = responseNumber;
485
+ /* Todo split into properties */
486
+ this.parameters = parameters;
487
+ this.fields = Object.keys(parameters.form).map((key) => parameters.form[key]);
488
+ if (parameters.onlineBanking) {
489
+ this.onlineBanking = {
490
+ url: parameters.onlineBanking.value,
491
+ };
492
+ }
493
+ this.isNeedRedirect =
494
+ parameters.currentCommand === XpsCommand.account ||
495
+ (parameters.currentCommand === XpsCommand.checkout &&
496
+ Boolean(parameters.checkout));
497
+ this.buyData = parameters.buyData;
498
+ this.fixInvoice = this.fields.find((field) => field.name === FieldNames.fixInvoice)?.value;
499
+ this.signature = this.fields.find((field) => field.name === FieldNames.signature)?.value;
500
+ this.hasFatalErrors = parameters.textAll?.fatal;
501
+ this.userSession = parameters.userSession;
502
+ this.pid = parameters.pid;
503
+ this.errors = parameters.errors;
504
+ this.summary = parameters.summary;
505
+ this.title = parameters.title;
506
+ this.currentCommand = parameters.currentCommand;
507
+ this.messages = parameters.messages;
508
+ }
509
+ }
510
+
511
+ const isSubmitResponse = (value) => {
512
+ return value instanceof SubmitResponse;
513
+ };
514
+
405
515
  class InitializeResponse {
406
516
  constructor(response) {
407
517
  this.paymentForm = null;
@@ -533,109 +643,6 @@ const submitRequestFactoryProvider = {
533
643
  useValue: (...args) => new SubmitRequest(...args),
534
644
  };
535
645
 
536
- var XpsCommand;
537
- (function (XpsCommand) {
538
- XpsCommand["form"] = "form";
539
- XpsCommand["check"] = "check";
540
- XpsCommand["status"] = "status";
541
- XpsCommand["checkout"] = "checkout";
542
- XpsCommand["account"] = "account";
543
- XpsCommand["create"] = "create";
544
- })(XpsCommand || (XpsCommand = {}));
545
-
546
- var FieldNames;
547
- (function (FieldNames) {
548
- FieldNames["address1"] = "address1";
549
- FieldNames["address2"] = "address2";
550
- FieldNames["address"] = "address";
551
- FieldNames["allowRecurrentSubscription"] = "allowRecurrentSubscription";
552
- FieldNames["allowSubscription"] = "allowSubscription";
553
- FieldNames["apt"] = "apt";
554
- FieldNames["availableCardTypes"] = "available_card_types";
555
- FieldNames["bank"] = "bank";
556
- FieldNames["birthDate"] = "birth_date";
557
- FieldNames["cardMonth"] = "card_month";
558
- FieldNames["cardYear"] = "card_year";
559
- FieldNames["cardNumber"] = "card_number";
560
- FieldNames["cardholdername"] = "cardholdername";
561
- FieldNames["city"] = "city";
562
- FieldNames["couponCode"] = "couponCode";
563
- FieldNames["cpfName"] = "cpf_name";
564
- FieldNames["cpfNumber"] = "cpf_number";
565
- FieldNames["cvv"] = "cvv";
566
- FieldNames["description"] = "description";
567
- FieldNames["email"] = "email";
568
- FieldNames["psEmail"] = "psEmail";
569
- FieldNames["euCheck"] = "eu_check";
570
- FieldNames["extraCvv"] = "extra_cvv";
571
- FieldNames["extraCardNumber"] = "extra_card_number";
572
- FieldNames["extraCardType"] = "extra_card_type";
573
- FieldNames["fName"] = "f_name";
574
- FieldNames["installments"] = "installments";
575
- FieldNames["lName"] = "l_name";
576
- FieldNames["needInstallments"] = "needInstallments";
577
- FieldNames["personId"] = "person_id";
578
- FieldNames["personIdAr"] = "person_id_ar";
579
- FieldNames["personIdCo"] = "person_id_co";
580
- FieldNames["phone"] = "phone";
581
- FieldNames["purchaseDescription"] = "purchaseDescription";
582
- FieldNames["recurrentType"] = "recurrent_type";
583
- FieldNames["rockstarTaxes"] = "rockstar_taxes";
584
- FieldNames["state"] = "state";
585
- FieldNames["street"] = "street";
586
- FieldNames["streetNumber"] = "street_number";
587
- FieldNames["take2Taxes"] = "take2_taxes";
588
- FieldNames["termsAndConditions"] = "termsAndConditions";
589
- FieldNames["termsAndConditionsAtariPp"] = "termsAndConditionsAtariPP";
590
- FieldNames["termsAndConditionsAtariTc"] = "termsAndConditionsAtariTC";
591
- FieldNames["termsAndConditionsHtcEula"] = "termsAndConditionsHtcEula";
592
- FieldNames["termsAndConditionsRobloxEula"] = "termsAndConditionsRobloxEula";
593
- FieldNames["termsAndConditionsRolandEula"] = "termsAndConditionsRolandEula";
594
- FieldNames["termsAndConditionsDeusLoVultEula"] = "termsAndConditionsDeusLoVultEula";
595
- FieldNames["termsAndConditionsOnzenga"] = "termsAndConditionsOnzenga";
596
- FieldNames["xsollaTipsAmount"] = "xsollaTipsAmount";
597
- FieldNames["zip"] = "zip";
598
- FieldNames["allowSave"] = "allowSave";
599
- FieldNames["koreaLimitsInstruction"] = "korea_limits_instruction";
600
- FieldNames["tokenApplePay"] = "token_applepay";
601
- FieldNames["fixInvoice"] = "fix_invoice";
602
- FieldNames["fixPid"] = "fix_pid";
603
- FieldNames["signature"] = "signature";
604
- FieldNames["qr"] = "qr";
605
- FieldNames["sum"] = "sum";
606
- FieldNames["out"] = "out";
607
- FieldNames["tinkoffDisclaimer"] = "ps.tinkoff.disclaimer";
608
- })(FieldNames || (FieldNames = {}));
609
-
610
- class SubmitResponse {
611
- constructor(parameters, responseNumber = 0) {
612
- this.responseNumber = responseNumber;
613
- /* Todo split into properties */
614
- this.parameters = parameters;
615
- this.fields = Object.keys(parameters.form).map((key) => parameters.form[key]);
616
- if (parameters.onlineBanking) {
617
- this.onlineBanking = {
618
- url: parameters.onlineBanking.value,
619
- };
620
- }
621
- this.isNeedRedirect =
622
- parameters.currentCommand === XpsCommand.account ||
623
- (parameters.currentCommand === XpsCommand.checkout &&
624
- Boolean(parameters.checkout));
625
- this.buyData = parameters.buyData;
626
- this.fixInvoice = this.fields.find((field) => field.name === FieldNames.fixInvoice)?.value;
627
- this.signature = this.fields.find((field) => field.name === FieldNames.signature)?.value;
628
- this.hasFatalErrors = parameters.textAll?.fatal;
629
- this.userSession = parameters.userSession;
630
- this.pid = parameters.pid;
631
- this.errors = parameters.errors;
632
- this.summary = parameters.summary;
633
- this.title = parameters.title;
634
- this.currentCommand = parameters.currentCommand;
635
- this.messages = parameters.messages;
636
- }
637
- }
638
-
639
646
  const submitResponseFactoryToken = new InjectionToken('SubmitResponse');
640
647
  const submitResponseFactoryProvider = {
641
648
  provide: submitResponseFactoryToken,
@@ -987,7 +994,9 @@ class SyncService extends EmitDataService {
987
994
  return null;
988
995
  }
989
996
  const rewritableError = control.errors?.rewritableError;
990
- return rewritableError ? { message: rewritableError.message } : null;
997
+ return rewritableError
998
+ ? { message: rewritableError.message, code: rewritableError.code }
999
+ : null;
991
1000
  }
992
1001
  async request(field) {
993
1002
  const requestParams = this.requestFactory({
@@ -1044,7 +1053,7 @@ class TextControlConfig extends ControlConfig {
1044
1053
  }
1045
1054
  }
1046
1055
 
1047
- function convert(validator, message) {
1056
+ function convert(validator, message, errorCode) {
1048
1057
  return (control) => {
1049
1058
  const errors = validator(control);
1050
1059
  if (!errors) {
@@ -1055,6 +1064,7 @@ function convert(validator, message) {
1055
1064
  error = typeof error === 'object' && error !== null ? error : {};
1056
1065
  const rewritableError = { ...error };
1057
1066
  rewritableError.message = message;
1067
+ rewritableError.code = errorCode;
1058
1068
  if (error[firstErrorKey] != null) {
1059
1069
  rewritableError.value = error[firstErrorKey];
1060
1070
  }
@@ -1066,13 +1076,21 @@ function convert(validator, message) {
1066
1076
  };
1067
1077
  }
1068
1078
 
1079
+ var ErrorsCodes;
1080
+ (function (ErrorsCodes) {
1081
+ ErrorsCodes["minLength"] = "min-length";
1082
+ ErrorsCodes["maxLength"] = "max-length";
1083
+ ErrorsCodes["invalidValue"] = "invalid-value";
1084
+ ErrorsCodes["required"] = "required";
1085
+ })(ErrorsCodes || (ErrorsCodes = {}));
1086
+
1069
1087
  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
1070
1088
  function emailValidator() {
1071
- return convert(Validators.pattern(emailRegexp), 'Enter a valid email');
1089
+ return convert(Validators.pattern(emailRegexp), 'Enter a valid email', ErrorsCodes.invalidValue);
1072
1090
  }
1073
1091
 
1074
1092
  function requiredValidator() {
1075
- return convert(Validators.required, 'Required');
1093
+ return convert(Validators.required, 'Required', ErrorsCodes.required);
1076
1094
  }
1077
1095
 
1078
1096
  class Converter {
@@ -1101,7 +1119,7 @@ class Converter {
1101
1119
  const errorMessage = field.validation_error_msg
1102
1120
  ? field.validation_error_msg
1103
1121
  : 'Enter valid data';
1104
- validators.push(convert(Validators.pattern(pattern), errorMessage));
1122
+ validators.push(convert(Validators.pattern(pattern), errorMessage, ErrorsCodes.invalidValue));
1105
1123
  }
1106
1124
  }
1107
1125
  return validators;
@@ -1190,11 +1208,11 @@ class ZipConverter extends Converter {
1190
1208
  const validators = super
1191
1209
  .getValidators(field)
1192
1210
  .concat([
1193
- convert(Validators.minLength(minLength), `Enter at least ${minLength} characters`),
1194
- convert(Validators.maxLength(maxLength), `Enter no more than ${maxLength} characters`),
1211
+ convert(Validators.minLength(minLength), `Enter at least ${minLength} characters`, ErrorsCodes.minLength),
1212
+ convert(Validators.maxLength(maxLength), `Enter no more than ${maxLength} characters`, ErrorsCodes.maxLength),
1195
1213
  ]);
1196
1214
  if (this.isUsCountry) {
1197
- validators.push(convert(restrictedValueValidator('00000'), 'Enter a valid ZIP code'));
1215
+ validators.push(convert(restrictedValueValidator('00000'), 'Enter a valid ZIP code', ErrorsCodes.invalidValue));
1198
1216
  }
1199
1217
  return validators;
1200
1218
  }
@@ -1203,16 +1221,6 @@ class ZipConverter extends Converter {
1203
1221
  config.icon = 'location';
1204
1222
  if (this.isUsCountry) {
1205
1223
  config.maskConfig = {
1206
- // mask: () => new Array(this.usCountryLength).fill('9').join(''),
1207
- // mask: () => new Array(5).fill('9').join(''),
1208
- // mask: function() { return new Array(5).fill('9').join('') },
1209
- // mask: MasksFunctionsMap['zip'],
1210
- // mask: function mask() {
1211
- // const length = this.usCountryLength;
1212
- // return function() {
1213
- // return new Array(length).fill('9').join('');
1214
- // }
1215
- // },
1216
1224
  guide: false,
1217
1225
  unmaskModelValue: true,
1218
1226
  showMask: true,
@@ -2296,7 +2304,7 @@ class ShowFieldsAction {
2296
2304
  messages: [],
2297
2305
  order: {},
2298
2306
  };
2299
- this.data.fields = submitResponse.fields;
2307
+ this.data.fields = submitResponse.fields.filter((field) => field?.isVisible === "1" /* XpsBoolean.true */);
2300
2308
  this.data.errors = submitResponse.errors;
2301
2309
  this.data.messages = submitResponse.messages;
2302
2310
  this.data.order = submitResponse.summary;
@@ -2308,7 +2316,9 @@ const showFieldsActionFactoryProvider = {
2308
2316
  provide: showFieldsActionFactoryToken,
2309
2317
  useValue: {
2310
2318
  factory: (...args) => new ShowFieldsAction(...args),
2311
- type: 'show_fields',
2319
+ isSuitable: (response) => {
2320
+ return response.currentCommand === XpsCommand.check;
2321
+ },
2312
2322
  },
2313
2323
  };
2314
2324
 
@@ -2333,7 +2343,9 @@ const checkStatusActionFactoryProvider = {
2333
2343
  provide: checkStatusActionFactoryToken,
2334
2344
  useValue: {
2335
2345
  factory: (...args) => new CheckStatusAction(...args),
2336
- type: 'check_status',
2346
+ isSuitable: (response) => {
2347
+ return response.currentCommand === XpsCommand.status;
2348
+ },
2337
2349
  },
2338
2350
  };
2339
2351
 
@@ -2342,7 +2354,40 @@ const statusUpdatedActionFactoryProvider = {
2342
2354
  provide: statusUpdatedActionFactoryToken,
2343
2355
  useValue: {
2344
2356
  factory: (...args) => new StatusUpdatedAction(...args),
2345
- type: 'status_updated',
2357
+ isSuitable: () => false,
2358
+ },
2359
+ };
2360
+
2361
+ class RedirectAction {
2362
+ constructor(submitResponse) {
2363
+ this.type = 'redirect';
2364
+ this.data = {
2365
+ fields: submitResponse.fields,
2366
+ errors: submitResponse.errors,
2367
+ messages: submitResponse.messages,
2368
+ order: submitResponse.summary,
2369
+ invoiceId: submitResponse.fixInvoice,
2370
+ redirect: this.getRedirect(submitResponse),
2371
+ };
2372
+ }
2373
+ getRedirect(submitResponse) {
2374
+ return {
2375
+ redirectUrl: submitResponse.parameters.checkout.action,
2376
+ data: submitResponse.parameters.checkout.data,
2377
+ };
2378
+ }
2379
+ }
2380
+
2381
+ const redirectActionFactoryToken = new InjectionToken('RedirectAction');
2382
+ const redirectActionFactoryProvider = {
2383
+ provide: redirectActionFactoryToken,
2384
+ useValue: {
2385
+ factory: (...args) => new RedirectAction(...args),
2386
+ isSuitable: (response) => {
2387
+ return (response.currentCommand === XpsCommand.account ||
2388
+ (response.currentCommand === XpsCommand.checkout &&
2389
+ Boolean(response.parameters.checkout)));
2390
+ },
2346
2391
  },
2347
2392
  };
2348
2393
 
@@ -2351,13 +2396,9 @@ const nextActions = [
2351
2396
  showFieldsActionFactoryProvider,
2352
2397
  checkStatusActionFactoryProvider,
2353
2398
  statusUpdatedActionFactoryProvider,
2399
+ redirectActionFactoryProvider,
2354
2400
  ];
2355
2401
 
2356
- const actionTypeCommandMap = {
2357
- [XpsCommand.check]: 'show_fields',
2358
- [XpsCommand.status]: 'check_status',
2359
- };
2360
-
2361
2402
  class NextActionService {
2362
2403
  get flowUpdates$() {
2363
2404
  return this.flowUpdatesSubject.asObservable();
@@ -2366,14 +2407,14 @@ class NextActionService {
2366
2407
  this.nextActionTokens = nextActionTokens;
2367
2408
  this.injector = injector;
2368
2409
  this.flowUpdatesSubject = new Subject();
2369
- this.nextActionsMap = new Map();
2370
- this.fillNextActionsMap();
2410
+ this.nextActionsList = [];
2411
+ this.fillNextActionsList();
2371
2412
  }
2372
2413
  getNextAction(submitResponse) {
2373
2414
  if (!submitResponse.currentCommand) {
2374
2415
  return null;
2375
2416
  }
2376
- const nextActionFactory = this.findNextAction(submitResponse.currentCommand);
2417
+ const nextActionFactory = this.findNextAction(submitResponse);
2377
2418
  if (nextActionFactory) {
2378
2419
  return nextActionFactory(submitResponse);
2379
2420
  }
@@ -2382,18 +2423,20 @@ class NextActionService {
2382
2423
  emitFlowUpdates(action) {
2383
2424
  this.flowUpdatesSubject.next(action);
2384
2425
  }
2385
- fillNextActionsMap() {
2426
+ fillNextActionsList() {
2386
2427
  this.nextActionTokens.forEach((nextAction) => {
2387
2428
  const item = this.injector.get(nextAction.provide);
2388
- this.nextActionsMap.set(item.type, item.factory);
2429
+ this.nextActionsList.push(item);
2389
2430
  });
2390
2431
  }
2391
- findNextAction(command) {
2392
- const actionType = actionTypeCommandMap[command];
2432
+ findNextAction(submitResponse) {
2433
+ const actionType = this.nextActionsList.find((nextAction) => {
2434
+ return nextAction.isSuitable(submitResponse);
2435
+ });
2393
2436
  if (!actionType) {
2394
2437
  return;
2395
2438
  }
2396
- return this.nextActionsMap.get(actionType);
2439
+ return actionType.factory;
2397
2440
  }
2398
2441
  }
2399
2442
  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 });
@@ -2728,17 +2771,21 @@ class PaymentService {
2728
2771
  this.form = this.formService.createForm(this.fields);
2729
2772
  this.emitFinanceDetails(this.data.paymentForm?.summary);
2730
2773
  this.setupSyncService(this.form, this.fields);
2731
- return this.fields;
2774
+ return this.fields.filter((field) => field?.isVisible === "1" /* XpsBoolean.true */);
2732
2775
  }
2733
2776
  async submit() {
2734
2777
  if (!this.form) {
2735
2778
  throw new Error('form is empty!');
2736
2779
  }
2737
2780
  const submitResponse = await this.submitService.request(this.fields, this.form);
2781
+ this.data = submitResponse;
2738
2782
  this.emitFinanceDetails(submitResponse.summary);
2739
2783
  return this.nextActionService.getNextAction(submitResponse);
2740
2784
  }
2741
2785
  getFields() {
2786
+ if (this.data instanceof SubmitResponse) {
2787
+ return this.data.fields ?? [];
2788
+ }
2742
2789
  return this.data?.paymentForm?.fields ?? [];
2743
2790
  }
2744
2791
  async validate(field) {
@@ -2754,7 +2801,16 @@ class PaymentService {
2754
2801
  getFinanceDetails() {
2755
2802
  return this.financeDetails;
2756
2803
  }
2757
- async getStatus(params) {
2804
+ async getStatus() {
2805
+ if (!isSubmitResponse(this.data)) {
2806
+ throw new Error('Should submit form first');
2807
+ }
2808
+ const params = {
2809
+ invoice: parseInt(this.data.fixInvoice ?? ''),
2810
+ signature: this.data.signature ?? '',
2811
+ locale: this.data.fields.find((field) => field.name === 'locale')?.value ??
2812
+ 'en',
2813
+ };
2758
2814
  return this.statusService.getStatus({
2759
2815
  ...params,
2760
2816
  pid: this.config.paymentMethodId,
@@ -2934,7 +2990,7 @@ class CoreLibraryService {
2934
2990
  validate: async (field) => this.paymentService.validate(field),
2935
2991
  getFinanceDetails: () => this.paymentService.getFinanceDetails(),
2936
2992
  runThreeDs: () => this.paymentService.runThreeDs(),
2937
- getStatus: async (params) => this.paymentService.getStatus(params),
2993
+ getStatus: async () => this.paymentService.getStatus(),
2938
2994
  flowUpdates$: this.nextActionService.flowUpdates$,
2939
2995
  financeDetailsUpdates$: this.financeDetailsService.data$,
2940
2996
  form: {