/**
  * Test converting a customer address object to a data address results in
  * a new data address object with matching address data.
  */
 public function testConvertCustomerAddress()
 {
     // When saving an address, new addresses may not have full region data.
     $regionData = ['region_id' => 51];
     $region = $this->objectManager->getObject('\\Magento\\Customer\\Model\\Data\\Region', ['data' => $regionData]);
     // Add the region model to the customer address data.
     $addressData = $this->customerAddressData;
     $addressData['region'] = $region;
     $customerAddress = $this->objectManager->getObject('\\Magento\\Customer\\Model\\Data\\Address', ['data' => $addressData]);
     // The region factory should be used to create a new directory region
     // model. The model should be loaded using the region id of the address
     // to get the region data needed, e.g. the region code.
     $this->regionHelper->expects($this->once())->method('loadRegion')->will($this->returnValue($this->directoryRegion));
     $this->addressFactory->expects($this->once())->method('create')->with($this->equalTo(['data' => $this->validationAddressData]))->will($this->returnValue($this->addressInterface));
     $this->converter->convertCustomerAddressToDataAddress($customerAddress);
 }
 /**
  * Plugin method to perform an address validation service request. Validate
  * the address and, if acceptable by the address validation service, return
  * the address to be passed through to be saved. If invalid, throw an
  * InputExepction to prevent the address from being saved.
  *
  * @param AddressRepositoryInterface $addressRepository Object the method is being invoked upon - $this in the wrapped method
  * @param AddressInterface
  * @return array Array of args to be passed through to original method call, e.g. array container the address being validated
  * @throws InputException If the address is not valid
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function beforeSave(AddressRepositoryInterface $addressRepository, AddressInterface $address)
 {
     $this->logger->debug('Validating customer address');
     $validationResult = $this->addressValidation->validate($this->addressConverter->convertCustomerAddressToDataAddress($address));
     $this->logger->debug(sprintf('Received validation results: Result Code %s, Valid %d, Acceptable %d', $validationResult->getResultCode(), $validationResult->isValid(), $validationResult->isAcceptable()));
     // Allow the address through if it is acceptable - return arguments to
     // continue through the plug-in chain as array of arguments to original
     // method.
     if ($validationResult->isAcceptable()) {
         // If the address is acceptable, apply any difinitive corrections or
         // normalizations to the address.
         return [$this->addressConverter->transferDataAddressToCustomerAddress($address, $validationResult->getCorrectedAddress())];
     }
     $this->session->setOriginalCustomerAddress($address);
     // Prevent the address save. Exception message will be the text of the
     // message displayed to the user.
     throw new InputException($this->phraseFactory->create(['text' => $validationResult->getFailureReason()]));
 }
 public function confirmSelection(CustomerAddressInterface $originalAddress, AddressInterface $selectedAddress)
 {
     $address = $this->addressConverter->transferDataAddressToCustomerAddress($originalAddress, $selectedAddress);
     $this->setResultForAddress($selectedAddress, $this->confirmedResultFactory->create(['originalAddress' => $selectedAddress]));
     return $address;
 }
 /**
  * Get validation results for a customer address.
  *
  * @param AddressInterface
  * @return \EbayEnterprise\Address\Model\Validation\Result
  */
 protected function getResultForAddress(AddressInterface $customerAddress)
 {
     return $this->addressSession->getResultForAddress($this->addressConverter->convertCustomerAddressToDataAddress($this->customerAddress));
 }