/** * @covers Auspost\Postage\PostageClient::factory * @dataProvider provider */ public function testFactoryInitalisesClient($userAuthKey, $developerMode = true, $reqUrl = 'https://test.npe.auspost.com.au', $reqAuthKey = '28744ed5982391881611cca6cf5c2409') { $client = PostageClient::factory(array('developer_mode' => $developerMode, 'auth_key' => $userAuthKey)); $this->assertEquals($developerMode, $client->getConfig('developer_mode')); $this->assertEquals($reqUrl, $client->getBaseUrl()); $this->assertEquals($reqAuthKey, $client->getConfig('auth_key')); }
/** * @dataProvider calculateInternationalParcelPostageProvider */ public function testCalculateInternationalParcelPostage($mock, $args, $cost) { $this->setMockResponse($this->client, $mock); $response = $this->client->calculateInternationalParcelPostage($args); $this->assertArrayHasKey('postage_result', $response); $this->assertArrayHasKey('total_cost', $response['postage_result']); $postage = $response['postage_result']; $totalCost = $postage['total_cost']; $this->assertEquals($totalCost, $cost); }
protected function _getQuotes($extraCover, $config) { $destCountry = $config['country_code']; try { if ($destCountry == Fontis_Australia_Helper_Data::AUSTRALIA_COUNTRY_CODE) { $services = $this->_client->listDomesticParcelServices($config); } else { $services = $this->_client->listInternationalParcelServices($config); } } catch (Exception $e) { Mage::logException($e); return; } // TODO: Clean up this logic $allowedMethods = $this->getAllowedMethods(); $extraCoverParent = $this->getCode('extra_cover'); foreach ($services['services']['service'] as $service) { $serviceCode = $service['code']; // e.g. AUS_PARCEL_REGULAR if (in_array($serviceCode, $allowedMethods)) { $serviceName = $service['name']; // e.g. Parcel Post $servicePrice = $service['price']; // Just add the shipping method if the call to Australia Post // returns no options for that method if (!isset($service['options']['option']) && $this->_isAvailableShippingMethod($serviceName, $destCountry)) { $method = $this->createMethod($serviceCode, $serviceName, $servicePrice); $this->_result->append($method); // If a shipping method has a bunch of options, we will have to // create a specific method for each of the variants } else { $serviceOption = $service['options']['option']; // Unlike domestic shipping methods where the "default" // method is listed as simply another service option (this // allows us to simply loop through each one), we have to // extrapolate the default international shipping method // from what we know about the service itself if ($destCountry != Fontis_Australia_Helper_Data::AUSTRALIA_COUNTRY_CODE && $this->_isAvailableShippingMethod($serviceName, $destCountry)) { $method = $this->createMethod($serviceCode, $serviceName, $servicePrice); $this->_result->append($method); } // Checks to see if the API has returned either a single // service option or an array of them. If it is a single // option then turn it into an array. if (isset($serviceOption['name'])) { $serviceOption = array($serviceOption); } foreach ($serviceOption as $option) { $serviceOptionName = $option['name']; $serviceOptionCode = $option['code']; $config = array_merge($config, array('service_code' => $serviceCode, 'option_code' => $serviceOptionCode, 'extra_cover' => $extraCover)); try { if ($destCountry == Fontis_Australia_Helper_Data::AUSTRALIA_COUNTRY_CODE) { $postage = $this->_client->calculateDomesticParcelPostage($config); } else { $postage = $this->_client->calculateInternationalParcelPostage($config); } } catch (Exception $e) { continue; } $servicePrice = $postage['postage_result']['total_cost']; /** @var Fontis_Australia_Helper_Clickandsend $clickandsendHelper */ $clickandsendHelper = Mage::helper('australia/clickandsend'); // Create a shipping method with only the top-level options $_finalCode = $serviceCode . '_' . $serviceOptionCode; $_finalName = $serviceName . ' (' . $serviceOptionName . ')'; if ($this->_isAvailableShippingMethod($_finalName, $destCountry) && !(in_array($serviceOptionCode, $clickandsendHelper->getDisallowedServiceOptions()) && in_array($serviceCode, $clickandsendHelper->getDisallowedServiceCodes()) && $clickandsendHelper->isClickAndSendEnabled() && $clickandsendHelper->isFilterShippingMethods())) { $method = $this->createMethod($_finalCode, $_finalName, $servicePrice); $this->_result->append($method); } // Add the extra cover options (these are suboptions of // the top-level options) if (array_key_exists($serviceOptionCode, $extraCoverParent) && !($clickandsendHelper->isClickAndSendEnabled() && $clickandsendHelper->isFilterShippingMethods())) { try { if ($destCountry == Fontis_Australia_Helper_Data::AUSTRALIA_COUNTRY_CODE) { $config = array_merge($config, array('suboption_code' => ServiceOption::AUS_SERVICE_OPTION_EXTRA_COVER)); $postageWithExtraCover = $this->_client->calculateDomesticParcelPostage($config); } else { $postageWithExtraCover = $this->_client->calculateInternationalParcelPostage($config); } unset($config['suboption_code']); } catch (Exception $e) { continue; } if ($serviceOptionName == 'Signature on Delivery') { $serviceOptionName = $serviceOptionName . ' + Extra Cover'; } else { $serviceOptionName = 'Extra Cover'; } if ($serviceOptionCode == ServiceOption::AUS_SERVICE_OPTION_SIGNATURE_ON_DELIVERY) { $serviceOptionCode = 'FULL_PACKAGE'; } else { $serviceOptionCode = 'EXTRA_COVER'; } $servicePrice = $postageWithExtraCover['postage_result']['total_cost']; $_finalCode = $serviceCode . '_' . $serviceOptionCode; $_finalName = $serviceName . ' (' . $serviceOptionName . ')'; if ($this->_isAvailableShippingMethod($_finalName, $destCountry)) { $method = $this->createMethod($_finalCode, $_finalName, $servicePrice); $this->_result->append($method); } } } } } } }