UNPKG

@stackend/api

Version:

JS bindings to api.stackend.com

195 lines 6.08 kB
import { Thunk, XcapJsonResult } from '../api'; import { ShopState } from './shopReducer'; import { Cart, Checkout, MoneyV2, Product, ProductVariant, SlimProduct } from './index'; import { Community } from '../stackend'; export declare enum TradeRegion { /** Domestic trade */ NATIONAL = "national", /** Trade within EU, etc */ REGIONAL = "regional", /** Trade with the rest, etc */ WORLDWIDE = "worldwide" } export declare enum CustomerType { CONSUMER = "b2c", BUSINESS = "b2b" } /** * Format 1.25 as 25% * @param vatMultiplier */ export declare function formatVatPercentage(vatMultiplier: number): string; /** * Convert a vat multiplier to a percentage * @param vatMultiplier */ export declare function vatMultiplierToPercent(vatMultiplier: number): number; /** * Convert a percentage (25%) to a vat multiplier (1.25) * @param percent */ export declare function percentToVatMultiplier(percent: number): number; export declare enum VatType { STANDARD = "standardRate", REDUCED = "reducedRate", REDUCED_ALT = "reducedRateAlt", SUPER_REDUCED = "superReducedRate", PARKING = "parkingRate" } /** National vat rates in percent or null if not applicable */ export interface NationalVatRates { /** ISO country code */ countryCode: string; country: string; /** The local name of the VAT */ vatName: string; vatAbbreviatedName: string; standardRate: number | null; reducedRate: number | null; reducedRateAlt: number | null; superReducedRate: number | null; parkingRate: number | null; } export interface GetVatsResult extends XcapJsonResult { shopCountryCode: string; vats: NationalVatRates; } /** * Get VATs for a country. Will try to use the stacks default country if not specified. * @param shopCountryCode * @returns {Thunk<XcapJsonResult>} */ export declare function getVats({ shopCountryCode }: { shopCountryCode?: string; }): Thunk<Promise<GetVatsResult>>; export interface ListVatsResult extends XcapJsonResult { vats: Array<NationalVatRates>; } /** * Get all supported VATs. * @returns {Thunk<XcapJsonResult>} */ export declare function listVats(): Thunk<Promise<ListVatsResult>>; export interface VatCountry { countryCode: string; name: string; } export interface ListCountriesResult extends XcapJsonResult { countries: Array<VatCountry>; } /** * Get all countries. * @returns {Thunk<ListCountriesResult>} */ export declare function listCountries(): Thunk<Promise<ListCountriesResult>>; export interface GetTradeRegionResult extends XcapJsonResult { tradeRegion: TradeRegion; customerCountryCode: string; shopCountryCode: string; } /** * Get the trade region * @returns {Thunk<XcapJsonResult>} */ export declare function getTradeRegion({ customerCountryCode, shopCountryCode }: { customerCountryCode: string; shopCountryCode?: string; }): Thunk<Promise<GetTradeRegionResult>>; /** * Should VATs be used? * @param shopState * @param customerType * @param tradeRegion */ export declare function useVATS({ shopState, customerType, tradeRegion }: { shopState: ShopState; customerType?: CustomerType; tradeRegion?: TradeRegion; }): boolean; /** * Get the price including vat. * Supply the price, a product variant or get the minVariantPrice of the product. * @param shopState * @param product * @param productVariant * @param customerType * @param tradeRegion * @param price Optional price. Overrides the product and product variant price if supplied. * @param quantity Optional quantity, defaults to 1 */ export declare function getPriceIncludingVAT({ shopState, product, productVariant, customerType, tradeRegion, price, quantity }: { shopState: ShopState; product: SlimProduct | Product; productVariant?: ProductVariant | null; customerType?: CustomerType; tradeRegion?: TradeRegion; price?: MoneyV2 | null; quantity?: number; }): MoneyV2; /** * Apply VAT to the price * @param shopState * @param vatType * @param price * @param quantity */ export declare function applyVat(shopState: ShopState, vatType: VatType, price: MoneyV2, quantity?: number): MoneyV2; export declare function multiplyPrice(price: MoneyV2, factor: number): MoneyV2; /** * Get the vat type for a product * @param shopState * @param product */ export declare function getVATType(shopState: ShopState, product: SlimProduct): VatType; /** * Get the total price for a checkout * @param shopState * @param checkout * @param customerType * @param tradeRegion */ export declare function getTotalPriceIncludingVAT({ shopState, checkout, customerType, tradeRegion }: { shopState: ShopState; checkout: Checkout; customerType?: CustomerType; tradeRegion?: TradeRegion; }): MoneyV2; /** * Get the total price for a cart * @param shopState * @param cart * @param customerType * @param tradeRegion */ export declare function getCartTotalPriceIncludingVAT({ shopState, cart, customerType, tradeRegion }: { shopState: ShopState; cart: Cart; customerType?: CustomerType; tradeRegion?: TradeRegion; }): MoneyV2; /** * Get the shops country code, fall back to the locale or 'EN' if not set. */ export declare function getShopCountryCode(): Thunk<Promise<string>>; /** Customer info stored in local storage */ export interface CustomerInfo { customerCountryCode: string; tradeRegion: TradeRegion; customerType: CustomerType; } /** * Set the customers country code and update trade region accordingly * @param customerCountryCode */ export declare function setCustomerCountryCode(customerCountryCode: string): Thunk<Promise<void>>; /** * Set the type of customer * @param customerType */ export declare function setCustomerType(customerType: CustomerType): Thunk<void>; /** * Get customer info from shop.vats, with fallback to local storage */ export declare function getCustomerInfo(): Thunk<CustomerInfo | null>; export declare function getLocalStorageCustomerInfoKey(community: Community): string; //# sourceMappingURL=vat.d.ts.map