Mage_GoogleCheckout_Model_Api_Xml_Callback Class Reference

Inheritance diagram for Mage_GoogleCheckout_Model_Api_Xml_Callback:

Mage_GoogleCheckout_Model_Api_Xml_Abstract Varien_Object

List of all members.

Public Member Functions

 process ()
 getOrder ()

Protected Member Functions

 _getApiUrl ()
 getGoogleOrderNumber ()
 _responseRequestReceived ()
 _responseError ()
 _responseDiagnosis ()
 _responseCheckoutRedirect ()
 _responseMerchantCalculationCallback ()
 _responseNewOrderNotification ()
 _importGoogleAddress ($gAddress, Varien_Object $qAddress=null)
 _importGoogleTotals ($qAddress)
 _responseRiskInformationNotification ()
 _responseAuthorizationAmountNotification ()
 _responseChargeAmountNotification ()
 _createInvoice ()
 _createShipment ()
 _responseChargebackAmountNotification ()
 _responseRefundAmountNotification ()
 _responseOrderStateChangeNotification ()
 _orderStateChangeFinancialReviewing ()
 _orderStateChangeFinancialChargeable ()
 _orderStateChangeFinancialCharging ()
 _orderStateChangeFinancialCharged ()
 _orderStateChangeFinancialPaymentDeclined ()
 _orderStateChangeFinancialCancelled ()
 _orderStateChangeFinancialCancelledByGoogle ()
 _orderStateChangeFulfillmentNew ()
 _orderStateChangeFulfillmentProcessing ()
 _orderStateChangeFulfillmentDelivered ()
 _orderStateChangeFulfillmentWillNotDeliver ()
 _formatAmount ($amount)


Detailed Description

Definition at line 27 of file Callback.php.


Member Function Documentation

_createInvoice (  )  [protected]

Definition at line 580 of file Callback.php.

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     }

_createShipment (  )  [protected]

Definition at line 602 of file Callback.php.

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     }

_formatAmount ( amount  )  [protected]

Format amount to be displayed

Parameters:
mixed $amount
Returns:
string

Definition at line 745 of file Callback.php.

00746     {
00747         // format currency in currency format, but don't enclose it into <span>
00748         return Mage::helper('core')->currency($amount, true, false);
00749     }

_getApiUrl (  )  [protected]

Reimplemented from Mage_GoogleCheckout_Model_Api_Xml_Abstract.

Definition at line 83 of file Callback.php.

00084     {
00085         return null;
00086     }

_importGoogleAddress ( gAddress,
Varien_Object qAddress = null 
) [protected]

Definition at line 390 of file Callback.php.

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     }

_importGoogleTotals ( qAddress  )  [protected]

Definition at line 428 of file Callback.php.

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     }

_orderStateChangeFinancialCancelled (  )  [protected]

Definition at line 706 of file Callback.php.

00707     {
00708         $this->getOrder()->setBeingCanceledFromGoogleApi(true)->cancel()->save();
00709     }

_orderStateChangeFinancialCancelledByGoogle (  )  [protected]

Definition at line 711 of file Callback.php.

00712     {
00713         $this->getOrder()->setBeingCanceledFromGoogleApi(true)->cancel()->save();
00714         $this->getGRequest()->SendBuyerMessage($this->getGoogleOrderNumber(), "Sorry, your order is cancelled by Google", true);
00715     }

_orderStateChangeFinancialChargeable (  )  [protected]

Definition at line 685 of file Callback.php.

00686     {
00687         #$this->getGRequest()->SendProcessOrder($this->getGoogleOrderNumber());
00688         #$this->getGRequest()->SendChargeOrder($this->getGoogleOrderNumber(), '');
00689     }

_orderStateChangeFinancialCharged (  )  [protected]

Definition at line 696 of file Callback.php.

00697     {
00698 
00699     }

_orderStateChangeFinancialCharging (  )  [protected]

Definition at line 691 of file Callback.php.

00692     {
00693 
00694     }

_orderStateChangeFinancialPaymentDeclined (  )  [protected]

Definition at line 701 of file Callback.php.

00702     {
00703 
00704     }

_orderStateChangeFinancialReviewing (  )  [protected]

Definition at line 680 of file Callback.php.

00681     {
00682 
00683     }

_orderStateChangeFulfillmentDelivered (  )  [protected]

Definition at line 727 of file Callback.php.

