function testLatLongValidation() { $address = new Address(); $address->setLine1("900 Winslow Way"); $address->setLine2("Ste 130"); $address->setCity("Bainbridge Island"); $address->setRegion("WA"); $address->setPostalCode("98110"); $address->setLongitude("-122.510359"); $address->setLatitude("47.624972"); $validateRequest = new ValidateRequest(); $validateRequest->setAddress($address); $validateRequest->setTextCase(TextCase::$Upper); //added for 4.13 changes $validateRequest->setCoordinates(true); //Sets Profile name from Configuration File to "Jaas" //this will force it to Jaas (PostLocate) $this->client = new AddressServiceSoap("JaasDevelopement"); //validate the Request $result = $this->client->validate($validateRequest); //Re-Assigning to the original Profile $this->client = new AddressServiceSoap("Development"); $this->assertEqual($result->getResultCode(), SeverityLevel::$Success); $validAddresses = $result->getValidAddresses(); $this->assertEqual(1, count($validAddresses)); $validAddresses = $result->getValidAddresses(); if (count($validAddresses) != 1) { echo "Unexpected number of addresses returned. Expected one address."; } else { $validAddress = $validAddresses[0]; $this->assertEqual(strtoupper($address->getLine1()) . " E " . strtoupper($address->getLine2()), $validAddress->getLine1()); $this->assertEqual("", $validAddress->getLine2()); $this->assertEqual(strtoupper($address->getCity()), $validAddress->getCity()); $this->assertEqual(strtoupper($address->getRegion()), $validAddress->getRegion()); $this->assertEqual($address->getPostalCode() . "-2450", $validAddress->getPostalCode()); $this->assertEqual("H", $validAddress->getAddressType()); $this->assertEqual("C051", $validAddress->getCarrierRoute()); //Ticket 21203: Modified Fips Code value for jaas enabled account. //$this->assertEqual("5303500000", $validAddress->getFipsCode()); $this->assertEqual("5303503736", $validAddress->getFipsCode()); $this->assertEqual("KITSAP", $validAddress->getCounty()); $this->assertEqual(strtoupper($address->getCity()) . " " . strtoupper($address->getRegion()) . " " . $address->getPostalCode() . "-2450", $validAddress->getLine4()); $this->assertEqual("981102450307", $validAddress->getPostNet()); // Added 4.13 changes for the Lat Long // Update to check for ZIP+4 precision // Zip+4 precision coordinates if (strlen($validAddress->getLatitude()) > 7) { echo "ZIP+4 precision coordinates received"; $this->assertEqual($address->getLatitude(), $validAddress->getLatitude()); $this->assertEqual($address->getLongitude(), $validAddress->getLongitude()); } else { echo "ZIP5 precision coordinates received"; $this->assertEqual(substr($validAddress->getLatitude(), 0, 4), substr($address->getLatitude(), 0, 4), "Expected Latitude to start with '47.64'"); $this->assertEqual(substr($validAddress->getLongitude(), 0, 6), substr($address->getLongitude(), 0, 6), "Expected Longitude to start with '-122.53'"); } } }
/** * Sets attributes from the Mage address on the AvaTax Request address. * * @return $this */ protected function _convertRequestAddress() { if (!$this->_requestAddress) { $this->_requestAddress = new Address(); } $this->_requestAddress->setLine1($this->_mageAddress->getStreet(1)); $this->_requestAddress->setLine2($this->_mageAddress->getStreet(2)); $this->_requestAddress->setCity($this->_mageAddress->getCity()); $this->_requestAddress->setRegion($this->_mageAddress->getRegionCode()); $this->_requestAddress->setCountry($this->_mageAddress->getCountry()); $this->_requestAddress->setPostalCode($this->_mageAddress->getPostcode()); return $this; }
public function buildMerchants($xml) { $merchants = new Merchants(); $merchants->setPageOffset((string) $xml->PageOffset); $merchants->setTotalCount((string) $xml->TotalCount); // merchant $merchantArray = array(); foreach ($xml->Merchant as $merchant) { $tmpMerchant = new Merchant(); $tmpMerchant->setId((string) $merchant->Id); $tmpMerchant->setName((string) $merchant->Name); $tmpMerchant->setWebsiteUrl((string) $merchant->WebsiteUrl); $tmpMerchant->setPhoneNumber((string) $merchant->PhoneNumber); $tmpMerchant->setCategory((string) $merchant->Category); $tmpLocation = new Location(); $location = $merchant->Location; $tmpLocation->setName((string) $location->Name); $tmpLocation->setDistance((string) $location->Distance); $tmpLocation->setDistanceUnit((string) $location->DistanceUnit); $tmpAddress = new Address(); $address = $location->Address; $tmpAddress->setLine1((string) $address->Line1); $tmpAddress->setLine2((string) $address->Line2); $tmpAddress->setCity((string) $address->City); $tmpAddress->setPostalCode((string) $address->PostCode); $tmpCountry = new Country(); $tmpCountry->setName((string) $address->Country->Name); $tmpCountry->setCode((string) $address->Country->Code); $tmpCountrySubdivision = new CountrySubdivision(); $tmpCountrySubdivision->setName((string) $address->CountrySubdivision->Name); $tmpCountrySubdivision->setCode((string) $address->CountrySubdivision->Code); $tmpAddress->setCountry($tmpCountry); $tmpAddress->setCountrySubdivision($tmpCountrySubdivision); $tmpPoint = new Point(); $point = $location->Point; $tmpPoint->setLatitude((string) $point->Latitude); $tmpPoint->setLongitude((string) $point->Longitude); // ACCEPTANCE FRAMEWORK NEEDS LOOKED AT <RETURN XML AND DOC DOES NOT HAVE ALL VALUES> //$tmpAcceptance = new Acceptance(); //$acceptance = $merchant->Acceptance; // FEATURES FRAMEWORK NEEDS LOOKED AT <RETURN XML AND DOC DOES NOT HAVE ALL VALUES> //$tmpFeatures = new Features(); //$features = $merchant->Features; $tmpLocation->setPoint($tmpPoint); $tmpLocation->setAddress($tmpAddress); $tmpMerchant->setLocation($tmpLocation); array_push($merchantArray, $tmpMerchant); } $merchants->setMerchant($merchantArray); return $merchants; }
public function vault_add_creditcard($paydata) { $status = ''; $result = ''; $o_bcpc = new BaseCommerceClient(RENTSQUARE_MERCH_USER, RENTSQUARE_MERCH_PASS, RENTSQUARE_MERCH_KEY); $o_bcpc->setSandbox(BC_SANDBOXVALUE); $o_bc = new BankCard(); $o_bc->setExpirationMonth($paydata['expire_dt_month']); $o_bc->setExpirationYear($paydata['expire_dt_year']); $o_bc->setName($paydata['first_name'] . " " . $paydata['last_name']); $o_bc->setNumber($paydata['card_number']); $o_billing_address = new Address(Address::$XS_ADDRESS_NAME_BILLING); $o_billing_address->setLine1($paydata['billing_address1']); if (!empty($paydata['billing_address2'])) { $o_billing_address->setLine2($paydata['billing_address2']); } else { $o_billing_address->setLine2(" "); } $o_billing_address->setCity($paydata['billing_city']); if (!empty($paydata['billing_state_id'])) { $States = new State(); $billing_state = $States->findById($paydata['billing_state_id']); $billing_state = $billing_state['State']['abbr']; } $o_billing_address->setState($billing_state); $o_billing_address->setZipcode($paydata['billing_zip']); $o_billing_address->setCountry("USA"); $o_bc->setBillingAddress($o_billing_address); /* echo "<pre>"; print_r($o_bc); echo "</pre>"; exit; */ $o_bc = $o_bcpc->addBankCard($o_bc); $status = $o_bc->getStatus(); if ($status == BankCard::$XS_BC_STATUS_FAILED) { // Fail $status = 0; $result = $o_bc->getMessages(); } else { if ($status == BankCard::$XS_BC_STATUS_ACTIVE) { // Success $status = 1; $result = $o_bc->getToken(); } } return array($status, $result); }
public function buildAtms($xml) { $atms = new Atms(); $atms->setPageOffset($xml->PageOffset); $atms->setTotalCount($xml->TotalCount); $atmArray = array(); foreach ($xml->Atm as $atm) { $tmpAtm = new Atm(); $tmpAtm->setHandicapAccessible((string) $atm->HandicapAccessible); $tmpAtm->setCamera((string) $atm->Camera); $tmpAtm->setAvailability((string) $atm->Availability); $tmpAtm->setAccessFees((string) $atm->AccessFees); $tmpAtm->setOwner((string) $atm->Owner); $tmpAtm->setSharedDeposit((string) $atm->SharedDeposit); $tmpAtm->setSurchargeFreeAlliance((string) $atm->SurchargeFreeAlliance); $tmpAtm->setSponsor((string) $atm->Sponsor); $tmpAtm->setSupportEMV((string) $atm->SupportEMV); $tmpAtm->setSurchargeFreeAllianceNetwork((string) $atm->SurchargeFreeAllianceNetwork); $tmpLocation = new Location(); $location = $atm->Location; $tmpLocation->setName((string) $location->Name); $tmpLocation->setDistance((string) $location->Distance); $tmpLocation->setDistanceUnit((string) $location->DistanceUnit); $tmpAddress = new Address(); $address = $location->Address; $tmpAddress->setLine1((string) $address->Line1); $tmpAddress->setLine2((string) $address->Line2); $tmpAddress->setCity((string) $address->City); $tmpAddress->setPostalCode((string) $address->PostCode); $tmpCountry = new Country(); $tmpCountry->setName((string) $address->Country->Name); $tmpCountry->setCode((string) $address->Country->Code); $tmpCountrySubdivision = new CountrySubdivision(); $tmpCountrySubdivision->setName((string) $address->CountrySubdivision->Name); $tmpCountrySubdivision->setCode((string) $address->CountrySubdivision->Code); $tmpAddress->setCountry($tmpCountry); $tmpAddress->setCountrySubdivision($tmpCountrySubdivision); $tmpPoint = new Point(); $point = $location->Point; $tmpPoint->setLatitude((string) $point->Latitude); $tmpPoint->setLongitude((string) $point->Longitude); $tmpLocation->setPoint($tmpPoint); $tmpLocation->setAddress($tmpAddress); $tmpAtm->setLocation($tmpLocation); array_push($atmArray, $tmpAtm); } $atms->setAtm($atmArray); return $atms; }
public function buildAtms($xml) { $pageOffset = (string) $xml->PageOffset; $totalCount = (string) $xml->TotalCount; $restaurantArray = array(); foreach ($xml->Restaurant as $restaurant) { $tmpRestaurant = new Restaurant(); $tmpRestaurant->setId((string) $restaurant->Id); $tmpRestaurant->setName((string) $restaurant->Name); $tmpRestaurant->setWebsiteUrl((string) $restaurant->WebsiteUrl); $tmpRestaurant->setPhoneNumber((string) $restaurant->PhoneNumber); $tmpRestaurant->setCategory((string) $restaurant->Category); $tmpRestaurant->setLocalFavoriteInd((string) $restaurant->LocalFavoriteInd); $tmpRestaurant->setHiddenGemInd((string) $restaurant->HiddenGemInd); $tmpLocation = new Location(); $location = $restaurant->Location; $tmpLocation->setName((string) $location->Name); $tmpLocation->setDistance((string) $location->Distance); $tmpLocation->setDistanceUnit((string) $location->DistanceUnit); $tmpAddress = new Address(); $address = $location->Address; $tmpAddress->setLine1((string) $address->Line1); $tmpAddress->setLine2((string) $address->Line2); $tmpAddress->setCity((string) $address->City); $tmpAddress->setPostalCode((string) $address->PostCode); $tmpCountry = new Country(); $tmpCountry->setName((string) $address->Country->Name); $tmpCountry->setCode((string) $address->Country->Code); $tmpCountrySubdivision = new CountrySubdivision(); $tmpCountrySubdivision->setName((string) $address->CountrySubdivision->Name); $tmpCountrySubdivision->setCode((string) $address->CountrySubdivision->Code); $tmpAddress->setCountry($tmpCountry); $tmpAddress->setCountrySubdivision($tmpCountrySubdivision); $tmpPoint = new Point(); $point = $location->Point; $tmpPoint->setLatitude((string) $point->Latitude); $tmpPoint->setLongitude((string) $point->Longitude); $tmpLocation->setPoint($tmpPoint); $tmpLocation->setAddress($tmpAddress); $tmpRestaurant->setLocation($tmpLocation); array_push($restaurantArray, $tmpRestaurant); } $restaurants = new Restaurants($pageOffset, $totalCount, $restaurantArray); return $restaurants; }
public function buildMerchantIds($xml) { $merchantArray = array(); foreach ($xml->ReturnedMerchants->Merchant as $merchant) { $xmlAddress = $merchant->Address; $xmlCountrySubdivision = $merchant->Address->CountrySubdivision; $xmlCountry = $merchant->Address->Country; $xmlMerchant = $merchant; $address = new Address(); $address->setLine1((string) $xmlAddress->Line1); $address->setLine2((string) $xmlAddress->Line2); $address->setCity((string) $xmlAddress->City); $address->setPostalCode((string) $xmlAddress->PostalCode); $countrySubdivision = new CountrySubdivision(); $countrySubdivision->setCode((string) $xmlCountrySubdivision->Code); $countrySubdivision->setName((string) $xmlCountrySubdivision->Name); $country = new Country(); $country->setCode((string) $xmlCountry->Code); $country->setName((string) $xmlCountry->Name); $address->setCountrySubdivision($countrySubdivision); $address->setCountry($country); $tmpMerchant = new Merchant(); $tmpMerchant->setAddress($address); $tmpMerchant->setPhoneNumber((string) $xmlMerchant->PhoneNumber); $tmpMerchant->setBrandName((string) $xmlMerchant->BrandName); $tmpMerchant->setMerchantCategory((string) $xmlMerchant->MerchantCategory); $tmpMerchant->setMerchantDbaName((string) $xmlMerchant->MerchantDbaName); $tmpMerchant->setDescriptorText((string) $xmlMerchant->DescriptorText); $tmpMerchant->setLegalCorporateName((string) $xmlMerchant->LegalCorporateName); $tmpMerchant->setBrickCount((string) $xmlMerchant->BrickCount); $tmpMerchant->setComment((string) $xmlMerchant->Comment); $tmpMerchant->setLocationId((string) $xmlMerchant->LocationId); $tmpMerchant->setOnlineCount((string) $xmlMerchant->OnlineCount); $tmpMerchant->setOtherCount((string) $xmlMerchant->OtherCount); $tmpMerchant->setSoleProprietorName((string) $xmlMerchant->SoleProprietorName); array_push($merchantArray, $tmpMerchant); } $returnedMerchants = new ReturnedMerchants(); $returnedMerchants->setMerchant($merchantArray); $merchantIds = new MerchantIds(); $merchantIds->setReturnedMerchants($returnedMerchants); $merchantIds->setMessage($xml->Message); return $merchantIds; }
require '../../AvaTax4PHP/AvaTax.php'; // include in all Avalara Scripts require '../Credentials.php'; // where service URL, account, license key are set $client = new AddressServiceSoap('Development'); $STDIN = fopen('php://stdin', 'r'); try { $address = new Address(); // Get The address from the user via keyboard input echo "Address Line 1: "; $input = rtrim(fgets($STDIN)); $address->setLine1($input); echo "Address Line 2: "; $input = rtrim(fgets($STDIN)); $address->setLine2($input); echo "Address Line 3: "; $input = rtrim(fgets($STDIN)); $address->setLine3($input); echo "City: "; $input = rtrim(fgets($STDIN)); $address->setCity($input); echo "State/Province: "; $input = rtrim(fgets($STDIN)); $address->setRegion($input); echo "Postal Code: "; $input = rtrim(fgets($STDIN)); $address->setPostalCode($input); $textCase = TextCase::$Mixed; $coordinates = 1; $request = new ValidateRequest($address, $textCase ? $textCase : TextCase::$Default, $coordinates);
// where service URL, account, license key are set $client = new TaxServiceSoap('Development'); $request = new GetTaxRequest(); //Add Origin Address $origin = new Address(); $origin->setLine1("435 Ericksen Ave NE"); $origin->setLine2("Suite 200"); $origin->setCity("Bainbridge Island"); $origin->setRegion("WA"); $origin->setPostalCode("98110-1896"); $request->setOriginAddress($origin); //Address //Add Destination address $destination = new Address(); $destination->setLine1("900 Winslow Way"); $destination->setLine2("Suite 200"); $destination->setCity("Bainbridge Island"); $destination->setRegion("WA"); $destination->setPostalCode("98110"); $request->setDestinationAddress($destination); //Address $request->setCompanyCode('DEFAULT'); // Your Company Code From the Dashboard $request->setDocType(DocumentType::$SalesInvoice); // Only supported types are SalesInvoice or SalesOrder $dateTime = new DateTime(); $docCode = "PHPSample" . date_format($dateTime, "dmyGis"); $request->setDocCode($docCode); // invoice number $request->setDocDate(date_format($dateTime, "Y-m-d")); //date
function contactParser($data) { $contact = new Contact(); if (isset($data['id'])) { $contact->setId($data['id']); } if (isset($data['firstName'])) { $contact->setFirstName($data['firstName']); } if (isset($data['name'])) { $contact->setName($data['name']); } if (isset($data['mail'])) { $contact->setMail($data['mail']); } if (isset($data['phone'])) { $contact->setPhone($data['phone']); } if (isset($data['phone2'])) { $contact->setPhone2($data['phone2']); } if (isset($data['phone3'])) { $contact->setPhone3($data['phone3']); } if (isset($data['company'])) { $contact->setCompany($data['company']); } if (isset($data['address'])) { $dataAddress = $data['address']; $address = new Address(); if (isset($dataAddress['id'])) { $address->setId($dataAddress['id']); } if (isset($dataAddress['line1'])) { $address->setLine1($dataAddress['line1']); } if (isset($dataAddress['line2'])) { $address->setLine2($dataAddress['line2']); } if (isset($dataAddress['zipCode'])) { $address->setZipCode($dataAddress['zipCode']); } if (isset($dataAddress['city'])) { $address->setCity($dataAddress['city']); } if (isset($dataAddress['latitude']) && isset($dataAddress['longitude'])) { $address->setLatitude($dataAddress['latitude']); $address->setLongitude($dataAddress['longitude']); } else { $mapService = new GoogleMapService(); $latlng = $mapService->getLatLong($address); if ($latlng != [] && sizeof($latlng) == 2) { $address->setLatitude($latlng[0]); $address->setLongitude($latlng[1]); } } $contact->setAddress($address); } if (isset($data['type'])) { if (isset($data['type']['id']) && isset($data['type']['name'])) { $type = new Type($data['type']['id'], $data['type']['name']); } elseif (isset($data['type']['name'])) { $type = new Type(null, $data['type']['name']); } else { $type = null; } $contact->setType($type); } if (isset($data['exchangeId'])) { $contact->setExchangeId($data['exchangeId']); } return $contact; }
function CalcTax($taxSvcSoapClient, $companyCode) { $request = new GetTaxRequest(); $origin = new Address(); $destination = new Address(); $line1 = new Line(); $origin->setLine1("435 Ericksen Ave NE"); $origin->setLine2("Suite 200"); $origin->setCity("Bainbridge Island"); $origin->setRegion("WA"); $origin->setPostalCode("98110-1896"); $destination->setLine1("900 Winslow Way"); $destination->setLine2("Suite 200"); $destination->setCity("Bainbridge Island"); $destination->setRegion("WA"); $destination->setPostalCode("98110"); $request->setOriginAddress($origin); //Address $request->setDestinationAddress($destination); //Address $request->setCompanyCode($companyCode); // Your Company Code From the Dashboard $request->setDocType(DocumentType::$SalesInvoice); // Only supported types are SalesInvoice or SalesOrder $dateTime = new DateTime(); $docCode = "PHPSample" . date_format($dateTime, "dmyGis"); $request->setDocCode($docCode); // invoice number $request->setDocDate(date_format($dateTime, "Y-m-d")); //date $request->setSalespersonCode(""); // string Optional $request->setCustomerCode("Cust123"); //string Required $request->setCustomerUsageType(""); //string Entity Usage $request->setDiscount(0.0); //decimal $request->setPurchaseOrderNo(""); //string Optional $request->setExemptionNo(""); //string if not using ECMS which keys on customer code $request->setDetailLevel(DetailLevel::$Document); $request->setCommit("true"); // commit upon tax calc $request->setReferenceCode(""); //string Optional $request->setLocationCode(""); //string Optional - aka outlet id for tax forms $line1->setNo("1"); //string // line Number of invoice $line1->setItemCode("SKU123"); //string $line1->setDescription("Invoice Calculated From PHP SDK"); //string $line1->setTaxCode(""); //string $line1->setQty(1.0); //decimal $line1->setAmount(1000.0); //decimal // TotalAmmount $line1->setDiscounted(false); //boolean $line1->setRevAcct(""); //string $line1->setRef1(""); //string $line1->setRef2(""); //string $line1->setExemptionNo(""); //string $line1->setCustomerUsageType(""); //string $request->setLines(array($line1)); //array try { $getTaxResult = $taxSvcSoapClient->getTax($request); echo 'GetTax Result: ' . $getTaxResult->getResultCode() . "\n"; if ($getTaxResult->getResultCode() == SeverityLevel::$Success) { echo "DocCode: " . $request->getDocCode() . "\n"; echo "TotalAmount: " . $getTaxResult->getTotalAmount() . "\n"; echo "TotalTax: " . $getTaxResult->getTotalTax() . "\n"; } else { foreach ($getTaxResult->getMessages() as $msg) { echo $msg->getName() . ": " . $msg->getSummary() . "\n"; } } } catch (SoapFault $exception) { $msg = "Exception: "; if ($exception) { $msg .= $exception->faultstring; } echo $msg . "\n"; echo $taxSvcSoapClient->__getLastRequest() . "\n"; echo $taxSvcSoapClient->__getLastResponse() . "\n"; } return $request->getDocCode(); }
private function buildInquireMapping($xml) { $inquireMapping = new InquireMapping(); $inquireMapping->setRequestId((string) $xml->RequestId); $mappings = new Mappings(); $mappingArray = array(); foreach ($xml->Mappings->Mapping as $mapping) { $tmpMapping = new Mapping(); $tmpMapping->setMappingId((string) $mapping->MappingId); $tmpMapping->setSubscriberId((string) $mapping->SubscriberId); $tmpMapping->setAccountUsage((string) $mapping->AccountUsage); $tmpMapping->setDefaultIndicator((string) $mapping->DefaultIndicator); $tmpMapping->setAlias((string) $mapping->Alias); $tmpMapping->setICA((string) $mapping->ICA); $tmpMapping->setAccountNumber((string) $mapping->AccountNumber); $tmpCardholderFullName = new CardholderFullName(); $cardholderFullName = $mapping->CardholderFullName; $tmpCardholderFullName->setCardholderFirstName((string) $cardholderFullName->CardholderFirstName); $tmpCardholderFullName->setCardholderMiddleName((string) $cardholderFullName->CardholderMiddleName); $tmpCardholderFullName->setCardholderLastName((string) $cardholderFullName->CardholderLastName); $tmpAddress = new Address(); $address = $mapping->Address; $tmpAddress->setLine1((string) $address->line1); $tmpAddress->setLine2((string) $address->line2); $tmpAddress->setCity((string) $address->City); $tmpAddress->setCountrySubdivision((string) $address->CountrySubdivision); $tmpAddress->setPostalCode((string) $address->PostalCode); $tmpAddress->setCountry((string) $address->Country); $tmpReceivingEligibility = new ReceivingEligibility(); $receivingEligibility = $mapping->ReceivingEligibility; $tmpReceivingEligibility->setEligible((string) $receivingEligibility->Eligible); $tmpCurrency = new Currency(); $currency = $receivingEligibility->Currency; $tmpCurrency->setAlphaCurrencyCode((string) $currency->AlphaCurrencyCode); $tmpCurrency->setNumericCurrencyCode((string) $currency->NumericCurrencyCode); $tmpCountry = new Country(); $country = $receivingEligibility->Country; $tmpCountry->setAlphaCountryCode((string) $country->AlphaCountryCode); $tmpCountry->setAlphaCountryCode((string) $country->NumericCountryCode); $tmpBrand = new Brand(); $brand = $receivingEligibility->Brand; $tmpBrand->setAcceptanceBrandCode((string) $brand->AcceptanceBrandCode); $tmpBrand->setProductBrandCode((string) $brand->ProductBrandCode); $tmpMapping->setExpiryDate((string) $mapping->ExpiryDate); $tmpReceivingEligibility->setCurrency($tmpCurrency); $tmpReceivingEligibility->setCountry($tmpCountry); $tmpReceivingEligibility->setBrand($tmpBrand); $tmpMapping->setCardholderFullName($tmpCardholderFullName); $tmpMapping->setAddress($tmpAddress); $tmpMapping->setReceivingEligibility($tmpReceivingEligibility); array_push($mappingArray, $tmpMapping); } $mappings->setMapping($mappingArray); $inquireMapping->setMappings($mappings); return $inquireMapping; }
private function CreateTaxRequestForBINo($bino) { $request = new GetTaxRequest(); //Set origin Address $origin = new Address(); $origin->setLine1("Avalara"); $origin->setLine2("900 winslow way"); $origin->setLine3("Suite 100"); $origin->setCity("Bainbridge Island"); $origin->setRegion("WA"); $origin->setPostalCode("98110-1896"); $origin->setCountry("USA"); $request->setOriginAddress($origin); //Set destination address $destination = new Address(); $destination->setLine1("3130 Elliott"); $destination->setCity("Seattle"); $destination->setRegion("WA"); $destination->setPostalCode("98121"); $destination->setCountry("USA"); $request->setDestinationAddress($destination); //Set line $line = new Line(); $line->setNo("1"); //string // line Number of invoice $line->setBusinessIdentificationNo("LL123"); $line->setItemCode("Item123"); //string $line->setQty(1.0); //decimal $line->setAmount(1010.0); $request->setLines(array($line)); $request->setCompanyCode('DEFAULT'); // Your Company Code From the Dashboard $request->setDocCode("DocTypeTest"); $request->setBusinessIdentificationNo($bino); $request->setDocDate(date_format(new DateTime(), "Y-m-d")); $request->setCustomerCode("TaxSvcTest"); //string Required $request->setSalespersonCode(""); // string Optional $request->setDetailLevel(DetailLevel::$Tax); //Summary or Document or Line or Tax or Diagnostic return $request; }
/** * Generic address maker * * @param string $line1 * @param string $line2 * @param string $city * @param string $state * @param string $zip * @param string $country * @return Address */ protected function _newAddress($line1, $line2, $city, $state, $zip, $country = 'USA') { // force string type because hash key generation uses serialize() in Estimate.php $address = new Address(); $address->setLine1((string) $line1); $address->setLine2((string) $line2); $address->setCity((string) $city); $address->setRegion((string) $state); $address->setPostalCode((string) $zip); $address->setCountry((string) $country); return $address; }
/** * * Builds and Returns an Address object based off of the JSON input. * * @param vo_json JSON representation of an address * @return the Address * @throws JSONException if the json is not properly formatted */ static function buildFromJSON($o_data) { $o_instance = new Address(); if ($o_data != NULL) { if (array_key_exists("address_name", $o_data)) { $o_instance->setName($o_data['address_name']); } if (array_key_exists("address_line1", $o_data)) { $o_instance->setLine1($o_data['address_line1']); } if (array_key_exists("address_line2", $o_data)) { $o_instance->setLine2($o_data['address_line2']); } if (array_key_exists("address_city", $o_data)) { $o_instance->setCity($o_data['address_city']); } if (array_key_exists("address_state", $o_data)) { $o_instance->setState($o_data['address_state']); } if (array_key_exists("address_zipcode", $o_data)) { $o_instance->setZipcode($o_data['address_zipcode']); } if (array_key_exists("address_country", $o_data)) { $o_instance->setCountry($o_data['address_country']); } } return $o_instance; }
function createStandardRequest($calc, $products, $sign = 1) { if (!class_exists('TaxServiceSoap')) { require VMAVALARA_CLASS_PATH . DS . 'TaxServiceSoap.class.php'; } if (!class_exists('DocumentType')) { require VMAVALARA_CLASS_PATH . DS . 'DocumentType.class.php'; } if (!class_exists('DetailLevel')) { require VMAVALARA_CLASS_PATH . DS . 'DetailLevel.class.php'; } if (!class_exists('Line')) { require VMAVALARA_CLASS_PATH . DS . 'Line.class.php'; } if (!class_exists('ServiceMode')) { require VMAVALARA_CLASS_PATH . DS . 'ServiceMode.class.php'; } if (!class_exists('Line')) { require VMAVALARA_CLASS_PATH . DS . 'Line.class.php'; } if (!class_exists('GetTaxRequest')) { require VMAVALARA_CLASS_PATH . DS . 'GetTaxRequest.class.php'; } if (!class_exists('GetTaxResult')) { require VMAVALARA_CLASS_PATH . DS . 'GetTaxResult.class.php'; } if (!class_exists('Address')) { require VMAVALARA_CLASS_PATH . DS . 'Address.class.php'; } if (is_object($calc)) { $calc = get_object_vars($calc); } $request = new GetTaxRequest(); $origin = new Address(); //In Virtuemart we have not differenct warehouses, but we have a shipment address //So when the vendor has a shipment address, we assume that it is his warehouse //Later we can combine products with shipment addresses for different warehouse (yehye, future music) //But for now we just use the BT address if (!class_exists('VirtueMartModelVendor')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'vendor.php'; } $userId = VirtueMartModelVendor::getUserIdByVendorId($calc['virtuemart_vendor_id']); $userModel = VmModel::getModel('user'); $virtuemart_userinfo_id = $userModel->getBTuserinfo_id($userId); // this is needed to set the correct user id for the vendor when the user is logged $userModel->getVendor($calc['virtuemart_vendor_id']); $vendorFieldsArray = $userModel->getUserInfoInUserFields('mail', 'BT', $virtuemart_userinfo_id, FALSE, TRUE); $vendorFields = $vendorFieldsArray[$virtuemart_userinfo_id]; $origin->setLine1($vendorFields['fields']['address_1']['value']); $origin->setLine2($vendorFields['fields']['address_2']['value']); $origin->setCity($vendorFields['fields']['city']['value']); $origin->setCountry($vendorFields['fields']['virtuemart_country_id']['country_2_code']); $origin->setRegion($vendorFields['fields']['virtuemart_state_id']['state_2_code']); $origin->setPostalCode($vendorFields['fields']['zip']['value']); $request->setOriginAddress($origin); //Address if (isset($this->addresses[0])) { $destination = $this->addresses[0]; } else { return FALSE; } if (!class_exists('calculationHelper')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php'; } $calculator = calculationHelper::getInstance(); $request->setCurrencyCode($calculator->_currencyDisplay->_vendorCurrency_code_3); //CurrencyCode $request->setDestinationAddress($destination); //Address $request->setCompanyCode($calc['company_code']); // Your Company Code From the Dashboard $request->setDocDate(date('Y-m-d')); //date, checked $request->setCustomerCode(self::$vmadd['customer_number']); //string Required if (isset(self::$vmadd['tax_usage_type'])) { $request->setCustomerUsageType(self::$vmadd['tax_usage_type']); //string Entity Usage } if (isset(self::$vmadd['tax_exemption_number'])) { $request->setExemptionNo(self::$vmadd['tax_exemption_number']); //string if not using ECMS which keys on customer code } if (isset(self::$vmadd['taxOverride'])) { $request->setTaxOverride(self::$vmadd['taxOverride']); avadebug('I set tax override ', self::$vmadd['taxOverride']); } $setAllDiscounted = false; if (isset($products['discountAmount'])) { if (!empty($products['discountAmount'])) { //$request->setDiscount($sign * $products['discountAmount'] * (-1)); //decimal $request->setDiscount($sign * $products['discountAmount']); //decimal vmdebug('We sent as discount ' . $request->getDiscount()); $setAllDiscounted = true; } unset($products['discountAmount']); } $request->setDetailLevel('Tax'); //Summary or Document or Line or Tax or Diagnostic $lines = array(); $n = 0; $this->_lineNumbersToCartProductId = array(); foreach ($products as $k => $product) { $n++; $this->_lineNumbersToCartProductId[$n] = $k; $line = new Line(); $line->setNo($n); //string // line Number of invoice $line->setItemCode($product['product_sku']); //string $line->setDescription($product['product_name']); //product description, like in cart, atm only the name, todo add customfields if (!empty($product['categories'])) { //avadebug('AvaTax setTaxCode Product has categories !',$catNames); if (!class_exists('TableCategories')) { require JPATH_VM_ADMINISTRATOR . DS . 'tables' . DS . 'categories.php'; } $db = JFactory::getDbo(); $catTable = new TableCategories($db); foreach ($product['categories'] as $cat) { $catTable->load($cat); $catslug = $catTable->slug; if (strpos($catslug, 'avatax-') !== FALSE) { $taxCode = substr($catslug, 7); if (!empty($taxCode)) { $line->setTaxCode($taxCode); } else { vmError('AvaTax setTaxCode, category could not be parsed ' . $catslug); } break; } } } //$line->setTaxCode(""); //string $line->setQty($product['amount']); //decimal $line->setAmount($sign * $product['price'] * $product['amount']); //decimal // TotalAmmount if ($setAllDiscounted or !empty($product['discount'])) { $line->setDiscounted(1); } else { $line->setDiscounted(0); } $line->setRevAcct(""); //string $line->setRef1(""); //string $line->setRef2(""); //string if (isset(self::$vmadd['tax_usage_type'])) { $line->setCustomerUsageType(self::$vmadd['tax_usage_type']); //string Entity Usage } if (isset(self::$vmadd['tax_exemption_number'])) { $line->setExemptionNo(self::$vmadd['tax_exemption_number']); //string if not using ECMS which keys on customer code } if (isset(self::$vmadd['taxOverride'])) { //create new TaxOverride Object set //$line->setTaxOverride(self::$vmadd['taxOverride']); } $lines[] = $line; } $this->newATConfig($calc); $request->setLines($lines); return $request; }
function getTax($calculationHelper, $calc, $price, $sale = false, $committ = false) { if ($calc->activated == 0) { return false; } $shopperData = $this->getShopperData(); if (!$shopperData) { return false; } //if(self::$stop) return self::$stop; if (!class_exists('TaxServiceSoap')) { require VMAVALARA_CLASS_PATH . DS . 'TaxServiceSoap.class.php'; } if (!class_exists('DocumentType')) { require VMAVALARA_CLASS_PATH . DS . 'DocumentType.class.php'; } if (!class_exists('DetailLevel')) { require VMAVALARA_CLASS_PATH . DS . 'DetailLevel.class.php'; } if (!class_exists('Line')) { require VMAVALARA_CLASS_PATH . DS . 'Line.class.php'; } if (!class_exists('ServiceMode')) { require VMAVALARA_CLASS_PATH . DS . 'ServiceMode.class.php'; } if (!class_exists('Line')) { require VMAVALARA_CLASS_PATH . DS . 'Line.class.php'; } if (!class_exists('GetTaxRequest')) { require VMAVALARA_CLASS_PATH . DS . 'GetTaxRequest.class.php'; } if (!class_exists('GetTaxResult')) { require VMAVALARA_CLASS_PATH . DS . 'GetTaxResult.class.php'; } $client = new TaxServiceSoap('Development'); $request = new GetTaxRequest(); $origin = new Address(); //$destination = $this->fillValidateAvalaraAddress($calc); //In Virtuemart we have not differenct warehouses, but we have a shipment address //So when the vendor has a shipment address, we assume that it is his warehouse //Later we can combine products with shipment addresses for different warehouse (yehye, future music) //But for now we just use the BT address if (!class_exists('VirtueMartModelVendor')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'vendor.php'; } $userId = VirtueMartModelVendor::getUserIdByVendorId($calc->virtuemart_vendor_id); $userModel = VmModel::getModel('user'); $virtuemart_userinfo_id = $userModel->getBTuserinfo_id($userId); // this is needed to set the correct user id for the vendor when the user is logged $userModel->getVendor($calc->virtuemart_vendor_id); $vendorFieldsArray = $userModel->getUserInfoInUserFields('mail', 'BT', $virtuemart_userinfo_id, FALSE, TRUE); $vendorFields = $vendorFieldsArray[$virtuemart_userinfo_id]; //vmdebug('my vendor fields',$vendorFields); $origin->setLine1($vendorFields['fields']['address_1']['value']); $origin->setLine2($vendorFields['fields']['address_2']['value']); $origin->setCity($vendorFields['fields']['city']['value']); $origin->setCountry($vendorFields['fields']['virtuemart_country_id']['country_2_code']); $origin->setRegion($vendorFields['fields']['virtuemart_state_id']['state_2_code']); $origin->setPostalCode($vendorFields['fields']['zip']['value']); $request->setOriginAddress($origin); //Address if (isset($this->addresses[0])) { $destination = $this->addresses[0]; } else { return FALSE; } $request->setDestinationAddress($destination); //Address //vmdebug('The date',$origin,$destination); $request->setCompanyCode($calc->company_code); // Your Company Code From the Dashboard if ($calc->committ and $sale) { $request->setDocType(DocumentType::$SalesInvoice); // Only supported types are SalesInvoice or SalesOrder $request->setCommit(true); //invoice number, problem is that the invoice number is at this time not known, but the order_number may reachable $request->setDocCode($committ); vmdebug('Request as SalesInvoice with invoiceNumber ' . $committ); } else { $request->setDocType(DocumentType::$SalesOrder); $request->setCommit(false); //invoice number, problem is that the invoice number is at this time not known, neither the order_number $request->setDocCode('VM2.0.16_order_request'); vmdebug('Request as SalesOrder'); } $request->setDocDate(date('Y-m-d')); //date //$request->setSalespersonCode(""); // string Optional $request->setCustomerCode($shopperData['customer_id']); //string Required if (isset($shopperData['tax_usage_type'])) { $request->setCustomerUsageType($shopperData['tax_usage_type']); //string Entity Usage } $cartPrices = $calculationHelper->getCartPrices(); //vmdebug('$cartPrices',$cartPrices); $request->setDiscount($cartPrices['discountAmount']); //decimal //$request->setDiscount(0.0); // $request->setPurchaseOrderNo(""); //string Optional //If I understand correctly, we need to add for this an userfield, for example with the name //exemption_no, then user could enter their number. if (isset($shopperData['tax_exemption_number'])) { $request->setExemptionNo($shopperData['tax_exemption_number']); //string if not using ECMS which keys on customer code } $request->setDetailLevel('Tax'); //Summary or Document or Line or Tax or Diagnostic // $request->setReferenceCode1(""); //string Optional // $request->setReferenceCode2(""); //string Optional // $request->setLocationCode(""); //string Optional - aka outlet id for tax forms ///////////////////////////////////////// if (!class_exists('VirtueMartCart')) { require JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php'; } $cart = VirtueMartCart::getCart(); $products = array(); if ($calculationHelper->inCart) { $products = $cart->products; $prices = $calculationHelper->getCartPrices(); foreach ($products as $k => $product) { if (!empty($prices[$k]['discountedPriceWithoutTax'])) { $price = $prices[$k]['discountedPriceWithoutTax']; } else { if (!empty($prices[$k]['basePriceVariant'])) { $price = $prices[$k]['basePriceVariant']; } else { vmdebug('There is no price in getTax for product ' . $k . ' ', $prices); $price = 0.0; } } $product->price = $price; if (!empty($price[$k]['discountAmount'])) { $product->discount = $price[$k]['discountAmount']; } else { $product->discount = FALSE; } } } else { $calculationHelper->_product->price = $price; $products[0] = $calculationHelper->_product; if (!isset($products[0]->amount)) { $products[0]->amount = 1; } if (isset($calculationHelper->productPrices['discountAmount'])) { $products[0]->discount = $calculationHelper->productPrices['discountAmount']; } else { $products[0]->discount = FALSE; } } $lines = array(); $n = 0; $lineNumbersToCartProductId = array(); foreach ($products as $k => $product) { $n++; $lineNumbersToCartProductId[$n] = $k; $line = new Line(); $line->setNo($n); //string // line Number of invoice $line->setItemCode($product->product_sku); //string $line->setDescription($product->product_name); //product description, like in cart, atm only the name, todo add customfields //$line->setTaxCode(""); //string $line->setQty($product->amount); //decimal $line->setAmount($product->price * $product->amount); //decimal // TotalAmmount $line->setDiscounted($product->discount * $product->amount); //boolean $line->setRevAcct(""); //string $line->setRef1(""); //string $line->setRef2(""); //string if (isset($shopperData['tax_exemption_number'])) { $line->setExemptionNo($shopperData['tax_exemption_number']); //string } if (isset($shopperData['tax_usage_type'])) { $line->setCustomerUsageType($shopperData['tax_usage_type']); //string } $lines[] = $line; } $line = new Line(); $line->setNo(++$n); //$lineNumbersToCartProductId[$n] = count($products)+1; $line->setItemCode($cart->virtuemart_shipmentmethod_id); $line->setDescription('Shipment'); $line->setQty(1); //$line->setTaxCode(); $cartPrices = $calculationHelper->getCartPrices(); //vmdebug('$calculationHelper $cartPrices',$cartPrices); $line->setAmount($cartPrices['shipmentValue']); if (isset($shopperData['tax_exemption_number'])) { $line->setExemptionNo($shopperData['tax_exemption_number']); //string } if (isset($shopperData['tax_usage_type'])) { $line->setCustomerUsageType($shopperData['tax_usage_type']); //string } $lines[] = $line; //vmdebug('avalaragetTax setLines',$lines); $request->setLines($lines); //vmdebug('My request',$request); $totalTax = 0.0; try { if (!class_exists('TaxLine')) { require VMAVALARA_CLASS_PATH . DS . 'TaxLine.class.php'; } if (!class_exists('TaxDetail')) { require VMAVALARA_CLASS_PATH . DS . 'TaxDetail.class.php'; } vmSetStartTime('avagetTax'); $getTaxResult = $client->getTax($request); vmTime('Avalara getTax', 'avagetTax'); /* * [0] => getDocCode [1] => getAdjustmentDescription [2] => getAdjustmentReason [3] => getDocDate [4] => getTaxDate [5] => getDocType [6] => getDocStatus [7] => getIsReconciled [8] => getLocked [9] => getTimestamp [10] => getTotalAmount [11] => getTotalDiscount [12] => getTotalExemption [13] => getTotalTaxable [14] => getTotalTax [15] => getHashCode [16] => getVersion [17] => getTaxLines [18] => getTotalTaxCalculated [19] => getTaxSummary [20] => getTaxLine [21] => getTransactionId [22] => getResultCode [23] => getMessages */ //vmdebug( 'GetTax is: '. $getTaxResult->getResultCode(),$getTaxResult); if ($getTaxResult->getResultCode() == SeverityLevel::$Success) { //vmdebug("DocCode: ".$request->getDocCode() ); //vmdebug("DocId: ".$getTaxResult->getDocId()."\n"); vmdebug("TotalAmount: " . $getTaxResult->getTotalAmount()); $totalTax = $getTaxResult->getTotalTax(); vmdebug("TotalTax: " . $totalTax); foreach ($getTaxResult->getTaxLines() as $ctl) { if ($calculationHelper->inCart) { $nr = $ctl->getNo(); if (isset($lineNumbersToCartProductId[$nr])) { $quantity = $products[$lineNumbersToCartProductId[$nr]]->amount; //on the long hand, the taxAmount must be replaced by taxAmountQuantity to avoid rounding errors $prices[$lineNumbersToCartProductId[$ctl->getNo()]]['taxAmount'] = $ctl->getTax() / $quantity; $prices[$lineNumbersToCartProductId[$ctl->getNo()]]['taxAmountQuantity'] = $ctl->getTax(); } else { //$this->_cartPrices['shipmentValue'] = 0; //could be automatically set to a default set in the globalconfig //$this->_cartPrices['shipmentTax'] = 0; //$this->_cartPrices['shipmentTotal'] = 0; //$prices = array('shipmentValue'=>$cartPrices['shipmentValue'],'shipmentTax'=> $ctl->getTax(), 'shipmentTotal' =>($cartPrices['shipmentValue'] +$ctl->getTax() )); //vmdebug('my $cartPrices',$cartPrices); $prices['shipmentTax'] = $ctl->getTax(); $prices['salesPriceShipment'] = $prices['shipmentValue'] + $ctl->getTax(); //$cartPrices = array_merge($prices,$cartPrices); //$calculationHelper->setCartPrices( $cartPrices ); $totalTax = $totalTax - $ctl->getTax(); //vmdebug('my $cartPrices danach',$cartPrices); } } //vmdebug('my lines ',$ctl); //vmdebug( " Line: ".$ctl->getNo()." Tax: ".$ctl->getTax()." TaxCode: ".$ctl->getTaxCode()); foreach ($ctl->getTaxDetails() as $ctd) { //vmdebug( " Juris Type: ".$ctd->getJurisType()."; Juris Name: ".$ctd->getJurisName()."; Rate: ".$ctd->getRate()."; Amt: ".$ctd->getTax() ); } } if ($calculationHelper->inCart) { $calculationHelper->setCartPrices($prices); } } else { foreach ($getTaxResult->getMessages() as $msg) { vmError($msg->getName() . ": " . $msg->getSummary()); } } } catch (SoapFault $exception) { $msg = "Exception: "; if ($exception) { $msg .= $exception->faultstring; } vmdebug($msg . '<br />' . $client->__getLastRequest() . '<br />' . $client->__getLastResponse()); } //self::$stop = $totalTax; return $totalTax; }
/** * Generic address maker * * @param string $line1 * @param string $line2 * @param string $city * @param string $state * @param string $zip * @param string $country * @return Address */ protected function _newAddress($line1, $line2, $city, $state, $zip, $country = 'USA') { $address = new Address(); $address->setLine1($line1); $address->setLine2($line2); $address->setCity($city); $address->setRegion($state); $address->setPostalCode($zip); $address->setCountry($country); return $address; }
public function getAddressesByRayon($address, $rayon) { $list = []; try { if (!parent::getBdd()->inTransaction()) { parent::getBdd()->beginTransaction(); } $query = "SELECT *, ( 6371 * acos( cos( radians(:latitude) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:longitude) )\n + sin( radians(:latitude) ) * sin( radians( latitude ) ) ) ) AS distance FROM address HAVING distance < :rayon ORDER BY distance LIMIT 0 , 150;"; $request = parent::getBdd()->prepare($query); $request->bindParam(':latitude', $address->getLatitude()); $request->bindParam(':longitude', $address->getLongitude()); $request->bindParam(':rayon', $rayon); $request->execute(); while ($data = $request->fetch()) { $address = new Address(); $address->setId($data['id']); $address->setLine1($data['line1']); $address->setLine2($data['line2']); $address->setZipCode($data['zipcode']); $address->setCity($data['city']); $address->setLatitude($data['latitude']); $address->setLongitude($data['longitude']); array_push($list, $address); } if ($list == []) { return null; } return $list; } catch (Exception $e) { error_log($e->getMessage()); } return null; }