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_Xml_Order extends Mage_GoogleCheckout_Model_Api_Xml_Abstract
28: {
29: protected function _getApiUrl()
30: {
31: $url = $this->_getBaseApiUrl();
32: $url .= 'request/Merchant/'.Mage::getStoreConfig('google/checkout/merchant_id', $this->getStoreId());
33: return $url;
34: }
35:
36: protected function _processGResponse($response)
37: {
38: if ($response[0]===200) {
39: return true;
40: } else {
41: $xml = simplexml_load_string(html_entity_decode($response[1]));
42: if (!$xml || !$xml->{'error-message'}) {
43: return false;
44: }
45: Mage::throwException($this->__('Google Checkout: %s', (string)$xml->{'error-message'}));
46: }
47: }
48:
49:
50:
51: public function authorize()
52: {
53: $GRequest = $this->getGRequest();
54:
55: $postargs = '<?xml version="1.0" encoding="UTF-8"?>
56: <authorize-order xmlns="'
57: . $GRequest->schema_url
58: . '" google-order-number="'
59: . $this->getGoogleOrderNumber()
60: . '"/>';
61:
62: $response = $GRequest->SendReq($GRequest->request_url,
63: $GRequest->GetAuthenticationHeaders(), $postargs);
64: return $this->_processGResponse($response);
65: }
66:
67: public function charge($amount)
68: {
69: $response = $this->getGRequest()
70: ->SendChargeOrder($this->getGoogleOrderNumber(), $amount);
71: return $this->_processGResponse($response);
72: }
73:
74: public function refund($amount, $reason, $comment = '')
75: {
76: $response = $this->getGRequest()
77: ->SendRefundOrder($this->getGoogleOrderNumber(), $amount, $reason, $comment);
78: return $this->_processGResponse($response);
79: }
80:
81: public function cancel($reason, $comment = '')
82: {
83: $response = $this->getGRequest()
84: ->SendCancelOrder($this->getGoogleOrderNumber(), $reason, $comment);
85: return $this->_processGResponse($response);
86: }
87:
88:
89:
90: public function process()
91: {
92: $response = $this->getGRequest()
93: ->SendProcessOrder($this->getGoogleOrderNumber());
94: return $this->_processGResponse($response);
95: }
96:
97: public function deliver($carrier, $trackingNo, $sendMail = true)
98: {
99: $response = $this->getGRequest()
100: ->SendDeliverOrder($this->getGoogleOrderNumber(), $carrier, $trackingNo, $sendMail ? 'true' : 'false');
101: return $this->_processGResponse($response);
102: }
103:
104: public function addTrackingData($carrier, $trackingNo)
105: {
106: $response = $this->getGRequest()
107: ->SendTrackingData($this->getGoogleOrderNumber(), $carrier, $trackingNo);
108: return $this->_processGResponse($response);
109: }
110:
111: public function shipItems($items, $sendMail = true)
112: {
113: $googleShipItems = array();
114: foreach ($items as $item) {
115: $googleShipItems[] = new GoogleShipItem($item);
116: }
117:
118: $response = $this->getGRequest()
119: ->SendShipItems($this->getGoogleOrderNumber(), $googleShipItems, $sendMail ? 'true' : 'false');
120: return $this->_processGResponse($response);
121: }
122:
123: public function backorderItems($items, $sendMail = true)
124: {
125: $response = $this->getGRequest()
126: ->SendBackorderItems($this->getGoogleOrderNumber(), $items, $sendMail ? 'true' : 'false');
127: return $this->_processGResponse($response);
128: }
129:
130: public function cancelItems($items, $reason, $comment = '', $sendMail = true)
131: {
132: $response = $this->getGRequest()
133: ->SendCancelItems($this->getGoogleOrderNumber(), $items, $reason, $comment, $sendMail ? 'true' : 'false');
134: return $this->_processGResponse($response);
135: }
136:
137: public function returnItems($items, $sendMail = true)
138: {
139: $response = $this->getGRequest()
140: ->SendReturnItems($this->getGoogleOrderNumber(), $items, $sendMail ? 'true' : 'false');
141: return $this->_processGResponse($response);
142: }
143:
144: public function resetItems($items, $sendMail = true)
145: {
146: $response = $this->getGRequest()
147: ->SendRResetItemsShippingInformation($this->getGoogleOrderNumber(), $items, $sendMail ? 'true' : 'false');
148: return $this->_processGResponse($response);
149: }
150:
151:
152:
153: public function archive()
154: {
155: $response = $this->getGRequest()
156: ->SendArchiveOrder($this->getGoogleOrderNumber());
157: return $this->_processGResponse($response);
158: }
159:
160: public function unarchive()
161: {
162: $response = $this->getGRequest()
163: ->SendUnarchiveOrder($this->getGoogleOrderNumber());
164: return $this->_processGResponse($response);
165: }
166:
167: public function addOrderNumber($merchantOrder)
168: {
169: $response = $this->getGRequest()
170: ->SendMerchantOrderNumber($this->getGoogleOrderNumber(), $merchantOrder);
171: return $this->_processGResponse($response);
172: }
173:
174:
175: public function addBuyerMessage($message, $sendMail = true)
176: {
177: $response = $this->getGRequest()
178: ->SendBuyerMessage($this->getGoogleOrderNumber(), $message, $sendMail ? 'true' : 'false');
179: return $this->_processGResponse($response);
180: }
181: }
182: