@xsolla/payment-client-core 0.1.6 → 0.1.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 (73) hide show
  1. package/esm2020/lib/core/country/country-iso-code.enum.mjs +6 -0
  2. package/esm2020/lib/core/payment/finance-details/cart-summary.interface.mjs +1 -1
  3. package/esm2020/lib/core/payment/finance-details/finance-details.interface.mjs +2 -0
  4. package/esm2020/lib/core/payment/finance-details/finance-details.service.mjs +25 -12
  5. package/esm2020/lib/core/payment/finance-details/price.helpers.mjs +2 -2
  6. package/esm2020/lib/core/payment/finance-details/status/field-with-amount-and-currency.interface.mjs +2 -0
  7. package/esm2020/lib/core/payment/finance-details/status/fields-with-currency.mjs +16 -0
  8. package/esm2020/lib/core/payment/finance-details/status/finance-info.interface.mjs +2 -0
  9. package/esm2020/lib/core/payment/finance-details/status/status-finance-details-adapter.service.mjs +290 -0
  10. package/esm2020/lib/core/payment/finance-details/summary/default-image-patterns.const.mjs +10 -0
  11. package/esm2020/lib/core/payment/finance-details/summary/sales-tax-details-key.enum.mjs +7 -0
  12. package/esm2020/lib/core/payment/finance-details/summary/summary-finance-details-adapter.service.mjs +264 -0
  13. package/esm2020/lib/core/payment/finance-details/vat-details-key.enum.mjs +14 -0
  14. package/esm2020/lib/core/payment/form/controls/phone-control.config.mjs +8 -0
  15. package/esm2020/lib/core/payment/form/converters/converters-map.mjs +3 -1
  16. package/esm2020/lib/core/payment/form/converters/phone.converter.mjs +37 -0
  17. package/esm2020/lib/core/payment/form/form.module.mjs +6 -1
  18. package/esm2020/lib/core/payment/form/validators/max-length-validator.mjs +6 -0
  19. package/esm2020/lib/core/payment/form/validators/min-length-validator.mjs +6 -0
  20. package/esm2020/lib/core/payment/form/validators/phone-validator.mjs +6 -0
  21. package/esm2020/lib/core/payment/payment.interface.mjs +1 -1
  22. package/esm2020/lib/core/payment/payment.service.mjs +2 -2
  23. package/esm2020/lib/core/payment/status/status-finance-info.interface.mjs +2 -0
  24. package/esm2020/lib/core/payment/status/status-order.interface.mjs +2 -0
  25. package/esm2020/lib/core/payment/status/status.interface.mjs +1 -1
  26. package/esm2020/lib/core/payment/status/status.service.mjs +10 -6
  27. package/esm2020/lib/core/payment/xps-summary.interface.mjs +1 -1
  28. package/esm2020/lib/core/session/session.service.mjs +57 -0
  29. package/esm2020/lib/core/type-guards/is-null.function.mjs +4 -0
  30. package/esm2020/lib/core/type-guards/is-undefined.function.mjs +4 -0
  31. package/esm2020/lib/core-library.module.mjs +1 -4
  32. package/esm2020/lib/core-library.service.mjs +4 -1
  33. package/fesm2015/xsolla-payment-client-core.mjs +829 -352
  34. package/fesm2015/xsolla-payment-client-core.mjs.map +1 -1
  35. package/fesm2020/xsolla-payment-client-core.mjs +812 -344
  36. package/fesm2020/xsolla-payment-client-core.mjs.map +1 -1
  37. package/lib/core/country/country-iso-code.enum.d.ts +4 -0
  38. package/lib/core/payment/finance-details/cart-summary.interface.d.ts +2 -2
  39. package/lib/core/payment/finance-details/finance-details.interface.d.ts +11 -0
  40. package/lib/core/payment/finance-details/finance-details.service.d.ts +12 -5
  41. package/lib/core/payment/finance-details/price.helpers.d.ts +3 -3
  42. package/lib/core/payment/finance-details/status/field-with-amount-and-currency.interface.d.ts +7 -0
  43. package/lib/core/payment/finance-details/status/fields-with-currency.d.ts +1 -0
  44. package/lib/core/payment/finance-details/status/finance-info.interface.d.ts +4 -0
  45. package/lib/core/payment/finance-details/status/status-finance-details-adapter.service.d.ts +31 -0
  46. package/lib/core/payment/finance-details/summary/sales-tax-details-key.enum.d.ts +5 -0
  47. package/lib/core/payment/finance-details/summary/summary-finance-details-adapter.service.d.ts +24 -0
  48. package/lib/core/payment/finance-details/vat-details-key.enum.d.ts +12 -0
  49. package/lib/core/payment/form/controls/phone-control.config.d.ts +6 -0
  50. package/lib/core/payment/form/converters/phone.converter.d.ts +13 -0
  51. package/lib/core/payment/form/validators/max-length-validator.d.ts +2 -0
  52. package/lib/core/payment/form/validators/min-length-validator.d.ts +2 -0
  53. package/lib/core/payment/form/validators/phone-validator.d.ts +2 -0
  54. package/lib/core/payment/payment.interface.d.ts +1 -1
  55. package/lib/core/payment/payment.service.d.ts +1 -1
  56. package/lib/core/payment/status/status-finance-info.interface.d.ts +4 -0
  57. package/lib/core/payment/status/status-order.interface.d.ts +12 -0
  58. package/lib/core/payment/status/status.interface.d.ts +4 -16
  59. package/lib/core/payment/status/status.service.d.ts +3 -1
  60. package/lib/core/payment/xps-summary.interface.d.ts +1 -1
  61. package/lib/core/session/session.service.d.ts +18 -0
  62. package/lib/core/type-guards/is-null.function.d.ts +1 -0
  63. package/lib/core/type-guards/is-undefined.function.d.ts +1 -0
  64. package/lib/core-library.service.d.ts +1 -0
  65. package/package.json +1 -1
  66. package/xsolla-payment-client-core-0.1.8.tgz +0 -0
  67. package/esm2020/lib/core/payment/finance-details/default-image-patterns.const.mjs +0 -10
  68. package/esm2020/lib/core/payment/finance-details/finance-details-response.token.mjs +0 -8
  69. package/esm2020/lib/core/payment/finance-details/finance-details.class.mjs +0 -237
  70. package/lib/core/payment/finance-details/finance-details-response.token.d.ts +0 -7
  71. package/lib/core/payment/finance-details/finance-details.class.d.ts +0 -29
  72. package/xsolla-payment-client-core-0.1.6.tgz +0 -0
  73. /package/lib/core/payment/finance-details/{default-image-patterns.const.d.ts → summary/default-image-patterns.const.d.ts} +0 -0
@@ -2557,6 +2557,53 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
2557
2557
  type: Injectable
2558
2558
  }], ctorParameters: function () { return [{ type: SyncService }]; } });
2559
2559
 
2560
+ function phoneValidator() {
2561
+ return convert(Validators.pattern(/^\d*$/), 'Enter a valid phone');
2562
+ }
2563
+
2564
+ function minLengthValidator(minLength) {
2565
+ return convert(Validators.minLength(minLength), `Enter at least ${minLength} characters`);
2566
+ }
2567
+
2568
+ function maxLengthValidator(maxLength) {
2569
+ return convert(Validators.maxLength(maxLength), `Enter no more than ${maxLength} characters`);
2570
+ }
2571
+
2572
+ class PhoneControlConfig extends ControlConfig {
2573
+ constructor() {
2574
+ super(...arguments);
2575
+ this.controlType = 'phone';
2576
+ }
2577
+ }
2578
+
2579
+ class PhoneConverter extends Converter {
2580
+ constructor(syncService) {
2581
+ super(syncService);
2582
+ }
2583
+ getValidators(field) {
2584
+ const minLength = 10;
2585
+ const maxLength = 15;
2586
+ return super
2587
+ .getValidators(field)
2588
+ .concat([
2589
+ convertedRequiredValidator(),
2590
+ phoneValidator(),
2591
+ minLengthValidator(minLength),
2592
+ maxLengthValidator(maxLength),
2593
+ ]);
2594
+ }
2595
+ createControlConfig(field) {
2596
+ const config = this.createDefaultControlConfig(PhoneControlConfig, field);
2597
+ config.inputMode = 'numeric';
2598
+ return config;
2599
+ }
2600
+ }
2601
+ PhoneConverter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PhoneConverter, deps: [{ token: SyncService }], target: i0.ɵɵFactoryTarget.Injectable });
2602
+ PhoneConverter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PhoneConverter });
2603
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: PhoneConverter, decorators: [{
2604
+ type: Injectable
2605
+ }], ctorParameters: function () { return [{ type: SyncService }]; } });
2606
+
2560
2607
  const convertersMapToken = new InjectionToken('ConvertersTokensMap');
