public function AddressValidator::process in Drupal Commerce Connector for AvaTax 8
Provides address validation.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request.
Return value
\Symfony\Component\HttpFoundation\JsonResponse The response.
1 string reference to 'AddressValidator::process'
File
- src/
Controller/ AddressValidator.php, line 76
Class
- AddressValidator
- Address validator controller.
Namespace
Drupal\commerce_avatax\ControllerCode
public function process(Request $request) {
$content = $request
->getContent();
if (empty($content)) {
return new JsonResponse([
'valid' => FALSE,
'output' => NULL,
], 400);
}
$data = $this->avataxLib
->validateAddress(Json::decode($content));
// If we have suggestion show it.
if (!empty($data['suggestion'])) {
$data['output'] = $this
->formatSuggestedAddress($data['original'], $data['suggestion'], $data['fields']);
$data['payload'] = base64_encode(Json::encode($data['suggestion']));
}
elseif (!empty($data['original']) && !$data['valid']) {
$data['output'] = $this
->formatSuggestedAddress($data['original']);
}
return new JsonResponse($data);
}