@automattic/wpcom-checkout
Version:
Functions and components used by WordPress.com checkout.
42 lines • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCountryTaxRequirements = getCountryTaxRequirements;
/**
* Returns tax requirements for the specified country code.
*
* NOTE: Will return an empty object if the countries list is empty or if the country
* code is not in the list! Always check that the countries list has loaded
* before calling this.
*/
function getCountryTaxRequirements(countries, countryCode) {
if (!countryCode) {
return {};
}
if (!countries?.length) {
// eslint-disable-next-line no-console
console.error('Error: getCountryVatRequirements was called without a countries list. This will result in incorrect data!');
return {};
}
const countryListItem = countries.find((country) => country.code === countryCode.toUpperCase() ||
(country.vat_supported && country.tax_country_codes.includes(countryCode.toUpperCase())));
if (!countryListItem) {
// eslint-disable-next-line no-console
console.warn(`Warning: getCountryVatRequirements could not find the country "${countryCode}"!`);
return {};
}
const requirements = {};
if (countryListItem.tax_needs_city) {
requirements.city = true;
}
if (countryListItem.tax_needs_subdivision) {
requirements.subdivision = true;
}
if (countryListItem.tax_needs_organization) {
requirements.organization = true;
}
if (countryListItem.tax_needs_address) {
requirements.address = true;
}
return requirements;
}
//# sourceMappingURL=get-country-tax-requirements.js.map