Esempio n. 1
0
function google_checkout_state_change($check_status, $status, $oID, $cust_notify, $notify_comments)
{
    global $db, $messageStack, $orders_statuses;
    define('API_CALLBACK_ERROR_LOG', DIR_FS_CATALOG . "/googlecheckout/logs/response_error.log");
    define('API_CALLBACK_MESSAGE_LOG', DIR_FS_CATALOG . "/googlecheckout/logs/response_message.log");
    include_once DIR_FS_CATALOG . '/includes/modules/payment/googlecheckout.php';
    include_once DIR_FS_CATALOG . '/googlecheckout/library/googlerequest.php';
    require_once DIR_FS_CATALOG . '/googlecheckout/library/configuration/google_configuration.php';
    require_once DIR_FS_CATALOG . '/googlecheckout/library/configuration/google_configuration_keys.php';
    $config = new GoogleConfigurationKeys();
    $googlecheckout = new googlecheckout();
    $google_request = new GoogleRequest($googlecheckout->merchantid, $googlecheckout->merchantkey, MODULE_PAYMENT_GOOGLECHECKOUT_MODE == 'https://sandbox.google.com/checkout/' ? "sandbox" : "production", DEFAULT_CURRENCY);
    $google_request->SetLogFiles(API_CALLBACK_ERROR_LOG, API_CALLBACK_MESSAGE_LOG);
    $google_answer = tep_db_fetch_array(tep_db_query("SELECT go.google_order_number, go.order_amount, o.customers_email_address, gc.buyer_id, o.customers_id\n                                  FROM " . $googlecheckout->table_order . " go \n                                  inner join " . TABLE_ORDERS . " o on go.orders_id = o.orders_id\n                                  inner join " . $googlecheckout->table_name . " gc on gc.customers_id = o.customers_id\n                                  WHERE go.orders_id = '" . (int) $oID . "'\n                                  group by o.customers_id order by o.orders_id desc"));
    $google_order = $google_answer['google_order_number'];
    $amount = $google_answer['order_amount'];
    // If status update is from Google New -> Google Processing on the Admin UI
    // this invokes the processing-order and charge-order commands
    // 1->Google New, 2-> Google Processing
    if ($check_status['orders_status'] == GC_STATE_NEW && $status == GC_STATE_PROCESSING && $google_order != '') {
        list($curl_status, ) = $google_request->SendChargeOrder($google_order, $amount);
        if ($curl_status != 200) {
            $messageStack->add_session(GOOGLECHECKOUT_ERR_SEND_CHARGE_ORDER, 'error');
        } else {
            $messageStack->add_session(GOOGLECHECKOUT_SUCCESS_SEND_CHARGE_ORDER, 'success');
        }
        list($curl_status, ) = $google_request->SendProcessOrder($google_order);
        if ($curl_status != 200) {
            $messageStack->add_session(GOOGLECHECKOUT_ERR_SEND_PROCESS_ORDER, 'error');
        } else {
            $messageStack->add_session(GOOGLECHECKOUT_SUCCESS_SEND_PROCESS_ORDER, 'success');
        }
    } else {
        if (($check_status['orders_status'] == GC_STATE_PROCESSING || $check_status['orders_status'] == GC_STATE_REFUNDED) && ($status == GC_STATE_SHIPPED || $status == GC_STATE_SHIPPED_REFUNDED) && $google_order != '') {
            $carrier = $tracking_no = "";
            // Add tracking Data
            if (isset($_POST['carrier_select']) && $_POST['carrier_select'] != 'select' && isset($_POST['tracking_number']) && !empty($_POST['tracking_number'])) {
                $carrier = $_POST['carrier_select'];
                $tracking_no = $_POST['tracking_number'];
                $comments = GOOGLECHECKOUT_STATE_STRING_TRACKING . "\n" . GOOGLECHECKOUT_STATE_STRING_TRACKING_CARRIER . $_POST['carrier_select'] . "\n" . GOOGLECHECKOUT_STATE_STRING_TRACKING_NUMBER . $_POST['tracking_number'] . "";
                tep_db_query("insert into " . TABLE_ORDERS_STATUS_HISTORY . "\n                  (orders_id, orders_status_id, date_added, customer_notified, comments)\n                  values ('" . (int) $oID . "',\n                  '" . tep_db_input($check_status['orders_status'] == GC_STATE_REFUNDED ? GC_STATE_SHIPPED_REFUNDED : GC_STATE_SHIPPED) . "',\n                  now(),\n                  '" . tep_db_input($cust_notify) . "',\n                  '" . tep_db_input($comments) . "')");
            }
            list($curl_status, ) = $google_request->SendDeliverOrder($google_order, $carrier, $tracking_no, $cust_notify == 1 ? "true" : "false");
            if ($curl_status != 200) {
                $messageStack->add_session(GOOGLECHECKOUT_ERR_SEND_DELIVER_ORDER, 'error');
            } else {
                $messageStack->add_session(GOOGLECHECKOUT_SUCCESS_SEND_DELIVER_ORDER, 'success');
            }
            list($curl_status, ) = $google_request->SendArchiveOrder($google_order);
            if ($curl_status != 200) {
                $messageStack->add_session(GOOGLECHECKOUT_ERR_SEND_ARCHIVE_ORDER, 'error');
            } else {
                $messageStack->add_session(GOOGLECHECKOUT_SUCCESS_SEND_ARCHIVE_ORDER, 'success');
            }
        } else {
            if ($check_status['orders_status'] != GC_STATE_CANCELED && $status == GC_STATE_CANCELED && $google_order != '') {
                if ($check_status['orders_status'] != GC_STATE_NEW) {
                    list($curl_status, ) = $google_request->SendRefundOrder($google_order, 0, GOOGLECHECKOUT_STATE_STRING_ORDER_CANCELED);
                    if ($curl_status != 200) {
                        $messageStack->add_session(GOOGLECHECKOUT_ERR_SEND_REFUND_ORDER, 'error');
                    } else {
                        $messageStack->add_session(GOOGLECHECKOUT_SUCCESS_SEND_REFUND_ORDER, 'success');
                    }
                } else {
                    // Tell google witch is the OSC's internal order Number
                    list($curl_status, ) = $google_request->SendMerchantOrderNumber($google_order, $oID);
                    if ($curl_status != 200) {
                        $messageStack->add_session(GOOGLECHECKOUT_ERR_SEND_MERCHANT_ORDER_NUMBER, 'error');
                    } else {
                        $messageStack->add_session(GOOGLECHECKOUT_SUCCESS_SEND_MERCHANT_ORDER_NUMBER, 'success');
                    }
                }
                // Is the order is not archive, I do it
                if ($check_status['orders_status'] != GC_STATE_SHIPPED && $check_status['orders_status'] != GC_STATE_SHIPPED_REFUNDED) {
                    list($curl_status, ) = $google_request->SendArchiveOrder($google_order);
                    if ($curl_status != 200) {
                        $messageStack->add_session(GOOGLECHECKOUT_ERR_SEND_ARCHIVE_ORDER, 'error');
                    } else {
                        $messageStack->add_session(GOOGLECHECKOUT_SUCCESS_SEND_ARCHIVE_ORDER, 'success');
                    }
                }
                // Cancel the order
                list($curl_status, ) = $google_request->SendCancelOrder($google_order, GOOGLECHECKOUT_STATE_STRING_ORDER_CANCELED, $notify_comments);
                if ($curl_status != 200) {
                    $messageStack->add_session(GOOGLECHECKOUT_ERR_SEND_CANCEL_ORDER, 'error');
                } else {
                    $messageStack->add_session(GOOGLECHECKOUT_SUCCESS_SEND_CANCEL_ORDER, 'success');
                }
            } else {
                if ($google_order != '' && $check_status['orders_status'] != $status) {
                    $statuses = array();
                    foreach ($orders_statuses as $status_array) {
                        $statuses[$status_array['id']] = $status_array['text'];
                    }
                    $messageStack->add_session(sprintf(GOOGLECHECKOUT_ERR_INVALID_STATE_TRANSITION, $statuses[$check_status['orders_status']], $statuses[$status], $statuses[$check_status['orders_status']]), 'error');
                }
            }
        }
    }
    // Send Buyer's message
    if ($cust_notify == 1 && isset($notify_comments) && !empty($notify_comments)) {
        $cust_notify_ok = '0';
        $use_cart_messaging = gc_get_configuration_value($config->useCartMessaging()) == 'True';
        if (!(strlen(htmlentities(strip_tags($notify_comments))) > GOOGLE_MESSAGE_LENGTH && $use_cart_messaging)) {
            list($curl_status, ) = $google_request->sendBuyerMessage($google_order, $notify_comments, "true");
            if ($curl_status != 200) {
                $messageStack->add_session(GOOGLECHECKOUT_ERR_SEND_MESSAGE_ORDER, 'error');
                $cust_notify_ok = '0';
            } else {
                $messageStack->add_session(GOOGLECHECKOUT_SUCCESS_SEND_MESSAGE_ORDER, 'success');
                $cust_notify_ok = '1';
            }
            if (strlen(htmlentities(strip_tags($notify_comments))) > GOOGLE_MESSAGE_LENGTH) {
                $messageStack->add_session(sprintf(GOOGLECHECKOUT_WARNING_CHUNK_MESSAGE, GOOGLE_MESSAGE_LENGTH), 'warning');
            }
        }
        // Cust notified
        return $cust_notify_ok;
    }
    // Cust notified
    return '0';
}
Esempio n. 2
0
 */