2561
2608
  const convertersMap = {
2562
2609
  card_number: CardNumberConverter,
@@ -2581,6 +2628,7 @@ const convertersMap = {
2581
2628
  sum: PricepointConverter,
2582
2629
  out: PricepointConverter,
2583
2630
  couponCode: CouponConverter,
2631
+ phone: PhoneConverter,
2584
2632
  };
2585
2633
 
2586
2634
  class ControlConfigService {
@@ -2928,63 +2976,762 @@ const statusResponseFactoryProvider = {
2928
2976
  useValue: (...args) => new StatusResponse(...args),
2929
2977
  };
2930
2978
 
2931
- class StatusRequestService extends XpsApiPart {
2932
- constructor(secureApiClient, settingsService, requestFactory, responseFactory) {
2979
+ class StatusRequestService extends XpsApiPart {
2980
+ constructor(secureApiClient, settingsService, requestFactory, responseFactory) {
2981
+ super();
2982
+ this.secureApiClient = secureApiClient;
2983
+ this.settingsService = settingsService;
2984
+ this.requestFactory = requestFactory;
2985
+ this.responseFactory = responseFactory;
2986
+ this.apiRoute = 'directpayment';
2987
+ }
2988
+ setRequestParams(params) {
2989
+ this.requestParams = {
2990
+ locale: params.locale,
2991
+ testProject: params.testProject,
2992
+ testPs: params.testPs,
2993
+ testXsolla: params.testXsolla,
2994
+ userReturnStatus: params.userReturnStatus,
2995
+ invoice: params.invoice,
2996
+ pid: params.pid,
2997
+ signature: params.signature,
2998
+ };
2999
+ }
3000
+ request() {
3001
+ const requestParams = this.requestFactory({
3002
+ token: this.settingsService.token,
3003
+ ...this.requestParams,
3004
+ });
3005
+ lastValueFrom(this.secureApiClient.post(this.apiRoute, new URLSearchParams(requestParams), {
3006
+ headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
3007
+ responseType: 'json',
3008
+ }))
3009
+ .then((response) => {
3010
+ const statusResponse = this.responseFactory({
3011
+ status: response.status,
3012
+ errors: response.errors,
3013
+ form: response.form,
3014
+ });
3015
+ this.emitResponse(statusResponse);
3016
+ })
3017
+ .catch((e) => {
3018
+ throw new TerminalError(e.message, e.code);
3019
+ });
3020
+ }
3021
+ }
3022
+ StatusRequestService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusRequestService, deps: [{ token: SecureApiClient }, { token: SettingsService }, { token: statusRequestFactoryToken }, { token: statusResponseFactoryToken }], target: i0.ɵɵFactoryTarget.Injectable });
3023
+ StatusRequestService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusRequestService, providedIn: 'root' });
3024
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusRequestService, decorators: [{
3025
+ type: Injectable,
3026
+ args: [{
3027
+ providedIn: 'root',
3028
+ }]
3029
+ }], ctorParameters: function () { return [{ type: SecureApiClient }, { type: SettingsService }, { type: undefined, decorators: [{
3030
+ type: Inject,
3031
+ args: [statusRequestFactoryToken]
3032
+ }] }, { type: undefined, decorators: [{
3033
+ type: Inject,
3034
+ args: [statusResponseFactoryToken]
3035
+ }] }]; } });
3036
+
3037
+ function isNull(value) {
3038
+ return value === null;
3039
+ }
3040
+
3041
+ function isUndefined(value) {
3042
+ return typeof value === 'undefined';
3043
+ }
3044
+
3045
+ class SessionService {
3046
+ constructor(window, settingsService) {
3047
+ this.window = window;
3048
+ this.settingsService = settingsService;
3049
+ this.cache = {};
3050
+ }
3051
+ /**
3052
+ * @param {string} key must be uniq entire all app
3053
+ * @param {unknown} value can be anything
3054
+ */
3055
+ set(key, value) {
3056
+ this.cache[key] = value;
3057
+ try {
3058
+ this.window.sessionStorage.setItem(this.getStorageKey(key), JSON.stringify(value));
3059
+ }
3060
+ catch (error) {
3061
+ console.warn('Session storage not available.');
3062
+ }
3063
+ }
3064
+ get(key) {
3065
+ const cacheValue = this.cache[key];
3066
+ if (!isUndefined(cacheValue)) {
3067
+ return cacheValue;
3068
+ }
3069
+ try {
3070
+ const storageValue = this.window.sessionStorage.getItem(this.getStorageKey(key));
3071
+ if (isNull(storageValue)) {
3072
+ return null;
3073
+ }
3074
+ return JSON.parse(storageValue);
3075
+ }
3076
+ catch (error) {
3077
+ return null;
3078
+ }
3079
+ }
3080
+ getStorageKey(key) {
3081
+ return `${key}${this.settingsService.token}`;
3082
+ }
3083
+ }
3084
+ SessionService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SessionService, deps: [{ token: windowToken }, { token: SettingsService }], target: i0.ɵɵFactoryTarget.Injectable });
3085
+ SessionService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SessionService, providedIn: 'root' });
3086
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SessionService, decorators: [{
3087
+ type: Injectable,
3088
+ args: [{
3089
+ providedIn: 'root',
3090
+ }]
3091
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
3092
+ type: Inject,
3093
+ args: [windowToken]
3094
+ }] }, { type: SettingsService }]; } });
3095
+
3096
+ function extractMoneyCurrency(money, allowZero = true) {
3097
+ return {
3098
+ amount: money?.amount ?? (allowZero ? 0 : null),
3099
+ currency: money?.currency ?? '',
3100
+ };
3101
+ }
3102
+ function createPriceOrUndefined(amount, currency) {
3103
+ return amount !== undefined && amount !== null && currency !== undefined
3104
+ ? {
3105
+ amount,
3106
+ currency,
3107
+ }
3108
+ : undefined;
3109
+ }
3110
+
3111
+ /**
3112
+ * default image for purchase item is set on Publisher Account side.
3113
+ * for purchase checkout items the image url is converted into base64 string.
3114
+ * to determine default image fixed templates are used
3115
+ */
3116
+ const defaultImagePatterns = [
3117
+ /^data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAAAAADmVT4XAAACMUlEQVR4Ae3YgYqdMBSE4fP/,
3118
+ /virtual_item_default_image/,
3119
+ ];
3120
+
3121
+ var VatDetailsKey;
3122
+ (function (VatDetailsKey) {
3123
+ VatDetailsKey["vat"] = "vat";
3124
+ VatDetailsKey["vatPercent"] = "vat-percent";
3125
+ VatDetailsKey["vatIncluding"] = "vat-including";
3126
+ VatDetailsKey["vatPercentIncluding"] = "vat-percent-including";
3127
+ VatDetailsKey["vatIndia"] = "vat-india";
3128
+ VatDetailsKey["vatIndiaPercent"] = "vat-india-percent";
3129
+ VatDetailsKey["vatIndiaIncluding"] = "vat-india-including";
3130
+ VatDetailsKey["vatIndiaPercentIncluding"] = "vat-india-percent-including";
3131
+ VatDetailsKey["vatGhana"] = "vat-ghana";
3132
+ VatDetailsKey["vatGhanaIncluding"] = "vat-ghana-including";
3133
+ })(VatDetailsKey || (VatDetailsKey = {}));
3134
+
3135
+ var SalesTaxDetailsKey;
3136
+ (function (SalesTaxDetailsKey) {
3137
+ SalesTaxDetailsKey["salesTax"] = "sales-tax";
3138
+ SalesTaxDetailsKey["salesTaxPercent"] = "sales-tax-percent";
3139
+ SalesTaxDetailsKey["salesTaxIncluding"] = "sales-tax-including";
3140
+ })(SalesTaxDetailsKey || (SalesTaxDetailsKey = {}));
3141
+
3142
+ class SummaryFinanceDetailsAdapterService {
3143
+ getFinanceDetails(summary) {
3144
+ const { purchase, finance } = summary;
3145
+ return {
3146
+ purchase: purchase,
3147
+ finance: finance,
3148
+ cartItems: this.getCartItems(purchase, finance),
3149
+ cartSummary: this.getCartSummary(finance),
3150
+ paymentCountry: this.getPaymentCountry(finance),
3151
+ };
3152
+ }
3153
+ shouldShowZeroIndirectTaxRate(finance) {
3154
+ return !!(finance?.vat?.visible ?? finance?.vat_user?.visible);
3155
+ }
3156
+ isSalesTaxes(finance) {
3157
+ return !!(finance?.sales_tax?.amount ?? finance?.sales_tax_user?.amount);
3158
+ }
3159
+ getCartItems(purchase, finance) {
3160
+ const checkouts = purchase.checkout_items?.map((item) => {
3161
+ return {
3162
+ imgSrc: item.image_url,
3163
+ hasDefaultImg: this.isDefaultImage(item.image_url),
3164
+ title: item.name,
3165
+ price: extractMoneyCurrency(item, false),
3166
+ priceBeforeDiscount: createPriceOrUndefined(item.amount_before_discount, item.currency),
3167
+ quantity: item.quantity,
3168
+ description: item.description,
3169
+ tax: this.getTaxForItem(finance, item.indirect_tax_rate),
3170
+ isBonus: item.is_bonus,
3171
+ };
3172
+ });
3173
+ const virtualCurrencies = purchase.virtual_currency?.map((item) => {
3174
+ return {
3175
+ imgSrc: item.image_url,
3176
+ hasDefaultImg: this.isDefaultImage(item.image_url),
3177
+ title: `${item.quantity} ${item.name}`,
3178
+ price: extractMoneyCurrency(item),
3179
+ description: item.description,
3180
+ isBonus: item.is_bonus,
3181
+ };
3182
+ });
3183
+ const virtualItems = purchase.virtual_items?.map((item) => {
3184
+ return {
3185
+ imgSrc: item.image_url,
3186
+ hasDefaultImg: this.isDefaultImage(item.image_url),
3187
+ title: item.name,
3188
+ price: extractMoneyCurrency(item),
3189
+ description: item.description,
3190
+ quantity: item.quantity,
3191
+ isBonus: item.is_bonus,
3192
+ };
3193
+ });
3194
+ let checkoutArray = undefined;
3195
+ if (purchase.checkout) {
3196
+ checkoutArray = [
3197
+ {
3198
+ key: 'checkout',
3199
+ title: purchase.checkout.description,
3200
+ price: extractMoneyCurrency(purchase.checkout),
3201
+ isBonus: purchase.checkout.is_bonus ?? false,
3202
+ },
3203
+ ];
3204
+ }
3205
+ return [
3206
+ ...(checkouts ?? []),
3207
+ ...(virtualCurrencies ?? []),
3208
+ ...(virtualItems ?? []),
3209
+ ...(checkoutArray ?? []),
3210
+ ];
3211
+ }
3212
+ getCartSummary(finance) {
3213
+ return {
3214
+ subtotal: {
3215
+ title: 'Subtotal',
3216
+ money: createPriceOrUndefined(finance?.sub_total?.amount, finance?.sub_total?.currency),
3217
+ },
3218
+ subtotalPayment: {
3219
+ title: '',
3220
+ money: createPriceOrUndefined(finance?.sub_total?.payment_amount, finance?.sub_total?.payment_currency),
3221
+ },
3222
+ total: {
3223
+ title: 'Total',
3224
+ money: extractMoneyCurrency(finance?.total),
3225
+ },
3226
+ totalDetails: this.getTaxesForTotalDetails(finance),
3227
+ subtotalDetails: [
3228
+ ...this.getSubtotalDetails(finance),
3229
+ ...this.getTaxesForSubtotalDetails(finance),
3230
+ ],
3231
+ };
3232
+ }
3233
+ getPaymentCountry(finance) {
3234
+ return finance?.payment_country?.iso ?? '';
3235
+ }
3236
+ getTaxForItem(finance, indirectTaxRate) {
3237
+ if (indirectTaxRate ||
3238
+ (this.shouldShowZeroIndirectTaxRate(finance) && indirectTaxRate === 0)) {
3239
+ if (this.isSalesTaxes(finance)) {
3240
+ return {
3241
+ key: SalesTaxDetailsKey.salesTaxPercent,
3242
+ content: `Sales tax ${indirectTaxRate}%`,
3243
+ rate: indirectTaxRate,
3244
+ };
3245
+ }
3246
+ if (this.isIndia(finance)) {
3247
+ return {
3248
+ key: VatDetailsKey.vatIndiaPercent,
3249
+ content: `GST ${indirectTaxRate}%`,
3250
+ rate: indirectTaxRate,
3251
+ };
3252
+ }
3253
+ if (this.isGhana(finance)) {
3254
+ return {
3255
+ key: VatDetailsKey.vatGhana,
3256
+ content: 'VAT, NHIL, GETFund Levy, and Covid-19 Levy',
3257
+ rate: indirectTaxRate,
3258
+ };
3259
+ }
3260
+ return {
3261
+ key: VatDetailsKey.vatPercent,
3262
+ content: `VAT ${indirectTaxRate}%`,
3263
+ rate: indirectTaxRate,
3264
+ };
3265
+ }
3266
+ return null;
3267
+ }
3268
+ getSubtotalDetails(finance) {
3269
+ if (!finance) {
3270
+ return [];
3271
+ }
3272
+ // subtotal details fields
3273
+ const subtotalDetailsSorting = [
3274
+ {
3275
+ key: 'discount',
3276
+ responseKey: 'discount',
3277
+ title: 'Discount',
3278
+ },
3279
+ {
3280
+ key: 'fee',
3281
+ responseKey: 'fee',
3282
+ title: 'Payment system fee',
3283
+ },
3284
+ {
3285
+ key: 'user-balance',
3286
+ responseKey: 'user_balance',
3287
+ title: 'Balance',
3288
+ },
3289
+ ];
3290
+ return subtotalDetailsSorting.map((sorting) => {
3291
+ const field = finance[sorting.responseKey];
3292
+ if (field) {
3293
+ return {
3294
+ key: sorting.key,
3295
+ title: sorting.title,
3296
+ money: {
3297
+ amount: sorting.key === 'discount' && field.amount
3298
+ ? -field.amount
3299
+ : field.amount,
3300
+ currency: field.currency,
3301
+ },
3302
+ };
3303
+ }
3304
+ return sorting;
3305
+ });
3306
+ }
3307
+ getTaxesForSubtotalDetails(finance) {
3308
+ const ret = [];
3309
+ // subtotal. VAT %p
3310
+ if (finance?.vat_user &&
3311
+ (finance?.vat_user?.amount ?? finance?.vat_user?.visible)) {
3312
+ ret.push({
3313
+ key: this.getVatNotIncludingKeyForDetails(finance),
3314
+ title: this.getVatLabelForSubtotalDetails(finance),
3315
+ money: extractMoneyCurrency(finance?.vat_user),
3316
+ });
3317
+ }
3318
+ if (finance?.sales_tax_user?.amount) {
3319
+ ret.push({
3320
+ key: SalesTaxDetailsKey.salesTax,
3321
+ title: 'Sales tax',
3322
+ money: extractMoneyCurrency(finance?.sales_tax_user),
3323
+ });
3324
+ }
3325
+ return ret;
3326
+ }
3327
+ getVatLabelForSubtotalDetails(finance) {
3328
+ if (this.isIndia(finance)) {
3329
+ return `GST ${finance?.vat_user?.percent ?? ''}%`;
3330
+ }
3331
+ if (this.isGhana(finance)) {
3332
+ return `VAT, NHIL, GETFund Levy, and Covid-19 Levy`;
3333
+ }
3334
+ return `VAT ${finance?.vat_user?.percent ?? ''}%`;
3335
+ }
3336
+ getTaxesForTotalDetails(finance) {
3337
+ const ret = [];
3338
+ // for totalDetails. VAT
3339
+ if ((finance?.vat?.amount || finance?.vat?.visible) &&
3340
+ !finance?.vat_user?.amount) {
3341
+ ret.push({
3342
+ key: this.getVatIncludingKeyForDetails(finance),
3343
+ title: this.getVatLabelForTotalDetails(finance),
3344
+ money: extractMoneyCurrency(finance?.vat),
3345
+ });
3346
+ }
3347
+ if (finance?.sales_tax?.amount && !finance?.sales_tax_user?.amount) {
3348
+ ret.push({
3349
+ key: SalesTaxDetailsKey.salesTaxIncluding,
3350
+ title: 'Sales tax included',
3351
+ money: extractMoneyCurrency(finance?.sales_tax),
3352
+ });
3353
+ }
3354
+ return ret;
3355
+ }
3356
+ getVatNotIncludingKeyForDetails(finance) {
3357
+ if (this.isIndia(finance)) {
3358
+ return VatDetailsKey.vatIndiaPercent;
3359
+ }
3360
+ if (this.isGhana(finance)) {
3361
+ return VatDetailsKey.vatGhana;
3362
+ }
3363
+ return VatDetailsKey.vatPercent;
3364
+ }
3365
+ getVatIncludingKeyForDetails(finance) {
3366
+ if (this.isIndia(finance)) {
3367
+ return VatDetailsKey.vatIndiaPercentIncluding;
3368
+ }
3369
+ if (this.isGhana(finance)) {
3370
+ return VatDetailsKey.vatGhanaIncluding;
3371
+ }
3372
+ return VatDetailsKey.vatPercentIncluding;
3373
+ }
3374
+ getVatLabelForTotalDetails(finance) {
3375
+ if (this.isIndia(finance)) {
3376
+ return `Including ${finance?.vat.percent ?? ''}% GST`;
3377
+ }
3378
+ if (this.isGhana(finance)) {
3379
+ return 'Including VAT, NHIL, GETFund Levy, and Covid-19 Levy';
3380
+ }
3381
+ return `Including ${finance?.vat.percent ?? ''}% VAT`;
3382
+ }
3383
+ isIndia(finance) {
3384
+ return finance?.payment_country.iso === 'IN';
3385
+ }
3386
+ isGhana(finance) {
3387
+ return finance?.payment_country.iso === 'GH';
3388
+ }
3389
+ isDefaultImage(url) {
3390
+ return defaultImagePatterns.some((regex) => regex.test(url));
3391
+ }
3392
+ }
3393
+ SummaryFinanceDetailsAdapterService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SummaryFinanceDetailsAdapterService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
3394
+ SummaryFinanceDetailsAdapterService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SummaryFinanceDetailsAdapterService, providedIn: 'root' });
3395
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: SummaryFinanceDetailsAdapterService, decorators: [{
3396
+ type: Injectable,
3397
+ args: [{ providedIn: 'root' }]
3398
+ }] });
3399
+
3400
+ const fieldsWithCurrency = new Set([
3401
+ 'sum',
3402
+ 'commissionUserVatPrc',
3403
+ 'salesTaxCommission',
3404
+ 'vatUserNotIncluded',
3405
+ 'xsollaTipsAmount',
3406
+ 'paymentSystemFee',
3407
+ 'discount',
3408
+ 'userWallet',
3409
+ 'subtotal',
3410
+ 'subtotalSummaryBeforeConversion',
3411
+ 'grandTotal',
3412
+ 'subtotalBeforeDiscount',
3413
+ 'redeemedPoints',
3414
+ ]);
3415
+
3416
+ var CountryIsoCode;
3417
+ (function (CountryIsoCode) {
3418
+ CountryIsoCode["India"] = "IN";
3419
+ CountryIsoCode["Ghana"] = "GH";
3420
+ })(CountryIsoCode || (CountryIsoCode = {}));
3421
+
3422
+ class StatusFinanceDetailsAdapterService {
3423
+ constructor(summarFinanceDetailsAdapterService) {
3424
+ this.summarFinanceDetailsAdapterService = summarFinanceDetailsAdapterService;
3425
+ }
3426
+ getFinanceDetails(status, purchase) {
3427
+ const financeInfo = this.fillFinanceInfo(status.financeInfo);
3428
+ const country = status.paymentCountryIso;
3429
+ const order = status.order ?? null;
3430
+ const summaryFinance = this.convertStatusFinanceToSummaryFinance(purchase, order, country);
3431
+ return {
3432
+ purchase,
3433
+ finance: summaryFinance,
3434
+ cartItems: this.getCartItems(purchase, summaryFinance),
3435
+ cartSummary: this.getCartSummary(status, financeInfo, country),
3436
+ paymentCountry: country,
3437
+ };
3438
+ }
3439
+ fillFinanceInfo(financeInfo) {
3440
+ return Object.keys(financeInfo).reduce((financeInfoWithAmountAndCurrency, key) => {
3441
+ const field = financeInfo[key];
3442
+ if (field?.key && fieldsWithCurrency.has(field?.key)) {
3443
+ this.addAmountAndCurrencyToField(field);
3444
+ }
3445
+ return { ...financeInfoWithAmountAndCurrency, [key]: field };
3446
+ }, {});
3447
+ }
3448
+ addAmountAndCurrencyToField(field) {
3449
+ const amountAndCurrency = /(^[-\d.]+) ([A-Z]{3})$/;
3450
+ const currencyParts = field.value?.trim().match(amountAndCurrency);
3451
+ if (currencyParts) {
3452
+ const amountPosition = 1;
3453
+ const currencyPosition = 2;
3454
+ field.amount = Number(currencyParts[amountPosition]);
3455
+ field.currency = currencyParts[currencyPosition];
3456
+ }
3457
+ }
3458
+ getCartItems(purchase, summaryFinance) {
3459
+ if (!purchase) {
3460
+ return null;
3461
+ }
3462
+ const financeDetails = this.summarFinanceDetailsAdapterService.getFinanceDetails({
3463
+ purchase,
3464
+ finance: summaryFinance,
3465
+ });
3466
+ return financeDetails.cartItems;
3467
+ }
3468
+ convertStatusFinanceToSummaryFinance(purchase, order, country) {
3469
+ if (!order || !purchase?.checkout_items?.length) {
3470
+ return null;
3471
+ }
3472
+ const finance = {
3473
+ payment_country: {
3474
+ iso: country,
3475
+ },
3476
+ };
3477
+ const firstCheckoutItem = purchase?.checkout_items[0];
3478
+ const firstCheckoutItemAmount = firstCheckoutItem?.amount ?? 0;
3479
+ const oneHundredPercent = 100;
3480
+ const taxAmount = (firstCheckoutItemAmount * firstCheckoutItem?.indirect_tax_rate) /
3481
+ oneHundredPercent;
3482
+ if (order.contained_taxes?.sales_tax) {
3483
+ finance.sales_tax = {
3484
+ amount: taxAmount,
3485
+ percent: firstCheckoutItem?.indirect_tax_rate,
3486
+ currency: purchase?.checkout?.currency ?? '',
3487
+ };
3488
+ }
3489
+ if (order.contained_taxes?.user_vat) {
3490
+ finance.vat = {
3491
+ amount: taxAmount,
3492
+ percent: firstCheckoutItem?.indirect_tax_rate,
3493
+ currency: purchase?.checkout?.currency ?? '',
3494
+ visible: true,
3495
+ };
3496
+ }
3497
+ return finance;
3498
+ }
3499
+ getCartSummary(status, financeInfo, country) {
3500
+ const cart = {
3501
+ total: this.getTotal(financeInfo),
3502
+ totalDetails: this.getTotalDetails(financeInfo, country),
3503
+ subtotalDetails: [
3504
+ ...this.getSubtotalDetails(financeInfo),
3505
+ ...this.getTaxesForSubtotalDetails(financeInfo, country),
3506
+ ],
3507
+ transactionDetails: this.getTransactionDetails(status, financeInfo),
3508
+ subtotal: this.getInitialCurrencySubtotal(financeInfo) ?? null,
3509
+ subtotalPayment: this.getSubtotalPayment(financeInfo) ?? null,
3510
+ };
3511
+ return cart;
3512
+ }
3513
+ getTotal(financeInfo) {
3514
+ return {
3515
+ title: 'Total',
3516
+ money: extractMoneyCurrency(financeInfo.sum),
3517
+ };
3518
+ }
3519
+ getSubtotalPayment(financeInfo) {
3520
+ if (!financeInfo?.subtotal) {
3521
+ return null;
3522
+ }
3523
+ return {
3524
+ title: 'Subtotal',
3525
+ money: extractMoneyCurrency(financeInfo.subtotal),
3526
+ };
3527
+ }
3528
+ getInitialCurrencySubtotal(financeInfo) {
3529
+ if (!financeInfo?.subtotalSummaryBeforeConversion) {
3530
+ return null;
3531
+ }
3532
+ return {
3533
+ title: '',
3534
+ money: extractMoneyCurrency(financeInfo.subtotalSummaryBeforeConversion),
3535
+ };
3536
+ }
3537
+ getTotalDetails(financeInfo, country) {
3538
+ const totalDetails = [];
3539
+ const salesTaxCommissionField = financeInfo['salesTaxCommission'];
3540
+ if (salesTaxCommissionField) {
3541
+ totalDetails.push({
3542
+ title: salesTaxCommissionField.pref,
3543
+ money: {
3544
+ amount: salesTaxCommissionField.amount ?? null,
3545
+ currency: salesTaxCommissionField.currency ?? '',
3546
+ },
3547
+ });
3548
+ }
3549
+ const commissionUserVatPrcField = financeInfo['commissionUserVatPrc'];
3550
+ if (commissionUserVatPrcField?.pref) {
3551
+ const percents = this.getPercents(commissionUserVatPrcField.pref);
3552
+ totalDetails.push({
3553
+ key: this.getVatIncludingKeyDetails(percents, country),
3554
+ title: this.geVatIncludingTitleDetails(percents, country),
3555
+ money: {
3556
+ amount: commissionUserVatPrcField.amount ?? null,
3557
+ currency: commissionUserVatPrcField.currency ?? '',
3558
+ },
3559
+ });
3560
+ }
3561
+ return totalDetails;
3562
+ }
3563
+ getSubtotalDetails(financeInfo) {
3564
+ const subtotalDetailsSorting = [
3565
+ {
3566
+ key: 'discount',
3567
+ responseKey: 'discount',
3568
+ title: 'Discount',
3569
+ },
3570
+ {
3571
+ key: 'fee',
3572
+ responseKey: 'paymentSystemFee',
3573
+ title: 'Payment system fee',
3574
+ },
3575
+ {
3576
+ key: 'user-balance',
3577
+ responseKey: 'userWallet',
3578
+ title: 'Balance',
3579
+ },
3580
+ ];
3581
+ const redeemedPoints = financeInfo['redeemedPoints'];
3582
+ if (redeemedPoints?.pref) {
3583
+ subtotalDetailsSorting.push({
3584
+ key: 'redeem-points',
3585
+ responseKey: 'redeemedPoints',
3586
+ title: redeemedPoints.pref,
3587
+ });
3588
+ }
3589
+ return subtotalDetailsSorting.reduce((subTotalDetails, sorting) => {
3590
+ const field = financeInfo[sorting.responseKey];
3591
+ if (field) {
3592
+ subTotalDetails.push({
3593
+ title: sorting.title,
3594
+ money: {
3595
+ amount: field.amount ?? null,
3596
+ currency: field.currency ?? '',
3597
+ },
3598
+ });
3599
+ }
3600
+ return subTotalDetails;
3601
+ }, []);
3602
+ }
3603
+ getTaxesForSubtotalDetails(financeInfo, country) {
3604
+ const taxesForSubtotalDetails = [];
3605
+ const vatUserNotIncludedField = financeInfo['vatUserNotIncluded'];
3606
+ if (vatUserNotIncludedField?.pref) {
3607
+ const percents = this.getPercents(vatUserNotIncludedField.pref);
3608
+ taxesForSubtotalDetails.push({
3609
+ key: this.getVatNotIncludingKeyDetails(percents, country),
3610
+ title: this.getVatNotIncludingTitleDetails(percents, country),
3611
+ money: {
3612
+ amount: vatUserNotIncludedField.amount ?? null,
3613
+ currency: vatUserNotIncludedField.currency ?? '',
3614
+ },
3615
+ });
3616
+ }
3617
+ return taxesForSubtotalDetails;
3618
+ }
3619
+ getVatNotIncludingKeyDetails(percents, country) {
3620
+ if (this.isIndia(country)) {
3621
+ return percents ? VatDetailsKey.vatIndiaPercent : VatDetailsKey.vatIndia;
3622
+ }
3623
+ if (this.isGhana(country)) {
3624
+ return VatDetailsKey.vatGhana;
3625
+ }
3626
+ return percents ? VatDetailsKey.vatPercent : VatDetailsKey.vat;
3627
+ }
3628
+ getVatNotIncludingTitleDetails(percents, country) {
3629
+ if (this.isIndia(country)) {
3630
+ return percents ? `GST ${percents}%` : 'GST';
3631
+ }
3632
+ if (this.isGhana(country)) {
3633
+ return 'VAT, NHIL, GETFund Levy, and Covid-19 Levy';
3634
+ }
3635
+ return percents ? `VAT ${percents}%` : 'VAT';
3636
+ }
3637
+ getVatIncludingKeyDetails(percents, country) {
3638
+ if (this.isIndia(country)) {
3639
+ return percents
3640
+ ? VatDetailsKey.vatIndiaPercentIncluding
3641
+ : VatDetailsKey.vatIndiaIncluding;
3642
+ }
3643
+ if (this.isGhana(country)) {
3644
+ return VatDetailsKey.vatGhanaIncluding;
3645
+ }
3646
+ return percents
3647
+ ? VatDetailsKey.vatPercentIncluding
3648
+ : VatDetailsKey.vatIncluding;
3649
+ }
3650
+ geVatIncludingTitleDetails(percents, country) {
3651
+ if (this.isIndia(country)) {
3652
+ return percents ? `Including ${percents}% GST` : 'Including GST';
3653
+ }
3654
+ if (this.isGhana(country)) {
3655
+ return 'Including VAT, NHIL, GETFund Levy, and Covid-19 Levy';
3656
+ }
3657
+ return percents ? `Including ${percents}% VAT` : `Including VAT`;
3658
+ }
3659
+ isGhana(country) {
3660
+ return country === CountryIsoCode.Ghana;
3661
+ }
3662
+ isIndia(country) {
3663
+ return country === CountryIsoCode.India;
3664
+ }
3665
+ getTransactionDetails(status, financeInfo) {
3666
+ const transactionDetails = [];
3667
+ if (financeInfo.invoice?.value) {
3668
+ transactionDetails.push({
3669
+ key: 'invoice',
3670
+ title: 'Transaction',
3671
+ content: financeInfo.invoice.value,
3672
+ });
3673
+ }
3674
+ const isCompleted = status.isCancelUser ||
3675
+ (status.statusState !== StatusEnum.processing &&
3676
+ status.statusState !== StatusEnum.created &&
3677
+ status.statusState !== StatusEnum.held);
3678
+ if (isCompleted && financeInfo.time?.value) {
3679
+ transactionDetails.push({
3680
+ key: 'time',
3681
+ title: 'Date',
3682
+ content: financeInfo.time.value,
3683
+ isDateLine: true,
3684
+ });
3685
+ }
3686
+ return transactionDetails;
3687
+ }
3688
+ getPercents(value) {
3689
+ const percentsTemplate = /(\d+(.\d+)?)/;
3690
+ const percentsMatchResult = percentsTemplate.exec(value);
3691
+ if (!percentsMatchResult) {
3692
+ return null;
3693
+ }
3694
+ return percentsMatchResult[0];
3695
+ }
3696
+ }
3697
+ StatusFinanceDetailsAdapterService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusFinanceDetailsAdapterService, deps: [{ token: SummaryFinanceDetailsAdapterService }], target: i0.ɵɵFactoryTarget.Injectable });
3698
+ StatusFinanceDetailsAdapterService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusFinanceDetailsAdapterService, providedIn: 'root' });
3699
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusFinanceDetailsAdapterService, decorators: [{
3700
+ type: Injectable,
3701
+ args: [{ providedIn: 'root' }]
3702
+ }], ctorParameters: function () { return [{ type: SummaryFinanceDetailsAdapterService }]; } });
3703
+
3704
+ class FinanceDetailsService extends EmitDataService {
3705
+ constructor(sessionService, summaryFinanceDetailsAdapterService, statusFinanceDetailsAdapterService) {
2933
3706
  super();
2934
- this.secureApiClient = secureApiClient;
2935
- this.settingsService = settingsService;
2936
- this.requestFactory = requestFactory;
2937
- this.responseFactory = responseFactory;
2938
- this.apiRoute = 'directpayment';
3707
+ this.sessionService = sessionService;
3708
+ this.summaryFinanceDetailsAdapterService = summaryFinanceDetailsAdapterService;
3709
+ this.statusFinanceDetailsAdapterService = statusFinanceDetailsAdapterService;
3710
+ this.purchaseSessionKey = 'purchase';
2939
3711
  }
2940
- setRequestParams(params) {
2941
- this.requestParams = {
2942
- locale: params.locale,
2943
- testProject: params.testProject,
2944
- testPs: params.testPs,
2945
- testXsolla: params.testXsolla,
2946
- userReturnStatus: params.userReturnStatus,
2947
- invoice: params.invoice,
2948
- pid: params.pid,
2949
- signature: params.signature,
2950
- };
3712
+ emitWithSummary(summary) {
3713
+ if (summary) {
3714
+ const financeDetails = this.summaryFinanceDetailsAdapterService.getFinanceDetails(summary);
3715
+ if (financeDetails.purchase) {
3716
+ this.sessionService.set(this.purchaseSessionKey, financeDetails.purchase);
3717
+ }
3718
+ super.emit(financeDetails);
3719
+ }
2951
3720
  }
2952
- request() {
2953
- const requestParams = this.requestFactory({
2954
- token: this.settingsService.token,
2955
- ...this.requestParams,
2956
- });
2957
- lastValueFrom(this.secureApiClient.post(this.apiRoute, new URLSearchParams(requestParams), {
2958
- headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8'),
2959
- responseType: 'json',
2960
- }))
2961
- .then((response) => {
2962
- const statusResponse = this.responseFactory({
2963
- status: response.status,
2964
- errors: response.errors,
2965
- form: response.form,
2966
- });
2967
- this.emitResponse(statusResponse);
2968
- })
2969
- .catch((e) => {
2970
- throw new TerminalError(e.message, e.code);
2971
- });
3721
+ emitWithStatus(status) {
3722
+ if (status) {
3723
+ const purchase = this.sessionService.get(this.purchaseSessionKey);
3724
+ const financeDetails = this.statusFinanceDetailsAdapterService.getFinanceDetails(status, purchase);
3725
+ super.emit(financeDetails);
3726
+ }
2972
3727
  }
2973
3728
  }
2974
- StatusRequestService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusRequestService, deps: [{ token: SecureApiClient }, { token: SettingsService }, { token: statusRequestFactoryToken }, { token: statusResponseFactoryToken }], target: i0.ɵɵFactoryTarget.Injectable });
2975
- StatusRequestService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusRequestService, providedIn: 'root' });
2976
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusRequestService, decorators: [{
3729
+ FinanceDetailsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FinanceDetailsService, deps: [{ token: SessionService }, { token: SummaryFinanceDetailsAdapterService }, { token: StatusFinanceDetailsAdapterService }], target: i0.ɵɵFactoryTarget.Injectable });
3730
+ FinanceDetailsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FinanceDetailsService, providedIn: 'root' });
3731
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FinanceDetailsService, decorators: [{
2977
3732
  type: Injectable,
2978
- args: [{
2979
- providedIn: 'root',
2980
- }]
2981
- }], ctorParameters: function () { return [{ type: SecureApiClient }, { type: SettingsService }, { type: undefined, decorators: [{
2982
- type: Inject,
2983
- args: [statusRequestFactoryToken]
2984
- }] }, { type: undefined, decorators: [{
2985
- type: Inject,
2986
- args: [statusResponseFactoryToken]
2987
- }] }]; } });
3733
+ args: [{ providedIn: 'root' }]
3734
+ }], ctorParameters: function () { return [{ type: SessionService }, { type: SummaryFinanceDetailsAdapterService }, { type: StatusFinanceDetailsAdapterService }]; } });
2988
3735
 
