/**
  * @param SdkHelper
  * @param IValidationReply
  * @param AddressInterfaceFactory
  * @param AddressInterface
  */
 public function __construct(SdkHelper $sdkHelper, IValidationReply $replyPayload, AddressInterfaceFactory $addressFactory, AddressInterface $originalAddress)
 {
     $this->id = uniqid('AVR-');
     $this->originalAddress = $originalAddress;
     // Extract data from the payload so the payload instance doesn't need
     // to be stored (may not be session safe and this object may need
     // to go into the session).
     $this->isValid = $replyPayload->isValid();
     $this->isAcceptable = $replyPayload->isAcceptable();
     $this->resultCode = $replyPayload->getResultCode();
     $this->errorLocations = [];
     foreach ($replyPayload->getErrorLocations() as $errorLocation) {
         $this->errorLocations[] = $errorLocation->getFieldName();
     }
     $this->hasSuggestions = $replyPayload->hasSuggestions();
     $this->suggestions = [];
     foreach ($replyPayload->getSuggestedAddresses() as $suggestedAddress) {
         $this->suggestions[uniqid('AVS-')] = $sdkHelper->transferPhysicalAddressPayloadToAddress($suggestedAddress, $addressFactory->create());
     }
     $this->suggestionCount = $replyPayload->getResultSuggestionCount();
     $this->correctedAddress = $sdkHelper->transferPhysicalAddressPayloadToAddress($replyPayload, $addressFactory->create());
 }
 /**
  * Use the response to select the address to be used as the valid address.
  * If there is not a single, valid address, will set the value to null.
  * This method must be used after extracting all other address data from
  * the response in order to be able to properly select an address.
  *
  * @return self
  */
 protected function extractValidAddress(IValidationReply $response)
 {
     $validAddress = null;
     if ($response->isAcceptable()) {
         $validAddress = $response->getResultSuggestionCount() === 1 ? $this->getAddressSuggestions()[0] : $this->getOriginalAddress();
     }
     return $this->setData('valid_address', $validAddress);
 }