@xsolla/payment-client-core 0.1.7 → 0.1.9

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 (61) 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/payment.interface.mjs +1 -1
  15. package/esm2020/lib/core/payment/payment.service.mjs +2 -2
  16. package/esm2020/lib/core/payment/status/status-finance-info.interface.mjs +2 -0
  17. package/esm2020/lib/core/payment/status/status-order.interface.mjs +2 -0
  18. package/esm2020/lib/core/payment/status/status.interface.mjs +1 -1
  19. package/esm2020/lib/core/payment/status/status.service.mjs +10 -6
  20. package/esm2020/lib/core/payment/xps-summary.interface.mjs +1 -1
  21. package/esm2020/lib/core/session/session.service.mjs +57 -0
  22. package/esm2020/lib/core/type-guards/is-null.function.mjs +4 -0
  23. package/esm2020/lib/core/type-guards/is-undefined.function.mjs +4 -0
  24. package/esm2020/lib/core-library.module.mjs +1 -4
  25. package/esm2020/lib/core-library.service.mjs +4 -1
  26. package/fesm2015/xsolla-payment-client-core.mjs +729 -304
  27. package/fesm2015/xsolla-payment-client-core.mjs.map +1 -1
  28. package/fesm2020/xsolla-payment-client-core.mjs +709 -293
  29. package/fesm2020/xsolla-payment-client-core.mjs.map +1 -1
  30. package/lib/core/country/country-iso-code.enum.d.ts +4 -0
  31. package/lib/core/payment/finance-details/cart-summary.interface.d.ts +2 -2
  32. package/lib/core/payment/finance-details/finance-details.interface.d.ts +11 -0
  33. package/lib/core/payment/finance-details/finance-details.service.d.ts +12 -5
  34. package/lib/core/payment/finance-details/price.helpers.d.ts +3 -3
  35. package/lib/core/payment/finance-details/status/field-with-amount-and-currency.interface.d.ts +7 -0
  36. package/lib/core/payment/finance-details/status/fields-with-currency.d.ts +1 -0
  37. package/lib/core/payment/finance-details/status/finance-info.interface.d.ts +4 -0
  38. package/lib/core/payment/finance-details/status/status-finance-details-adapter.service.d.ts +31 -0
  39. package/lib/core/payment/finance-details/summary/sales-tax-details-key.enum.d.ts +5 -0
  40. package/lib/core/payment/finance-details/summary/summary-finance-details-adapter.service.d.ts +24 -0
  41. package/lib/core/payment/finance-details/vat-details-key.enum.d.ts +12 -0
  42. package/lib/core/payment/payment.interface.d.ts +1 -1
  43. package/lib/core/payment/payment.service.d.ts +1 -1
  44. package/lib/core/payment/status/status-finance-info.interface.d.ts +4 -0
  45. package/lib/core/payment/status/status-order.interface.d.ts +12 -0
  46. package/lib/core/payment/status/status.interface.d.ts +4 -16
  47. package/lib/core/payment/status/status.service.d.ts +3 -1
  48. package/lib/core/payment/xps-summary.interface.d.ts +1 -1
  49. package/lib/core/session/session.service.d.ts +18 -0
  50. package/lib/core/type-guards/is-null.function.d.ts +1 -0
  51. package/lib/core/type-guards/is-undefined.function.d.ts +1 -0
  52. package/lib/core-library.service.d.ts +2 -0
  53. package/package.json +1 -1
  54. package/xsolla-payment-client-core-0.1.9.tgz +0 -0
  55. package/esm2020/lib/core/payment/finance-details/default-image-patterns.const.mjs +0 -10
  56. package/esm2020/lib/core/payment/finance-details/finance-details-response.token.mjs +0 -8
  57. package/esm2020/lib/core/payment/finance-details/finance-details.class.mjs +0 -237
  58. package/lib/core/payment/finance-details/finance-details-response.token.d.ts +0 -7
  59. package/lib/core/payment/finance-details/finance-details.class.d.ts +0 -29
  60. package/xsolla-payment-client-core-0.1.7.tgz +0 -0
  61. /package/lib/core/payment/finance-details/{default-image-patterns.const.d.ts → summary/default-image-patterns.const.d.ts} +0 -0
