Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_GoogleCheckout_ApiController
  • Mage_GoogleCheckout_Block_Adminhtml_Shipping_Applicable_Countries
  • Mage_GoogleCheckout_Block_Adminhtml_Shipping_Merchant
  • Mage_GoogleCheckout_Block_Form
  • Mage_GoogleCheckout_Block_Link
  • Mage_GoogleCheckout_Block_Redirect
  • Mage_GoogleCheckout_Helper_Data
  • Mage_GoogleCheckout_Model_Api
  • Mage_GoogleCheckout_Model_Api_Debug
  • Mage_GoogleCheckout_Model_Api_Xml_Abstract
  • Mage_GoogleCheckout_Model_Api_Xml_Calculate
  • Mage_GoogleCheckout_Model_Api_Xml_Callback
  • Mage_GoogleCheckout_Model_Api_Xml_Checkout
  • Mage_GoogleCheckout_Model_Api_Xml_Order
  • Mage_GoogleCheckout_Model_Mysql4_Api_Debug
  • Mage_GoogleCheckout_Model_Mysql4_Api_Debug_Collection
  • Mage_GoogleCheckout_Model_Mysql4_Notification
  • Mage_GoogleCheckout_Model_Mysql4_Setup
  • Mage_GoogleCheckout_Model_Mysql4_Tax
  • Mage_GoogleCheckout_Model_Notification
  • Mage_GoogleCheckout_Model_Observer
  • Mage_GoogleCheckout_Model_Payment
  • Mage_GoogleCheckout_Model_Resource_Api_Debug
  • Mage_GoogleCheckout_Model_Resource_Api_Debug_Collection
  • Mage_GoogleCheckout_Model_Resource_Notification
  • Mage_GoogleCheckout_Model_Resource_Setup
  • Mage_GoogleCheckout_Model_Resource_Tax
  • Mage_GoogleCheckout_Model_Shipping
  • Mage_GoogleCheckout_Model_Source_Checkout_Image
  • Mage_GoogleCheckout_Model_Source_Locale
  • Mage_GoogleCheckout_Model_Source_Shipping_Carrier
  • Mage_GoogleCheckout_Model_Source_Shipping_Category
  • Mage_GoogleCheckout_Model_Source_Shipping_Units
  • Mage_GoogleCheckout_Model_Source_Shipping_Virtual_Method
  • Mage_GoogleCheckout_Model_Source_Shipping_Virtual_Schedule
  • Mage_GoogleCheckout_RedirectController