00728     {
00729         $shipment = $this->_createShipment();
00730         if (!is_null($shipment))
00731             $shipment->save();
00732     }

_orderStateChangeFulfillmentNew (  )  [protected]

Definition at line 717 of file Callback.php.

00718     {
00719 
00720     }

_orderStateChangeFulfillmentProcessing (  )  [protected]

Definition at line 722 of file Callback.php.

00723     {
00724 
00725     }

_orderStateChangeFulfillmentWillNotDeliver (  )  [protected]

Definition at line 734 of file Callback.php.

00735     {
00736 
00737     }

_responseAuthorizationAmountNotification (  )  [protected]

Process authorization notification

Definition at line 518 of file Callback.php.

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     }

_responseChargeAmountNotification (  )  [protected]

Process charge notification

Definition at line 545 of file Callback.php.

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     }

_responseChargebackAmountNotification (  )  [protected]

Definition at line 621 of file Callback.php.

00622     {
00623         $this->getGResponse()->SendAck();
00624 
00625     }

_responseCheckoutRedirect (  )  [protected]

Definition at line 108 of file Callback.php.

00109     {
00110 
00111     }

_responseDiagnosis (  )  [protected]

Definition at line 103 of file Callback.php.

00104     {
00105 
00106     }

_responseError (  )  [protected]

Definition at line 98 of file Callback.php.

00099     {
00100 
00101     }

_responseMerchantCalculationCallback (  )  [protected]

Definition at line 113 of file Callback.php.

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     }

_responseNewOrderNotification (  )  [protected]

Definition at line 265 of file Callback.php.

00266     {
00267         $this->getGResponse()->SendAck();
00268 
00269         // LOOK FOR EXISTING ORDER TO AVOID DUPLICATES
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         // IMPORT GOOGLE ORDER DATA INTO QUOTE
00279 
00280         $quoteId = $this->getData('root/shopping-cart/merchant-private-data/quote-id/VALUE');
00281         $quote = Mage::getModel('sales/quote')->load($quoteId);
00282 //
00283 //        $quoteItems = $quote->getItemsCollection();
00284 //        foreach ($this->getData('root/shopping-cart/items') as $item) {
00285 //            if (!isset($item['merchant-private-item-data']['quote-item-id']['VALUE'])
00286 //                || !isset($item['quantity']['VALUE'])) {
00287 //                continue;
00288 //            }
00289 //            $quoteItem = $quoteItems->getItemById($item['merchant-private-item-data']['quote-item-id']['VALUE']);
00290 //            $quoteItem->setQty($item['quantity']['VALUE']);
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         // CONVERT QUOTE TO ORDER
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 //        $order->setCustomerNote(
00355 //            $this->__('Google Order Number: %s', '<strong>'.$this->getGoogleOrderNumber()).'</strong>'.
00356 //            '<br />'.
00357 //            $this->__('Google Buyer Id: %s', '<strong>'.$this->getData('root/buyer-id/VALUE').'</strong>').
00358 //            '<br />'.
00359 //            $this->__('Is Buyer Willing To Receive Marketing E-Mails: %s', '<strong>' . ($emailAllowed ? $this->__('Yes') : $this->__('No')) . '</strong>')
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         if (!$tmpQuote->getIsChanged()) {
00384             $tmpQuote->delete();
00385         }
00386 */
00387         $this->getGRequest()->SendMerchantOrderNumber($order->getExtOrderId(), $order->getIncrementId());
00388     }

_responseOrderStateChangeNotification (  )  [protected]

Definition at line 649 of file Callback.php.

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     }

_responseRefundAmountNotification (  )  [protected]

Process refund notification

Definition at line 631 of file Callback.php.

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     }

_responseRequestReceived (  )  [protected]

Definition at line 93 of file Callback.php.

00094     {
00095 
00096     }

_responseRiskInformationNotification (  )  [protected]

Definition at line 488 of file Callback.php.

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     }

getGoogleOrderNumber (  )  [protected]

Definition at line 88 of file Callback.php.

00089     {
00090         return $this->getData('root/google-order-number/VALUE');
00091     }

getOrder (  ) 

Enter description here...

Returns:
Mage_Sales_Model_Order

Definition at line 475 of file Callback.php.

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     }

process (  ) 

Definition at line 29 of file Callback.php.

00030     {
00031         // Retrieve the XML sent in the HTTP POST request to the ResponseHandler
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     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:16 2009 for Magento by  doxygen 1.5.8