2989
3736
  /* eslint-disable @typescript-eslint/naming-convention */
2990
3737
  class CheckStatusRequest extends XpsApiPartRequest {
@@ -3698,9 +4445,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
3698
4445
  }], ctorParameters: function () { return [{ type: StatusRequestService }, { type: CheckStatusService }, { type: WebsocketStatusService }]; } });
3699
4446
 
3700
4447
  class StatusService {
3701
- constructor(urlService, statusRequestService, listenStatusService, nextActionService) {
4448
+ constructor(urlService, statusRequestService, financeDetailsService, listenStatusService, nextActionService) {
3702
4449
  this.urlService = urlService;
3703
4450
  this.statusRequestService = statusRequestService;
4451
+ this.financeDetailsService = financeDetailsService;
3704
4452
  this.listenStatusService = listenStatusService;
3705
4453
  this.nextActionService = nextActionService;
3706
4454
  }
@@ -3709,6 +4457,7 @@ class StatusService {
3709
4457
  this.startWaitingStatusUpdates(params.invoice);
3710
4458
  this.statusRequestService.request();
3711
4459
  const statusResponse = await firstValueFrom(this.statusRequestService.response$);
4460
+ this.financeDetailsService.emitWithStatus(statusResponse.status);
3712
4461
  return statusResponse.status;
3713
4462
  }
3714
4463
  async getStatusWithUrlSearchParams(url) {
@@ -3735,305 +4484,19 @@ class StatusService {
3735
4484
  this.listenStatusService.statusUpdated$
3736
4485
  .pipe(skip(1))
3737
4486
  .subscribe(({ statusResponse }) => {
4487
+ this.financeDetailsService.emitWithStatus(statusResponse.status);
3738
4488
  this.nextActionService.emitFlowUpdates(new StatusUpdatedAction(statusResponse));
3739
4489
  });
3740
4490
  }
3741
4491
  }
3742
- StatusService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, deps: [{ token: UrlService }, { token: StatusRequestService }, { token: ListenStatusService }, { token: NextActionService }], target: i0.ɵɵFactoryTarget.Injectable });
4492
+ StatusService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, deps: [{ token: UrlService }, { token: StatusRequestService }, { token: FinanceDetailsService }, { token: ListenStatusService }, { token: NextActionService }], target: i0.ɵɵFactoryTarget.Injectable });
3743
4493
  StatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, providedIn: 'root' });
