public function getIntlRates($zipOrigin, $countryCode, $value, $pounds = 0, $ounces = 0, $commercial = 'N', $mailType = 'Package', $container = 'VARIABLE', $size = "REGULAR", $machinable = 'true', $width = 10, $length = 15, $height = 10, $girth = 0) { $rateReq = 'IntlRateV2Request USERID="' . $this->_uspsUsername . '"'; $countryName = Cart66Common::getCountryName($countryCode); $weight = $this->_convertToPoundOunces($pounds); $pounds = $weight->pounds; $ounces += $weight->ounces; $data = array('Revision' => '4', 'Package ID="1"' => array('Pounds' => $pounds, 'Ounces' => $ounces, 'Machinable' => $machinable, 'MailType' => $mailType, 'ValueOfContents' => $value, 'Country' => $countryName, 'Container' => $container, 'Size' => $size, 'Width' => $width, 'Length' => $length, 'Height' => $height, 'Girth' => $girth, 'OriginZip' => $zipOrigin)); $xml = Cart66Common::arrayToXml($data, $rateReq); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] USPS Intl rate request xml:\n{$xml}"); $url = 'http://production.shippingapis.com/ShippingAPI.dll?API=IntlRateV2&Xml=' . urlencode($xml); $result = Cart66Common::curl($url); // Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] USPS Result:\n" . $result); $this->_parseIntlResult($result); return $this->_rates; }
/** * Pay a spreedly invoice. The invoice token is required for payment. * Returns the paid invoice token. * * @param mixed $paymentMethod Either "on-file" or a SpreedlyCreditCard object * @param string $invoiceToken * @return string The invoice token that was paid. * @throws SpreedlyException on failure */ public function pay($paymentMethod, $invoiceToken = null) { $payment = array('account-type' => 'on-file'); if (get_class($paymentMethod) == 'SpreedlyCreditCard') { if (!$paymentMethod->validate()) { $errorDetails = print_r($paymentMethod->getErrors(), true); throw new SpreedlyException('Spreedly Payment: Invalid credit card data trying to be used to pay a spreedly invoice: ' . $errorDetails, 66001); } $cardData = $paymentMethod->getCardData(); $payment = array('account-type' => 'credit-card', 'credit-card' => $cardData); } // Set invoice token if provided if (isset($invoiceToken)) { $this->setToken($invoiceToken); } // Make sure there is an invoice token before trying to process the payment if (empty($this->_invoiceToken)) { throw new SpreedlyException('Spreedly Payment: Trying to pay spreedly invoice without a valid invoice token', 66002); } $xml = Cart66Common::arrayToXml($payment, 'payment'); $result = SpreedlyCommon::curlRequest('/invoices/' . $this->_invoiceToken . '/pay.xml', "put", $xml); $responseCode = $result->code; if (!empty($responseCode)) { if ($responseCode != 200) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Spreedly Invoice Payment: Failed to pay invoice. \n Code: " . $responseCode . "\nResponse: " . $result->response . "\n Payment XML:\n{$xml}"); $errorResponse = $result->response; throw new SpreedlyException("Spreedly Payment: Failed to pay spreedly invoice. \n\n{$errorResponse}", $responseCode); } try { $invoice = new SimpleXMLElement($result->response); $this->_invoiceToken = $invoice->token; } catch (Exception $e) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] SpreedlyInvoice pay(): \n Unable to create SimpleXmlElement from result response: " . $result->response); } } }
/** * All fields are optional - any field that is not provided will not be updated. */ public static function updateRemoteAccount($customerId, $subscriberData) { $subscriberXml = Cart66Common::arrayToXml($subscriberData, 'subscriber'); $result = SpreedlyCommon::curlRequest("/subscribers/{$customerId}.xml", "put", $subscriberXml); if ($result->code != '200') { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Spreedly Subscriber: Account information could not be updated. " . $result->response . "\nCode: {$result->code}"); throw new SpreedlyException('Spreedly Subscriber: Account information could not be updated.', $result->code); } }