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_Callback extends Mage_GoogleCheckout_Model_Api_Xml_Abstract
00028 {
00029 public function process()
00030 {
00031
00032 $xmlResponse = isset($GLOBALS['HTTP_RAW_POST_DATA']) ?
00033 $GLOBALS['HTTP_RAW_POST_DATA'] : file_get_contents("php://input");
00034 if (get_magic_quotes_gpc()) {
00035 $xmlResponse = stripslashes($xmlResponse);
00036 }
00037
00038 #$this->log($xmlResponse);
00039 $debug = Mage::getModel('googlecheckout/api_debug')->setDir('in')
00040 ->setUrl('process')
00041 ->setRequestBody($xmlResponse)
00042 ->save();
00043
00044 if (empty($xmlResponse)) {
00045 return false;
00046 }
00047
00048 list($root, $data) = $this->getGResponse()->GetParsedXML($xmlResponse);
00049
00050 $debug->setUrl($root)->save();
00051
00052 $this->getGResponse()->SetMerchantAuthentication($this->getMerchantId(), $this->getMerchantKey());
00053 $status = $this->getGResponse()->HttpAuthentication();
00054
00055 if (!$status || empty($data[$root])) {
00056 exit;
00057 }
00058
00059 $this->setRootName($root)->setRoot($data[$root]);
00060
00061 $this->getGResponse()->setSerialNumber($this->getData('root/serial-number'));
00062
00063 $method = '_response'.uc_words($root, '', '-');
00064 if (method_exists($this, $method)) {
00065 ob_start();
00066
00067 try {
00068 $this->$method();
00069 } catch (Exception $e) {
00070 $this->getGResponse()->log->logError($e->getMessage());
00071 }
00072
00073 $response = ob_get_flush();
00074 #$this->log($response);
00075 $debug->setResponseBody($response)->save();
00076 } else {
00077 $this->getGResponse()->SendBadRequestStatus("Invalid or not supported Message");
00078 }
00079
00080 return $this;
00081 }
00082
00083 protected function _getApiUrl()
00084 {
00085 return null;
00086 }
00087
00088 protected function getGoogleOrderNumber()
00089 {
00090 return $this->getData('root/google-order-number/VALUE');
00091 }
00092
00093 protected function _responseRequestReceived()
00094 {
00095
00096 }
00097
00098 protected function _responseError()
00099 {
00100
00101 }
00102
00103 protected function _responseDiagnosis()
00104 {
00105
00106 }
00107
00108 protected function _responseCheckoutRedirect()
00109 {
00110
00111 }
00112
00113 protected function _responseMerchantCalculationCallback()
00114 {
00115 $merchantCalculations = new GoogleMerchantCalculations($this->getCurrency());
00116
00117 $quoteId = $this->getData('root/shopping-cart/merchant-private-data/quote-id/VALUE');
00118 $quote = Mage::getModel('sales/quote')->load($quoteId);
00119
00120 $billingAddress = $quote->getBillingAddress();
00121 $address = $quote->getShippingAddress();
00122
00123 $googleAddress = $this->getData('root/calculate/addresses/anonymous-address');
00124
00125 $googleAddresses = array();
00126 if ( isset( $googleAddress['id'] ) ) {
00127 $googleAddresses[] = $googleAddress;
00128 } else {
00129 $googleAddresses = $googleAddress;
00130 }
00131
00132 $methods = Mage::getStoreConfig('google/checkout_shipping_merchant/allowed_methods', $this->getStoreId());
00133 $methods = unserialize($methods);
00134 $limitCarrier = array();
00135 foreach ($methods['method'] as $method) {
00136 if ($method) {
00137 list($carrierCode, $methodCode) = explode('/', $method);
00138 $limitCarrier[] = $carrierCode;
00139 }
00140 }
00141
00142 foreach($googleAddresses as $googleAddress) {
00143 $addressId = $googleAddress['id'];
00144
00145
00146 $regionCode = $googleAddress['region']['VALUE'];
00147 $countryCode = $googleAddress['country-code']['VALUE'];
00148 $regionModel = Mage::getModel('directory/region')->loadByCode($regionCode, $countryCode);
00149 $regionId = $regionModel->getId();
00150
00151 $address->setCountryId($countryCode)
00152 ->setRegion($regionCode)
00153 ->setRegionId($regionId)
00154 ->setCity($googleAddress['city']['VALUE'])
00155 ->setPostcode($googleAddress['postal-code']['VALUE'])
00156 ->setLimitCarrier($limitCarrier);
00157 $billingAddress->setCountryId($countryCode)
00158 ->setRegion($regionCode)
00159 ->setRegionId($regionId)
00160 ->setCity($googleAddress['city']['VALUE'])
00161 ->setPostcode($googleAddress['postal-code']['VALUE'])
00162 ->setLimitCarrier($limitCarrier);
00163
00164 $address->setCollectShippingRates(true)->collectShippingRates();
00165
00166 if ($gRequestMethods = $this->getData('root/calculate/shipping/method')) {
00167 $carriers = array();
00168 $errors = array();
00169 foreach (Mage::getStoreConfig('carriers', $this->getStoreId()) as $carrierCode=>$carrierConfig) {
00170 if (!isset($carrierConfig['title'])) {
00171 continue;
00172 }
00173 $title = $carrierConfig['title'];
00174 foreach ($gRequestMethods as $method) {
00175 $methodName = is_array($method) ? $method['name'] : $method;
00176 if ($title && $method && strpos($methodName, $title)===0) {
00177 $carriers[$carrierCode] = $title;
00178 $errors[$title] = true;
00179 }
00180 }
00181 }
00182
00183 $result = Mage::getModel('shipping/shipping')
00184 ->collectRatesByAddress($address, array_keys($carriers))
00185 ->getResult();
00186
00187 $rates = array();
00188 $rateCodes = array();
00189 foreach ($result->getAllRates() as $rate) {
00190 if ($rate instanceof Mage_Shipping_Model_Rate_Result_Error) {
00191 $errors[$rate->getCarrierTitle()] = 1;
00192 } else {
00193 $k = $rate->getCarrierTitle().' - '.$rate->getMethodTitle();
00194
00195 if ($address->getFreeShipping()) {
00196 $price = 0;
00197 } else {
00198 $price = $rate->getPrice();
00199 }
00200
00201 if ($price) {
00202 $price = Mage::helper('tax')->getShippingPrice($price, false, $address);
00203 }
00204
00205 $rates[$k] = $price;
00206 $rateCodes[$k] = $rate->getCarrier() . '_' . $rate->getMethod();
00207 unset($errors[$rate->getCarrierTitle()]);
00208 }
00209 }
00210
00211 foreach ($gRequestMethods as $method) {
00212 $methodName = is_array($method) ? $method['name'] : $method;
00213 $result = new GoogleResult($addressId);
00214
00215 if (!empty($errors)) {
00216 $continue = false;
00217 foreach ($errors as $carrier=>$dummy) {
00218 if (strpos($methodName, $carrier)===0) {
00219 $result->SetShippingDetails($methodName, 0, "false");
00220 $merchantCalculations->AddResult($result);
00221 $continue = true;
00222 break;
00223 }
00224 }
00225 if ($continue) {
00226 continue;
00227 }
00228 }
00229
00230 if (isset($rates[$methodName])) {
00231 if ($this->getData('root/calculate/tax/VALUE')=='true') {
00232 $address->setShippingMethod($rateCodes[$methodName]);
00233
00234 $address->setCollectShippingRates(true)->collectTotals();
00235 $billingAddress->setCollectShippingRates(true)->collectTotals();
00236
00237 $taxAmount = $address->getTaxAmount();
00238 $taxAmount += $billingAddress->getTaxAmount();
00239
00240 $result->setTaxDetails($taxAmount);
00241 }
00242
00243 $result->SetShippingDetails($methodName, $rates[$methodName], "true");
00244 $merchantCalculations->AddResult($result);
00245 }
00246 }
00247 } elseif ($this->getData('root/calculate/tax/VALUE')=='true') {
00248 $address->setShippingMethod(null);
00249
00250 $address->setCollectShippingRates(true)->collectTotals();
00251 $billingAddress->setCollectShippingRates(true)->collectTotals();
00252
00253 $taxAmount = $address->getTaxAmount();
00254 $taxAmount += $billingAddress->getTaxAmount();
00255
00256 $result = new GoogleResult($addressId);
00257 $result->setTaxDetails($taxAmount);
00258 $merchantCalculations->addResult($result);
00259 }
00260 }
00261
00262 $this->getGResponse()->ProcessMerchantCalculations($merchantCalculations);
00263 }
00264
00265 protected function _responseNewOrderNotification()
00266 {
00267 $this->getGResponse()->SendAck();
00268
00269
00270
00271 $orders = Mage::getModel('sales/order')->getCollection()
00272 ->addAttributeToFilter('ext_order_id', $this->getGoogleOrderNumber());
00273
00274 if (count($orders)) {
00275 return;
00276 }
00277
00278
00279
00280 $quoteId = $this->getData('root/shopping-cart/merchant-private-data/quote-id/VALUE');
00281 $quote = Mage::getModel('sales/quote')->load($quoteId);
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 $billing = $this->_importGoogleAddress($this->getData('root/buyer-billing-address'));
00294 $quote->setBillingAddress($billing);
00295
00296 $shipping = $this->_importGoogleAddress($this->getData('root/buyer-shipping-address'));
00297 $quote->setShippingAddress($shipping);
00298
00299 $quote->collectTotals();
00300
00301 $this->_importGoogleTotals($quote->getShippingAddress());
00302
00303
00304
00305 $convertQuote = Mage::getSingleton('sales/convert_quote');
00306
00307 $order = $convertQuote->toOrder($quote);
00308
00309 if ($quote->isVirtual()) {
00310 $convertQuote->addressToOrder($quote->getBillingAddress(), $order);
00311 } else {
00312 $convertQuote->addressToOrder($quote->getShippingAddress(), $order);
00313 }
00314
00315
00316 $order->setExtOrderId($this->getGoogleOrderNumber());
00317 $order->setExtCustomerId($this->getData('root/buyer-id/VALUE'));
00318
00319 if (!$order->getCustomerEmail()) {
00320 $order->setCustomerEmail($billing->getEmail())
00321 ->setCustomerPrefix($billing->getPrefix())
00322 ->setCustomerFirstname($billing->getFirstname())
00323 ->setCustomerMiddlename($billing->getMiddlename())
00324 ->setCustomerLastname($billing->getLastname())
00325 ->setCustomerSuffix($billing->getSuffix())
00326 ;
00327 }
00328
00329 $order->setBillingAddress($convertQuote->addressToOrderAddress($quote->getBillingAddress()));
00330 if (!$quote->isVirtual()) {
00331 $order->setShippingAddress($convertQuote->addressToOrderAddress($quote->getShippingAddress()));
00332 }
00333 #$order->setPayment($convertQuote->paymentToOrderPayment($quote->getPayment()));
00334
00335 foreach ($quote->getAllItems() as $item) {
00336 $order->addItem($convertQuote->itemToOrderItem($item));
00337 }
00338
00339 $payment = Mage::getModel('sales/order_payment')->setMethod('googlecheckout');
00340 $order->setPayment($payment);
00341 $order->setCanShipPartiallyItem(false);
00342
00343 $emailAllowed = ($this->getData('root/buyer-marketing-preferences/email-allowed/VALUE')==='true');
00344
00345 $order->addStatusToHistory(
00346 $order->getStatus(),
00347 $this->__('Google Order Number: %s', '<strong>'.$this->getGoogleOrderNumber()).'</strong>'.
00348 '<br />'.
00349 $this->__('Google Buyer Id: %s', '<strong>'.$this->getData('root/buyer-id/VALUE').'</strong>').
00350 '<br />'.
00351 $this->__('Is Buyer Willing To Receive Marketing E-Mails: %s', '<strong>' . ($emailAllowed ? $this->__('Yes') : $this->__('No')) . '</strong>')
00352 );
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362 #ob_start(array($this, 'log'));
00363
00364 $order->place();
00365 $order->save();
00366 #$this->log(ob_get_clean());
00367
00368 $order->sendNewOrderEmail();
00369
00370 Mage::getSingleton('checkout/session')
00371 ->setLastQuoteId($quote->getId())
00372 ->setLastOrderId($order->getId())
00373 ->setLastSuccessQuoteId($quote->getId())
00374 ->setLastRealOrderId($order->getIncrementId());
00375
00376 if ($emailAllowed) {
00377 Mage::getModel('newsletter/subscriber')->subscribe($order->getCustomerEmail());
00378 }
00379
00380 $shoppingCartQuoteId = Mage::getSingleton('checkout/session')->getQuoteId();
00381 $tmpQuote = Mage::getModel('sales/quote')->load($shoppingCartQuoteId);
00382
00383
00384
00385
00386
00387 $this->getGRequest()->SendMerchantOrderNumber($order->getExtOrderId(), $order->getIncrementId());
00388 }
00389
00390 protected function _importGoogleAddress($gAddress, Varien_Object $qAddress=null)
00391 {
00392 if (is_array($gAddress)) {
00393 $gAddress = new Varien_Object($gAddress);
00394 }
00395
00396 if (!$qAddress) {
00397 $qAddress = Mage::getModel('sales/quote_address');
00398 }
00399
00400 if ($nameArr = $gAddress->getData('structured-name')) {
00401 $qAddress
00402 ->setFirstname($nameArr['first-name']['VALUE'])
00403 ->setLastname($nameArr['last-name']['VALUE']);
00404 } else {
00405 $nameArr = explode(' ', $gAddress->getData('contact-name/VALUE'), 2);
00406 $qAddress->setFirstname($nameArr[0]);
00407 if (!empty($nameArr[1])) {
00408 $qAddress->setLastname($nameArr[1]);
00409 }
00410 }
00411 $region = Mage::getModel('directory/region')->loadByCode($gAddress->getData('region/VALUE'), $gAddress->getData('country-code/VALUE'));
00412
00413 $qAddress
00414 ->setCompany($gAddress->getData('company-name/VALUE'))
00415 ->setEmail($gAddress->getData('email/VALUE'))
00416 ->setStreet(trim($gAddress->getData('address1/VALUE')."\n".$gAddress->getData('address2/VALUE')))
00417 ->setCity($gAddress->getData('city/VALUE'))
00418 ->setRegion($gAddress->getData('region/VALUE'))
00419 ->setRegionId($region->getId())
00420 ->setPostcode($gAddress->getData('postal-code/VALUE'))
00421 ->setCountryId($gAddress->getData('country-code/VALUE'))
00422 ->setTelephone($gAddress->getData('phone/VALUE'))
00423 ->setFax($gAddress->getData('fax/VALUE'));
00424
00425 return $qAddress;
00426 }
00427
00428 protected function _importGoogleTotals($qAddress)
00429 {
00430 $qAddress->setTaxAmount($this->getData('root/order-adjustment/total-tax/VALUE'));
00431 $qAddress->setBaseTaxAmount($this->getData('root/order-adjustment/total-tax/VALUE'));
00432
00433 $prefix = 'root/order-adjustment/shipping/';
00434 if ($shipping = $this->getData($prefix.'carrier-calculated-shipping-adjustment')) {
00435 $method = 'googlecheckout_carrier';
00436 } elseif ($shipping = $this->getData($prefix.'merchant-calculated-shipping-adjustment')) {
00437 $method = 'googlecheckout_merchant';
00438 } elseif ($shipping = $this->getData($prefix.'flat-rate-shipping-adjustment')) {
00439 $method = 'googlecheckout_flatrate';
00440 } elseif ($shipping = $this->getData($prefix.'pickup-shipping-adjustment')) {
00441 $method = 'googlecheckout_pickup';
00442 }
00443 if (!empty($method)) {
00444 $excludingTax = $shipping['shipping-cost']['VALUE'];
00445 $qAddress->setShippingMethod($method)
00446 ->setShippingDescription($shipping['shipping-name']['VALUE'])
00447 ->setShippingAmount($excludingTax, true)
00448 ->setBaseShippingAmount($excludingTax, true);
00449
00450 if (!Mage::helper('tax')->shippingPriceIncludesTax()) {
00451 $includingTax = Mage::helper('tax')->getShippingPrice($excludingTax, true, $qAddress, $qAddress->getQuote()->getCustomerTaxClassId());
00452 $shippingTax = $includingTax - $excludingTax;
00453 $qAddress->setShippingTaxAmount($shippingTax)
00454 ->setBaseShippingTaxAmount($shippingTax);
00455 } else {
00456 if ($method == 'googlecheckout_carrier') {
00457 $qAddress->setShippingTaxAmount(0)
00458 ->setBaseShippingTaxAmount(0);
00459 }
00460 }
00461 } else {
00462 $qAddress->setShippingMethod(null);
00463 }
00464
00465
00466 $qAddress->setGrandTotal($this->getData('root/order-total/VALUE'));
00467 $qAddress->setBaseGrandTotal($this->getData('root/order-total/VALUE'));
00468 }
00469
00470
00471
00472
00473
00474
00475 public function getOrder()
00476 {
00477 if (!$this->hasData('order')) {
00478 $order = Mage::getModel('sales/order')
00479 ->loadByAttribute('ext_order_id', $this->getGoogleOrderNumber());
00480 if (!$order->getId()) {
00481 Mage::throwException('Invalid Order: '.$this->getGoogleOrderNumber());
00482 }
00483 $this->setData('order', $order);
00484 }
00485 return $this->getData('order');
00486 }
00487
00488 protected function _responseRiskInformationNotification()
00489 {
00490 $this->getGResponse()->SendAck();
00491
00492 $order = $this->getOrder();
00493 $payment = $order->getPayment();
00494
00495 $order
00496 ->setRemoteIp($this->getData('root/risk-information/ip-address/VALUE'));
00497
00498 $payment
00499 ->setCcLast4($this->getData('root/risk-information/partial-cc-number/VALUE'))
00500 ->setCcAvsStatus($this->getData('root/risk-information/avs-response/VALUE'))
00501 ->setCcCidStatus($this->getData('root/risk-information/cvn-response/VALUE'));
00502
00503 $msg = $this->__('Google Risk Information:');
00504 $msg .= '<br />'.$this->__('IP Address: %s', '<strong>'.$order->getRemoteIp().'</strong>');
00505 $msg .= '<br />'.$this->__('CC Partial: xxxx-%s', '<strong>'.$payment->getCcLast4().'</strong>');
00506 $msg .= '<br />'.$this->__('AVS Status: %s', '<strong>'.$payment->getCcAvsStatus().'</strong>');
00507 $msg .= '<br />'.$this->__('CID Status: %s', '<strong>'.$payment->getCcCidStatus().'</strong>');
00508 $msg .= '<br />'.$this->__('Eligible for protection: %s', '<strong>'.($this->getData('root/risk-information/eligible-for-protection/VALUE')=='true' ? 'Yes' : 'No').'</strong>');
00509 $msg .= '<br />'.$this->__('Buyer account age: %s days', '<strong>'.$this->getData('root/risk-information/buyer-account-age/VALUE').'</strong>');
00510
00511 $order->addStatusToHistory($order->getStatus(), $msg);
00512 $order->save();
00513 }
00514
00515
00516
00517
00518 protected function _responseAuthorizationAmountNotification()
00519 {
00520 $this->getGResponse()->SendAck();
00521
00522 $order = $this->getOrder();
00523 $payment = $order->getPayment();
00524
00525 $payment->setAmountAuthorized($this->getData('root/authorization-amount/VALUE'));
00526
00527 $expDate = $this->getData('root/authorization-expiration-date/VALUE');
00528 $expDate = new Zend_Date($expDate);
00529 $msg = $this->__('Google Authorization:');
00530 $msg .= '<br />'.$this->__('Amount: %s', '<strong>' . $this->_formatAmount($payment->getAmountAuthorized()) . '</strong>');
00531 $msg .= '<br />'.$this->__('Expiration: %s', '<strong>' . $expDate->toString() . '</strong>');
00532
00533 $order->addStatusToHistory($order->getStatus(), $msg);
00534
00535 $order->setPaymentAuthorizationAmount($payment->getAmountAuthorized());
00536 $order->setPaymentAuthorizationExpiration(Mage::getModel('core/date')->gmtTimestamp($this->getData('root/authorization-expiration-date/VALUE')));
00537
00538 $order->save();
00539 }
00540
00541
00542
00543
00544
00545 protected function _responseChargeAmountNotification()
00546 {
00547 $this->getGResponse()->SendAck();
00548
00549 $order = $this->getOrder();
00550 $payment = $order->getPayment();
00551
00552 $latestCharged = $this->getData('root/latest-charge-amount/VALUE');
00553 $totalCharged = $this->getData('root/total-charge-amount/VALUE');
00554 $payment->setAmountCharged($totalCharged);
00555 $order->setIsInProcess(true);
00556
00557 $msg = $this->__('Google Charge:');
00558 $msg .= '<br />'.$this->__('Latest Charge: %s', '<strong>' . $this->_formatAmount($latestCharged) . '</strong>');
00559 $msg .= '<br />'.$this->__('Total Charged: %s', '<strong>' . $this->_formatAmount($totalCharged) . '</strong>');
00560
00561 if (!$order->hasInvoices() && abs($order->getGrandTotal()-$latestCharged)<.0001) {
00562 $invoice = $this->_createInvoice();
00563 $msg .= '<br />'.$this->__('Invoice auto-created: %s', '<strong>'.$invoice->getIncrementId().'</strong>');
00564 }
00565
00566 foreach ($order->getInvoiceCollection() as $orderInvoice) {
00567 $open = Mage_Sales_Model_Order_Invoice::STATE_OPEN;
00568 $paid = Mage_Sales_Model_Order_Invoice::STATE_PAID;
00569 if ($orderInvoice->getState() == $open && $orderInvoice->getGrandTotal() == $latestCharged) {
00570 $orderInvoice->setState($paid)->save();
00571 break;
00572 }
00573 }
00574
00575 $order->addStatusToHistory($order->getStatus(), $msg);
00576 $order->save();
00577
00578 }
00579
00580 protected function _createInvoice()
00581 {
00582 $order = $this->getOrder();
00583
00584 $invoice = $order->prepareInvoice();
00585
00586 if (!empty($data['comment_text'])) {
00587 $invoice->addComment(Mage::helper('googlecheckout')->__('Auto-generated from GoogleCheckout Charge'));
00588 }
00589
00590 $invoice->register();
00591 $invoice->pay();
00592
00593 $transactionSave = Mage::getModel('core/resource_transaction')
00594 ->addObject($invoice)
00595 ->addObject($invoice->getOrder());
00596
00597 $transactionSave->save();
00598
00599 return $invoice;
00600 }
00601
00602 protected function _createShipment()
00603 {
00604 $order = $this->getOrder();
00605 $shipment = $order->prepareShipment();
00606 if ($shipment) {
00607 $shipment->register();
00608
00609 $order->setIsInProcess(true);
00610
00611 $transactionSave = Mage::getModel('core/resource_transaction')
00612 ->addObject($shipment)
00613 ->addObject($shipment->getOrder())
00614 ->save();
00615 }
00616
00617 return $shipment;
00618 }
00619
00620
00621 protected function _responseChargebackAmountNotification()
00622 {
00623 $this->getGResponse()->SendAck();
00624
00625 }
00626
00627
00628
00629
00630
00631 protected function _responseRefundAmountNotification()
00632 {
00633 $this->getGResponse()->SendAck();
00634
00635 $order = $this->getOrder();
00636 $payment = $order->getPayment();
00637
00638 $totalRefunded = $this->getData('root/total-refund-amount/VALUE');
00639 $payment->setAmountCharged($totalRefunded);
00640
00641 $msg = $this->__('Google Refund:');
00642 $msg .= '<br />'.$this->__('Latest Refund: %s', '<strong>' . $this->_formatAmount($this->getData('root/latest-refund-amount/VALUE')) . '</strong>');
00643 $msg .= '<br />'.$this->__('Total Refunded: %s', '<strong>' . $this->_formatAmount($totalRefunded) . '</strong>');
00644
00645 $order->addStatusToHistory($order->getStatus(), $msg);
00646 $order->save();
00647 }
00648
00649 protected function _responseOrderStateChangeNotification()
00650 {
00651 $this->getGResponse()->SendAck();
00652
00653 $prevFinancial = $this->getData('root/previous-financial-order-state/VALUE');
00654 $newFinancial = $this->getData('root/new-financial-order-state/VALUE');
00655 $prevFulfillment = $this->getData('root/previous-fulfillment-order-state/VALUE');
00656 $newFulfillment = $this->getData('root/new-fulfillment-order-state/VALUE');
00657
00658 $msg = $this->__('Google order status change:');
00659 if ($prevFinancial!=$newFinancial) {
00660 $msg .= "<br />".$this->__('Financial: %s -> %s', '<strong>'.$prevFinancial.'</strong>', '<strong>'.$newFinancial.'</strong>');
00661 }
00662 if ($prevFulfillment!=$newFulfillment) {
00663 $msg .= "<br />".$this->__('Fulfillment: %s -> %s', '<strong>'.$prevFulfillment.'</strong>', '<strong>'.$newFulfillment.'</strong>');
00664 }
00665 $this->getOrder()
00666 ->addStatusToHistory($this->getOrder()->getStatus(), $msg)
00667 ->save();
00668
00669 $method = '_orderStateChangeFinancial'.uc_words(strtolower($newFinancial), '', '_');
00670 if (method_exists($this, $method)) {
00671 $this->$method();
00672 }
00673
00674 $method = '_orderStateChangeFulfillment'.uc_words(strtolower($newFulfillment), '', '_');
00675 if (method_exists($this, $method)) {
00676 $this->$method();
00677 }
00678 }
00679
00680 protected function _orderStateChangeFinancialReviewing()
00681 {
00682
00683 }
00684
00685 protected function _orderStateChangeFinancialChargeable()
00686 {
00687 #$this->getGRequest()->SendProcessOrder($this->getGoogleOrderNumber());
00688 #$this->getGRequest()->SendChargeOrder($this->getGoogleOrderNumber(), '');
00689 }
00690
00691 protected function _orderStateChangeFinancialCharging()
00692 {
00693
00694 }
00695
00696 protected function _orderStateChangeFinancialCharged()
00697 {
00698
00699 }
00700
00701 protected function _orderStateChangeFinancialPaymentDeclined()
00702 {
00703
00704 }
00705
00706 protected function _orderStateChangeFinancialCancelled()
00707 {
00708 $this->getOrder()->setBeingCanceledFromGoogleApi(true)->cancel()->save();
00709 }
00710
00711 protected function _orderStateChangeFinancialCancelledByGoogle()
00712 {
00713 $this->getOrder()->setBeingCanceledFromGoogleApi(true)->cancel()->save();
00714 $this->getGRequest()->SendBuyerMessage($this->getGoogleOrderNumber(), "Sorry, your order is cancelled by Google", true);
00715 }
00716
00717 protected function _orderStateChangeFulfillmentNew()
00718 {
00719
00720 }
00721
00722 protected function _orderStateChangeFulfillmentProcessing()
00723 {
00724
00725 }
00726
00727 protected function _orderStateChangeFulfillmentDelivered()
00728 {
00729 $shipment = $this->_createShipment();
00730 if (!is_null($shipment))
00731 $shipment->save();
00732 }
00733
00734 protected function _orderStateChangeFulfillmentWillNotDeliver()
00735 {
00736
00737 }
00738
00739
00740
00741
00742
00743
00744
00745 protected function _formatAmount($amount)
00746 {
00747
00748 return Mage::helper('core')->currency($amount, true, false);
00749 }
00750
00751 }