3744
4494
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, decorators: [{
3745
4495
  type: Injectable,
3746
4496
  args: [{
3747
4497
  providedIn: 'root',
3748
4498
  }]
3749
- }], ctorParameters: function () { return [{ type: UrlService }, { type: StatusRequestService }, { type: ListenStatusService }, { type: NextActionService }]; } });
3750
-
3751
- /**
3752
- * default image for purchase item is set on Publisher Account side.
3753
- * for purchase checkout items the image url is converted into base64 string.
3754
- * to determine default image fixed templates are used
3755
- */
3756
- const defaultImagePatterns = [
3757
- /^data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAAAAADmVT4XAAACMUlEQVR4Ae3YgYqdMBSE4fP/,
3758
- /virtual_item_default_image/,
3759
- ];
3760
-
3761
- function extractMoneyCurrency(money, allowZero = true) {
3762
- return {
3763
- amount: money?.amount ?? (allowZero ? 0 : null),
3764
- currency: money?.currency ?? '',
3765
- };
3766
- }
3767
- function createPriceOrUndefined(amount, currency) {
3768
- return amount !== undefined && amount !== null
3769
- ? {
3770
- amount,
3771
- currency,
3772
- }
3773
- : undefined;
3774
- }
3775
-
3776
- class FinanceDetails {
3777
- get shouldShowZeroIndirectTaxRate() {
3778
- return !!(this.finance?.vat?.visible || this.finance?.vat_user?.visible);
3779
- }
3780
- get isSalesTaxes() {
3781
- return !!(this.finance?.sales_tax?.amount || this.finance?.sales_tax_user?.amount);
3782
- }
3783
- constructor(parameters) {
3784
- this.purchase = parameters.purchase;
3785
- this.finance = parameters.finance;
3786
- this.cartItems = this.getFormattedPurchaseForCart();
3787
- this.cartSummary = this.getFormattedPricingForCart();
3788
- this.paymentCountry = this.getPaymentCountry();
3789
- }
3790
- getFormattedPurchaseForCart() {
3791
- const checkouts = this.purchase.checkout_items?.map((item) => {
3792
- return {
3793
- imgSrc: item.image_url,
3794
- hasDefaultImg: this.isDefaultImage(item.image_url),
3795
- title: item.name,
3796
- price: extractMoneyCurrency(item, false),
3797
- priceBeforeDiscount: createPriceOrUndefined(item.amount_before_discount, item.currency),
3798
- quantity: item.quantity,
3799
- description: item.description,
3800
- tax: this.getTaxForItem(item.indirect_tax_rate),
3801
- isBonus: item.is_bonus,
3802
- };
3803
- });
3804
- const virtualCurrencies = this.purchase.virtual_currency?.map((item) => {
3805
- return {
3806
- imgSrc: item.image_url,
3807
- hasDefaultImg: this.isDefaultImage(item.image_url),
3808
- title: `${item.quantity} ${item.name}`,
3809
- price: extractMoneyCurrency(item),
3810
- description: item.description,
3811
- isBonus: item.is_bonus,
3812
- };
3813
- });
3814
- const virtualItems = this.purchase.virtual_items?.map((item) => {
3815
- return {
3816
- imgSrc: item.image_url,
3817
- hasDefaultImg: this.isDefaultImage(item.image_url),
3818
- title: item.name,
3819
- price: extractMoneyCurrency(item),
3820
- description: item.description,
3821
- quantity: item.quantity,
3822
- isBonus: item.is_bonus,
3823
- };
3824
- });
3825
- let checkoutArray = undefined;
3826
- if (this.purchase.checkout) {
3827
- checkoutArray = [
3828
- {
3829
- key: 'checkout',
3830
- title: this.purchase.checkout.description,
3831
- price: extractMoneyCurrency(this.purchase.checkout),
3832
- isBonus: this.purchase.checkout.is_bonus ?? false,
3833
- },
3834
- ];
3835
- }
3836
- return [
3837
- ...(checkouts ?? []),
3838
- ...(virtualCurrencies ?? []),
3839
- ...(virtualItems ?? []),
3840
- ...(checkoutArray ?? []),
3841
- ];
3842
- }
3843
- getFormattedPricingForCart() {
3844
- // subtotal details fields
3845
- const subtotalDetailsSorting = [
3846
- {
3847
- key: 'discount',
3848
- responseKey: 'discount',
3849
- title: 'Discount',
3850
- },
3851
- {
3852
- key: 'fee',
3853
- responseKey: 'fee',
3854
- title: 'Payment system fee',
3855
- },
3856
- {
3857
- key: 'user-balance',
3858
- responseKey: 'user_balance',
3859
- title: 'Balance',
3860
- },
3861
- ];
3862
- return {
3863
- subtotal: {
3864
- title: 'Subtotal',
3865
- money: createPriceOrUndefined(this.finance.sub_total.amount, this.finance.sub_total.currency),
3866
- },
3867
- subtotalPayment: {
3868
- title: '',
3869
- money: createPriceOrUndefined(this.finance.sub_total.payment_amount, this.finance.sub_total.payment_currency),
3870
- },
3871
- total: {
3872
- title: 'Total',
3873
- money: extractMoneyCurrency(this.finance.total),
3874
- },
3875
- totalDetails: this.getTaxesForTotalDetails(),
3876
- subtotalDetails: [
3877
- ...subtotalDetailsSorting.map((sorting) => {
3878
- const field = this.finance[sorting.responseKey];
3879
- if (field) {
3880
- return {
3881
- key: sorting.key,
3882
- title: sorting.title,
3883
- money: {
3884
- amount: sorting.key === 'discount' && field.amount
3885
- ? -field.amount
3886
- : field.amount,
3887
- currency: field.currency,
3888
- },
3889
- };
3890
- }
3891
- return sorting;
3892
- }),
3893
- ...this.getTaxesForSubtotalDetails(),
3894
- ],
3895
- };
3896
- }
3897
- getPaymentCountry() {
3898
- return this.finance.payment_country.iso;
3899
- }
3900
- getTaxForItem(indirectTaxRate) {
3901
- if (indirectTaxRate ||
3902
- (this.shouldShowZeroIndirectTaxRate && indirectTaxRate === 0)) {
3903
- if (this.isSalesTaxes) {
3904
- return {
3905
- key: 'sales-tax',
3906
- content: `Sales tax ${indirectTaxRate}%`,
3907
- rate: indirectTaxRate,
3908
- };
3909
- }
3910
- if (this.isIndia()) {
3911
- return {
3912
- key: 'vat-india',
3913
- content: `GST ${indirectTaxRate}%`,
3914
- rate: indirectTaxRate,
3915
- };
3916
- }
3917
- if (this.isGhana()) {
3918
- return {
3919
- key: 'vat-ghana',
3920
- content: 'VAT, NHIL, GETFund Levy, and Covid-19 Levy',
3921
- rate: indirectTaxRate,
3922
- };
3923
- }
3924
- return {
3925
- key: 'vat',
3926
- content: `VAT ${indirectTaxRate}%`,
3927
- rate: indirectTaxRate,
3928
- };
3929
- }
3930
- return null;
3931
- }
3932
- getTaxesForSubtotalDetails() {
3933
- const ret = [];
3934
- // subtotal. VAT %p
3935
- if (this.finance.vat_user &&
3936
- (this.finance?.vat_user?.amount ?? this.finance?.vat_user?.visible)) {
3937
- ret.push({
3938
- key: this.getVatKeyForDetails(),
3939
- title: this.getVatLabelForSubtotalDetails(),
3940
- money: extractMoneyCurrency(this.finance.vat_user),
3941
- });
3942
- }
3943
- if (this.finance.sales_tax_user?.amount) {
3944
- ret.push({
3945
- key: 'sales-tax',
3946
- title: 'Sales tax',
3947
- money: extractMoneyCurrency(this.finance.sales_tax_user),
3948
- });
3949
- }
3950
- return ret;
3951
- }
3952
- getVatLabelForSubtotalDetails() {
3953
- if (this.isIndia()) {
3954
- return `GST ${this.finance.vat_user?.percent ?? ''}%`;
3955
- }
3956
- if (this.isGhana()) {
3957
- return `VAT, NHIL, GETFund Levy, and Covid-19 Levy`;
3958
- }
3959
- return `VAT ${this.finance.vat_user?.percent ?? ''}%`;
3960
- }
3961
- getTaxesForTotalDetails() {
3962
- const ret = [];
3963
- // for totalDetails. VAT
3964
- if ((this.finance?.vat?.amount || this.finance?.vat?.visible) &&
3965
- !this.finance?.vat_user?.amount) {
3966
- ret.push({
3967
- key: this.getVatKeyForDetails(),
3968
- title: this.getVatLabelForTotalDetails(),
3969
- money: extractMoneyCurrency(this.finance.vat),
3970
- });
3971
- }
3972
- if (this.finance?.sales_tax?.amount &&
3973
- !this.finance?.sales_tax_user?.amount) {
3974
- ret.push({
3975
- key: 'sales-tax',
3976
- title: 'Sales tax included',
3977
- money: extractMoneyCurrency(this.finance.sales_tax),
3978
- });
3979
- }
3980
- return ret;
3981
- }
3982
- getVatKeyForDetails() {
3983
- if (this.isIndia()) {
3984
- return 'vat-india';
3985
- }
3986
- if (this.isGhana()) {
3987
- return 'vat-ghana';
3988
- }
3989
- return 'vat';
3990
- }
3991
- getVatLabelForTotalDetails() {
3992
- if (this.isIndia()) {
3993
- return `Including ${this.finance.vat.percent}% GST`;
3994
- }
3995
- if (this.isGhana()) {
3996
- return 'Including VAT, NHIL, GETFund Levy, and Covid-19 Levy';
3997
- }
3998
- return `Including ${this.finance.vat.percent}% VAT`;
3999
- }
4000
- isIndia() {
4001
- return this.finance?.payment_country.iso === 'IN';
4002
- }
4003
- isGhana() {
4004
- return this.finance?.payment_country.iso === 'GH';
4005
- }
4006
- isDefaultImage(url) {
4007
- return defaultImagePatterns.some((regex) => regex.test(url));
4008
- }
4009
- }
4010
-
4011
- const financeDetailsResponseFactoryToken = new InjectionToken('FinanceDetails');
4012
- const financeDetailsResponseFactoryProvider = {
4013
- provide: financeDetailsResponseFactoryToken,
4014
- useValue: (...args) => new FinanceDetails(...args),
4015
- };
4016
-
4017
- class FinanceDetailsService extends EmitDataService {
4018
- constructor(responseFactory) {
4019
- super();
4020
- this.responseFactory = responseFactory;
4021
- }
4022
- emit(summary) {
4023
- if (summary) {
4024
- super.emit(this.responseFactory(summary));
4025
- }
4026
- }
4027
- }
4028
- FinanceDetailsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FinanceDetailsService, deps: [{ token: financeDetailsResponseFactoryToken }], target: i0.ɵɵFactoryTarget.Injectable });
4029
- FinanceDetailsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FinanceDetailsService, providedIn: 'root' });
4030
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FinanceDetailsService, decorators: [{
4031
- type: Injectable,
4032
- args: [{ providedIn: 'root' }]
4033
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
4034
- type: Inject,
4035
- args: [financeDetailsResponseFactoryToken]
4036
- }] }]; } });
4499
+ }], ctorParameters: function () { return [{ type: UrlService }, { type: StatusRequestService }, { type: FinanceDetailsService }, { type: ListenStatusService }, { type: NextActionService }]; } });
4037
4500
 
