00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 class Mage_GoogleCheckout_Model_Api extends Varien_Object
00028 {
00029 protected function _getApi($area)
00030 {
00031 $api = Mage::getModel('googlecheckout/api_xml_'.$area)->setStoreId($this->getStoreId());
00032 $api->setApi($this);
00033 return $api;
00034 }
00035
00036
00037 public function checkout(Mage_Sales_Model_Quote $quote)
00038 {
00039 $api = $this->_getApi('checkout')
00040 ->setQuote($quote)
00041 ->checkout();
00042 return $api;
00043 }
00044
00045
00046 public function authorize($gOrderId)
00047 {
00048 $api = $this->_getApi('order')
00049 ->setGoogleOrderNumber($gOrderId)
00050 ->authorize();
00051 return $api;
00052 }
00053
00054 public function charge($gOrderId, $amount)
00055 {
00056 $api = $this->_getApi('order')
00057 ->setGoogleOrderNumber($gOrderId)
00058 ->charge($amount);
00059 return $api;
00060 }
00061
00062 public function refund($gOrderId, $amount, $reason, $comment='')
00063 {
00064 $api = $this->_getApi('order')
00065 ->setGoogleOrderNumber($gOrderId)
00066 ->refund($amount, $reason, $comment);
00067 return $api;
00068 }
00069
00070 public function cancel($gOrderId, $reason, $comment='')
00071 {
00072 $api = $this->_getApi('order')
00073 ->setGoogleOrderNumber($gOrderId)
00074 ->cancel($reason, $comment);
00075 return $api;
00076 }
00077
00078
00079
00080 public function process($gOrderId)
00081 {
00082 $api = $this->_getApi('order')
00083 ->setGoogleOrderNumber($gOrderId)
00084 ->process();
00085 return $api;
00086 }
00087
00088 public function deliver($gOrderId, $carrier, $trackingNo, $sendMail=true)
00089 {
00090 $gCarriers = array('dhl'=>'DHL', 'fedex'=>'FedEx', 'ups'=>'UPS', 'usps'=>'USPS');
00091 $carrier = strtolower($carrier);
00092 $carrier = isset($gCarriers[$carrier]) ? $gCarriers[$carrier] : 'Other';
00093
00094 $api = $this->_getApi('order')
00095 ->setGoogleOrderNumber($gOrderId)
00096 ->deliver($carrier, $trackingNo, $sendMail);
00097 return $api;
00098 }
00099
00100 public function addTrackingData($gOrderId, $carrier, $trackingNo)
00101 {
00102 $api = $this->_getApi('order')
00103 ->setGoogleOrderNumber($gOrderId)
00104 ->addTrackingData($carrier, $trackingNo);
00105 return $api;
00106 }
00107
00108
00109
00110 public function shipItems($gOrderId, array $items)
00111 {
00112 $api = $this->_getApi('order')
00113 ->setGoogleOrderNumber($gOrderId)
00114 ->shipItems($items);
00115 return $api;
00116 }
00117
00118 public function backorderItems()
00119 {
00120 $api = $this->_getApi('order')
00121 ->setOrder($order)
00122 ->setItems($items)
00123 ->shipItems();
00124 return $api;
00125 }
00126
00127 public function returnItems()
00128 {
00129 $api = $this->_getApi('order')
00130 ->setOrder($order)
00131 ->setItems($items)
00132 ->shipItems();
00133 return $api;
00134 }
00135
00136 public function cancelItems()
00137 {
00138 $api = $this->_getApi('order')
00139 ->setOrder($order)
00140 ->setItems($items)
00141 ->shipItems();
00142 return $api;
00143 }
00144
00145 public function resetItemsShippingInformation()
00146 {
00147
00148 }
00149
00150 public function addMerchantOrderNumber()
00151 {
00152
00153 }
00154
00155 public function sendBuyerMessage()
00156 {
00157 $api = $this->_getApi('order')
00158 ->setOrder($order)
00159 ->setItems($items)
00160 ->shipItems();
00161 return $api;
00162 }
00163
00164
00165
00166 public function archiveOrder()
00167 {
00168 $api = $this->_getApi('order')
00169 ->setOrder($order)
00170 ->setItems($items)
00171 ->shipItems();
00172 return $api;
00173 }
00174
00175 public function unarchiveOrder()
00176 {
00177 $api = $this->_getApi('order')
00178 ->setOrder($order)
00179 ->setItems($items)
00180 ->shipItems();
00181 return $api;
00182 }
00183
00184
00185
00186 public function processCallback()
00187 {
00188 $api = $this->_getApi('callback')->process();
00189 return $api;
00190 }
00191
00192 public function processBeacon()
00193 {
00194 $debug = Mage::getModel('googlecheckout/api_debug')->setDir('in')
00195 ->setUrl('googlecheckout/api/beacon')
00196 ->setRequestBody($_SERVER['QUERY_STRING'])
00197 ->save();
00198 }
00199 }