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_Xml_Order extends Mage_GoogleCheckout_Model_Api_Xml_Abstract
00028 {
00029 protected function _getApiUrl()
00030 {
00031 $url = $this->_getBaseApiUrl();
00032 $url .= 'request/Merchant/'.Mage::getStoreConfig('google/checkout/merchant_id', $this->getStoreId());
00033 return $url;
00034 }
00035
00036 protected function _processGResponse($response)
00037 {
00038 if ($response[0]===200) {
00039 return true;
00040 } else {
00041 $xml = simplexml_load_string(html_entity_decode($response[1]));
00042 if (!$xml || !$xml->{'error-message'}) {
00043 return false;
00044 }
00045 Mage::throwException($this->__('Google Checkout: %s', (string)$xml->{'error-message'}));
00046 }
00047 }
00048
00049
00050
00051 public function authorize()
00052 {
00053 $GRequest = $this->getGRequest();
00054
00055 $postargs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
00056 <authorize-order xmlns=\"".$GRequest->schema_url.
00057 "\" google-order-number=\"". $this->getGoogleOrderNumber() . "\"/>";
00058
00059 $response = $GRequest->SendReq($GRequest->request_url,
00060 $GRequest->GetAuthenticationHeaders(), $postargs);
00061 return $this->_processGResponse($response);
00062 }
00063
00064 public function charge($amount)
00065 {
00066 $response = $this->getGRequest()
00067 ->SendChargeOrder($this->getGoogleOrderNumber(), $amount);
00068 return $this->_processGResponse($response);
00069 }
00070
00071 public function refund($amount, $reason, $comment='')
00072 {
00073 $response = $this->getGRequest()
00074 ->SendRefundOrder($this->getGoogleOrderNumber(), $amount, $reason, $comment);
00075 return $this->_processGResponse($response);
00076 }
00077
00078 public function cancel($reason, $comment='')
00079 {
00080 $response = $this->getGRequest()
00081 ->SendCancelOrder($this->getGoogleOrderNumber(), $reason, $comment);
00082 return $this->_processGResponse($response);
00083 }
00084
00085
00086
00087 public function process()
00088 {
00089 $response = $this->getGRequest()
00090 ->SendProcessOrder($this->getGoogleOrderNumber());
00091 return $this->_processGResponse($response);
00092 }
00093
00094 public function deliver($carrier, $trackingNo, $sendMail=true)
00095 {
00096 $response = $this->getGRequest()
00097 ->SendDeliverOrder($this->getGoogleOrderNumber(), $carrier, $trackingNo, $sendMail?'true':'false');
00098 return $this->_processGResponse($response);
00099 }
00100
00101 public function addTrackingData($carrier, $trackingNo)
00102 {
00103 $response = $this->getGRequest()
00104 ->SendTrackingData($this->getGoogleOrderNumber(), $carrier, $trackingNo);
00105 return $this->_processGResponse($response);
00106 }
00107
00108 public function shipItems($items, $sendMail=true)
00109 {
00110 $googleShipItems = array();
00111 foreach ($items as $item) {
00112 $googleShipItems[] = new GoogleShipItem($item);
00113 }
00114
00115 $response = $this->getGRequest()
00116 ->SendShipItems($this->getGoogleOrderNumber(), $googleShipItems, $sendMail?'true':'false');
00117 return $this->_processGResponse($response);
00118 }
00119
00120 public function backorderItems($items, $sendMail=true)
00121 {
00122 $response = $this->getGRequest()
00123 ->SendBackorderItems($this->getGoogleOrderNumber(), $items, $sendMail?'true':'false');
00124 return $this->_processGResponse($response);
00125 }
00126
00127 public function cancelItems($items, $reason, $comment='', $sendMail=true)
00128 {
00129 $response = $this->getGRequest()
00130 ->SendCancelItems($this->getGoogleOrderNumber(), $items, $reason, $comment, $sendMail?'true':'false');
00131 return $this->_processGResponse($response);
00132 }
00133
00134 public function returnItems($items, $sendMail=true)
00135 {
00136 $response = $this->getGRequest()
00137 ->SendReturnItems($this->getGoogleOrderNumber(), $items, $sendMail?'true':'false');
00138 return $this->_processGResponse($response);
00139 }
00140
00141 public function resetItems($items, $sendMail=true)
00142 {
00143 $response = $this->getGRequest()
00144 ->SendRResetItemsShippingInformation($this->getGoogleOrderNumber(), $items, $sendMail?'true':'false');
00145 return $this->_processGResponse($response);
00146 }
00147
00148
00149
00150 public function archive()
00151 {
00152 $response = $this->getGRequest()
00153 ->SendArchiveOrder($this->getGoogleOrderNumber());
00154 return $this->_processGResponse($response);
00155 }
00156
00157 public function unarchive()
00158 {
00159 $response = $this->getGRequest()
00160 ->SendUnarchiveOrder($this->getGoogleOrderNumber());
00161 return $this->_processGResponse($response);
00162 }
00163
00164 public function addOrderNumber($merchantOrder)
00165 {
00166 $response = $this->getGRequest()
00167 ->SendMerchantOrderNumber($this->getGoogleOrderNumber(), $merchantOrder);
00168 return $this->_processGResponse($response);
00169 }
00170
00171
00172 public function addBuyerMessage($message, $sendMail=true)
00173 {
00174 $response = $this->getGRequest()
00175 ->SendBuyerMessage($this->getGoogleOrderNumber(), $message, $sendMail?'true':'false');
00176 return $this->_processGResponse($response);
00177 }
00178 }