PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/magento/app/code/core/Mage/GoogleCheckout/Model/Api.php

https://bitbucket.org/jit_bec/shopifine
PHP | 231 lines | 152 code | 30 blank | 49 comment | 2 complexity | ee8d41d87cc19af5a1ea38892191f272 MD5 | raw file
Possible License(s): LGPL-3.0
  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. class Mage_GoogleCheckout_Model_Api extends Varien_Object
  27. {
  28. /**
  29. * Fields that should be replaced in debug with '***'
  30. *
  31. * @var array
  32. */
  33. protected $_debugReplacePrivateDataKeys = array();
  34. protected function _getApi($area)
  35. {
  36. $api = Mage::getModel('googlecheckout/api_xml_' . $area)->setStoreId($this->getStoreId());
  37. $api->setApi($this);
  38. return $api;
  39. }
  40. // CHECKOUT
  41. public function checkout(Mage_Sales_Model_Quote $quote)
  42. {
  43. $api = $this->_getApi('checkout')
  44. ->setQuote($quote)
  45. ->checkout();
  46. return $api;
  47. }
  48. // FINANCIAL COMMANDS
  49. public function authorize($gOrderId)
  50. {
  51. $api = $this->_getApi('order')
  52. ->setGoogleOrderNumber($gOrderId)
  53. ->authorize();
  54. return $api;
  55. }
  56. public function charge($gOrderId, $amount)
  57. {
  58. $api = $this->_getApi('order')
  59. ->setGoogleOrderNumber($gOrderId)
  60. ->charge($amount);
  61. return $api;
  62. }
  63. public function refund($gOrderId, $amount, $reason, $comment = '')
  64. {
  65. $api = $this->_getApi('order')
  66. ->setGoogleOrderNumber($gOrderId)
  67. ->refund($amount, $reason, $comment);
  68. return $api;
  69. }
  70. public function cancel($gOrderId, $reason, $comment = '')
  71. {
  72. $api = $this->_getApi('order')
  73. ->setGoogleOrderNumber($gOrderId)
  74. ->cancel($reason, $comment);
  75. return $api;
  76. }
  77. // FULFILLMENT COMMANDS (ORDER BASED)
  78. public function process($gOrderId)
  79. {
  80. $api = $this->_getApi('order')
  81. ->setGoogleOrderNumber($gOrderId)
  82. ->process();
  83. return $api;
  84. }
  85. public function deliver($gOrderId, $carrier, $trackingNo, $sendMail = true)
  86. {
  87. $gCarriers = array('dhl' => 'DHL', 'fedex' => 'FedEx', 'ups' => 'UPS', 'usps' => 'USPS');
  88. $carrier = strtolower($carrier);
  89. $carrier = isset($gCarriers[$carrier]) ? $gCarriers[$carrier] : 'Other';
  90. $api = $this->_getApi('order')
  91. ->setGoogleOrderNumber($gOrderId)
  92. ->deliver($carrier, $trackingNo, $sendMail);
  93. return $api;
  94. }
  95. public function addTrackingData($gOrderId, $carrier, $trackingNo)
  96. {
  97. $api = $this->_getApi('order')
  98. ->setGoogleOrderNumber($gOrderId)
  99. ->addTrackingData($carrier, $trackingNo);
  100. return $api;
  101. }
  102. // FULFILLMENT COMMANDS (ITEM BASED)
  103. public function shipItems($gOrderId, array $items)
  104. {
  105. $api = $this->_getApi('order')
  106. ->setGoogleOrderNumber($gOrderId)
  107. ->shipItems($items);
  108. return $api;
  109. }
  110. public function backorderItems()
  111. {
  112. $api = $this->_getApi('order')
  113. ->setOrder($order)
  114. ->setItems($items)
  115. ->shipItems();
  116. return $api;
  117. }
  118. public function returnItems()
  119. {
  120. $api = $this->_getApi('order')
  121. ->setOrder($order)
  122. ->setItems($items)
  123. ->shipItems();
  124. return $api;
  125. }
  126. public function cancelItems()
  127. {
  128. $api = $this->_getApi('order')
  129. ->setOrder($order)
  130. ->setItems($items)
  131. ->shipItems();
  132. return $api;
  133. }
  134. public function resetItemsShippingInformation()
  135. {
  136. }
  137. public function addMerchantOrderNumber()
  138. {
  139. }
  140. public function sendBuyerMessage()
  141. {
  142. $api = $this->_getApi('order')
  143. ->setOrder($order)
  144. ->setItems($items)
  145. ->shipItems();
  146. return $api;
  147. }
  148. // OTHER ORDER COMMANDS
  149. public function archiveOrder()
  150. {
  151. $api = $this->_getApi('order')
  152. ->setOrder($order)
  153. ->setItems($items)
  154. ->shipItems();
  155. return $api;
  156. }
  157. public function unarchiveOrder()
  158. {
  159. $api = $this->_getApi('order')
  160. ->setOrder($order)
  161. ->setItems($items)
  162. ->shipItems();
  163. return $api;
  164. }
  165. // WEB SERVICE SERVER PROCEDURES
  166. public function processCallback()
  167. {
  168. $api = $this->_getApi('callback')->process();
  169. return $api;
  170. }
  171. /**
  172. * @deprecated after 1.4.1.0
  173. *
  174. */
  175. public function processBeacon(){}
  176. /**
  177. * Log debug data to file
  178. *
  179. * @param mixed $debugData
  180. */
  181. public function debugData($debugData)
  182. {
  183. if ($this->getDebugFlag()) {
  184. Mage::getModel('core/log_adapter', 'payment_googlecheckout.log')
  185. ->setFilterDataKeys($this->_debugReplacePrivateDataKeys)
  186. ->log($debugData);
  187. }
  188. }
  189. /**
  190. * Define if debugging is enabled
  191. *
  192. * @return bool
  193. */
  194. public function getDebugFlag()
  195. {
  196. if (!$this->hasData('debug_flag')) {
  197. $this->setData('debug_flag', Mage::getStoreConfig('google/checkout/debug', $this->getStoreId()));
  198. }
  199. return $this->getData('debug_flag');
  200. }
  201. }