@xsolla/payment-client-core 0.0.1 → 0.0.3-1

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 (124) hide show
  1. package/README.md +8 -11
  2. package/esm2020/lib/core/boolean-number.enum.mjs +6 -0
  3. package/esm2020/lib/core/country/country.service.mjs +27 -0
  4. package/esm2020/lib/core/deep-readonly.type.mjs +2 -0
  5. package/esm2020/lib/core/exceptions-handling/errors/api-error.interface.mjs +2 -0
  6. package/esm2020/lib/core/exceptions-handling/errors/app-error.class.mjs +6 -0
  7. package/esm2020/lib/core/exceptions-handling/errors/http-error.class.mjs +40 -0
  8. package/esm2020/lib/core/exceptions-handling/errors/response-error.class.mjs +7 -0
  9. package/esm2020/lib/core/exceptions-handling/http-interceptor/http-error-data.interface.mjs +2 -0
  10. package/esm2020/lib/core/exceptions-handling/http-interceptor/http-error-response-data.interface.mjs +2 -0
  11. package/esm2020/lib/core/exceptions-handling/http-interceptor/http-exceptions.interceptor.mjs +22 -0
  12. package/esm2020/lib/core/extended-window.interface.mjs +2 -0
  13. package/esm2020/lib/core/http/secure-api/api-url.const.mjs +3 -0
  14. package/esm2020/lib/core/http/secure-api/options.interface.mjs +2 -0
  15. package/esm2020/lib/core/http/secure-api/secure-api.service.mjs +55 -0
  16. package/esm2020/lib/core/legal/legal.component.config.mjs +2 -0
  17. package/esm2020/lib/core/legal/legal.service.mjs +30 -0
  18. package/esm2020/lib/core/legal/refund-policy.service.mjs +30 -0
  19. package/esm2020/lib/core/payment-methods/payment-method-api.interface.mjs +2 -0
  20. package/esm2020/lib/core/payment-methods/payment-method.interface.mjs +2 -0
  21. package/esm2020/lib/core/payment-methods/payment-methods-api.interface.mjs +2 -0
  22. package/esm2020/lib/core/payment-methods/payment-methods-request-params.interface.mjs +2 -0
  23. package/esm2020/lib/core/payment-methods/payment-methods-response.class.mjs +26 -0
  24. package/esm2020/lib/core/payment-methods/payment-methods-response.interface.mjs +2 -0
  25. package/esm2020/lib/core/payment-methods/payment-methods-response.token.mjs +8 -0
  26. package/esm2020/lib/core/payment-methods/payment-methods.service.mjs +58 -0
  27. package/esm2020/lib/core/saved-methods/saved-method-api.interface.mjs +2 -0
  28. package/esm2020/lib/core/saved-methods/saved-method.interface.mjs +2 -0
  29. package/esm2020/lib/core/saved-methods/saved-methods-request-params.interface.mjs +2 -0
  30. package/esm2020/lib/core/saved-methods/saved-methods-response.class.mjs +24 -0
  31. package/esm2020/lib/core/saved-methods/saved-methods-response.interface.mjs +2 -0
  32. package/esm2020/lib/core/saved-methods/saved-methods-response.token.mjs +8 -0
  33. package/esm2020/lib/core/saved-methods/saved-methods.service.mjs +53 -0
  34. package/esm2020/lib/core/settings/auto-redirect-on-status.mjs +14 -0
  35. package/esm2020/lib/core/settings/balance.interface.mjs +2 -0
  36. package/esm2020/lib/core/settings/bonus.interface.mjs +2 -0
  37. package/esm2020/lib/core/settings/configuration.interface.mjs +2 -0
  38. package/esm2020/lib/core/settings/empty-utils-response.error.mjs +7 -0
  39. package/esm2020/lib/core/settings/header-type.enum.mjs +6 -0
  40. package/esm2020/lib/core/settings/offer.interface.mjs +2 -0
  41. package/esm2020/lib/core/settings/project.interface.mjs +2 -0
  42. package/esm2020/lib/core/settings/purchase.interface.mjs +2 -0
  43. package/esm2020/lib/core/settings/settings-mode.enum.mjs +5 -0
  44. package/esm2020/lib/core/settings/settings.interface.mjs +2 -0
  45. package/esm2020/lib/core/settings/settings.service.mjs +85 -0
  46. package/esm2020/lib/core/settings/status-back-show.mjs +16 -0
  47. package/esm2020/lib/core/settings/tracking-info.interface.mjs +2 -0
  48. package/esm2020/lib/core/settings/user.interface.mjs +2 -0
  49. package/esm2020/lib/core/settings/utils-response.interface.mjs +2 -0
  50. package/esm2020/lib/core/user-balance/user-balance-api.interface.mjs +2 -0
  51. package/esm2020/lib/core/user-balance/user-balance-request-params.interface.mjs +2 -0
  52. package/esm2020/lib/core/user-balance/user-balance-response.class.mjs +8 -0
  53. package/esm2020/lib/core/user-balance/user-balance-response.token.mjs +8 -0
  54. package/esm2020/lib/core/user-balance/user-balance.service.mjs +50 -0
  55. package/esm2020/lib/core/window.token.mjs +3 -0
  56. package/esm2020/lib/core-library.module.mjs +31 -7
  57. package/esm2020/lib/core-library.service.mjs +32 -3
  58. package/esm2020/public-api.mjs +2 -2
  59. package/fesm2015/xsolla-payment-client-core.mjs +582 -16
  60. package/fesm2015/xsolla-payment-client-core.mjs.map +1 -1
  61. package/fesm2020/xsolla-payment-client-core.mjs +554 -16
  62. package/fesm2020/xsolla-payment-client-core.mjs.map +1 -1
  63. package/lib/core/boolean-number.enum.d.ts +4 -0
  64. package/lib/core/country/country.service.d.ts +12 -0
  65. package/lib/core/deep-readonly.type.d.ts +3 -0
  66. package/lib/core/exceptions-handling/errors/api-error.interface.d.ts +4 -0
  67. package/lib/core/exceptions-handling/errors/app-error.class.d.ts +3 -0
  68. package/lib/core/exceptions-handling/errors/http-error.class.d.ts +10 -0
  69. package/lib/core/exceptions-handling/errors/response-error.class.d.ts +4 -0
  70. package/lib/core/exceptions-handling/http-interceptor/http-error-data.interface.d.ts +20 -0
  71. package/lib/core/exceptions-handling/http-interceptor/http-error-response-data.interface.d.ts +7 -0
  72. package/lib/core/exceptions-handling/http-interceptor/http-exceptions.interceptor.d.ts +11 -0
  73. package/lib/core/extended-window.interface.d.ts +1 -0
  74. package/lib/core/http/secure-api/api-url.const.d.ts +2 -0
  75. package/lib/core/http/secure-api/options.interface.d.ts +14 -0
  76. package/lib/core/http/secure-api/secure-api.service.d.ts +20 -0
  77. package/lib/core/legal/legal.component.config.d.ts +5 -0
  78. package/lib/core/legal/legal.service.d.ts +14 -0
  79. package/lib/core/legal/refund-policy.service.d.ts +11 -0
  80. package/lib/core/payment-methods/payment-method-api.interface.d.ts +11 -0
  81. package/lib/core/payment-methods/payment-method.interface.d.ts +11 -0
  82. package/lib/core/payment-methods/payment-methods-api.interface.d.ts +10 -0
  83. package/lib/core/payment-methods/payment-methods-request-params.interface.d.ts +4 -0
  84. package/lib/core/payment-methods/payment-methods-response.class.d.ts +13 -0
  85. package/lib/core/payment-methods/payment-methods-response.interface.d.ts +4 -0
  86. package/lib/core/payment-methods/payment-methods-response.token.d.ts +7 -0
  87. package/lib/core/payment-methods/payment-methods.service.d.ts +20 -0
  88. package/lib/core/saved-methods/saved-method-api.interface.d.ts +22 -0
  89. package/lib/core/saved-methods/saved-method.interface.d.ts +21 -0
  90. package/lib/core/saved-methods/saved-methods-request-params.interface.d.ts +3 -0
  91. package/lib/core/saved-methods/saved-methods-response.class.d.ts +7 -0
  92. package/lib/core/saved-methods/saved-methods-response.interface.d.ts +4 -0
  93. package/lib/core/saved-methods/saved-methods-response.token.d.ts +7 -0
  94. package/lib/core/saved-methods/saved-methods.service.d.ts +19 -0
  95. package/lib/core/settings/auto-redirect-on-status.d.ts +12 -0
  96. package/lib/core/settings/balance.interface.d.ts +4 -0
  97. package/lib/core/settings/bonus.interface.d.ts +10 -0
  98. package/lib/core/settings/configuration.interface.d.ts +5 -0
  99. package/lib/core/settings/empty-utils-response.error.d.ts +4 -0
  100. package/lib/core/settings/header-type.enum.d.ts +4 -0
  101. package/lib/core/settings/offer.interface.d.ts +6 -0
  102. package/lib/core/settings/project.interface.d.ts +32 -0
  103. package/lib/core/settings/purchase.interface.d.ts +47 -0
  104. package/lib/core/settings/settings-mode.enum.d.ts +3 -0
  105. package/lib/core/settings/settings.interface.d.ts +45 -0
  106. package/lib/core/settings/settings.service.d.ts +30 -0
  107. package/lib/core/settings/status-back-show.d.ts +14 -0
  108. package/lib/core/settings/tracking-info.interface.d.ts +5 -0
  109. package/lib/core/settings/user.interface.d.ts +23 -0
  110. package/lib/core/settings/utils-response.interface.d.ts +16 -0
  111. package/lib/core/user-balance/user-balance-api.interface.d.ts +4 -0
  112. package/lib/core/user-balance/user-balance-request-params.interface.d.ts +3 -0
  113. package/lib/core/user-balance/user-balance-response.class.d.ts +6 -0
  114. package/lib/core/user-balance/user-balance-response.token.d.ts +7 -0
  115. package/lib/core/user-balance/user-balance.service.d.ts +17 -0
  116. package/lib/core/window.token.d.ts +3 -0
  117. package/lib/core-library.module.d.ts +2 -2
  118. package/lib/core-library.service.d.ts +27 -0
  119. package/package.json +4 -3
  120. package/public-api.d.ts +1 -1
  121. package/xsolla-payment-client-core-0.0.3-1.tgz +0 -0
  122. package/esm2020/lib/core-library.component.mjs +0 -11
  123. package/lib/core-library.component.d.ts +0 -5
  124. package/xsolla-payment-client-core-0.0.1.tgz +0 -0
