Public Member Functions | |
log ($text, $nl=true) | |
__ () | |
getMerchantId () | |
getMerchantKey () | |
getServerType () | |
getLocale () | |
getCurrency () | |
getGRequest () | |
getGResponse () | |
_call ($xml) | |
Protected Member Functions | |
_getBaseApiUrl () | |
_getApiUrl () | |
_getCallbackUrl () |
Definition at line 34 of file Abstract.php.
__ | ( | ) |
Definition at line 42 of file Abstract.php.
00043 { 00044 $args = func_get_args(); 00045 $expr = new Mage_Core_Model_Translate_Expr(array_shift($args), 'Mage_GoogleCheckout'); 00046 array_unshift($args, $expr); 00047 return Mage::app()->getTranslator()->translate($args); 00048 }
_call | ( | $ | xml | ) |
Definition at line 154 of file Abstract.php.
00155 { 00156 $auth = 'Basic '.base64_encode($this->getMerchantId().':'.$this->getMerchantKey()); 00157 00158 $headers = array( 00159 'Authorization: '.$auth, 00160 'Content-Type: application/xml;charset=UTF-8', 00161 'Accept: application/xml;charset=UTF-8', 00162 ); 00163 00164 $url = $this->_getApiUrl(); 00165 00166 $xml = '<?xml version="1.0" encoding="UTF-8"?>'."\r\n".$xml; 00167 00168 if (Mage::getStoreConfig('google/checkout/debug', $this->getStoreId())) { 00169 $debug = Mage::getModel('googlecheckout/api_debug'); 00170 $debug->setDir('out')->setUrl($url)->setRequestBody($xml)->save(); 00171 } 00172 00173 $http = new Varien_Http_Adapter_Curl(); 00174 $http->write('POST', $url, '1.1', $headers, $xml); 00175 $response = $http->read(); 00176 $response = preg_split('/^\r?$/m', $response, 2); 00177 $response = trim($response[1]); 00178 00179 if (!empty($debug)) { 00180 $debug->setResponseBody($response)->save(); 00181 } 00182 00183 $result = @simplexml_load_string($response); 00184 if (!$result) { 00185 $result = simplexml_load_string('<error><error-message>Invalid response from Google Checkout server</error-message></error>'); 00186 } 00187 if ($result->getName()=='error') { 00188 $this->setError($this->__('Google Checkout: %s', (string)$result->{'error-message'})); 00189 $this->setWarnings((array)$result->{'warning-messages'}); 00190 } else { 00191 $this->unsError()->unsWarnings(); 00192 } 00193 00194 $this->setResult($result); 00195 00196 return $result; 00197 }
_getApiUrl | ( | ) | [abstract, protected] |
_getBaseApiUrl | ( | ) | [protected] |
Definition at line 141 of file Abstract.php.
00142 { 00143 $url = 'https://'; 00144 if ($this->getServerType()=='sandbox') { 00145 $url .= 'sandbox.google.com/checkout/api/checkout/v2/'; 00146 } else { 00147 $url .= 'checkout.google.com/api/checkout/v2/'; 00148 } 00149 return $url; 00150 }
_getCallbackUrl | ( | ) | [protected] |
Definition at line 199 of file Abstract.php.
00200 { 00201 return Mage::getUrl('googlecheckout/api', array('_forced_secure'=>Mage::getStoreConfig('google/checkout/use_secure_callback_url', $this->getStoreId()))); 00202 }
getCurrency | ( | ) |
Definition at line 82 of file Abstract.php.
00083 { 00084 if (!$this->hasData('currency')) { 00085 $this->setData('currency', Mage::app()->getStore()->getBaseCurrencyCode()); 00086 //$this->setData('currency', $this->getLocale()=='en_US' ? 'USD' : 'GBP'); 00087 } 00088 return $this->getData('currency'); 00089 }
getGRequest | ( | ) |
Google Checkout Request instance
Definition at line 96 of file Abstract.php.
00097 { 00098 if (!$this->hasData('g_request')) { 00099 $this->setData('g_request', new GoogleRequest( 00100 $this->getMerchantId(), 00101 $this->getMerchantKey(), 00102 $this->getServerType(), 00103 $this->getCurrency() 00104 )); 00105 00106 //Setup the log file 00107 $logDir = Mage::getBaseDir('log'); 00108 $this->getData('g_request')->SetLogFiles( 00109 $logDir.DS.'googleerror.log', 00110 $logDir.DS.'googlemessage.log', 00111 L_ALL 00112 ); 00113 } 00114 return $this->getData('g_request'); 00115 }
getGResponse | ( | ) |
Google Checkout Response instance
Definition at line 122 of file Abstract.php.
00123 { 00124 if (!$this->hasData('g_response')) { 00125 $this->setData('g_response', new GoogleResponse( 00126 $this->getMerchantId(), 00127 $this->getMerchantKey() 00128 )); 00129 00130 //Setup the log file 00131 $logDir = Mage::getBaseDir('log'); 00132 $this->getData('g_response')->SetLogFiles( 00133 $logDir.DS.'googleerror.log', 00134 $logDir.DS.'googlemessage.log', 00135 L_ALL 00136 ); 00137 } 00138 return $this->getData('g_response'); 00139 }
getLocale | ( | ) |
Definition at line 74 of file Abstract.php.
00075 { 00076 if (!$this->hasData('locale')) { 00077 $this->setData('locale', Mage::getStoreConfig('google/checkout/locale', $this->getStoreId())); 00078 } 00079 return $this->getData('locale'); 00080 }
getMerchantId | ( | ) |
Definition at line 50 of file Abstract.php.
00051 { 00052 if (!$this->hasData('merchant_id')) { 00053 $this->setData('merchant_id', Mage::getStoreConfig('google/checkout/merchant_id', $this->getStoreId())); 00054 } 00055 return $this->getData('merchant_id'); 00056 }
getMerchantKey | ( | ) |
Definition at line 58 of file Abstract.php.
00059 { 00060 if (!$this->hasData('merchant_key')) { 00061 $this->setData('merchant_key', Mage::getStoreConfig('google/checkout/merchant_key', $this->getStoreId())); 00062 } 00063 return $this->getData('merchant_key'); 00064 }
getServerType | ( | ) |
Definition at line 66 of file Abstract.php.
00067 { 00068 if (!$this->hasData('server_type')) { 00069 $this->setData('server_type', Mage::getStoreConfig('google/checkout/sandbox', $this->getStoreId()) ? "sandbox" : ""); 00070 } 00071 return $this->getData('server_type'); 00072 }
log | ( | $ | text, | |
$ | nl = true | |||
) |
Definition at line 36 of file Abstract.php.
00037 { 00038 error_log(print_r($text,1).($nl?"\n":''), 3, Mage::getBaseDir('log').DS.'callback.log'); 00039 return $this; 00040 }