Skip to content

Instantly share code, notes, and snippets.

@irineujunior
Created September 27, 2019 14:10
Show Gist options
  • Save irineujunior/76d11fcd955b052fc987d61a51a0b64f to your computer and use it in GitHub Desktop.
Save irineujunior/76d11fcd955b052fc987d61a51a0b64f to your computer and use it in GitHub Desktop.
// /app/code/community/PayU/API/Model/WebServiceOrder.php
...
$data->transaction->order->buyer->shippingAddress->state = $this->_sanitizeRegion($this->shippingAddress['region']);
...
$data->transaction->payer->billingAddress->state = $this->_sanitizeRegion($this->billingAddress['region']);
...
private function _sanitizeRegion($region)
{
$regions = [
'Acre' => 'AC',
'Alagoas' => 'AL',
'Amapá' => 'AP',
'Amazonas' => 'AM',
'Bahia' => 'BA',
'Ceará' => 'CE',
'Distrito Federal' => 'DF',
'Espírito Santo' => 'ES',
'Goiás' => 'GO',
'Maranhão' => 'MA',
'Mato Grosso' => 'MT',
'Mato Grosso do Sul' => 'MS',
'Minas Gerais' => 'MG',
'Pará' => 'PA',
'Paraíba' => 'PB',
'Paraná' => 'PR',
'Pernambuco' => 'PE',
'Piauí' => 'PI',
'Rio de Janeiro' => 'RJ',
'Rio Grande do Norte' => 'RN',
'Rio Grande do Sul' => 'RS',
'Rondônia' => 'RO',
'Roraima' => 'RR',
'Santa Catarina' => 'SC',
'São Paulo' => 'SP',
'Sergipe' => 'SE',
'Tocantins' => 'TO'
];
if (isset($regions[$region])) {
return $regions[$region];
}
return $region;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment