// Set the username and password. define("USERNAME", "ws_eval_3371_ext"); define("PASSWORD", "Younique123"); // URL of local isntance of QASOnDemand.txt. This is pointing to the "qas" folder. $WSDL = dirname(__FILE__) . DIRECTORY_SEPARATOR . "qas" . DIRECTORY_SEPARATOR . "QASOnDemand.txt"; // Get search information $action = isset($_REQUEST['action']) ? rawurldecode($_REQUEST['action']) : ""; $addLayout = isset($_REQUEST['addlayout']) ? rawurldecode($_REQUEST['addlayout']) : ""; $country = isset($_REQUEST['country']) ? rawurldecode($_REQUEST['country']) : ""; $searchstring = isset($_REQUEST['searchstring']) ? rawurldecode($_REQUEST['searchstring']) : ""; $moniker = isset($_REQUEST['moniker']) ? rawurldecode($_REQUEST['moniker']) : ""; $refineText = isset($_REQUEST['refinetext']) ? rawurldecode($_REQUEST['refinetext']) : ""; // Instantiate the client. try { $qAddress = new QuickAddress($WSDL); $qAddress->setEngineType(QAS_VERIFICATION_ENGINE); $qAddress->setFlatten(true); // Perform action based on request. if ($action == "search") { $result = $qAddress->search($country, explode(",", $searchstring), QAS_DEFAULT_PROMPT, $addLayout); ?> <verifylevel><?php echo $result->sVerifyLevel; ?> </verifylevel> <?php if ($result->sVerifyLevel == "Verified" || $result->sVerifyLevel == "InteractionRequired") { ?> <dpvstatus><?php echo $result->address->sDpvStatus; ?>
/** * Validate an address with QAS * @param array $postData * @param \Foundation\Form $countryForm * @return \Foundation\Form\Input | false */ protected function validateAddress(array $postData, \Foundation\Form $countryForm) { $countryName = $countryForm->getElementByName('countryName')->getValue(); $country = $countryForm->getElementByName('country')->getValue(); $countriesToValidate = explode(',', $this->_applicationPage->getPage()->getVar('validatedCountries')); //Create the QuickAddress Object and set the engine and picklist type $qas = new \QuickAddress($this->_applicationPage->getPage()->getVar('wsdlAddress')); $qas->setEngineType(QAS_VERIFICATION_ENGINE); $qas->setFlatten(true); $qasCountryCode = $this->getQASCodeForCountry($countryName); $qasLayout = "Database layout"; switch ($postData['type']) { case 'confirmAddress': if ($postData['addressChoice'] == 'validated') { return unserialize(base64_decode($postData['validatedInput'])); } else { if ($postData['addressChoice'] == 'original') { return unserialize(base64_decode($postData['originalInput'])); } else { $input = unserialize(base64_decode($postData['originalInput'])); foreach ($countryForm->getElements() as $formElement) { if ($input->checkIsSet($formElement->getName())) { $formElement->setValue($input->get($formElement->getName())); } } $this->_form = $countryForm; return false; } } break; case 'validate': if (!($input = $countryForm->processInput($postData))) { $this->_form = $countryForm; return false; } //Check to see if this is the second time the user has input this address, //if it is then just use that as the address unverified $sameUserInput = false; if ($str = $input->get('originalInput')) { $str = base64_decode($str); $originalInput = unserialize($str); $sameUserInput = true; foreach (array('address1', 'address2', 'address3', 'city', 'state', 'postalCode', 'country') as $name) { if ($originalInput->get($name) != $input->get($name)) { $sameUserInput = false; break; } } } $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_ADDRESS1)->getId(), $input->get('address1')); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_ADDRESS2)->getId(), $input->get('address2')); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_ADDRESS3)->getId(), $input->get('address3')); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_CITY)->getId(), $input->get('city')); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_STATE)->getId(), $input->get('state')); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_POSTALCODE)->getId(), $input->get('postalCode')); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_COUNTRY)->getId(), $countryName); if ($sameUserInput or !in_array($this->getQASCodeForCountry($countryName), $countriesToValidate) or !$qas->canSearch($qasCountryCode, $qasLayout)->IsOk) { return $input; } $search = array(); $search[0] = $input->get('address1'); $search[1] = $input->get('address2'); $search[2] = $input->get('city'); $search[3] = $input->get('state'); $search[4] = $input->get('postalCode'); //Perform the search itself $result = $qas->search($qasCountryCode, $search, QAS_DEFAULT_PROMPT, $qasLayout); switch ($result->sVerifyLevel) { case 'Verified': case 'InteractionRequired': $originalInput = clone $input; $arr = $result->address->atAddressLines; $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_ADDRESS1)->getId(), $arr[0]->Line); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_ADDRESS2)->getId(), $arr[1]->Line); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_ADDRESS3)->getId(), $input->get('address3')); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_CITY)->getId(), $arr[3]->Line); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_STATE)->getId(), $arr[4]->Line); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_POSTALCODE)->getId(), $arr[5]->Line); $input->set('el' . $this->_applicationPage->getPage()->getElementByFixedId(self::FID_COUNTRY)->getId(), $countryName); $validatedInput = clone $input; $confirmationForm = new \Foundation\Form(); $confirmationForm->setAction($countryForm->getAction()); $confirmationForm->setCSRFToken($this->_controller->getCSRFToken()); $field = $confirmationForm->newField(); $field->setLegend('Confirm Address'); $element = $field->newElement('RadioList', 'addressChoice'); $element->setLabel('Confirm Address'); $element->newItem('validated', 'Use Our Sugested Address <br />' . $this->formatAddressFromInput($validatedInput)); $element->newItem('original', 'Use Address as Entered<br />' . $this->formatAddressFromInput($originalInput)); $element->newItem('edit', 'Edit the Address you Entered'); $element->setValue('validated'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $confirmationForm->newHiddenElement('type', 'confirmAddress'); $confirmationForm->newHiddenElement('countryName', $countryName); $confirmationForm->newHiddenElement('country', $country); $confirmationForm->newHiddenElement('originalInput', base64_encode(serialize($originalInput))); $confirmationForm->newHiddenElement('validatedInput', base64_encode(serialize($validatedInput))); $confirmationForm->newButton('submit', 'Save'); $this->_form = $confirmationForm; return false; break; case 'Multiple': $this->_controller->addMessage('error', 'We were unable to validate your address.'); $this->_controller->setVar('confirm', true); $countryForm->getElementByName('submit')->setValue('Confirm Address as Entered'); $this->_controller->setVar('originalInput', base64_encode(serialize($input))); $countryForm->newHiddenElement('originalInput', base64_encode(serialize($input))); $this->_controller->setVar('picklist', $result->picklist); $this->_form = $countryForm; break; case 'StreetPartial': case 'PremisesPartial': $this->_controller->addMessage('error', 'We were unable to validate your address. If you are sure this address is correct then click the "Confirm Address as Entered" button.'); $countryForm->getElementByName('address1')->addMessage('Your address is incomplete'); $countryForm->getElementByName('address2')->addMessage('Your address is incomplete'); $countryForm->getElementByName('submit')->setValue('Confirm Address as Entered'); $countryForm->newHiddenElement('originalInput', base64_encode(serialize($input))); $this->_form = $countryForm; break; case 'None': $this->_controller->addMessage('error', 'We were unable to validate your address.'); $countryForm->getElementByName('submit')->setValue('Confirm Address as Entered'); $countryForm->newHiddenElement('originalInput', base64_encode(serialize($input))); $this->_form = $countryForm; break; default: throw new \Jazzee\Exception("{$result->sVerifyLevel} is not a known QAS address verification type.", E_USER_ERROR, 'There was a problem verifying your address. Please try entering it again.'); } break; } return false; }