@@ -1,37 +1,603 @@
1
+ import { __awaiter } from 'tslib';
1
2
  import * as i0 from '@angular/core';
2
- import { Injectable, Component, NgModule } from '@angular/core';
3
+ import { InjectionToken, Injectable, Inject, NgModule } from '@angular/core';
4
+ import { firstValueFrom, lastValueFrom, map, throwError } from 'rxjs';
5
+ import * as i1 from '@angular/common/http';
6
+ import { HttpParams, HttpHeaders, HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
7
+ import { catchError } from 'rxjs/operators';
8
+ import * as i1$1 from '@angular/router';
9
+
10
+ class AppError extends Error {
11
+ constructor(message) {
12
+ super(message);
13
+ }
14
+ }
15
+
16
+ class EmptyUtilsResponseError extends AppError {
17
+ constructor() {
18
+ super('Utils response is empty or not requested. Check your token.');
19
+ }
20
+ }
21
+
22
+ const windowToken = new InjectionToken('window');
23
+
24
+ const defaultApiUrl = 'https://secure.xsolla.com/paystation2/api/';
25
+ const sandboxApiUrl = 'https://sandbox-secure.xsolla.com/paystation2/api/';
26
+
27
+ class SecureApiClient {
28
+ constructor(httpClient, window) {
29
+ this.httpClient = httpClient;
30
+ this.window = window;
31
+ this.isSandboxMode = false;
32
+ }
33
+ setSandboxMode(isSandboxMode) {
34
+ this.isSandboxMode = isSandboxMode;
35
+ }
36
+ get(url, options) {
37
+ return this.httpClient.get(`${this.baseUrl}${url}`, options);
38
+ }
39
+ post(url, body, options) {
40
+ return this.httpClient.post(`${this.baseUrl}${url}`, body, options);
41
+ }
42
+ patch(url, body, options) {
43
+ return this.httpClient.patch(`${this.baseUrl}${url}`, body, options);
44
+ }
45
+ put(url, body, options) {
46
+ return this.httpClient.put(`${this.baseUrl}${url}`, body, options);
47
+ }
48
+ delete(url, options) {
49
+ return this.httpClient.delete(`${this.baseUrl}${url}`, options);
50
+ }
51
+ get baseUrl() {
52
+ let predefinedBaseUrl = null;
53
+ try {
54
+ predefinedBaseUrl = this.window.localStorage.getItem('devApiUrl');
55
+ }
56
+ catch (e) {
57
+ console.warn('localStorage is not available');
58
+ }
59
+ if (predefinedBaseUrl) {
60
+ return predefinedBaseUrl;
61
+ }
62
+ return this.isSandboxMode ? sandboxApiUrl : defaultApiUrl;
63
+ }
64
+ }
65
+ SecureApiClient.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SecureApiClient, deps: [{ token: i1.HttpClient }, { token: windowToken }], target: i0.ɵɵFactoryTarget.Injectable });
66
+ SecureApiClient.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SecureApiClient, providedIn: 'root' });
67
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SecureApiClient, decorators: [{
68
+ type: Injectable,
69
+ args: [{
70
+ providedIn: 'root',
71
+ }]
72
+ }], ctorParameters: function () {
73
+ return [{ type: i1.HttpClient }, { type: undefined, decorators: [{
74
+ type: Inject,
75
+ args: [windowToken]
76
+ }] }];
77
+ } });
78
+
79
+ class SettingsService {
80
+ get project() {
81
+ if (!this.response) {
82
+ throw new EmptyUtilsResponseError();
83
+ }
84
+ return this.response.project;
85
+ }
86
+ get purchase() {
87
+ if (!this.response) {
88
+ throw new EmptyUtilsResponseError();
89
+ }
90
+ return this.response.purchase;
91
+ }
92
+ get settings() {
93
+ var _a, _b;
94
+ if (!this.response) {
95
+ throw new EmptyUtilsResponseError();
96
+ }
97
+ if ((_a = this.response) === null || _a === void 0 ? void 0 : _a.purchase_external_id) {
98
+ return Object.assign(Object.assign({}, this.response.settings), { purchase_external_id: this.response.purchase_external_id });
99
+ }
100
+ return (_b = this.response) === null || _b === void 0 ? void 0 : _b.settings;
101
+ }
102
+ get user() {
103
+ if (!this.response) {
104
+ throw new EmptyUtilsResponseError();
105
+ }
106
+ return this.response.user;
107
+ }
108
+ get utilsResponse() {
109
+ if (!this.response) {
110
+ throw new EmptyUtilsResponseError();
111
+ }
112
+ return this.response;
113
+ }
114
+ get isEmpty() {
115
+ return !this.response;
116
+ }
117
+ get token() {
118
+ return this._token;
119
+ }
120
+ get hasResponse() {
121
+ return !!this.response;
122
+ }
123
+ constructor(secureApi) {
124
+ this.secureApi = secureApi;
125
+ this.isInitialized = false;
126
+ this._token = '';
127
+ this.sandboxMode = false;
128
+ }
129
+ init(configuration) {
130
+ return __awaiter(this, void 0, void 0, function* () {
131
+ if (!configuration.token) {
132
+ return Promise.reject('token is missing');
133
+ }
134
+ this._token = configuration.token;
135
+ this.sandboxMode = !!configuration.sandbox;
136
+ yield this.sendRequest(this.token);
137
+ this.isInitialized = true;
138
+ });
139
+ }
140
+ isSandboxMode() {
141
+ return this.sandboxMode;
142
+ }
143
+ sendRequest(token) {
144
+ return __awaiter(this, void 0, void 0, function* () {
145
+ const params = new HttpParams().set('access_token', token);
146
+ this.secureApi.setSandboxMode(this.isSandboxMode());
147
+ this.response = yield firstValueFrom(this.secureApi.get('utils', { params }));
148
+ });
149
+ }
150
+ }
151
+ SettingsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SettingsService, deps: [{ token: SecureApiClient }], target: i0.ɵɵFactoryTarget.Injectable });
152
+ SettingsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SettingsService, providedIn: 'root' });
153
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SettingsService, decorators: [{
154
+ type: Injectable,
155
+ args: [{
156
+ providedIn: 'root',
157
+ }]
158
+ }], ctorParameters: function () { return [{ type: SecureApiClient }]; } });
159
+
160
+ class CountryService {
161
+ constructor(settingsService) {
162
+ this.settingsService = settingsService;
163
+ this.userDefinedCountry = null;
164
+ }
165
+ setCountry(country) {
166
+ this.userDefinedCountry = country;
167
+ }
168
+ getCountry() {
169
+ var _a;
170
+ return (_a = this.userDefinedCountry) !== null && _a !== void 0 ? _a : this.getTokenCountry();
171
+ }
172
+ getTokenCountry() {
173
+ return this.settingsService.user.country.value;
174
+ }
175
+ }
176
+ CountryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CountryService, deps: [{ token: SettingsService }], target: i0.ɵɵFactoryTarget.Injectable });
177
+ CountryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CountryService, providedIn: 'root' });
178
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CountryService, decorators: [{
179
+ type: Injectable,
180
+ args: [{
181
+ providedIn: 'root',
182
+ }]
183
+ }], ctorParameters: function () { return [{ type: SettingsService }]; } });
184
+
185
+ class ResponseError extends AppError {
186
+ constructor(message) {
187
+ super('Response failed' + (message ? `: "${message}".` : '.'));
188
+ }
189
+ }
190
+
191
+ var BooleanNumber;
192
+ (function (BooleanNumber) {
193
+ BooleanNumber[BooleanNumber["false"] = 0] = "false";
194
+ BooleanNumber[BooleanNumber["true"] = 1] = "true";
195
+ })(BooleanNumber || (BooleanNumber = {}));
196
+
197
+ class PaymentMethodsResponse {
198
+ constructor(paymentMethods) {
199
+ this.especial = paymentMethods.especial.map((method) => this.mapPaymentMethod(method));
200
+ this.top = paymentMethods.top.map((method) => this.mapPaymentMethod(method));
201
+ this.remained = paymentMethods.remained.map((method) => this.mapPaymentMethod(method));
202
+ this.remainedCount = {
203
+ total: paymentMethods.remained_count.total,
204
+ visible: paymentMethods.remained_count.visible,
205
+ };
206
+ }
207
+ mapPaymentMethod(method) {
208
+ return {
209
+ id: method.id,
210
+ rank: method.rank,
211
+ name: method.name,
212
+ aliases: method.aliases,
213
+ categories: method.cat,
214
+ isVisible: method.is_visible,
215
+ recommended: method.recommended === BooleanNumber.true,
216
+ enabledSaveAccount: method.enabled_save_account,
217
+ iconName: method.switch_icon_name,
218
+ };
219
+ }
220
+ }
221
+
222
+ const paymentMethodsResponseFactoryToken = new InjectionToken('PaymentMethodsResponse');
223
+ const paymentMethodsResponseFactoryProvider = {
224
+ provide: paymentMethodsResponseFactoryToken,
225
+ useValue: (...args) => new PaymentMethodsResponse(...args),
226
+ };
227
+
228
+ class PaymentMethodsService {
229
+ constructor(responseFactory, settingsService, countryService, secureApi) {
230
+ this.responseFactory = responseFactory;
231
+ this.settingsService = settingsService;
232
+ this.countryService = countryService;
233
+ this.secureApi = secureApi;
234
+ this.apiRoute = 'remained_payment_methods';
235
+ this.cache = new Map();
236
+ }
237
+ getList() {
238
+ return __awaiter(this, void 0, void 0, function* () {
239
+ const response = yield this.request();
240
+ return response.remained;
241
+ });
242
+ }
243
+ getQuickMethods() {
244
+ return __awaiter(this, void 0, void 0, function* () {
245
+ const response = yield this.request();
246
+ return response.especial;
247
+ });
248
+ }
249
+ request() {
250
+ return __awaiter(this, void 0, void 0, function* () {
251
+ const requestParams = {
252
+ access_token: this.settingsService.token,
253
+ country: this.countryService.getCountry(),
254
+ };
255
+ const cacheKey = JSON.stringify(requestParams);
256
+ if (!this.cache.has(cacheKey)) {
257
+ this.cache.set(cacheKey, lastValueFrom(this.secureApi
258
+ .post(this.apiRoute, new URLSearchParams(Object.assign({}, requestParams)), {
259
+ headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
260
+ responseType: 'json',
261
+ })
262
+ .pipe(map((response) => this.responseFactory(response.payment_methods)))).catch((error) => {
263
+ throw new ResponseError(error.message);
264
+ }));
265
+ }
266
+ // @ts-expect-error the map already has the cache with key
267
+ return this.cache.get(cacheKey);
268
+ });
269
+ }
270
+ }
271
+ PaymentMethodsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentMethodsService, deps: [{ token: paymentMethodsResponseFactoryToken }, { token: SettingsService }, { token: CountryService }, { token: SecureApiClient }], target: i0.ɵɵFactoryTarget.Injectable });
272
+ PaymentMethodsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentMethodsService, providedIn: 'root' });
273
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PaymentMethodsService, decorators: [{
274
+ type: Injectable,
275
+ args: [{
276
+ providedIn: 'root',
277
+ }]
278
+ }], ctorParameters: function () {
279
+ return [{ type: undefined, decorators: [{
280
+ type: Inject,
281
+ args: [paymentMethodsResponseFactoryToken]
282
+ }] }, { type: SettingsService }, { type: CountryService }, { type: SecureApiClient }];
283
+ } });
284
+
285
+ class SavedMethodsResponse {
286
+ constructor(savedMethods) {
287
+ this.list = savedMethods.list.map((method) => this.mapSavedMethod(method));
288
+ }
289
+ mapSavedMethod(method) {
290
+ return {
291
+ currency: method.currency,
292
+ form: method.form,
293
+ id: method.id,
294
+ isSelected: method.isSelected,
295
+ isBabkaPay: method.is_babka_pay,
296
+ name: method.name,
297
+ pid: method.pid,
298
+ psName: method.psName,
299
+ recurrentType: method.recurrent_type,
300
+ replaced: method.replaced,
301
+ type: method.type,
302
+ cardExpiryDate: method.card_expiry_date,
303
+ iconName: method.switch_icon_name,
304
+ partner: method.partner,
305
+ };
306
+ }
307
+ }
308
+
309
+ const savedMethodsResponseFactoryToken = new InjectionToken('SavedMethodsResponse');
310
+ const savedMethodsResponseFactoryProvider = {
311
+ provide: savedMethodsResponseFactoryToken,
312
+ useValue: (...args) => new SavedMethodsResponse(...args),
313
+ };
314
+
315
+ class SavedMethodsService {
316
+ constructor(responseFactory, settingsService, countryService, secureApi) {
317
+ this.responseFactory = responseFactory;
318
+ this.settingsService = settingsService;
319
+ this.countryService = countryService;
320
+ this.secureApi = secureApi;
321
+ this.apiRoute = 'savedmethods';
322
+ this.cache = new Map();
323
+ }
324
+ getList() {
325
+ return __awaiter(this, void 0, void 0, function* () {
326
+ const response = yield this.request();
327
+ return response.list;
328
+ });
329
+ }
330
+ request() {
331
+ return __awaiter(this, void 0, void 0, function* () {
332
+ const requestParams = {
333
+ access_token: this.settingsService.token,
334
+ };
335
+ const cacheKey = JSON.stringify(requestParams);
336
+ if (!this.cache.has(cacheKey)) {
337
+ this.cache.set(cacheKey, lastValueFrom(this.secureApi
338
+ .post(this.apiRoute, new URLSearchParams(Object.assign({}, requestParams)), {
339
+ headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
340
+ responseType: 'json',
341
+ })
342
+ .pipe(map((response) => this.responseFactory(response)))).catch((error) => {
343
+ throw new ResponseError(error.message);
344
+ }));
345
+ }
346
+ // @ts-expect-error the map already has the cache with key
347
+ return this.cache.get(cacheKey);
348
+ });
349
+ }
350
+ }
351
+ SavedMethodsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavedMethodsService, deps: [{ token: savedMethodsResponseFactoryToken }, { token: SettingsService }, { token: CountryService }, { token: SecureApiClient }], target: i0.ɵɵFactoryTarget.Injectable });
352
+ SavedMethodsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavedMethodsService, providedIn: 'root' });
353
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SavedMethodsService, decorators: [{
354
+ type: Injectable,
355
+ args: [{
356
+ providedIn: 'root',
357
+ }]
358
+ }], ctorParameters: function () {
359
+ return [{ type: undefined, decorators: [{
360
+ type: Inject,
361
+ args: [savedMethodsResponseFactoryToken]
362
+ }] }, { type: SettingsService }, { type: CountryService }, { type: SecureApiClient }];
363
+ } });
364
+
365
+ class UserBalanceResponse {
366
+ constructor(userBalance) {
367
+ var _a, _b;
368
+ this.isEnoughUserBalance = (_a = userBalance.is_enough_user_balance) !== null && _a !== void 0 ? _a : false;
369
+ this.isEnoughUserRecurrentBalance =
370
+ (_b = userBalance.is_enough_user_recurrent_balance) !== null && _b !== void 0 ? _b : false;
371
+ }
372
+ }
373
+
374
+ const userBalanceResponseFactoryToken = new InjectionToken('UserBalanceResponse');
375
+ const userBalanceResponseFactoryProvider = {
376
+ provide: userBalanceResponseFactoryToken,
377
+ useValue: (...args) => new UserBalanceResponse(...args),
378
+ };
379
+
380
+ class UserBalanceService {
381
+ constructor(responseFactory, settingsService, secureApi) {
382
+ this.responseFactory = responseFactory;
383
+ this.settingsService = settingsService;
384
+ this.secureApi = secureApi;
385
+ this.apiRoute = 'balance/sufficiency';
386
+ this.cache = new Map();
387
+ }
388
+ getUserBalance() {
389
+ return __awaiter(this, void 0, void 0, function* () {
390
+ return this.request();
391
+ });
392
+ }
393
+ request() {
394
+ return __awaiter(this, void 0, void 0, function* () {
395
+ const requestParams = {
396
+ access_token: this.settingsService.token,
397
+ };
398
+ const cacheKey = JSON.stringify(requestParams);
399
+ if (!this.cache.has(cacheKey)) {
400
+ this.cache.set(cacheKey, lastValueFrom(this.secureApi
401
+ .post(this.apiRoute, new URLSearchParams(Object.assign({}, requestParams)), {
402
+ headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
403
+ responseType: 'json',
404
+ })
405
+ .pipe(map((response) => this.responseFactory(response)))).catch((error) => {
406
+ throw new ResponseError(error.message);
407
+ }));
408
+ }
409
+ // @ts-expect-error the map already has the cache with key
410
+ return this.cache.get(cacheKey);
411
+ });
412
+ }
413
+ }
414
+ UserBalanceService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: UserBalanceService, deps: [{ token: userBalanceResponseFactoryToken }, { token: SettingsService }, { token: SecureApiClient }], target: i0.ɵɵFactoryTarget.Injectable });
415
+ UserBalanceService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: UserBalanceService, providedIn: 'root' });
416
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: UserBalanceService, decorators: [{
417
+ type: Injectable,
418
+ args: [{
419
+ providedIn: 'root',
420
+ }]
421
+ }], ctorParameters: function () {
422
+ return [{ type: undefined, decorators: [{
423
+ type: Inject,
424
+ args: [userBalanceResponseFactoryToken]
425
+ }] }, { type: SettingsService }, { type: SecureApiClient }];
426
+ } });
427
+
428
+ class RefundPolicyService {
429
+ constructor(settingsService) {
430
+ this.settingsService = settingsService;
431
+ this.defaultVersionId = 2;
432
+ this.defaultUrl = 'https://xsolla.com/refund-policy-ps';
433
+ }
434
+ get url() {
435
+ var _a, _b, _c, _d;
436
+ if (!this.settingsService.token) {
437
+ return 'https://xsolla.com/refundpolicy/en-us';
438
+ }
439
+ const language = (_a = this.settingsService.user.local) !== null && _a !== void 0 ? _a : 'en';
440
+ const versionId = (_c = (_b = this.settingsService.project.refundPolicySettings) === null || _b === void 0 ? void 0 : _b.policy_version_id) !== null && _c !== void 0 ? _c : this.defaultVersionId;
441
+ const countryIso = (_d = this.settingsService.user.country.value) !== null && _d !== void 0 ? _d : '';
442
+ const projectId = this.settingsService.project.id;
443
+ return `${this.defaultUrl}?policy_version_id=${versionId}&language=${language}&country=${countryIso}&project_id=${projectId}`;
444
+ }
445
+ }
446
+ RefundPolicyService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: RefundPolicyService, deps: [{ token: SettingsService }], target: i0.ɵɵFactoryTarget.Injectable });
447
+ RefundPolicyService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: RefundPolicyService, providedIn: 'root' });
448
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: RefundPolicyService, decorators: [{
449
+ type: Injectable,
450
+ args: [{
451
+ providedIn: 'root',
452
+ }]
453
+ }], ctorParameters: function () { return [{ type: SettingsService }]; } });
454
+
455
+ class LegalService {
456
+ get isJapanUser() {
457
+ var _a;
458
+ return ((_a = this.settingsService.user) === null || _a === void 0 ? void 0 : _a.local) === 'ja';
459
+ }
460
+ constructor(settingsService, refundPolicyService) {
461
+ this.settingsService = settingsService;
462
+ this.refundPolicyService = refundPolicyService;
463
+ this.sctlPolicyUrl = 'https://xsolla.com/sctl';
464
+ }
465
+ getLegalComponentConfig() {
466
+ return {
467
+ isJapanUser: this.isJapanUser,
468
+ refundPolicyUrl: this.refundPolicyService.url,
469
+ sctlPolicyUrl: this.sctlPolicyUrl,
470
+ };
471
+ }
472
+ }
473
+ LegalService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: LegalService, deps: [{ token: SettingsService }, { token: RefundPolicyService }], target: i0.ɵɵFactoryTarget.Injectable });
474
+ LegalService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: LegalService, providedIn: 'root' });
475
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: LegalService, decorators: [{
476
+ type: Injectable,
477
+ args: [{
478
+ providedIn: 'root',
479
+ }]
480
+ }], ctorParameters: function () { return [{ type: SettingsService }, { type: RefundPolicyService }]; } });
3
481
 
