Get States by Country
The EBANX Get States by Country feature allows you to dynamically retrieve a list of states or provinces for a given country, simplifying the checkout process for your customers. This feature ensures that the list of states is always up-to-date and tailored to the specific country the customer is selecting, making your forms more intuitive and localized.
Features
- Improved user experience - By automatically populating the state dropdown based on the selected country, you reduce errors and improve the accuracy of the data your customers provide, leading to fewer failed transactions or address mismatches.
- Seamless integration - The API can be easily integrated into your existing checkout or registration forms, ensuring that the correct state or province list is shown for each country without requiring manual updates.
- Localized checkout - Supporting country-specific state/province listings makes the checkout process feel more localized, which can increase trust and conversion rates among international customers.
- Real-time data - Since the data is fetched directly from the EBANX API, you always have the most current state/province information for each supported country, ensuring consistency and accuracy in your forms.
Requirements
- Credentials - Ensure you have your EBANX.js Public Integration Key, which can be found in your EBANX Dashboard. If you don't have it, complete the Merchant Signup Form.
Instructions
To get the list of states for a given country using EBANX.js, follow the steps below:
Install EBANX.js
Insert script tag
Add the following to your HTML.
<script src="https://ebanx-js.ebanx.com/latest/dist/ebanx.min.js"></script>Initialize
Include the following function in your JavaScript.
EBANX.init({
publicIntegrationKey: '{your_public_integration_key}',
country: '{country_code_here}',
mode: 'test',
});Initialization parameters
Field Description publicIntegrationKeyMerchant's public integration key countryCustomer country code.
2-digit String
International standard - ISO 3166-1 alpha-2modetestorproductionCreate object using country code
Create an object with the country code.
const options = {
country: 'br',
};The available countries are:
Country Country Code Argentina arBrazil brChile clCosta Rica crDominican Republic doEgypt egGuatemala gtIndia inKenya keMexico mxPanama paPeru peParaguay pySouth Africa zaEl Salvador svUruguay uyRequest list of states
Call the
EBANX.referenceData.statesfunction using the object created in the previous step.EBANX.referenceData
.states(options)
.get()
.then((statesList) => {
// use statesList to fullfil payment
})
.catch((error) => {
// handle errors
});Response
The following object is returned as a Promise.
Example -> Brazil states list
// statesList
{
"quantity": 27,
"stateList": [
{
"stateCode": "AC",
"stateName": "Acre"
},
{
"stateCode": "AL",
"stateName": "Alagoas"
},
{
"stateCode": "AP",
"stateName": "Amapá"
},
{
"stateCode": "AM",
"stateName": "Amazonas"
},
{
"stateCode": "BA",
"stateName": "Bahia"
},
{
"stateCode": "CE",
"stateName": "Ceará"
},
{
"stateCode": "DF",
"stateName": "Distrito Federal"
},
{
"stateCode": "ES",
"stateName": "Espírito Santo"
},
{
"stateCode": "GO",
"stateName": "Goiás"
},
{
"stateCode": "MA",
"stateName": "Maranhão"
},
{
"stateCode": "MT",
"stateName": "Mato Grosso"
},
{
"stateCode": "MS",
"stateName": "Mato Grosso do Sul"
},
{
"stateCode": "MG",
"stateName": "Minas Gerais"
},
{
"stateCode": "PA",
"stateName": "Pará"
},
{
"stateCode": "PB",
"stateName": "Paraíba"
},
{
"stateCode": "PR",
"stateName": "Paraná"
},
{
"stateCode": "PE",
"stateName": "Pernambuco"
},
{
"stateCode": "PI",
"stateName": "Piauí"
},
{
"stateCode": "RJ",
"stateName": "Rio de Janeiro"
},
{
"stateCode": "RN",
"stateName": "Rio Grande do Norte"
},
{
"stateCode": "RS",
"stateName": "Rio Grande do Sul"
},
{
"stateCode": "RO",
"stateName": "Rondônia"
},
{
"stateCode": "RR",
"stateName": "Roraima"
},
{
"stateCode": "SC",
"stateName": "Santa Catarina"
},
{
"stateCode": "SP",
"stateName": "São Paulo"
},
{
"stateCode": "SE",
"stateName": "Sergipe"
},
{
"stateCode": "TO",
"stateName": "Tocantins"
}
]
}Congratulations!
You have succesfully integrated the Get states by country feature using EBANX.js.
Still need help?
We hope this article was helpful. If you still have questions, you can explore the following options:
- Merchant support: Contact our support team at sales.engineering@ebanx.com for assistance.
- Not a partner yet? Please complete the Merchant Signup Form, and our commercial team will reach out to you.