/** * @see uspsQuery::prepareRequest() * @throws waException */ protected function prepareRequest() { $services = $this->getServices(); $type = uspsServices::getServiceType($services[0]['id']); if (!$this->plugin->zip) { throw new waException($this->plugin->_w("Cannot calculate shipping rate because origin (sender's) ZIP code is not defined in USPS module settings")); } switch ($type) { case uspsServices::TYPE_DOMESTIC: $this->api = 'RateV4'; $xml = new SimpleXMLElement('<RateV4Request/>'); $xml->addChild('Revision'); break; case uspsServices::TYPE_INTERNATIONAL: $this->api = 'IntlRateV2'; $xml = new SimpleXMLElement('<IntlRateV2Request/>'); break; default: throw new waException($this->plugin->_w("Unknown type of service")); } $xml->addAttribute('USERID', $this->plugin->user_id); $xml->addAttribute('PASSWORD', ''); foreach ($services as $service) { $package = $xml->addChild('Package'); $package->addAttribute('ID', str_replace(' ', '_', $service['code'])); switch ($type) { case 'Domestic': $this->prepareDomesticPackage($package, $service); break; case 'International': $this->prepareInternationalPackage($package, $service); break; } } return $xml->saveXML(); }
public function getPrintForms(waOrder $order = null) { $all_forms = array('usps_tracking' => array('name' => 'USPS Tracking™', 'description' => 'Generate USPS Tracking barcoded labels for Priority Mail®, First-Class Mail® parcels, and package services parcels, including Standard Post™, Media Mail®, and Library Mail. '), 'express_mail' => array('name' => 'Express Mail®', 'description' => 'Generate a single-ply Express Mail shipping label complete with return and delivery addresses, a barcode, and a mailing record for your use.'), 'signature_confirmation' => array('name' => 'Signature Confirmation™ Labels', 'description' => 'Generate a Signature Confirmation barcoded label for Priority Mail, First-Class Mail parcels, Standard Post, Media Mail, and Library Mail services, and we’ll provide the complete address label, including the Signature Confirmation Service barcode.'), 'international_shipping' => array('name' => 'International Shipping Labels', 'description' => 'Send documents and packages globally. USPS® offers reliable, affordable shipping to more than 180 countries. Generate Express Mail International®, Priority Mail International®, First-Class Mail International®, or First-Class Package International Service shipping labels complete with addresses, barcode, customs form, and mailing receipt.')); $forms = array(); foreach ($all_forms as $name => $form) { $query_name = implode('', array_map("ucfirst", explode('_', $name))); $query = $this->getQuery('labels' . $query_name, true); $service = $this->getServiceCodeByOrder($order); $type = uspsServices::getServiceType($service['id']); if ($name == 'international_shipping') { if ($type == uspsServices::TYPE_INTERNATIONAL) { $forms[$name] = $form; } } else { if ($type == uspsServices::TYPE_DOMESTIC && call_user_func_array(array($query, 'isSupportedService'), array($service['code']))) { $forms[$name] = $form; } } } return $forms; }