@@ -3034,6 +3034,705 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
3034
3034
  args: [statusResponseFactoryToken]
3035
3035
  }] }]; } });
3036
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) {
3706
+ super();
3707
+ this.sessionService = sessionService;
3708
+ this.summaryFinanceDetailsAdapterService = summaryFinanceDetailsAdapterService;
3709
+ this.statusFinanceDetailsAdapterService = statusFinanceDetailsAdapterService;
3710
+ this.purchaseSessionKey = 'purchase';
3711
+ }
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
+ }
3720
+ }
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
+ }
3727
+ }
3728
+ }
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: [{
3732
+ type: Injectable,
3733
+ args: [{ providedIn: 'root' }]
3734
+ }], ctorParameters: function () { return [{ type: SessionService }, { type: SummaryFinanceDetailsAdapterService }, { type: StatusFinanceDetailsAdapterService }]; } });
3735
+
3037
3736
  /* eslint-disable @typescript-eslint/naming-convention */
3038
3737
  class CheckStatusRequest extends XpsApiPartRequest {
3039
3738
  constructor(token, invoice) {
@@ -3746,9 +4445,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
3746
4445
  }], ctorParameters: function () { return [{ type: StatusRequestService }, { type: CheckStatusService }, { type: WebsocketStatusService }]; } });
3747
4446
 
3748
4447
  class StatusService {
3749
- constructor(urlService, statusRequestService, listenStatusService, nextActionService) {
4448
+ constructor(urlService, statusRequestService, financeDetailsService, listenStatusService, nextActionService) {
3750
4449
  this.urlService = urlService;
3751
4450
  this.statusRequestService = statusRequestService;
4451
+ this.financeDetailsService = financeDetailsService;
3752
4452
  this.listenStatusService = listenStatusService;
3753
4453
  this.nextActionService = nextActionService;
3754
4454
  }
@@ -3757,6 +4457,7 @@ class StatusService {
3757
4457
  this.startWaitingStatusUpdates(params.invoice);
3758
4458
  this.statusRequestService.request();
3759
4459
  const statusResponse = await firstValueFrom(this.statusRequestService.response$);
4460
+ this.financeDetailsService.emitWithStatus(statusResponse.status);
3760
4461
  return statusResponse.status;
3761
4462
  }
3762
4463
  async getStatusWithUrlSearchParams(url) {
@@ -3783,305 +4484,19 @@ class StatusService {
3783
4484
  this.listenStatusService.statusUpdated$
3784
4485
  .pipe(skip(1))
3785
4486
  .subscribe(({ statusResponse }) => {
4487
+ this.financeDetailsService.emitWithStatus(statusResponse.status);
3786
4488
  this.nextActionService.emitFlowUpdates(new StatusUpdatedAction(statusResponse));
3787
4489
  });
3788
4490
  }
3789
4491
  }
3790
- 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 });
3791
4493
  StatusService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, providedIn: 'root' });