4
482
  class CoreLibraryService {
483
+ constructor(settingsService, countryService, paymentMethodsService, savedMethodsService, userBalanceService, legalService) {
484
+ this.settingsService = settingsService;
485
+ this.countryService = countryService;
486
+ this.paymentMethodsService = paymentMethodsService;
487
+ this.savedMethodsService = savedMethodsService;
488
+ this.userBalanceService = userBalanceService;
489
+ this.legalService = legalService;
490
+ this.paymentMethods = {
491
+ getList: () => __awaiter(this, void 0, void 0, function* () { return this.paymentMethodsService.getList(); }),
492
+ getQuickMethods: () => __awaiter(this, void 0, void 0, function* () { return this.paymentMethodsService.getQuickMethods(); }),
493
+ getSavedMethods: () => __awaiter(this, void 0, void 0, function* () { return this.savedMethodsService.getList(); }),
494
+ getUserBalance: () => __awaiter(this, void 0, void 0, function* () { return this.userBalanceService.getUserBalance(); }),
495
+ };
496
+ }
497
+ init(configuration) {
498
+ return __awaiter(this, void 0, void 0, function* () {
499
+ return this.settingsService.init(configuration);
500
+ });
501
+ }
502
+ setCountry(country) {
503
+ this.countryService.setCountry(country);
504
+ }
505
+ getLegalComponentConfig() {
506
+ return this.legalService.getLegalComponentConfig();
507
+ }
5
508
  }