chdir("./..");
require_once DIR_WS_LANGUAGES . $language . '/googlecheckout.php';
require_once DIR_FS_CATALOG . '/googlecheckout/library/configuration/google_configuration.php';
require_once DIR_FS_CATALOG . '/googlecheckout/library/configuration/google_configuration_keys.php';
$config = new GoogleConfigurationKeys();
$payment_value = MODULE_PAYMENT_GOOGLECHECKOUT_TEXT_TITLE;
$num_rows = tep_db_num_rows(tep_db_query("select google_order_number from google_orders where orders_id= " . (int) $oID));
if ($num_rows != 0) {
    $customer_notified = google_checkout_state_change($check_status, $status, $oID, @$_POST['notify'] == 'on' ? 1 : 0, @$_POST['notify_comments'] == 'on' ? $comments : '');
}
$customer_notified = isset($customer_notified) ? $customer_notified : '0';
if (isset($_POST['notify']) && $_POST['notify'] == 'on') {
    $notify_comments = '';
    if (isset($HTTP_POST_VARS['notify_comments']) && $HTTP_POST_VARS['notify_comments'] == 'on') {
        $notify_comments = sprintf(EMAIL_TEXT_COMMENTS_UPDATE, $comments) . "\n\n";
    }
    $force_email = false;
    $use_cart_messaging = gc_get_configuration_value($config->useCartMessaging()) == 'True';
    if ($num_rows != 0 && (strlen(htmlentities(strip_tags($notify_comments))) > GOOGLE_MESSAGE_LENGTH && $user_cart_messaging)) {
        $force_email = true;
        $messageStack->add_session(GOOGLECHECKOUT_WARNING_SYSTEM_EMAIL_SENT, 'warning');
    }
    if ($num_rows == 0 || $force_email) {
        // send emails, not a google order or configured to use both messaging systems
        $email = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $oID . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . tep_catalog_href_link(FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id=' . $oID, 'SSL') . "\n" . EMAIL_TEXT_DATE_ORDERED . ' ' . tep_date_long($check_status['date_purchased']) . "\n\n" . $notify_comments . sprintf(EMAIL_TEXT_STATUS_UPDATE, $orders_status_array[$status]);
        tep_mail($check_status['customers_name'], $check_status['customers_email_address'], EMAIL_TEXT_SUBJECT, $email, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
        $customer_notified = '1';
        // send extra emails
    }
}