3792
4494
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: StatusService, decorators: [{
3793
4495
  type: Injectable,
3794
4496
  args: [{
3795
4497
  providedIn: 'root',
3796
4498
  }]
3797
- }], ctorParameters: function () { return [{ type: UrlService }, { type: StatusRequestService }, { type: ListenStatusService }, { type: NextActionService }]; } });
3798
-
3799
- /**
3800
- * default image for purchase item is set on Publisher Account side.
3801
- * for purchase checkout items the image url is converted into base64 string.
3802
- * to determine default image fixed templates are used
3803
- */
3804
- const defaultImagePatterns = [
3805
- /^data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAAAAADmVT4XAAACMUlEQVR4Ae3YgYqdMBSE4fP/,
3806
- /virtual_item_default_image/,
3807
- ];
3808
-
3809
- function extractMoneyCurrency(money, allowZero = true) {
3810
- return {
3811
- amount: money?.amount ?? (allowZero ? 0 : null),
3812
- currency: money?.currency ?? '',
3813
- };
3814
- }
3815
- function createPriceOrUndefined(amount, currency) {
3816
- return amount !== undefined && amount !== null
3817
- ? {
3818
- amount,
3819
- currency,
3820
- }
3821
- : undefined;
3822
- }
3823
-
3824
- class FinanceDetails {
3825
- get shouldShowZeroIndirectTaxRate() {
3826
- return !!(this.finance?.vat?.visible || this.finance?.vat_user?.visible);
3827
- }
3828
- get isSalesTaxes() {
3829
- return !!(this.finance?.sales_tax?.amount || this.finance?.sales_tax_user?.amount);
3830
- }
3831
- constructor(parameters) {
3832
- this.purchase = parameters.purchase;
3833
- this.finance = parameters.finance;
3834
- this.cartItems = this.getFormattedPurchaseForCart();
3835
- this.cartSummary = this.getFormattedPricingForCart();
3836
- this.paymentCountry = this.getPaymentCountry();
3837
- }
3838
- getFormattedPurchaseForCart() {
3839
- const checkouts = this.purchase.checkout_items?.map((item) => {
3840
- return {
3841
- imgSrc: item.image_url,
3842
- hasDefaultImg: this.isDefaultImage(item.image_url),
3843
- title: item.name,
3844
- price: extractMoneyCurrency(item, false),
3845
- priceBeforeDiscount: createPriceOrUndefined(item.amount_before_discount, item.currency),
3846
- quantity: item.quantity,
3847
- description: item.description,
3848
- tax: this.getTaxForItem(item.indirect_tax_rate),
3849
- isBonus: item.is_bonus,
3850
- };
3851
- });
3852
- const virtualCurrencies = this.purchase.virtual_currency?.map((item) => {
3853
- return {
3854
- imgSrc: item.image_url,
3855
- hasDefaultImg: this.isDefaultImage(item.image_url),
3856
- title: `${item.quantity} ${item.name}`,
3857
- price: extractMoneyCurrency(item),
3858
- description: item.description,
3859
- isBonus: item.is_bonus,
3860
- };
3861
- });
3862
- const virtualItems = this.purchase.virtual_items?.map((item) => {
3863
- return {
3864
- imgSrc: item.image_url,
3865
- hasDefaultImg: this.isDefaultImage(item.image_url),
3866
- title: item.name,
3867
- price: extractMoneyCurrency(item),
3868
- description: item.description,
3869
- quantity: item.quantity,
3870
- isBonus: item.is_bonus,
3871
- };
3872
- });
3873
- let checkoutArray = undefined;
3874
- if (this.purchase.checkout) {
3875
- checkoutArray = [
3876
- {
3877
- key: 'checkout',
3878
- title: this.purchase.checkout.description,
3879
- price: extractMoneyCurrency(this.purchase.checkout),
3880
- isBonus: this.purchase.checkout.is_bonus ?? false,
3881
- },
3882
- ];
3883
- }
3884
- return [
3885
- ...(checkouts ?? []),
3886
- ...(virtualCurrencies ?? []),
3887
- ...(virtualItems ?? []),
3888
- ...(checkoutArray ?? []),
3889
- ];
3890
- }
3891
- getFormattedPricingForCart() {
3892
- // subtotal details fields
3893
- const subtotalDetailsSorting = [
3894
- {
3895
- key: 'discount',
3896
- responseKey: 'discount',
3897
- title: 'Discount',
3898
- },
3899
- {
3900
- key: 'fee',
3901
- responseKey: 'fee',
3902
- title: 'Payment system fee',
3903
- },
3904
- {
3905
- key: 'user-balance',
3906
- responseKey: 'user_balance',
3907
- title: 'Balance',
3908
- },
3909
- ];
3910
- return {
3911
- subtotal: {
3912
- title: 'Subtotal',
3913
- money: createPriceOrUndefined(this.finance.sub_total.amount, this.finance.sub_total.currency),
3914
- },
3915
- subtotalPayment: {
3916
- title: '',
3917
- money: createPriceOrUndefined(this.finance.sub_total.payment_amount, this.finance.sub_total.payment_currency),
3918
- },
3919
- total: {
3920
- title: 'Total',
3921
- money: extractMoneyCurrency(this.finance.total),
3922
- },
3923
- totalDetails: this.getTaxesForTotalDetails(),
3924
- subtotalDetails: [
3925
- ...subtotalDetailsSorting.map((sorting) => {
3926
- const field = this.finance[sorting.responseKey];
3927
- if (field) {
3928
- return {
3929
- key: sorting.key,
3930
- title: sorting.title,
3931
- money: {
3932
- amount: sorting.key === 'discount' && field.amount
3933
- ? -field.amount
3934
- : field.amount,
3935
- currency: field.currency,
3936
- },
3937
- };
3938
- }
3939
- return sorting;
3940
- }),
3941
- ...this.getTaxesForSubtotalDetails(),
3942
- ],
3943
- };
3944
- }
3945
- getPaymentCountry() {
3946
- return this.finance.payment_country.iso;
3947
- }
3948
- getTaxForItem(indirectTaxRate) {
3949
- if (indirectTaxRate ||
3950
- (this.shouldShowZeroIndirectTaxRate && indirectTaxRate === 0)) {
3951
- if (this.isSalesTaxes) {
3952
- return {
3953
- key: 'sales-tax',
3954
- content: `Sales tax ${indirectTaxRate}%`,
3955
- rate: indirectTaxRate,
3956
- };
3957
- }
3958
- if (this.isIndia()) {
3959
- return {
3960
- key: 'vat-india',
3961
- content: `GST ${indirectTaxRate}%`,
3962
- rate: indirectTaxRate,
3963
- };
3964
- }
3965
- if (this.isGhana()) {
3966
- return {
3967
- key: 'vat-ghana',
3968
- content: 'VAT, NHIL, GETFund Levy, and Covid-19 Levy',
3969
- rate: indirectTaxRate,
3970
- };
3971
- }
3972
- return {
3973
- key: 'vat',
3974
- content: `VAT ${indirectTaxRate}%`,
3975
- rate: indirectTaxRate,
3976
- };
3977
- }
3978
- return null;
3979
- }
3980
- getTaxesForSubtotalDetails() {
3981
- const ret = [];
3982
- // subtotal. VAT %p
3983
- if (this.finance.vat_user &&
3984
- (this.finance?.vat_user?.amount ?? this.finance?.vat_user?.visible)) {
3985
- ret.push({
3986
- key: this.getVatKeyForDetails(),
3987
- title: this.getVatLabelForSubtotalDetails(),
3988
- money: extractMoneyCurrency(this.finance.vat_user),
3989
- });
3990
- }
3991
- if (this.finance.sales_tax_user?.amount) {
3992
- ret.push({
3993
- key: 'sales-tax',
3994
- title: 'Sales tax',
3995
- money: extractMoneyCurrency(this.finance.sales_tax_user),
3996
- });
3997
- }
3998
- return ret;
3999
- }
4000
- getVatLabelForSubtotalDetails() {
4001
- if (this.isIndia()) {
4002
- return `GST ${this.finance.vat_user?.percent ?? ''}%`;
4003
- }
4004
- if (this.isGhana()) {
4005
- return `VAT, NHIL, GETFund Levy, and Covid-19 Levy`;
4006
- }
4007
- return `VAT ${this.finance.vat_user?.percent ?? ''}%`;
4008
- }
4009
- getTaxesForTotalDetails() {
4010
- const ret = [];
4011
- // for totalDetails. VAT
4012
- if ((this.finance?.vat?.amount || this.finance?.vat?.visible) &&
4013
- !this.finance?.vat_user?.amount) {
4014
- ret.push({
4015
- key: this.getVatKeyForDetails(),
4016
- title: this.getVatLabelForTotalDetails(),
4017
- money: extractMoneyCurrency(this.finance.vat),
4018
- });
4019
- }
4020
- if (this.finance?.sales_tax?.amount &&
4021
- !this.finance?.sales_tax_user?.amount) {
4022
- ret.push({
4023
- key: 'sales-tax',
4024
- title: 'Sales tax included',
4025
- money: extractMoneyCurrency(this.finance.sales_tax),
4026
- });
4027
- }
4028
- return ret;
4029
- }
4030
- getVatKeyForDetails() {
4031
- if (this.isIndia()) {
4032
- return 'vat-india';
4033
- }
4034
- if (this.isGhana()) {
4035
- return 'vat-ghana';
4036
- }
4037
- return 'vat';
4038
- }
4039
- getVatLabelForTotalDetails() {
4040
- if (this.isIndia()) {
4041
- return `Including ${this.finance.vat.percent}% GST`;
4042
- }
4043
- if (this.isGhana()) {
4044
- return 'Including VAT, NHIL, GETFund Levy, and Covid-19 Levy';
4045
- }
4046
- return `Including ${this.finance.vat.percent}% VAT`;
4047
- }
4048
- isIndia() {
4049
- return this.finance?.payment_country.iso === 'IN';
4050
- }
4051
- isGhana() {
4052
- return this.finance?.payment_country.iso === 'GH';
4053
- }
4054
- isDefaultImage(url) {
4055
- return defaultImagePatterns.some((regex) => regex.test(url));
4056
- }
4057
- }
4058
-
4059
- const financeDetailsResponseFactoryToken = new InjectionToken('FinanceDetails');
4060
- const financeDetailsResponseFactoryProvider = {
4061
- provide: financeDetailsResponseFactoryToken,
4062
- useValue: (...args) => new FinanceDetails(...args),
4063
- };
4064
-
4065
- class FinanceDetailsService extends EmitDataService {
4066
- constructor(responseFactory) {
4067
- super();
4068
- this.responseFactory = responseFactory;
4069
- }
4070
- emit(summary) {
4071
- if (summary) {
4072
- super.emit(this.responseFactory(summary));
4073
- }
4074
- }
4075
- }
4076
- FinanceDetailsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FinanceDetailsService, deps: [{ token: financeDetailsResponseFactoryToken }], target: i0.ɵɵFactoryTarget.Injectable });
4077
- FinanceDetailsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FinanceDetailsService, providedIn: 'root' });
4078
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: FinanceDetailsService, decorators: [{
4079
- type: Injectable,
4080
- args: [{ providedIn: 'root' }]
4081
- }], ctorParameters: function () { return [{ type: undefined, decorators: [{
4082
- type: Inject,
4083
- args: [financeDetailsResponseFactoryToken]
4084
- }] }]; } });
4499
+ }], ctorParameters: function () { return [{ type: UrlService }, { type: StatusRequestService }, { type: FinanceDetailsService }, { type: ListenStatusService }, { type: NextActionService }]; } });
4085
4500
 
