@xsolla/payment-client-core 0.2.7 → 0.2.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.
Files changed (50) hide show
  1. package/esm2020/lib/core/agreementsGroup.const.mjs +14 -0
  2. package/esm2020/lib/core/extended-window.interface.mjs +1 -1
  3. package/esm2020/lib/core/payment/actions/redirect/ps4-pages/pages-payment-methods-id.const.mjs +2 -2
  4. package/esm2020/lib/core/payment/actions/redirect/ps4-pages/pages-routes.const.mjs +3 -3
  5. package/esm2020/lib/core/payment/field-names.enum.mjs +2 -1
  6. package/esm2020/lib/core/payment/form-response.interface.mjs +2 -0
  7. package/esm2020/lib/core/payment/payment.interface.mjs +1 -1
  8. package/esm2020/lib/core/payment/payment.service.mjs +56 -2
  9. package/esm2020/lib/core/sdk-payment-systems/apple-pay/apple-pay-integration.type.mjs +2 -0
  10. package/esm2020/lib/core/sdk-payment-systems/apple-pay/apple-pay-params.interface.mjs +2 -0
  11. package/esm2020/lib/core/sdk-payment-systems/apple-pay/apple-pay.const.mjs +2 -0
  12. package/esm2020/lib/core/sdk-payment-systems/apple-pay/apple-pay.errors.enum.mjs +6 -0
  13. package/esm2020/lib/core/sdk-payment-systems/apple-pay/apple-pay.service.mjs +265 -0
  14. package/esm2020/lib/core/sdk-payment-systems/apple-pay/checkout-params.interface.mjs +2 -0
  15. package/esm2020/lib/core/user-agent/browserInfo.interface.mjs +2 -0
  16. package/esm2020/lib/core/user-agent/browsers.mjs +44 -0
  17. package/esm2020/lib/core/user-agent/device.enum.mjs +6 -0
  18. package/esm2020/lib/core/user-agent/os.mjs +255 -0
  19. package/esm2020/lib/core/user-agent/user-agent-data.interface.mjs +2 -0
  20. package/esm2020/lib/core/user-agent/user-agent.service.mjs +200 -0
  21. package/esm2020/lib/core-library.service.mjs +11 -1
  22. package/esm2020/public-api.mjs +3 -1
  23. package/fesm2015/xsolla-payment-client-core.mjs +849 -4
  24. package/fesm2015/xsolla-payment-client-core.mjs.map +1 -1
  25. package/fesm2020/xsolla-payment-client-core.mjs +842 -4
  26. package/fesm2020/xsolla-payment-client-core.mjs.map +1 -1
  27. package/lib/core/agreementsGroup.const.d.ts +2 -0
  28. package/lib/core/extended-window.interface.d.ts +11 -0
  29. package/lib/core/payment/actions/redirect/ps4-pages/pages-payment-methods-id.const.d.ts +1 -1
  30. package/lib/core/payment/field-names.enum.d.ts +2 -1
  31. package/lib/core/payment/form-response.interface.d.ts +8 -0
  32. package/lib/core/payment/payment.interface.d.ts +1 -0
  33. package/lib/core/payment/payment.service.d.ts +9 -1
  34. package/lib/core/sdk-payment-systems/apple-pay/apple-pay-integration.type.d.ts +1 -0
  35. package/lib/core/sdk-payment-systems/apple-pay/apple-pay-params.interface.d.ts +4 -0
  36. package/lib/core/sdk-payment-systems/apple-pay/apple-pay.const.d.ts +1 -0
  37. package/lib/core/sdk-payment-systems/apple-pay/apple-pay.errors.enum.d.ts +4 -0
  38. package/lib/core/sdk-payment-systems/apple-pay/apple-pay.service.d.ts +46 -0
  39. package/lib/core/sdk-payment-systems/apple-pay/checkout-params.interface.d.ts +9 -0
  40. package/lib/core/user-agent/browserInfo.interface.d.ts +13 -0
  41. package/lib/core/user-agent/browsers.d.ts +9 -0
  42. package/lib/core/user-agent/device.enum.d.ts +4 -0
  43. package/lib/core/user-agent/os.d.ts +7 -0
  44. package/lib/core/user-agent/user-agent-data.interface.d.ts +10 -0
  45. package/lib/core/user-agent/user-agent.service.d.ts +36 -0
  46. package/lib/core-library.service.d.ts +5 -0
  47. package/package.json +4 -2
  48. package/public-api.d.ts +2 -0
  49. package/xsolla-payment-client-core-0.2.8.tgz +0 -0
  50. package/xsolla-payment-client-core-0.2.7.tgz +0 -0
@@ -564,6 +564,7 @@ var FieldNames;
564
564
  FieldNames["sum"] = "sum";
565
565
  FieldNames["out"] = "out";
566
566
  FieldNames["tinkoffDisclaimer"] = "ps.tinkoff.disclaimer";
567
+ FieldNames["omnibusDirective"] = "omnibus_directive";
567
568
  })(FieldNames || (FieldNames = {}));
568
569
 
