function testGoogleLogResponse()
 {
     $Glog = new GoogleLog(API_CALLBACK_ERROR_LOG, API_CALLBACK_MESSAGE_LOG, L_RESP, false);
     $this->assert($Glog->LogResponse("response"));
 }
예제 #2
0
 function callback()
 {
     // Log the message from Google
     chdir('library/google');
     require_once 'library/googlelog.php';
     $log = new GoogleLog('../../logs/google_log/googleerror.log', '../../logs/google_log/googlemessage.log', L_ALL);
     foreach ($_POST as $key => $val) {
         $log->LogRequest("{$key} = {$val}");
     }
     $type = '';
     if (isset($_POST['_type'])) {
         $type = $_POST['_type'];
     }
     if ($type == 'new-order-notification') {
         // Google has received a newly submitted order
         // Store Google's order number and total into database
         if (isset($_POST['google-order-number'])) {
             $orderNumber = $_POST['google-order-number'];
             if (isset($_POST['shopping-cart_items_item-1_item-description'])) {
                 $orderReference = $_POST['shopping-cart_items_item-1_item-description'];
                 $i = strpos($orderReference, 'order# ', 0);
                 if (!($i === FALSE)) {
                     $orderReference = substr($orderReference, $i + strlen('order# '));
                     if (isset($_POST['order-total'])) {
                         $orderTotal = $_POST['order-total'];
                         $this->modelPayment->delete_order_google($orderReference);
                         $this->modelPayment->insert_order_google($orderReference, $orderNumber, $orderTotal);
                     }
                 }
             }
         }
     } else {
         if ($type == 'charge-amount-notification') {
             // Google has successfully processed the payment
             // Change AlegroCart order status to 'pending' and remove Google order entry from database
             if (isset($_POST['google-order-number'])) {
                 $orderNumber = $_POST['google-order-number'];
                 $result = $this->modelPayment->get_google_order($orderNumber);
                 if ($result) {
                     $orderReference = $result['order_reference'];
                     $total = $result['total'];
                     $result = $this->modelPayment->get_orderstatus_id($this->language->get('order_status_pending'), $this->language->getId());
                     if ($result) {
                         $orderStatusId = $result['order_status_id'];
                         if (isset($_POST['total-charge-amount'])) {
                             $amountCharged = $_POST['total-charge-amount'];
                             if ($amountCharged == $total) {
                                 $this->modelPayment->update_order_status($orderStatusId, $orderReference);
                                 $this->modelPayment->delete_order_google($orderReference);
                             }
                         }
                     }
                 }
             }
         } else {
             if ($type == 'order-state-change-notification') {
                 // Google has changed the order state.
                 if (isset($_POST['new-financial-order-state'])) {
                     $orderState = $_POST['new-financial-order-state'];
                     if ($orderState == 'CANCELLED') {
                         // Google has cancelled the order.
                         // We have to remove the order from the AlegroCart database.
                         if (isset($_POST['google-order-number'])) {
                             $orderNumber = $_POST['google-order-number'];
                             $result = $this->modelPayment->get_google_order($orderNumber);
                             if ($result) {
                                 $orderReference = $result['order_reference'];
                                 $result = $this->modelPayment->get_orderstatus_id($this->language->get('order_status_canceled'), $this->language->getId());
                                 if ($result) {
                                     $orderStatusId = $result['order_status_id'];
                                     $this->modelPayment->update_order_status($orderStatusId, $orderReference);
                                     $this->modelPayment->delete_order_google($orderReference);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     exit;
 }