4038
4501
  class CreditCardStateService extends EmitDataService {
4039
4502
  }
@@ -4600,7 +5063,7 @@ class PaymentService {
4600
5063
  this.threeDsService.stopChecking();
4601
5064
  }
4602
5065
  emitFinanceDetails(summary) {
4603
- this.financeDetailsService.emit(summary);
5066
+ this.financeDetailsService.emitWithSummary(summary);
4604
5067
  }
4605
5068
  emitCreditCardState(idCardType) {
4606
5069
  this.creditCardStateService.emit({ idCardType });
@@ -4789,6 +5252,9 @@ class CoreLibraryService {
4789
5252
  setCountry(country) {
4790
5253
  this.countryService.setCountry(country);
4791
5254
  }
5255
+ getCountry() {
5256
+ return this.countryService.getCountry();
5257
+ }
4792
5258
  createPayment(config) {
4793
5259
  const enrichedConfig = this.paymentConfigService.enrich(config);
4794
5260
  return {
@@ -4935,6 +5401,8 @@ FormModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15
4935
5401
  PricepointConverter,
4936
5402
  PricepointConverter,
4937
5403
  CouponConverter,
5404
+ TextConverter,
5405
+ PhoneConverter,
4938
5406
  { provide: convertersMapToken, useValue: convertersMap },
4939
5407
  ], imports: [ReactiveFormsModule, ValidatorsModule] });
4940
5408
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FormModule, decorators: [{
@@ -4966,6 +5434,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
4966
5434
  PricepointConverter,
4967
5435
  PricepointConverter,
4968
5436
  CouponConverter,
5437
+ TextConverter,
5438
+ PhoneConverter,
4969
5439
  { provide: convertersMapToken, useValue: convertersMap },
4970
5440
  ],
4971
5441
  }]
@@ -4994,7 +5464,6 @@ CoreLibraryModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", versi
4994
5464
  statusResponseFactoryProvider,
4995
5465
  checkStatusRequestFactoryProvider,
4996
5466
  checkStatusResponseFactoryProvider,
4997
- financeDetailsResponseFactoryProvider,
4998
5467
  statusThreeDsRequestFactoryProvider,
4999
5468
  statusThreeDsResponseFactoryProvider,
5000
5469
  notifyDfpStatusRequestFactoryProvider,
@@ -5028,7 +5497,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
5028
5497
  statusResponseFactoryProvider,
5029
5498
  checkStatusRequestFactoryProvider,
5030
5499
  checkStatusResponseFactoryProvider,
5031
- financeDetailsResponseFactoryProvider,
5032
5500
  statusThreeDsRequestFactoryProvider,
5033
5501
  statusThreeDsResponseFactoryProvider,
5034
5502
  notifyDfpStatusRequestFactoryProvider,