4086
4501
  class CreditCardStateService extends EmitDataService {
4087
4502
  }
@@ -4648,7 +5063,7 @@ class PaymentService {
4648
5063
  this.threeDsService.stopChecking();
4649
5064
  }
4650
5065
  emitFinanceDetails(summary) {
4651
- this.financeDetailsService.emit(summary);
5066
+ this.financeDetailsService.emitWithSummary(summary);
4652
5067
  }
4653
5068
  emitCreditCardState(idCardType) {
4654
5069
  this.creditCardStateService.emit({ idCardType });
@@ -4868,6 +5283,9 @@ class CoreLibraryService {
4868
5283
  cardTypeUpdates$: this.creditCardStateService.data$,
4869
5284
  };
4870
5285
  }
5286
+ get financeDetailsUpdates$() {
5287
+ return this.financeDetailsService.data$;
5288
+ }
4871
5289
  get cardTypeUpdates$() {
4872
5290
  return this.creditCardStateService.data$;
4873
5291
  }
@@ -5049,7 +5467,6 @@ CoreLibraryModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", versi
5049
5467
  statusResponseFactoryProvider,
5050
5468
  checkStatusRequestFactoryProvider,
5051
5469
  checkStatusResponseFactoryProvider,
5052
- financeDetailsResponseFactoryProvider,
5053
5470
  statusThreeDsRequestFactoryProvider,
5054
5471
  statusThreeDsResponseFactoryProvider,
5055
5472
  notifyDfpStatusRequestFactoryProvider,
@@ -5083,7 +5500,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImpor
5083
5500
  statusResponseFactoryProvider,
5084
5501
  checkStatusRequestFactoryProvider,
5085
5502
  checkStatusResponseFactoryProvider,
5086
- financeDetailsResponseFactoryProvider,
5087
5503
  statusThreeDsRequestFactoryProvider,
5088
5504
  statusThreeDsResponseFactoryProvider,
5089
5505
  notifyDfpStatusRequestFactoryProvider,