-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(PAYMENTS-15236): add finance details component
- Loading branch information
1 parent
42692f6
commit 64ddf84
Showing
41 changed files
with
885 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum CountryCode { | ||
Croatia = 'HR', | ||
Ghana = 'GH', | ||
India = 'IN', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export enum Currency { | ||
EUR = 'EUR', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { CartLine } from './cart-line.interface'; | ||
import { Price } from './price.interface'; | ||
|
||
export interface CartItem { | ||
key?: string; | ||
imgSrc?: string; | ||
hasDefaultImg?: boolean; | ||
title: string; | ||
price: Price; | ||
priceBeforeDiscount?: Price; | ||
description?: string | null; | ||
tax?: CartLine | null; | ||
quantity?: number; | ||
isBonus: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Price } from './price.interface'; | ||
|
||
export interface CartLine { | ||
key?: string; | ||
title?: string; | ||
content?: string; | ||
money?: Price; | ||
rate?: number; | ||
isDateLine?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { CartLine } from './cart-line.interface'; | ||
|
||
export interface CartSummary { | ||
transactionDetails?: CartLine[]; | ||
shipping?: CartLine[]; | ||
subtotal?: CartLine; | ||
subtotalPayment?: CartLine; | ||
subtotalDetails?: CartLine[]; | ||
total: CartLine; | ||
totalDetails?: CartLine[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export interface CheckoutItem { | ||
quantity: number; | ||
amount: number | null; | ||
amount_before_discount?: number | null; | ||
name: string; | ||
image_url: string; | ||
description: string | null; | ||
currency: string; | ||
is_bonus: boolean; | ||
indirect_tax_rate: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { CartItem } from './cart-item.interface'; | ||
import { CartSummary } from './cart-summary.interface'; | ||
import { XpsFinance } from './xps-finance.interface'; | ||
import { XpsPurchase } from './xps-purchase.interface'; | ||
|
||
export interface FinanceDetails { | ||
purchase: XpsPurchase; | ||
finance: XpsFinance; | ||
cartItems: CartItem[]; | ||
cartSummary: CartSummary; | ||
paymentCountry: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface Price { | ||
amount: number | null; | ||
currency: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export interface VirtualCurrency { | ||
quantity: number; | ||
amount: number | null; | ||
name: string; | ||
image_url: string; | ||
description: string; | ||
longDescription: string | null; | ||
is_bonus: boolean; | ||
currency: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export interface XpsFinance { | ||
payment_country: { iso: string }; | ||
sub_total: { | ||
amount: number; | ||
currency: string; | ||
payment_amount: number; | ||
payment_currency: string; | ||
}; | ||
discount: { amount: number; currency: string }; | ||
vat_user?: { | ||
amount: number; | ||
percent: number; | ||
currency: string; | ||
visible: boolean; | ||
}; | ||
sales_tax: { amount: number; percent: number; currency: string }; | ||
sales_tax_user?: { amount: number; percent: number; currency: string }; | ||
fee: { amount: number; currency: string }; | ||
total: { amount: number; currency: string }; | ||
xsolla_credits?: { | ||
payment_amount: number; | ||
payment_currency: string; | ||
}; | ||
vat: { | ||
amount: number; | ||
percent: number; | ||
currency: string; | ||
visible: boolean; | ||
}; | ||
user_balance?: { amount: number; currency: string }; | ||
grand_total?: { amount: number; currency: string }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { CheckoutItem } from './checkout-item.interface'; | ||
import { VirtualCurrency } from './virtual-currency.interface'; | ||
|
||
export interface XpsPurchase { | ||
virtual_currency?: VirtualCurrency[]; | ||
checkout_items?: CheckoutItem[]; | ||
virtual_items?: VirtualCurrency[]; | ||
checkout?: { | ||
amount: number; | ||
currency: string; | ||
description: string; | ||
is_bonus?: boolean; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { EventName } from '../../core/event-name.enum'; | ||
import { Message } from '../../core/message.interface'; | ||
import { FinanceDetails } from '../finance-details/finance-details.interface'; | ||
import { isEventMessage } from './event-message.guard'; | ||
|
||
export const isFinanceDetailsEventMessage = ( | ||
messageData: unknown | ||
): messageData is Message<FinanceDetails> => { | ||
if (isEventMessage(messageData)) { | ||
return messageData.name === EventName.financeDetails; | ||
} | ||
|
||
return false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { Lang } from './lang.enum'; | ||
|
||
interface Translation { | ||
[key: string]: string | Translation; | ||
} | ||
|
||
export type Dictionary = { | ||
[key in Lang]?: { | ||
translation: { | ||
[key: string]: string; | ||
}; | ||
translation: Translation; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
interface SymbolFormat { | ||
grapheme: string; | ||
template: string; | ||
rtl: boolean; | ||
} | ||
|
||
export interface CurrencyFormat { | ||
name: string; | ||
fractionSize: number; | ||
symbol: SymbolFormat; | ||
uniqSymbol: SymbolFormat | null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import currencyFormat from 'currency-format/currency-format.json'; | ||
import { DecimalPipe } from '../decimal/decimal.pipe'; | ||
import { PipeTransform } from '../pipe-transform.interface'; | ||
import { CurrencyFormat } from './currency-format.interface'; | ||
|
||
export class CurrencyPipe implements PipeTransform { | ||
public transform( | ||
value: number | string | null, | ||
currencyCode?: string | ||
): string | null { | ||
if (!value || !currencyCode) { | ||
return ''; | ||
} | ||
|
||
return this.transformWithFormat(value, currencyCode); | ||
} | ||
|
||
private getCurrencyConfig(currencyCode: string): CurrencyFormat | null { | ||
// @ts-expect-error json don't have string type index | ||
const formatForCurrency = currencyFormat[ | ||
currencyCode.toUpperCase() | ||
] as unknown as CurrencyFormat | undefined; | ||
|
||
if (!formatForCurrency) { | ||
return null; | ||
} | ||
|
||
return formatForCurrency; | ||
} | ||
|
||
private transformWithFormat( | ||
value: number | string, | ||
currencyCode: string | ||
): string | null { | ||
const decimalPipe = new DecimalPipe(); | ||
const formatForCurrency = this.getCurrencyConfig(currencyCode); | ||
|
||
if (!formatForCurrency?.uniqSymbol) { | ||
return null; | ||
} | ||
|
||
const amount = decimalPipe.transform( | ||
value, | ||
1, | ||
formatForCurrency.fractionSize, | ||
formatForCurrency.fractionSize | ||
); | ||
|
||
if (!amount) { | ||
return null; | ||
} | ||
|
||
const formattedCurrency = formatForCurrency.uniqSymbol.template | ||
.replace('1', amount) | ||
.replace('$', formatForCurrency.uniqSymbol.grapheme); | ||
|
||
return formattedCurrency; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { LocalizeService } from '../../i18n/localize.service'; | ||
import { container } from 'tsyringe'; | ||
import { PipeTransform } from '../pipe-transform.interface'; | ||
import { localeValidator } from './locale.validator'; | ||
|
||
export class DecimalPipe implements PipeTransform { | ||
public transform( | ||
value: number | string, | ||
minIntegerDigits = 1, | ||
minFracDigits = 2, | ||
maxFracDigits = 2, | ||
locale = null | ||
): string { | ||
value = Number(value); | ||
|
||
if (isNaN(value)) { | ||
return ''; | ||
} | ||
|
||
const localizeService = container.resolve(LocalizeService); | ||
const formatLocale = localeValidator(locale ?? localizeService.language); | ||
return new Intl.NumberFormat(formatLocale, { | ||
minimumIntegerDigits: minIntegerDigits, | ||
minimumFractionDigits: minFracDigits, | ||
maximumFractionDigits: maxFracDigits, | ||
}).format(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Lang } from '../../i18n/lang.enum'; | ||
|
||
const specialLocaleMap = new Map<Lang, Lang>([ | ||
[Lang.ZH_HANS, Lang.CN], | ||
[Lang.ZH_HANT, Lang.CN], | ||
]); | ||
|
||
export const localeValidator = (locale: Lang): Lang => { | ||
if (specialLocaleMap.has(locale)) { | ||
return specialLocaleMap.get(locale)!; | ||
} | ||
|
||
return locale; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface PipeTransform { | ||
transform(value: unknown, ...args: unknown[]): unknown; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export const headlessCheckoutAppUrl = | ||
'https://secure.xsolla.com/headless-checkout'; | ||
export const headlessCheckoutAppUrl = 'http://localhost:4400'; | ||
export const cdnUrl = 'https://cdn3.xsolla.com'; |
Oops, something went wrong.