function do_payment($payment_id, $member_id, $product_id, $price, $begin_date, $expire_date, &$vars, $is_rebilling = false)
 {
     global $config, $db;
     $checkout_xml_schema = 'http://checkout.google.com/schema/2';
     $gCheckout = new gCheckout($this->config["merchant_id"], $this->config["merchant_key"], $cart_expires = '', $checkout_xml_schema, $this->config["currency"], $this->config["debug"], $this->config["sandbox"], $this->config["allow_create"]);
     // Specify an expiration date for the order and build <shopping-cart>
     $tomorrow = mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"));
     //$cart_expiration = date("Y-m-d", $tomorrow) . "T" . date("H:i:s");
     $cart_expiration = date("c", $tomorrow);
     if (!$is_rebilling) {
         $gCheckout->setCartExpirationDate($cart_expiration);
     }
     if (!is_array($price)) {
         $price = array($product_id => $price);
     }
     $payment = $db->get_payment($payment_id);
     if ($is_rebilling) {
         $payment['data']['google_is_rebilling'] = 1;
         $db->update_payment($payment['payment_id'], $payment);
     }
     if ($pr = $payment['data'][0]['BASKET_PRODUCTS']) {
         $product_id = $pr;
     }
     if ($prices = $payment['data'][0]['BASKET_PRICES']) {
         $price = $prices;
     }
     $taxes = $payment['data']['TAXES'];
     if (!is_array($product_id)) {
         $product_id = (array) $product_id;
     }
     $recurring_count = 0;
     foreach ((array) $product_id as $pid) {
         $product = $db->get_product($pid);
         if ($product['is_recurring']) {
             $recurring_count++;
         }
     }
     if ($recurring_count > 1) {
         //$db->log_error("Google Checkout ERROR: Only one subscription item is allowed per cart");
         return array("Google Checkout ERROR: Only one subscription item is allowed per cart");
     }
     foreach ((array) $product_id as $pid) {
         ///////////////////////////////////////
         // Add product
         ///////////////////////////////////////
         // Specify item data and create an item to include in the order
         $product = $db->get_product($pid);
         $item_name = trim(strip_tags($product['title']));
         $item_description = trim(strip_tags($product['description']));
         $quantity = "1";
         $item_currency = $product['google_currency'];
         //$unit_price = $product['price'];
         $unit_price = $price[$pid];
         $tax_table_selector = "";
         $merchant_private_item_data = "<product-id>{$pid}</product-id>";
         $digital_delivery = array();
         if ($product['digital_content']) {
             $digital_delivery['delivery_schedule'] = $product['delivery_schedule'];
             $digital_delivery['delivery_method'] = $product['delivery_method'];
             $digital_delivery['delivery_description'] = $product['delivery_description'];
             $digital_delivery['delivery_key'] = $product['delivery_key'];
             $digital_delivery['delivery_url'] = $product['delivery_url'];
         }
         $subscription = array();
         if ($product['is_recurring'] && !$is_rebilling) {
             if ($product['rebill_times']) {
                 if ($product['trial1_price'] && $product['trial1_days']) {
                     $subscription['rebill_times'] = $product['rebill_times'] - 1;
                 } else {
                     $subscription['rebill_times'] = $product['rebill_times'];
                 }
             }
             if ($product['trial1_days'] && $product['trial1_price'] != '') {
                 $unit_price = $product['price'];
             }
             $days = $product['expire_days'];
             if ($product['trial1_days'] && !$is_rebilling) {
                 $days = $product['trial1_days'];
             }
             list($period, $period_unit) = google_checkout_get_days($days);
             $ret = 0;
             switch ($period_unit) {
                 case 'Y':
                     $ret = $period * 365;
                     break;
                 case 'M':
                     $ret = $period * 30;
                     break;
                 case 'W':
                     $ret = $period * 7;
                     break;
                 case 'D':
                     $ret = $period;
                     break;
                 default:
                     fatal_error(sprintf("Unknown period unit: %s", $period_unit));
             }
             $start_date = time() + 3600 * 24 * $ret;
             $start_date = date("Y-m-d 00:00:00", $start_date);
             $start_date = strtotime($start_date);
             $subscription['start_date'] = date("c", $start_date);
             // ISO 8601 date (added in PHP 5)
             $subscription_period = "";
             list($period, $period_unit) = google_checkout_get_days($product['expire_days']);
             if ($period_unit == 'D' && $period == '1') {
                 $subscription_period = "DAILY";
             }
             if ($period_unit == 'W' && $period == '1' || $period_unit == 'D' && $period == '7') {
                 $subscription_period = "WEEKLY";
             }
             if ($period_unit == 'W' && $period == '2') {
                 $subscription_period = "SEMI_MONTHLY";
             }
             if ($period_unit == 'M' && $period == '1') {
                 $subscription_period = "MONTHLY";
             }
             if ($period_unit == 'M' && $period == '2') {
                 $subscription_period = "EVERY_TWO_MONTHS";
             }
             if ($period_unit == 'M' && $period == '4') {
                 $subscription_period = "QUARTERLY";
             }
             if ($period_unit == 'Y' && $period == '1') {
                 $subscription_period = "YEARLY";
             }
             $subscription['period'] = $subscription_period;
         }
         ///////////////////////////////////////
         // Add Taxes info
         ///////////////////////////////////////
         /* DISABLED. Taxes per product isn't supported
         
                     if ($config['use_tax']){
                         $area_type = "country";
                         $area_place = "ALL";
                         $tax_area = $gCheckout->getTaxArea($area_type, $area_place);
                         
                         if ($product['use_tax']){
                             $rate = $taxes[$pid] / $product['price'];
                         } else {
                             $rate = "0.00";
                         }
                         
                         if (!$rate) $rate = "0.00";
                         $gCheckout->addAlternateTaxRule($rate, $tax_area);
                         
                         $standalone = 'true';
                         $name = $pid;
                         $gCheckout->addAlternateTaxTable($standalone, $name);
                         
                         $tax_table_selector = $pid;
                     }
         */
         $gCheckout->addItem($item_name, $item_description, $quantity, $unit_price, $tax_table_selector, $merchant_private_item_data, $digital_delivery, $subscription, $item_currency);
         if ($product['is_recurring'] && !$is_rebilling) {
             if ($product['trial1_days'] && $product['trial1_price'] != '') {
                 //add regular <item> for initial trial charge
                 $gCheckout->addItem($item_name, $item_description, $quantity, $product['trial1_price'], $tax_table_selector, $merchant_private_item_data, $digital_delivery, '', $item_currency);
             } else {
                 //add regular <item> for first recurring charge
                 $gCheckout->addItem($item_name, $item_description, $quantity, $unit_price, $tax_table_selector, $merchant_private_item_data, $digital_delivery, '', $item_currency);
             }
         }
     }
     ///////////////////////////////////////
     // Add extra data
     ///////////////////////////////////////
     $merchant_private_data = "<payment-id>{$payment_id}</payment-id><member-id>{$member_id}</member-id>";
     $gCheckout->setMerchantPrivateData($merchant_private_data);
     ///////////////////////////////////////
     // Add Merchant Calculations data
     ///////////////////////////////////////
     //$merchant_calc_url = $config['root_surl']."/plugins/payment/google_checkout/ResponseHandler.php";
     //$gCheckout->setMerchantCalculations($merchant_calc_url, $accepts_coupons="", $accept_gift_certificates="");
     ///////////////////////////////////////
     // Add shipping info
     ///////////////////////////////////////
     // Create list of areas where a particular shipping option is available
     /*
     $allowed_country_area = "ALL";    // OR: "CONTINENTAL_48", "FULL_50_STATES"
     $allowed_state = array();        // Ex: array("CA", "NY", "DC", "NC")
     $allowed_zip = array();        // Ex: array("94043", "94086", "91801", "91362")
     $allowed_restrictions = $gCheckout->getAllowedAreas($allowed_country_area, $allowed_state, $allowed_zip);
     */
     /*
     $excluded_country_area = "TX";    // OR: "CONTINENTAL_48", "FULL_50_STATES"
     $excluded_state = array();        // Ex: array("CA", "NY", "DC", "NC")
     $excluded_zip = array();        // Ex: array("94043", "94086", "91801", "91362")
     $excluded_restrictions = $gCheckout->getExcludedAreas($excluded_country_area, $excluded_state, $excluded_zip);
     */
     /*
     $name = 'UPS Ground';
     $prc = '10.0';
     $gCheckout->setFlatRateShipping($name, $price, $allowed_restrictions, $excluded_restrictions);
     */
     /*
     $name = 'Merchant Shipping';
     $prc = '20.0';
     $gCheckout->setMerchantCalculatedShipping($name, $price, $allowed_restrictions, $excluded_restrictions);
     */
     // Create a <pickup> shipping option
     $name = "Pickup";
     $prc = "0.00";
     $gCheckout->setPickup($name, $prc);
     ///////////////////////////////////////
     // Add Taxes info
     ///////////////////////////////////////
     if ($config['use_tax']) {
         ////////// http://code.google.com/intl/ru/apis/checkout/developer/Google_Checkout_XML_API_Taxes.html //////////
         if ($config['tax_type'] == '2') {
             // TODO: MUST BE FIXED FOR NEW REGIONAL TAX STRUCTURE - alex@cgi-central.net
             foreach ($config['regional_taxes'] as $regional_tax) {
                 $area_type = "country";
                 $area_place = "ALL";
                 if ($regional_tax['state'] && $regional_tax['country']) {
                     if ($regional_tax['country'] == 'US') {
                         $area_type = "country";
                         $area_place = 'ALL';
                         //CONTINENTAL_48 - All U.S. states except Alaska and Hawaii
                         //FULL_50_STATES - All U.S. states
                         //ALL - All U.S. postal service addresses, including military addresses, U.S. insular areas, etc.
                         $tax_area = $gCheckout->getTaxArea($area_type, $area_place);
                         $area_type = "state";
                         $area_place = $regional_tax['state'];
                         $tax_area = $gCheckout->getTaxArea($area_type, $area_place);
                     } else {
                         $tax_area = "<tax-area><world-area/></tax-area>";
                     }
                 } elseif ($regional_tax['country'] && $regional_tax['country'] == 'US') {
                     $area_type = "country";
                     $area_place = "ALL";
                     $tax_area = $gCheckout->getTaxArea($area_type, $area_place);
                 } elseif ($regional_tax['country']) {
                     $tax_area = "<tax-area><world-area/></tax-area>";
                 }
                 $rate = $regional_tax['tax_value'] / 100;
                 $shipping_taxed = 'false';
                 $gCheckout->addDefaultTaxRule($rate, $tax_area, $shipping_taxed);
             }
         } else {
             $area_type = "country";
             $area_place = "ALL";
             $tax_area = $gCheckout->getTaxArea($area_type, $area_place);
             $rate = $config['tax_value'] / 100;
             $shipping_taxed = 'false';
             $gCheckout->addDefaultTaxRule($rate, $tax_area, $shipping_taxed);
         }
         $merchant_calculated = 'false';
         $gCheckout->CreateTaxTables($merchant_calculated);
     }
     ///////////////////////////////////////
     // Information about shipping, taxes, and merchant calculations used at checkout time.
     ///////////////////////////////////////
     $gCheckout->setMerchantCheckoutFlowSupport($edit_cart_url = "", $continue_shopping_url = "", $request_buyer_phone_number = false);
     ///////////////////////////////////////
     // Create Checkout Shopping Cart
     ///////////////////////////////////////
     // Get <checkout-shopping-cart> XML
     if (!$is_rebilling) {
         $xml_cart = $gCheckout->getCart();
     } else {
         //$oldp_id = $payment['data'][0]['RENEWAL_ORIG'];
         //$x = preg_split('/ /', $oldp_id);
         //$oldp_id = $x[1];
         //$oldp = $db->get_payment($oldp_id);
         //$xml_cart   = $gCheckout->get_recurrence_request($oldp['receipt_id']); //$oldp['data']['google-order-number']
         $initial_payment_id = $this->find_initial_payment($payment['payment_id']);
         $initial_payment = $db->get_payment($initial_payment_id);
         $xml_cart = $gCheckout->get_recurrence_request($initial_payment['receipt_id']);
     }
     $response = $gCheckout->SendRequest($xml_cart, 'request');
     $res = $gCheckout->ProcessXmlData($response);
     if ($res['error-message']) {
         $gCheckout->LogMessage($res['error-message'], $debug_only_msg = true);
         return array("Google Checkout payment error. Please contact site administrator: <a href=\"mailto:" . $config['admin_email'] . "\">" . $config['admin_email'] . "</a>", $res['error-message']);
     }
     return $res;
 }