569
570
  class SubmitResponse {
@@ -741,14 +742,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
741
742
 
742
743
  const vkPay = 3496;
743
744
  const googlePay = 3431;
744
- const applePay = 3175;
745
+ const applePayId = 3175;
745
746
  const barzahlenPay = 1679;
746
747
  const naverPay = 3563;
747
748
  const venmoPay = 3636;
748
749
 
749
750
  const pagesRoutes = new Map([
750
751
  [vkPay, '/payment/external-pages/vk-pay'],
751
- [applePay, '/payment/external-pages/apple-pay'],
752
+ [applePayId, '/payment/external-pages/apple-pay'],
752
753
  [barzahlenPay, '/payment/external-pages/barzahlen-pay'],
753
754
  [naverPay, '/payment/external-pages/naver-pay'],
754
755
  [venmoPay, '/payment/external-pages/venmo-pay'],
@@ -5373,6 +5374,15 @@ class PaymentService {
5373
5374
  get formFieldsStatus$() {
5374
5375
  return this.formFieldsStatusSubject.asObservable().pipe(filter$1(Boolean));
5375
5376
  }
5377
+ get paymentForm$() {
5378
+ return this._paymentForm$.asObservable();
5379
+ }
5380
+ get formResponse$() {
5381
+ return this._formResponse$.asObservable();
5382
+ }
5383
+ get formResponseValue() {
5384
+ return this._formResponse$.getValue();
5385
+ }
5376
5386
  constructor(initializeService, submitService, syncService, formService, statusService, financeDetailsService, creditCardStateService, nextActionService, controlConfigService, threeDsService, formMessagesService, settingsService, countryService) {
5377
5387
  this.initializeService = initializeService;
5378
5388
  this.submitService = submitService;
@@ -5394,7 +5404,9 @@ class PaymentService {
5394
5404
  this.fields = [];
5395
5405
  this.destroy$ = new Subject();
5396
5406
  this.formDestroy$ = new Subject();
5407
+ this._paymentForm$ = new BehaviorSubject(null);
5397
5408
  this.formFieldsStatusSubject = new BehaviorSubject(null);
5409
+ this._formResponse$ = new BehaviorSubject(null);
5398
5410
  this.isSavingMethodMode = false;
5399
5411
  }
5400
5412
  async initialize(config) {
@@ -5403,6 +5415,7 @@ class PaymentService {
5403
5415
  this.listenFinanceDetails();
5404
5416
  this.config = config;
5405
5417
  this.data = await this.initializeService.request(config);
5418
+ this.emitFormResponse(this.data);
5406
5419
  this.fields = this.getFields();
5407
5420
  this.form = this.formService.createForm(this.fields);
5408
5421
  this.updatePidConfig();
@@ -5425,6 +5438,7 @@ class PaymentService {
5425
5438
  this.isSavingMethodMode = this.fields.some(({ name, value }) => name === 'savePsAccountOnly' && value === "1" /* XpsBoolean.true */);
5426
5439
  const submitResponse = await this.submitService.request(this.fields, this.form);
5427
5440
  this.data = submitResponse;
5441
+ this.emitFormResponse(this.data);
5428
5442
  if (!this.isSavingMethodMode) {
5429
5443
  this.emitFinanceDetails(submitResponse.summary);
5430
5444
  }
@@ -5529,6 +5543,30 @@ class PaymentService {
5529
5543
  }
5530
5544
  this.emitFormFieldsStatus(this.form);
5531
5545
  }
5546
+ addExtraField(name, value) {
5547
+ const isHaveField = this.fields.find((field) => {
5548
+ return field.name === name;
5549
+ });
5550
+ if (isHaveField) {
5551
+ this.fields = this.fields.map((field) => {
5552
+ if (field.name === name) {
5553
+ field.value = value;
5554
+ }
5555
+ return field;
5556
+ });
5557
+ return;
5558
+ }
5559
+ const field = {
5560
+ name: name,
5561
+ value: value,
5562
+ title: '',
5563
+ type: 'text',
5564
+ example: '',
5565
+ isMandatory: "1" /* XpsBoolean.true */,
5566
+ isVisible: "0" /* XpsBoolean.false */,
5567
+ };
5568
+ this.fields.push(field);
5569
+ }
5532
5570
  destroy() {
5533
5571
  this.data = null;
5534
5572
  this.financeDetails = null;
@@ -5568,6 +5606,7 @@ class PaymentService {
5568
5606
  .subscribe((response) => {
5569
5607
  this.emitFinanceDetails(response.summary);
5570
5608
  this.emitFormMessages(response.messages);
5609
+ this.emitFormResponse(response);
5571
5610
  });
5572
5611
  this.syncService.fieldAsyncValidation$
5573
5612
  .pipe(takeUntil(this.destroy$))
@@ -5586,7 +5625,10 @@ class PaymentService {
5586
5625
  listenFormStatusChanges(form) {
5587
5626
  form.statusChanges
5588
5627
  .pipe(takeUntil(this.formDestroy$))
5589
- .subscribe(() => this.emitFormFieldsStatus(form));
5628
+ .subscribe((status) => {
5629
+ this.emitFormFieldsStatus(form);
5630
+ this._paymentForm$.next(status);
5631
+ });
5590
5632
  }
5591
5633
  /*
5592
5634
  * in case the form pid changes despite the one passed during initialization
@@ -5597,6 +5639,19 @@ class PaymentService {
5597
5639
  this.config.paymentMethodId = currentPid;
5598
5640
  }
5599
5641
  }
5642
+ emitFormResponse(data) {
5643
+ let type;
5644
+ if (data instanceof InitializeResponse) {
5645
+ type = 'initialize';
5646
+ }
5647
+ else if (data instanceof SubmitResponse) {
5648
+ type = 'submit';
5649
+ }
5650
+ else {
5651
+ type = 'sync';
5652
+ }
5653
+ this._formResponse$.next({ type, data, token: this.settingsService.token });
5654
+ }
5600
5655
  }
5601
5656
  PaymentService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentService, deps: [{ token: InitializeService }, { token: SubmitService }, { token: SyncService }, { token: FormService }, { token: StatusService }, { token: FinanceDetailsService }, { token: CreditCardStateService }, { token: NextActionService }, { token: ControlConfigService }, { token: ThreeDsService }, { token: FormMessagesService }, { token: SettingsService }, { token: CountryService }], target: i0.ɵɵFactoryTarget.Injectable });
5602
5657
  PaymentService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentService, providedIn: 'root' });
@@ -6071,6 +6126,7 @@ class CoreLibraryService {
6071
6126
  formMessages$: this.formMessagesService.data$,
6072
6127
  getFormStatus: () => this.paymentService.form?.status,
6073
6128
  },
6129
+ addExtraField: (name, value) => this.paymentService.addExtraField(name, value),
6074
6130
  };
6075
6131
  }
6076
6132
  getCreditCardService() {
@@ -6099,6 +6155,15 @@ class CoreLibraryService {
6099
6155
  getUserBalanceValue() {
6100
6156
  return this.userBalanceService.getUserBalanceValue();
6101
6157
  }
6158
+ get paymentForm$() {
6159
+ return this.paymentService.paymentForm$;
6160
+ }
6161
+ get formResponse$() {
6162
+ return this.paymentService.formResponse$;
6163
+ }
6164
+ get formResponseValue() {
6165
+ return this.paymentService.formResponseValue;
6166
+ }
6102
6167
  }
6103
6168
  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: PaymentConfigService }, { token: PaymentService }, { token: DeviceFingerPrintService }, { token: FinanceDetailsService }, { token: LegalService }, { token: StatusService }, { token: NextActionService }, { token: CreditCardService }, { token: CreditCardStateService }, { token: FormMessagesService }, { token: EditSavedMethodsService }, { token: GooglePayService }, { token: PaymentSystemProcessingService }], target: i0.ɵɵFactoryTarget.Injectable });
6104
6169
  CoreLibraryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, providedIn: 'root' });
@@ -6330,6 +6395,779 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
6330
6395
  }]
6331
6396
  }] });
6332
6397
 
6398
+ const applePayVersion = 3;
6399
+
6400
+ const agreementsGroup = [
6401
+ FieldNames.termsAndConditions,
6402
+ FieldNames.termsAndConditionsHtcEula,
6403
+ FieldNames.termsAndConditionsAtariTc,
6404
+ FieldNames.termsAndConditionsAtariPp,
6405
+ FieldNames.termsAndConditionsRolandEula,
6406
+ FieldNames.termsAndConditionsRobloxEula,
6407
+ FieldNames.termsAndConditionsOnzenga,
6408
+ FieldNames.take2Taxes,
6409
+ FieldNames.rockstarTaxes,
6410
+ FieldNames.omnibusDirective,
6411
+ ];
6412
+
6413
+ var ApplePayErrors;
6414
+ (function (ApplePayErrors) {
6415
+ ApplePayErrors["paymentError"] = "paymentError";
6416
+ ApplePayErrors["deviceIsNotCapableError"] = "deviceIsNotCapableError";
6417
+ })(ApplePayErrors || (ApplePayErrors = {}));
6418
+
6419
+ const unknownValue = 'unknown';
6420
+ const browsers = [
6421
+ {
6422
+ sentName: 'Mozilla Firefox',
6423
+ shortName: 'Firefox',
6424
+ regexpBrowserNameWithVersion: '(Firefox)\\/(.+)',
6425
+ },
6426
+ {
6427
+ sentName: 'Samsung Internet',
6428
+ shortName: 'SamsungBrowser',
6429
+ regexpBrowserNameWithVersion: '(SamsungBrowser)\\/(.+)\\s',
6430
+ },
6431
+ {
6432
+ sentName: 'Opera',
6433
+ shortName: 'Opera',
6434
+ regexpBrowserNameWithVersion: '(Opera)\\/(.+)',
6435
+ },
6436
+ {
6437
+ sentName: 'Opera',
6438
+ shortName: 'Opera',
6439
+ regexpBrowserNameWithVersion: '(OPR)\\/(.+)',
6440
+ },
6441
+ {
6442
+ sentName: 'Microsoft Edge (Legacy)',
6443
+ shortName: 'MSEdge-legacy',
6444
+ regexpBrowserNameWithVersion: '(Edge)\\/(.+)',
6445
+ },
6446
+ {
6447
+ sentName: 'Microsoft Edge (Chromium)',
6448
+ shortName: 'MSEdge',
6449
+ regexpBrowserNameWithVersion: '(Edg)\\/(.+)',
6450
+ },
6451
+ {
6452
+ sentName: 'Google Chrome or Chromium',
6453
+ shortName: 'Chrome',
6454
+ regexpBrowserNameWithVersion: '(Chrome)\\/(.+)\\s',
6455
+ },
6456
+ {
6457
+ sentName: 'Apple Safari',
6458
+ shortName: 'Safari',
6459
+ regexpBrowserNameWithVersion: '(Safari)\\/(.+)',
6460
+ },
6461
+ ];
6462
+
6463
+ var Device;
6464
+ (function (Device) {
6465
+ Device["mobile"] = "mobile";
6466
+ Device["desktop"] = "desktop";
6467
+ })(Device || (Device = {}));
6468
+
6469
+ const osList = [
6470
+ {
6471
+ name: 'Windows XP',
6472
+ regExp: 'Windows XP',
6473
+ },
6474
+ {
6475
+ name: 'Windows XP',
6476
+ regExp: 'Windows NT 5.1|Windows NT5.1',
6477
+ },
6478
+ {
6479
+ name: 'Windows Vista',
6480
+ regExp: 'Windows NT 6.0',
6481
+ },
6482
+ {
6483
+ name: 'Windows 7',
6484
+ regExp: 'Windows NT 6.1',
6485
+ },
6486
+ {
6487
+ name: 'Windows 8',
6488
+ regExp: 'Windows NT 6.2',
6489
+ },
6490
+ {
6491
+ name: 'Windows 8.1',
6492
+ regExp: 'Windows NT 6.3',
6493
+ },
6494
+ {
6495
+ name: 'Windows 10',
6496
+ regExp: 'Windows NT 10.0',
6497
+ },
6498
+ {
6499
+ name: 'Windows CE',
6500
+ regExp: 'Windows CE',
6501
+ },
6502
+ {
6503
+ name: 'iPhone',
6504
+ regExp: 'iphone',
6505
+ },
6506
+ {
6507
+ name: 'iPod',
6508
+ regExp: 'ipod',
6509
+ },
6510
+ {
6511
+ name: 'iPad',
6512
+ regExp: 'ipad',
6513
+ },
6514
+ {
6515
+ name: 'Android',
6516
+ regExp: 'Android ([0-9]{1,2}.[0-9]{1,2}.?[0-9]{0,3})',
6517
+ },
6518
+ {
6519
+ name: 'Android',
6520
+ regExp: 'Android',
6521
+ },
6522
+ {
6523
+ name: 'Android',
6524
+ regExp: 'android',
6525
+ },
6526
+ {
6527
+ name: 'BlackBerry',
6528
+ regExp: 'blackberry',
6529
+ },
6530
+ {
6531
+ name: 'Mobile',
6532
+ regExp: 'webos',
6533
+ },
6534
+ {
6535
+ name: 'Nintendo WiiU',
6536
+ regExp: 'Nintendo WiiU',
6537
+ },
6538
+ {
6539
+ name: 'Xbox One S',
6540
+ regExp: 'XBOX_ONE_ED',
6541
+ },
6542
+ {
6543
+ name: 'Xbox One',
6544
+ regExp: 'Xbox; Xbox One',
6545
+ },
6546
+ {
6547
+ name: 'PlayStation',
6548
+ regExp: 'PlayStation',
6549
+ },
6550
+ {
6551
+ name: 'Windows',
6552
+ regExp: '(win)([0-9]{1,2}\\.[0-9x]{1,2})',
6553
+ },
6554
+ {
6555
+ name: 'Windows',
6556
+ regExp: '(windows)([0-9x]{2})',
6557
+ },
6558
+ {
6559
+ name: 'Windows',
6560
+ regExp: '(windows)([0-9]{1,2}\\.[0-9]{1,2})',
6561
+ },
6562
+ {
6563
+ name: 'Windows',
6564
+ regExp: 'win32',
6565
+ },
6566
+ {
6567
+ name: 'Java',
6568
+ regExp: '(java)([0-9]{1,2}\\.[0-9]{1,2}\\.[0-9]{1,2})',
6569
+ },
6570
+ {
6571
+ name: 'Solaris',
6572
+ regExp: '(Solaris)([0-9]{1,2}\\.[0-9x]{1,2}){0,1}',
6573
+ },
6574
+ {
6575
+ name: 'Unix',
6576
+ regExp: 'unix',
6577
+ },
6578
+ {
6579
+ name: 'Mac OS X',
6580
+ regExp: 'Mac OS X',
6581
+ },
6582
+ {
6583
+ name: 'Mac OS',
6584
+ regExp: '(mac|Macintosh)',
6585
+ },
6586
+ {
6587
+ name: 'SunOS',
6588
+ regExp: '(sunos)([0-9]{1,2}\\.[0-9]{1,2}){0,1}',
6589
+ },
6590
+ {
6591
+ name: 'BeOS',
6592
+ regExp: '(beos)([0-9]{1,2}\\.[0-9]{1,2}){0,1}',
6593
+ },
6594
+ {
6595
+ name: 'RISC OS',
6596
+ regExp: '(risc os)([0-9]{1,2}\\.[0-9]{1,2})',
6597
+ },
6598
+ {
6599
+ name: 'FreeBSD',
6600
+ regExp: 'freebsd',
6601
+ },
6602
+ {
6603
+ name: 'OpenBSD',
6604
+ regExp: 'openbsd',
6605
+ },
6606
+ {
6607
+ name: 'NetBSD',
6608
+ regExp: 'netbsd',
6609
+ },
6610
+ {
6611
+ name: 'IRIX',
6612
+ regExp: 'irix',
6613
+ },
6614
+ {
6615
+ name: 'Plan9',
6616
+ regExp: 'plan9',
6617
+ },
6618
+ {
6619
+ name: 'OSF',
6620
+ regExp: 'osf',
6621
+ },
6622
+ {
6623
+ name: 'AIX',
6624
+ regExp: 'aix',
6625
+ },
6626
+ {
6627
+ name: 'GNU Hurd',
6628
+ regExp: 'GNU Hurd',
6629
+ },
6630
+ {
6631
+ name: 'Linux - Fedora',
6632
+ regExp: '(fedora)',
6633
+ },
6634
+ {
6635
+ name: 'Linux - Kubuntu',
6636
+ regExp: '(kubuntu)',
6637
+ },
6638
+ {
6639
+ name: 'Linux - Ubuntu',
6640
+ regExp: '(ubuntu)',
6641
+ },
6642
+ {
6643
+ name: 'Linux - Debian',
6644
+ regExp: '(debian)',
6645
+ },
6646
+ {
6647
+ name: 'Linux - CentOS',
6648
+ regExp: '(CentOS)',
6649
+ },
6650
+ {
6651
+ name: 'Linux - Mandriva',
6652
+ regExp: '(Mandriva).([0-9]{1,3}(\\.[0-9]{1,3})?(\\.[0-9]{1,3})?)',
6653
+ },
6654
+ {
6655
+ name: 'Linux - SUSE',
6656
+ regExp: '(SUSE).([0-9]{1,3}(\\.[0-9]{1,3})?(\\.[0-9]{1,3})?)',
6657
+ },
6658
+ {
6659
+ name: 'Linux - Slackware (Dropline GNOME)',
6660
+ regExp: '(Dropline)',
6661
+ },
6662
+ {
6663
+ name: 'Linux - ASPLinux',
6664
+ regExp: '(ASPLinux)',
6665
+ },
6666
+ {
6667
+ name: 'Linux - Red Hat',
6668
+ regExp: '(Red Hat)',
6669
+ },
6670
+ {
6671
+ name: 'Linux',
6672
+ regExp: '(linux)',
6673
+ },
6674
+ {
6675
+ name: 'AmigaOS',
6676
+ regExp: '(amigaos)([0-9]{1,2}\\.[0-9]{1,2})',
6677
+ },
6678
+ {
6679
+ name: 'AmigaOS',
6680
+ regExp: 'amiga-aweb',
6681
+ },
6682
+ {
6683
+ name: 'Amiga',
6684
+ regExp: 'amiga',
6685
+ },
6686
+ {
6687
+ name: 'PalmOS',
6688
+ regExp: 'AvantGo',
6689
+ },
6690
+ {
6691
+ name: 'WebTV',
6692
+ regExp: '(webtv)/([0-9]{1,2}\\.[0-9]{1,2})',
6693
+ },
6694
+ {
6695
+ name: 'Dreamcast OS',
6696
+ regExp: 'Dreamcast',
6697
+ },
6698
+ {
6699
+ name: 'Windows',
6700
+ regExp: 'wget',
6701
+ },
6702
+ {
6703
+ name: 'Unknown',
6704
+ regExp: 'Java',
6705
+ },
6706
+ {
6707
+ name: 'Windows',
6708
+ regExp: '(msie)([0-9]{1,2}.[0-9]{1,2})',
6709
+ },
6710
+ {
6711
+ name: 'Unix',
6712
+ regExp: 'libwww-perl',
6713
+ },
6714
+ {
6715
+ name: 'Windows CE',
6716
+ regExp: 'UP.Browser',
6717
+ },
6718
+ {
6719
+ name: 'Windows',
6720
+ regExp: 'NetAnts',
6721
+ },
6722
+ ];
6723
+
6724
+ class UserAgentService {
6725
+ constructor(window) {
6726
+ this.window = window;
6727
+ this._browserName = null;
6728
+ this._browserVersion = null;
6729
+ this._browserApp = null;
6730
+ this._platform = null;
6731
+ this._os = null;
6732
+ this.getUserPlatform();
6733
+ this.getBrowserInformation();
6734
+ this.getOsInformation();
6735
+ }
6736
+ get browserVersion() {
6737
+ return this._browserVersion;
6738
+ }
6739
+ get browserApp() {
6740
+ return this._browserApp;
6741
+ }
6742
+ get platform() {
6743
+ if (this._platform === unknownValue) {
6744
+ return this.osType;
6745
+ }
6746
+ return this._platform;
6747
+ }
6748
+ get userAgent() {
6749
+ return this.window.navigator.userAgent;
6750
+ }
6751
+ get browserDescription() {
6752
+ if (this.browserName === unknownValue || this.browserName === null) {
6753
+ return this.userAgent;
6754
+ }
6755
+ return this.browserName;
6756
+ }
6757
+ get isSafari() {
6758
+ return this._browserName === 'Apple Safari';
6759
+ }
6760
+ get iOsVersion() {
6761
+ if (this.osType !== 'ios') {
6762
+ return null;
6763
+ }
6764
+ const version = /OS (\d+)_(\d+)_?(\d+)?/.exec(this.window.navigator.appVersion);
6765
+ return version ? `${version[1]}.${version[2]}.${version[3] ?? 0}` : null;
6766
+ }
6767
+ get browserInfo() {
6768
+ const browserInfo = {
6769
+ name: this.browserDescription,
6770
+ [this.browserApp?.toLowerCase() ?? unknownValue]: true,
6771
+ version: this.browserVersion,
6772
+ [this.browserEngine.toLowerCase()]: true,
6773
+ ui_version: this.isMobileDevice ? Device.mobile : Device.desktop,
6774
+ os: this.os,
6775
+ };
6776
+ if (this.isMobileDevice) {
6777
+ browserInfo.mobile = true;
6778
+ }
6779
+ if (this.osType) {
6780
+ // @ts-expect-error index is string
6781
+ browserInfo[this.osType.toLowerCase()] = true;
6782
+ }
6783
+ if (this.window.navigator.platform?.includes('iPhone')) {
6784
+ browserInfo.iphone = true;
6785
+ }
6786
+ if (this.window.navigator.platform?.includes('iPod')) {
6787
+ browserInfo.ipod = true;
6788
+ }
6789
+ if (this.window.navigator.platform?.includes('iPad')) {
6790
+ browserInfo.ipad = true;
6791
+ browserInfo.tablet = true;
6792
+ }
6793
+ if (this.isAndroid) {
6794
+ browserInfo.android = true;
6795
+ }
6796
+ return browserInfo;
6797
+ }
6798
+ get isMobileDevice() {
6799
+ const deviceAgents = [
6800
+ 'Android',
6801
+ 'webOS',
6802
+ 'iPhone',
6803
+ 'iPad',
6804
+ 'iPod',
6805
+ 'BlackBerry',
6806
+ 'IEMobile',
6807
+ 'Opera Mini',
6808
+ 'Mobile',
6809
+ 'Tablet',
6810
+ 'Kindle',
6811
+ 'Playbook',
6812
+ 'Silk',
6813
+ 'Puffin',
6814
+ 'CriOS',
6815
+ ];
6816
+ return new RegExp(deviceAgents.join('|'), 'i').test(this.userAgent);
6817
+ }
6818
+ get isIosAndNotIpad() {
6819
+ return ['iPhone', 'iPod'].includes(this.window.navigator.platform);
6820
+ }
6821
+ getUserPlatform() {
6822
+ const experimentalPlatformApi = this.window.navigator?.userAgentData;
6823
+ const platform = experimentalPlatformApi?.platform ??
6824
+ this.window?.navigator?.platform ??
6825
+ unknownValue;
6826
+ this._platform = platform.toLowerCase();
6827
+ }
6828
+ getBrowserInformation() {
6829
+ for (const browser of browsers) {
6830
+ const browserRegExp = new RegExp(browser.regexpBrowserNameWithVersion);
6831
+ const browserNameWithVersion = browserRegExp.exec(this.userAgent);
6832
+ if (browserNameWithVersion !== null) {
6833
+ this._browserName = browser.sentName;
6834
+ this._browserApp = browser.shortName;
6835
+ this._browserVersion = browserNameWithVersion[2];
6836
+ break;
6837
+ }
6838
+ this._browserName = unknownValue;
6839
+ this._browserApp = unknownValue;
6840
+ this._browserVersion = unknownValue;
6841
+ }
6842
+ }
6843
+ getOsInformation() {
6844
+ for (const os of osList) {
6845
+ const osRegExp = new RegExp(os.regExp);
6846
+ const osName = osRegExp.exec(this.userAgent);
6847
+ if (osName !== null) {
6848
+ this._os = os.name;
6849
+ break;
6850
+ }
6851
+ this._os = unknownValue;
6852
+ }
6853
+ }
6854
+ get browserName() {
6855
+ return this._browserName;
6856
+ }
6857
+ get isAndroid() {
6858
+ return /Android\s+([\d.]+)/.test(this.userAgent);
6859
+ }
6860
+ get isXbox() {
6861
+ return /xbox/i.test(this.userAgent);
6862
+ }
6863
+ get isLinux() {
6864
+ return /linux/i.test(this.userAgent);
6865
+ }
6866
+ get isWindows() {
6867
+ return /windows/i.test(this.userAgent);
6868
+ }
6869
+ get browserEngine() {
6870
+ const engines = new Map([
6871
+ ['Firefox', 'Gecko'],
6872
+ ['Safari', 'Webkit'],
6873
+ ['MSEdge-legacy', 'EdgeHTML'],
6874
+ ['Chrome', 'Blink'],
6875
+ ['Opera', 'Blink'],
6876
+ ['MSEdge', 'Blink'],
6877
+ ['SamsungBrowser', 'Blink'],
6878
+ ]);
6879
+ return engines.get(this.browserApp) ?? unknownValue;
6880
+ }
6881
+ get os() {
6882
+ return this._os;
6883
+ }
6884
+ get osType() {
6885
+ if (['iPhone', 'iPod', 'iPad'].includes(this.window.navigator.platform)) {
6886
+ return 'ios';
6887
+ }
6888
+ if (this.window.navigator.platform?.includes('MacIntel')) {
6889
+ return 'mac';
6890
+ }
6891
+ if (this.isXbox) {
6892
+ return 'xbox';
6893
+ }
6894
+ if (this.isWindows) {
6895
+ return 'windows';
6896
+ }
6897
+ if (this.isAndroid) {
6898
+ return 'android';
6899
+ }
6900
+ if (this.isLinux) {
6901
+ return 'linux';
6902
+ }
6903
+ return null;
6904
+ }
6905
+ }
6906
+ UserAgentService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: UserAgentService, deps: [{ token: windowToken }], target: i0.ɵɵFactoryTarget.Injectable });
6907
+ UserAgentService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: UserAgentService, providedIn: 'root' });
6908
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: UserAgentService, decorators: [{
6909
+ type: Injectable,
6910
+ args: [{
6911
+ providedIn: 'root',
6912
+ }]
6913
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
6914
+ type: Inject,
6915
+ args: [windowToken]
6916
+ }] }]; } });
6917
+
6918
+ class ApplePayService {
6919
+ get paymentParameters() {
6920
+ return this.applePayParams;
6921
+ }
6922
+ get payment$() {
6923
+ return this.payment.asObservable();
6924
+ }
6925
+ get error$() {
6926
+ return this.error.asObservable();
6927
+ }
6928
+ get integrationType$() {
6929
+ return this.integrationType.asObservable();
6930
+ }
6931
+ constructor(window, userAgentService, summaryFinanceDetailsAdapterService) {
6932
+ this.window = window;
6933
+ this.userAgentService = userAgentService;
6934
+ this.summaryFinanceDetailsAdapterService = summaryFinanceDetailsAdapterService;
6935
+ this.agreementFieldsNames = agreementsGroup;
6936
+ this.payment = new Subject();
6937
+ this.error = new Subject();
6938
+ this.integrationType = new Subject();
6939
+ this.paymentClient = null;
6940
+ this.applePayParams = null;
6941
+ this.order = null;
6942
+ this.api = this.loadBraintree();
6943
+ }
6944
+ setApplePayParams(data) {
6945
+ const formFields = data?.paymentForm?.fields;
6946
+ const summary = data?.paymentForm?.summary;
6947
+ if (!formFields || !summary) {
6948
+ return;
6949
+ }
6950
+ const fields = formFields.reduce((acc, field) => {
6951
+ if (this.agreementFieldsNames.includes(field.name) &&
6952
+ field.isVisible === '1') {
6953
+ acc[field.name] = field.title;
6954
+ }
6955
+ else {
6956
+ acc[field.name] = field.value;
6957
+ }
6958
+ return acc;
6959
+ }, {});
6960
+ const agreements = this.agreementFieldsNames
6961
+ .map((fieldName) => fields[fieldName])
6962
+ .filter(Boolean);
6963
+ this.applePayParams = {
6964
+ tokenKey: this.getAppleToken(formFields),
6965
+ totalLabel: fields['label_applePay'] ?? '',
6966
+ totalAmount: this.getTotalAmount(summary),
6967
+ currencyCode: this.getTotalCurrency(summary),
6968
+ countryCode: fields['countryCode'] ?? '',
6969
+ merchantCapabilities: this.getJsonValueFromField(fields, 'merchantCapabilities'),
6970
+ supportedNetworks: this.getJsonValueFromField(fields, 'supportedNetworks'),
6971
+ agreements: agreements,
6972
+ };
6973
+ }
6974
+ async initLibrary(tokenKey) {
6975
+ try {
6976
+ const api = await this.api;
6977
+ const clientInstance = await api.client.create({
6978
+ authorization: tokenKey,
6979
+ });
6980
+ this.paymentClient = await api.applePay.create({
6981
+ client: clientInstance,
6982
+ });
6983
+ }
6984
+ catch (error) {
6985
+ console.error('apple pay: initialize failed', error);
6986
+ }
6987
+ this.emitIntegrationType();
6988
+ if (!this.paymentClient ||
6989
+ (!this.isDeviceCapable() && !this.userAgentService.isSafari)) {
6990
+ this.emitError(ApplePayErrors.deviceIsNotCapableError);
6991
+ }
6992
+ }
6993
+ redirectToPaymentPage(parameters, token) {
6994
+ const route = pagesRoutes.get(applePayId);
6995
+ if (!route) {
6996
+ return;
6997
+ }
6998
+ const query = new URLSearchParams({
6999
+ ...parameters,
7000
+ merchantCapabilities: JSON.stringify(parameters.merchantCapabilities),
7001
+ supportedNetworks: JSON.stringify(parameters.supportedNetworks),
7002
+ token,
7003
+ agreements: JSON.stringify(parameters.agreements),
7004
+ });
7005
+ if (this.order) {
7006
+ query.append('order', this.order);
7007
+ }
7008
+ const url = `${route}?${query.toString()}`;
7009
+ return url;
7010
+ }
7011
+ setOrder(data) {
7012
+ const summary = data?.paymentForm?.summary;
7013
+ if (!summary) {
7014
+ return;
7015
+ }
7016
+ const financeDetails = this.summaryFinanceDetailsAdapterService.getFinanceDetails(summary);
7017
+ if (financeDetails?.purchase && financeDetails?.finance) {
7018
+ const cartItems = financeDetails.cartItems;
7019
+ this.order = cartItems?.reduce((curr, item) => {
7020
+ if (curr) {
7021
+ return curr + `; ${item.title}`;
7022
+ }
7023
+ return curr + item.title;
7024
+ }, '');
7025
+ }
7026
+ }
7027
+ proceedCheckout(parameters) {
7028
+ if (!parameters) {
7029
+ return;
7030
+ }
7031
+ if (!this.paymentClient || !this.isDeviceCapable()) {
7032
+ console.warn('apple pay: device is not capable', this.paymentClient);
7033
+ this.emitError(ApplePayErrors.deviceIsNotCapableError);
7034
+ return;
7035
+ }
7036
+ try {
7037
+ const paymentRequest = this.paymentClient.createPaymentRequest({
7038
+ total: {
7039
+ label: parameters.totalLabel,
7040
+ amount: parameters.totalAmount,
7041
+ },
7042
+ currencyCode: parameters.currencyCode,
7043
+ countryCode: parameters.countryCode,
7044
+ merchantCapabilities: parameters.merchantCapabilities,
7045
+ supportedNetworks: parameters.supportedNetworks,
7046
+ });
7047
+ const session = new this.window.ApplePaySession(applePayVersion, paymentRequest);
7048
+ session.onvalidatemerchant = (event) => {
7049
+ console.info('apple pay: merchant validation', event);
7050
+ this.paymentClient
7051
+ ?.performValidation({
7052
+ validationURL: event.validationURL,
7053
+ displayName: parameters?.totalLabel,
7054
+ })
7055
+ .then((merchantSession) => {
7056
+ session.completeMerchantValidation(merchantSession);
7057
+ })
7058
+ .catch((error) => {
7059
+ console.error('apple pay: merchant validation error', error);
7060
+ session.abort();
7061
+ });
7062
+ };
7063
+ session.onpaymentauthorized = (event) => {
7064
+ console.info('apple pay: payment authorization', event);
7065
+ this.paymentClient
7066
+ ?.tokenize({
7067
+ token: event.payment.token,
7068
+ })
7069
+ .then((authorizationResponse) => {
7070
+ this.payment.next(authorizationResponse?.nonce ?? '');
7071
+ session.completePayment(this.window.ApplePaySession.STATUS_SUCCESS);
7072
+ })
7073
+ .catch((error) => {
7074
+ console.error('apple pay: payment authorization error', error);
7075
+ session.completePayment(this.window.ApplePaySession.STATUS_FAILURE);
7076
+ });
7077
+ };
7078
+ session.oncancel = (event) => {
7079
+ this.emitError(ApplePayErrors.paymentError);
7080
+ console.error('apple pay: user cancel payment', event);
7081
+ };
7082
+ session.begin();
7083
+ }
7084
+ catch (error) {
7085
+ console.error('apple pay: checkout error', error);
7086
+ this.emitError(ApplePayErrors.paymentError);
7087
+ }
7088
+ }
7089
+ isDeviceCapable() {
7090
+ try {
7091
+ return Boolean(this.window.ApplePaySession?.supportsVersion(applePayVersion) &&
7092
+ this.window.ApplePaySession?.canMakePayments());
7093
+ }
7094
+ catch (error) {
7095
+ return false;
7096
+ }
7097
+ }
7098
+ getTokenNonceFieldData(tokenNonce) {
7099
+ const name = FieldNames.tokenApplePay;
7100
+ const value = btoa(tokenNonce);
7101
+ return { name, value };
7102
+ }
7103
+ updateApplePayParams(data) {
7104
+ const summary = data?.summary;
7105
+ if (!this.applePayParams || !summary) {
7106
+ return;
7107
+ }
7108
+ this.applePayParams.totalAmount = this.getTotalAmount(summary);
7109
+ this.applePayParams.currencyCode = this.getTotalCurrency(summary);
7110
+ }
7111
+ async loadBraintree() {
7112
+ const api = await import('braintree-web');
7113
+ return api;
7114
+ }
7115
+ getAppleToken(formFields) {
7116
+ const appleTokenField = formFields.find((field) => {
7117
+ return field.name === 'token_key';
7118
+ });
7119
+ if (!appleTokenField) {
7120
+ return '';
7121
+ }
7122
+ return appleTokenField.value;
7123
+ }
7124
+ getTotalAmount(summary) {
7125
+ const finance = summary?.finance;
7126
+ const total = finance?.grand_total?.amount ?? finance?.total.amount;
7127
+ return total?.toString() ?? '';
7128
+ }
7129
+ getTotalCurrency(summary) {
7130
+ const finance = summary?.finance;
7131
+ return finance?.grand_total?.currency ?? finance?.total?.currency ?? '';
7132
+ }
7133
+ getJsonValueFromField(fields, fieldName) {
7134
+ const field = fields[fieldName];
7135
+ try {
7136
+ return field ? JSON.parse(field) : undefined;
7137
+ }
7138
+ catch (error) {
7139
+ return undefined;
7140
+ }
7141
+ }
7142
+ emitError(error) {
7143
+ this.error.next(error);
7144
+ }
7145
+ emitIntegrationType() {
7146
+ let integrationType;
7147
+ if (this.paymentClient && this.isDeviceCapable()) {
7148
+ integrationType = 'sdk';
7149
+ }
7150
+ else if (this.userAgentService.isSafari) {
7151
+ integrationType = 'redirect';
7152
+ }
7153
+ else {
7154
+ integrationType = 'none';
7155
+ }
7156
+ this.integrationType.next(integrationType);
7157
+ }
7158
+ }
7159
+ ApplePayService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ApplePayService, deps: [{ token: windowToken }, { token: UserAgentService }, { token: SummaryFinanceDetailsAdapterService }], target: i0.ɵɵFactoryTarget.Injectable });
7160
+ ApplePayService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ApplePayService, providedIn: 'root' });
7161
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: ApplePayService, decorators: [{
7162
+ type: Injectable,
7163
+ args: [{
7164
+ providedIn: 'root',
7165
+ }]
7166
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
7167
+ type: Inject,
7168
+ args: [windowToken]
7169
+ }] }, { type: UserAgentService }, { type: SummaryFinanceDetailsAdapterService }]; } });
7170
+
6333
7171
  /*
6334
7172
  * Public API Surface of core-library
6335
7173
  */
@@ -6338,5 +7176,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
6338
7176
  * Generated bundle index. Do not edit.
6339
7177
  */
6340
7178
 
6341
- export { CoreLibraryModule, CoreLibraryService };
7179
+ export { ApplePayService, CoreLibraryModule, CoreLibraryService };
6342
7180
  //# sourceMappingURL=xsolla-payment-client-core.mjs.map