6
- CoreLibraryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
509
+ 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: LegalService }], target: i0.ɵɵFactoryTarget.Injectable });
7
510
  CoreLibraryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, providedIn: 'root' });
8
511
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryService, decorators: [{
9
512
  type: Injectable,
10
513
  args: [{
11
514
  providedIn: 'root',
12
515
  }]
13
- }] });
516
+ }], ctorParameters: function () { return [{ type: SettingsService }, { type: CountryService }, { type: PaymentMethodsService }, { type: SavedMethodsService }, { type: UserBalanceService }, { type: LegalService }]; } });
14
517
 
15
- class CoreLibraryComponent {
518
+ class HttpError extends AppError {
519
+ constructor(error, req) {
520
+ var _a;
521
+ super(error.message);
522
+ this.RESTRICTED_KEYS_REGEXP = new RegExp('.*(card_number|number|cvv|cvn|month|year|cardholdername|client_data|dfp|password).*', 'i');
523
+ this.httpErrorData = {
524
+ request: {
525
+ url: req.url,
526
+ method: req.method,
527
+ headers: req.headers,
528
+ },
529
+ response: {
530
+ status: error.status,
531
+ headers: error.headers,
532
+ },
533
+ };
534
+ if (req.body) {
535
+ this.httpErrorData.request.data = this.cleanPersonalData(req.body);
536
+ }
537
+ if (error.statusText) {
538
+ const errorData = error.error;
539
+ this.httpErrorData.response.data = {
540
+ statusText: error.statusText,
541
+ errors: (_a = errorData === null || errorData === void 0 ? void 0 : errorData.errors) !== null && _a !== void 0 ? _a : [],
542
+ };
543
+ }
544
+ }
545
+ getHttpErrorData() {
546
+ return this.httpErrorData;
547
+ }
548
+ cleanPersonalData(data) {
549
+ return Object.entries(data).reduce((acc, [key, val]) => {
550
+ return Object.assign(Object.assign({}, acc), { [key]: this.RESTRICTED_KEYS_REGEXP.test(key) ? '***' : val });
551
+ }, {});
552
+ }
16
553
  }
17
- CoreLibraryComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
18
- CoreLibraryComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.7", type: CoreLibraryComponent, selector: "x-payment-client-core", ngImport: i0, template: ` <p>core-library works!</p> `, isInline: true });
19
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryComponent, decorators: [{
20
- type: Component,
21
- args: [{ selector: 'x-payment-client-core', template: ` <p>core-library works!</p> ` }]
22
- }] });
554
+
555
+ class HttpExceptionsInterceptor {
556
+ constructor(router) {
557
+ this.router = router;
558
+ }
559
+ intercept(req, next) {
560
+ return next.handle(req).pipe(catchError((error) => {
561
+ return throwError(() => new HttpError(error, req));
562
+ }));
563
+ }
564
+ }
565
+ HttpExceptionsInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: HttpExceptionsInterceptor, deps: [{ token: i1$1.Router }], target: i0.ɵɵFactoryTarget.Injectable });
566
+ HttpExceptionsInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: HttpExceptionsInterceptor });
567
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: HttpExceptionsInterceptor, decorators: [{
568
+ type: Injectable
569
+ }], ctorParameters: function () { return [{ type: i1$1.Router }]; } });
23
570
 