Exceptions

  • Mage_GoogleCheckout_Exception
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_GoogleCheckout
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: set_include_path(get_include_path().PS.Mage::getBaseDir('lib').DS.'googlecheckout');
 28: 
 29: require_once('googleresponse.php');
 30: require_once('googlemerchantcalculations.php');
 31: require_once('googleresult.php');
 32: require_once('googlerequest.php');
 33: 
 34: abstract class Mage_GoogleCheckout_Model_Api_Xml_Abstract extends Varien_Object
 35: {
 36:     public function log($text, $nl=true)
 37:     {
 38:         error_log(print_r($text, 1) . ($nl ? "\n" : ''), 3, Mage::getBaseDir('log') . DS . 'callback.log');
 39:         return $this;
 40:     }
 41: 
 42:     public function __()
 43:     {
 44:         $args = func_get_args();
 45:         $expr = new Mage_Core_Model_Translate_Expr(array_shift($args), 'Mage_GoogleCheckout');
 46:         array_unshift($args, $expr);
 47:         return Mage::app()->getTranslator()->translate($args);
 48:     }
 49: 
 50:     public function getMerchantId()
 51:     {
 52:         if (!$this->hasData('merchant_id')) {
 53:             $this->setData('merchant_id', Mage::getStoreConfig('google/checkout/merchant_id', $this->getStoreId()));
 54:         }
 55:         return $this->getData('merchant_id');
 56:     }
 57: 
 58:     public function getMerchantKey()
 59:     {
 60:         if (!$this->hasData('merchant_key')) {
 61:             $this->setData('merchant_key', Mage::getStoreConfig('google/checkout/merchant_key', $this->getStoreId()));
 62:         }
 63:         return $this->getData('merchant_key');
 64:     }
 65: 
 66:     public function getServerType()
 67:     {
 68:         if (!$this->hasData('server_type')) {
 69:             $this->setData(
 70:                 'server_type',
 71:                 Mage::getStoreConfig('google/checkout/sandbox', $this->getStoreId()) ? "sandbox" : ""
 72:             );
 73:         }
 74:         return $this->getData('server_type');
 75:     }
 76: 
 77:     public function getLocale()
 78:     {
 79:         if (!$this->hasData('locale')) {
 80:             $this->setData('locale', Mage::getStoreConfig('google/checkout/locale', $this->getStoreId()));
 81:         }
 82:         return $this->getData('locale');
 83:     }
 84: 
 85:     public function getCurrency()
 86:     {
 87:         if (!$this->hasData('currency')) {
 88:             $this->setData('currency', Mage::app()->getStore()->getBaseCurrencyCode());
 89:             //$this->setData('currency', $this->getLocale()=='en_US' ? 'USD' : 'GBP');
 90:         }
 91:         return $this->getData('currency');
 92:     }
 93: 
 94:     /**
 95:      * Google Checkout Request instance
 96:      *
 97:      * @return GoogleRequest
 98:      */
 99:     public function getGRequest()
100:     {
101:         if (!$this->hasData('g_request')) {
102:             $this->setData('g_request', new GoogleRequest(
103:                 $this->getMerchantId(),
104:                 $this->getMerchantKey(),
105:                 $this->getServerType(),
106:                 $this->getCurrency()
107:             ));
108: 
109:             //Setup the log file
110:             $logDir = Mage::getBaseDir('log');
111:             $this->getData('g_request')->SetLogFiles(
112:                 $logDir . DS . 'googleerror.log',
113:                 $logDir . DS . 'googlemessage.log',
114:                 L_ALL
115:             );
116:         }
117:         return $this->getData('g_request');
118:     }
119: 
120:     /**
121:      * Google Checkout Response instance
122:      *
123:      * @return GoogleResponse
124:      */
125:     public function getGResponse()
126:     {
127:         if (!$this->hasData('g_response')) {
128:             $this->setData('g_response', new GoogleResponse(
129:                 $this->getMerchantId(),
130:                 $this->getMerchantKey()
131:             ));
132: 
133:             //Setup the log file
134:             $logDir = Mage::getBaseDir('log');
135:             $this->getData('g_response')->SetLogFiles(
136:                 $logDir . DS . 'googleerror.log',
137:                 $logDir . DS . 'googlemessage.log',
138:                 L_ALL
139:             );
140:         }
141:         return $this->getData('g_response');
142:     }
143: 
144:     protected function _getBaseApiUrl()
145:     {
146:         $url = 'https://';
147:         if ($this->getServerType()=='sandbox') {
148:             $url .= 'sandbox.google.com/checkout/api/checkout/v2/';
149:         } else {
150:             $url .= 'checkout.google.com/api/checkout/v2/';
151:         }
152:         return $url;
153:     }
154: 
155:     abstract protected function _getApiUrl();
156: 
157:     public function _call($xml)
158:     {
159:         $auth = 'Basic ' . base64_encode($this->getMerchantId() . ':' . $this->getMerchantKey());
160: 
161:         $headers = array(
162:             'Authorization: ' . $auth,
163:             'Content-Type: application/xml;charset=UTF-8',
164:             'Accept: application/xml;charset=UTF-8',
165:         );
166: 
167:         $url = $this->_getApiUrl();
168:         $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n" . $xml;
169: 
170:         $debugData = array('request' => $xml, 'dir' => 'out');
171: 
172:         try {
173:             $http = new Varien_Http_Adapter_Curl();
174:             $http->write('POST', $url, '1.1', $headers, $xml);
175:             $response = $http->read();
176:             $response = preg_split('/^\r?$/m', $response, 2);
177:             $response = trim($response[1]);
178:             $debugData['result'] = $response;
179:             $http->close();
180:         }
181:         catch (Exception $e) {
182:             $debugData['result'] = array('error' => $e->getMessage(), 'code' => $e->getCode());
183:             $this->getApi()->debugData($debugData);
184:             throw $e;
185:         }
186: 
187:         $this->getApi()->debugData($debugData);
188:         $result = @simplexml_load_string($response);
189:         if (!$result) {
190:             $result = simplexml_load_string(
191:                 '<error><error-message>Invalid response from Google Checkout server</error-message></error>'
192:             );
193:         }
194:         if ($result->getName() == 'error') {
195:             $this->setError($this->__('Google Checkout: %s', (string)$result->{'error-message'}));
196:             $this->setWarnings((array)$result->{'warning-messages'});
197:         } else {
198:             $this->unsError()->unsWarnings();
199:         }
200: 
201:         $this->setResult($result);
202: 
203:         return $result;
204:     }
205: 
206:     protected function _getCallbackUrl()
207:     {
208:         return Mage::getUrl(
209:             'googlecheckout/api',
210:             array('_forced_secure'=>Mage::getStoreConfig('google/checkout/use_secure_callback_url',$this->getStoreId()))
211:         );
212:     }
213: 
214:     /**
215:      * Recalculate amount to store currency
216:      *
217:      * @param float $amount
218:      * @param Mage_Sales_Model_Quote $quote
219:      * @return float
220:      */
221:     protected function _reCalculateToStoreCurrency($amount, $quote)
222:     {
223:         if ($quote->getQuoteCurrencyCode() != $quote->getBaseCurrencyCode()) {
224:             $amount = $amount * $quote->getStoreToQuoteRate();
225:             $amount = Mage::app()->getStore()->roundPrice($amount);
226:         }
227:         return $amount;
228:     }
229: 
230:     /**
231:      * Get Tax Class for Shipping option
232:      *
233:      * @param Mage_Sales_Model_Quote $quote
234:      * @return mixed
235:      */
236:     protected function _getTaxClassForShipping($quote)
237:     {
238:         return Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, $quote->getStoreId());
239:     }
240: }
241: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0