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