24
571
  class CoreLibraryModule {
25
572
  }
26
573
  CoreLibraryModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
27
- CoreLibraryModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryModule, declarations: [CoreLibraryComponent], exports: [CoreLibraryComponent] });
28
- CoreLibraryModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryModule });
574
+ CoreLibraryModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryModule, imports: [HttpClientModule] });
575
+ CoreLibraryModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryModule, providers: [
576
+ {
577
+ provide: HTTP_INTERCEPTORS,
578
+ useClass: HttpExceptionsInterceptor,
579
+ multi: true,
580
+ },
581
+ { provide: windowToken, useValue: window },
582
+ paymentMethodsResponseFactoryProvider,
583
+ savedMethodsResponseFactoryProvider,
584
+ userBalanceResponseFactoryProvider,
585
+ ], imports: [HttpClientModule] });
29
586
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: CoreLibraryModule, decorators: [{
30
587
  type: NgModule,
31
588
  args: [{
32
- declarations: [CoreLibraryComponent],
33
- imports: [],
34
- exports: [CoreLibraryComponent],
589
+ imports: [HttpClientModule],
590
+ providers: [
591
+ {
592
+ provide: HTTP_INTERCEPTORS,
593
+ useClass: HttpExceptionsInterceptor,
594
+ multi: true,
595
+ },
596
+ { provide: windowToken, useValue: window },
597
+ paymentMethodsResponseFactoryProvider,
598
+ savedMethodsResponseFactoryProvider,
599
+ userBalanceResponseFactoryProvider,
600
+ ],
35
601
  }]
36
602
  }] });
37
603
 
@@ -43,5 +609,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
43
609
  * Generated bundle index. Do not edit.
44
610
  */
45
611
 
46
- export { CoreLibraryComponent, CoreLibraryModule, CoreLibraryService };
612
+ export { CoreLibraryModule, CoreLibraryService };
47
613
  //# sourceMappingURL=xsolla-payment-client-core.mjs.map