1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: class Mage_GoogleCheckout_Model_Api extends Varien_Object
28: {
29: 30: 31: 32: 33:
34: protected $_debugReplacePrivateDataKeys = array();
35:
36: protected function _getApi($area)
37: {
38: $api = Mage::getModel('googlecheckout/api_xml_' . $area)->setStoreId($this->getStoreId());
39: $api->setApi($this);
40: return $api;
41: }
42:
43:
44: public function checkout(Mage_Sales_Model_Quote $quote)
45: {
46: $api = $this->_getApi('checkout')
47: ->setQuote($quote)
48: ->checkout();
49: return $api;
50: }
51:
52:
53: public function authorize($gOrderId)
54: {
55: $api = $this->_getApi('order')
56: ->setGoogleOrderNumber($gOrderId)
57: ->authorize();
58: return $api;
59: }
60:
61: public function charge($gOrderId, $amount)
62: {
63: $api = $this->_getApi('order')
64: ->setGoogleOrderNumber($gOrderId)
65: ->charge($amount);
66: return $api;
67: }
68:
69: public function refund($gOrderId, $amount, $reason, $comment = '')
70: {
71: $api = $this->_getApi('order')
72: ->setGoogleOrderNumber($gOrderId)
73: ->refund($amount, $reason, $comment);
74: return $api;
75: }
76:
77: public function cancel($gOrderId, $reason, $comment = '')
78: {
79: $api = $this->_getApi('order')
80: ->setGoogleOrderNumber($gOrderId)
81: ->cancel($reason, $comment);
82: return $api;
83: }
84:
85:
86:
87: public function process($gOrderId)
88: {
89: $api = $this->_getApi('order')
90: ->setGoogleOrderNumber($gOrderId)
91: ->process();
92: return $api;
93: }
94:
95: public function deliver($gOrderId, $carrier, $trackingNo, $sendMail = true)
96: {
97: $gCarriers = array('dhl' => 'DHL', 'fedex' => 'FedEx', 'ups' => 'UPS', 'usps' => 'USPS');
98: $carrier = strtolower($carrier);
99: $carrier = isset($gCarriers[$carrier]) ? $gCarriers[$carrier] : 'Other';
100:
101: $api = $this->_getApi('order')
102: ->setGoogleOrderNumber($gOrderId)
103: ->deliver($carrier, $trackingNo, $sendMail);
104: return $api;
105: }
106:
107: public function addTrackingData($gOrderId, $carrier, $trackingNo)
108: {
109: $api = $this->_getApi('order')
110: ->setGoogleOrderNumber($gOrderId)
111: ->addTrackingData($carrier, $trackingNo);
112: return $api;
113: }
114:
115:
116:
117: public function shipItems($gOrderId, array $items)
118: {
119: $api = $this->_getApi('order')
120: ->setGoogleOrderNumber($gOrderId)
121: ->shipItems($items);
122: return $api;
123: }
124:
125: public function backorderItems()
126: {
127: $api = $this->_getApi('order')
128: ->setOrder($order)
129: ->setItems($items)
130: ->shipItems();
131: return $api;
132: }
133:
134: public function returnItems()
135: {
136: $api = $this->_getApi('order')
137: ->setOrder($order)
138: ->setItems($items)
139: ->shipItems();
140: return $api;
141: }
142:
143: public function cancelItems()
144: {
145: $api = $this->_getApi('order')
146: ->setOrder($order)
147: ->setItems($items)
148: ->shipItems();
149: return $api;
150: }
151:
152: public function resetItemsShippingInformation()
153: {
154:
155: }
156:
157: public function addMerchantOrderNumber()
158: {
159:
160: }
161:
162: public function sendBuyerMessage()
163: {
164: $api = $this->_getApi('order')
165: ->setOrder($order)
166: ->setItems($items)
167: ->shipItems();
168: return $api;
169: }
170:
171:
172:
173: public function archiveOrder()
174: {
175: $api = $this->_getApi('order')
176: ->setOrder($order)
177: ->setItems($items)
178: ->shipItems();
179: return $api;
180: }
181:
182: public function unarchiveOrder()
183: {
184: $api = $this->_getApi('order')
185: ->setOrder($order)
186: ->setItems($items)
187: ->shipItems();
188: return $api;
189: }
190:
191:
192:
193: public function processCallback()
194: {
195: $api = $this->_getApi('callback')->process();
196: return $api;
197: }
198:
199: 200: 201: 202:
203: public function processBeacon(){}
204:
205: 206: 207: 208: 209:
210: public function debugData($debugData)
211: {
212: if ($this->getDebugFlag()) {
213: Mage::getModel('core/log_adapter', 'payment_googlecheckout.log')
214: ->setFilterDataKeys($this->_debugReplacePrivateDataKeys)
215: ->log($debugData);
216: }
217: }
218:
219: 220: 221: 222: 223:
224: public function getDebugFlag()
225: {
226: if (!$this->hasData('debug_flag')) {
227: $this->setData('debug_flag', Mage::getStoreConfig('google/checkout/debug', $this->getStoreId()));
228: }
229: return $this->getData('debug_flag');
230: }
231: }
232: