/**
  * Test creating an address object from a SDK physical address payload.
  * Should fill out the builder object and then create a data object
  * containing the payload data.
  */
 public function testTransferPhysicalAddressPayloadToAddress()
 {
     $payload = $this->romFactory->buildPayload('\\eBayEnterprise\\RetailOrderManagement\\Payload\\Address\\SuggestedAddress');
     $payload->setLines(implode("\n", $this->street))->setCity($this->city)->setMainDivision($this->regionCode)->setCountryCode($this->countryId)->setPostalCode($this->postcode);
     $this->regionHelper->expects($this->any())->method('loadRegion')->will($this->returnValue($this->directoryRegion));
     $this->addressData->expects($this->once())->method('setStreet')->with($this->identicalTo($this->street))->will($this->returnSelf());
     $this->addressData->expects($this->once())->method('setCity')->with($this->identicalTo($this->city))->will($this->returnSelf());
     $this->addressData->expects($this->once())->method('setCountryId')->with($this->identicalTo($this->countryId))->will($this->returnSelf());
     $this->addressData->expects($this->once())->method('setRegionName')->with($this->identicalTo($this->regionName))->will($this->returnSelf());
     $this->addressData->expects($this->once())->method('setRegionCode')->with($this->identicalTo($this->regionCode))->will($this->returnSelf());
     $this->addressData->expects($this->once())->method('setRegionId')->with($this->identicalTo($this->regionId))->will($this->returnSelf());
     $this->addressData->expects($this->once())->method('setPostcode')->with($this->identicalTo($this->postcode))->will($this->returnSelf());
     $this->sdkHelper->transferPhysicalAddressPayloadToAddress($payload, $this->addressData);
 }
 /**
  * @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());
 }
 /**
  * Make a new request via the SDK to validate the address.
  *
  * @param AddressInterface
  * @return IValidationResult
  */
 protected function makeRequestForAddress(AddressInterface $address)
 {
     try {
         /** @var \eBayEnterprise\RetailOrderManagement\Api\IBidirectionalApi */
         $api = $this->httpApiFactory->create($this->scopeConfig);
         /** @var \eBayEnterprise\RetailOrderManagement\Payload\Address\IValidationReply */
         $response = $api->setRequestBody($this->sdkHelper->prepareSdkRequest($api->getRequestBody(), $address, $this->scopeConfig))->send()->getResponseBody();
         // @TODO evaluate log level for each of these, some may be more severe -
         //       UnsupportedOperation and UnsupportedHttpAction - or less severe
         //       - maybe NetworkError.
     } catch (NetworkError $e) {
         $this->logger->warning($e);
         return $this->exceptionResultFactory->create(['originalAddress' => $address, 'failureException' => $e]);
     } catch (UnsupportedOperation $e) {
         $this->logger->error($e);
         return $this->exceptionResultFactory->create(['originalAddress' => $address, 'failureException' => $e]);
     } catch (UnsupportedHttpAction $e) {
         $this->logger->error($e);
         return $this->exceptionResultFactory->create(['originalAddress' => $address, 'failureException' => $e]);
     }
     $result = $this->resultFactory->create(['replyPayload' => $response, 'originalAddress' => $address]);
     $this->session->setResultForAddress($address, $result)->setCurrentResult($result);
     return $result;
 }