@malga-checkout-full/core
Version:
Core components for Malga Checkout Full
30 lines (29 loc) • 853 B
JavaScript
import axios from 'axios';
export class MalgaCheckoutFullIdentificationService {
formatZipCodeData(zipCodeResponse) {
const zipCodeFormatted = {
street: zipCodeResponse.logradouro,
complement: zipCodeResponse.complemento,
district: zipCodeResponse.bairro,
state: zipCodeResponse.uf,
city: zipCodeResponse.localidade,
};
return zipCodeFormatted;
}
async getInformationsAboutZipCode(zipCode) {
try {
const response = await axios.get(`https://viacep.com.br/ws/${zipCode}/json`);
const zipCodeFormatted = Object.assign(Object.assign({}, this.formatZipCodeData(response.data)), { country: 'BR' });
return zipCodeFormatted;
}
catch (error) {
return {
street: '',
complement: '',
district: '',
state: '',
city: '',
};
}
}
}