//How to grab the serial number!!!!
/* $serial = $_POST["serial-number"];
  $Gresponse->log->LogResponse("serial:" . $serial);

  if ($serial != null) {
  $Grequest->SendNotificationRequest($serial);
  $Gresponse->SendAck($serial);
  return;
  } */
// Retrieve the XML sent in the HTTP POST request to the ResponseHandler
$xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input");
if (get_magic_quotes_gpc()) {
    $xml_response = stripslashes($xml_response);
}
list($root, $data) = $Gresponse->GetParsedXML($xml_response);
$Gresponse->SetMerchantAuthentication($merchant_id, $merchant_key);
/* $status = $Gresponse->HttpAuthentication();
  if(! $status) {
  die('authentication failed');

  } */
/* Commands to send the various order processing APIs
 * Send charge order : $Grequest->SendChargeOrder($data[$root]
 *    ['google-order-number']['VALUE'], <amount>);
 * Send process order : $Grequest->SendProcessOrder($data[$root]
 *    ['google-order-number']['VALUE']);
 * Send deliver order: $Grequest->SendDeliverOrder($data[$root]
 *    ['google-order-number']['VALUE'], <carrier>, <tracking-number>,
 *    <send_mail>);
 * Send archive order: $Grequest->SendArchiveOrder($data[$root]
 *    ['google-order-number']['VALUE']);
 public function gateway_ipn($config)
 {
     $cancel = $this->EE->input->get('cancel', TRUE);
     if ($cancel != '') {
         $this->EE->product_model->cart_update_status(session_id(), 0);
         $this->EE->functions->redirect($this->EE->functions->create_url($this->_config["store"][$this->site_id]["cart_url"]));
         exit;
     }
     $this->EE->load->library('logger');
     $this->EE->logger->developer('IPN Started');
     require_once 'assets/google-checkout/library/googleresponse.php';
     require_once 'assets/google-checkout/library/googlemerchantcalculations.php';
     require_once 'assets/google-checkout/library/googlerequest.php';
     require_once 'assets/google-checkout/library/googlenotificationhistory.php';
     //Definitions
     $merchant_id = $config['merchant_id'];
     // Your Merchant ID
     $merchant_key = $config['merchant_key'];
     // Your Merchant Key
     $server_type = $config['sandbox'];
     $currency = "USD";
     $certificate_path = "";
     // set your SSL CA cert path
     //Create the response object
     $Gresponse = new GoogleResponse($merchant_id, $merchant_key);
     //Retrieve the XML sent in the HTTP POST request to the ResponseHandler
     $xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input");
     //If serial-number-notification pull serial number and request xml
     if (strpos($xml_response, "xml") == FALSE) {
         //Find serial-number ack notification
         $serial_array = array();
         parse_str($xml_response, $serial_array);
         $serial_number = $serial_array["serial-number"];
         //Request XML notification
         $Grequest = new GoogleNotificationHistoryRequest($merchant_id, $merchant_key, $server_type);
         $raw_xml_array = $Grequest->SendNotificationHistoryRequest($serial_number);
         if ($raw_xml_array[0] != 200) {
             //Add code here to retry with exponential backoff
         } else {
             $raw_xml = $raw_xml_array[1];
         }
         $Gresponse->SendAck($serial_number, false);
     } else {
         //Else assume pre 2.5 XML notification
         //Check Basic Authentication
         $Gresponse->SetMerchantAuthentication($merchant_id, $merchant_key);
         $status = $Gresponse->HttpAuthentication();
         if (!$status) {
             die('authentication failed');
         }
         $raw_xml = $xml_response;
         $Gresponse->SendAck(null, false);
     }
     if (get_magic_quotes_gpc()) {
         $raw_xml = stripslashes($raw_xml);
     }
     list($root, $data) = $Gresponse->GetParsedXML($raw_xml);
     switch ($root) {
         case "new-order-notification":
             $this->EE->logger->developer('Google New Order Notification');
             $transaction_id = $data[$root]['shopping-cart']['merchant-private-data']['transaction_id']['VALUE'];
             $google_order_number = $data[$root]['google-order-number']['VALUE'];
             $this->ipn_create_order($transaction_id, 2);
             $this->add_gc_entry($transaction_id, $google_order_number);
             break;
         case "authorization-amount-notification":
             break;
         case "order-state-change-notification":
             $this->EE->logger->developer('Order State Change Triggered');
             $orderstate = $data[$root]['new-fulfillment-order-state']['VALUE'];
             $google_order_number = $data[$root]['google-order-number']['VALUE'];
             $br_merchant_id = $this->get_gc_entry($google_order_number);
             $status['NEW'] = 2;
             $status['PROCESSING'] = 3;
             $status['DELIVERED'] = 4;
             if (isset($status[$orderstate])) {
                 $this->ipn_create_order($br_merchant_id, $status[$orderstate]);
                 $this->EE->logger->developer("Updating order with status ID: " . $status[$orderstate]);
             }
             break;
     }
 }
示例#3
0
    if (function_exists('session_id')) {
        session_id($sess_id);
    }
    if (function_exists('session_name')) {
        session_name($sess_name);
    }
}
include_once 'includes/application_top.php';
include_once 'includes/modules/payment/googlecheckout.php';
if (tep_session_is_registered('cart') && is_object($cart)) {
    $cart->restore_contents();
} else {
    $google_response->SendServerErrorStatus("Shopping cart not obtained from session.");
}
$google_checkout = new googlecheckout();
$google_response->SetMerchantAuthentication($google_checkout->merchantid, $google_checkout->merchantkey);
// Check if this is CGI-installed; if so .htaccess is needed.
$htaccess = gc_get_configuration_value($config->htaccessAuthMode()) == 'True';
if ($htaccess) {
    $google_response->HttpAuthentication();
}
switch ($root) {
    case "request-received":
        process_request_received_response($google_response);
        break;
    case "error":
        process_error_response($google_response);
        break;
    case "diagnosis":
        process_diagnosis_response($google_response);
        break;
示例#4
0
 function googlecheckoutresponsehandler()
 {
     //chdir("..");
     require_once 'library/googleresponse.php';
     require_once 'library/googlemerchantcalculations.php';
     require_once 'library/googleresult.php';
     require_once 'library/googlerequest.php';
     $this->load->model('payment_model');
     $paymentGateways_google = $this->payment_model->getGooglecheckoutsettings();
     $base_url = $base_url();
     define('RESPONSE_HANDLER_ERROR_LOG_FILE', $base_url . 'googlelog/googleerror.log');
     define('RESPONSE_HANDLER_LOG_FILE', $base_url . 'googlelog/googlemessage.log');
     /*
     		  $merchant_id = "";  // Your Merchant ID
     		  $merchant_key = "";  // Your Merchant Key
     		  $server_type = "sandbox";  // change this to go live
     */
     $merchant_id = $paymentGateways_google['googlecheckout']['merchant_id'];
     // Your Merchant ID
     $merchant_key = $paymentGateways_google['googlecheckout']['merchant_key'];
     // Your Merchant Key
     $server_type = $paymentGateways_google['googlecheckout']['server_type'];
     $currency = 'USD';
     // set to GBP if in the UK
     $Gresponse = new GoogleResponse($merchant_id, $merchant_key);
     $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency);
     //Setup the log file
     $Gresponse->SetLogFiles(RESPONSE_HANDLER_ERROR_LOG_FILE, RESPONSE_HANDLER_LOG_FILE, L_ALL);
     // Retrieve the XML sent in the HTTP POST request to the ResponseHandler
     $xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input");
     if (get_magic_quotes_gpc()) {
         $xml_response = stripslashes($xml_response);
     }
     list($root, $data) = $Gresponse->GetParsedXML($xml_response);
     $Gresponse->SetMerchantAuthentication($merchant_id, $merchant_key);
     $status = $Gresponse->HttpAuthentication();
     if (!$status) {
         die('authentication failed');
     }
     /* Commands to send the various order processing APIs
      * Send charge order : $Grequest->SendChargeOrder($data[$root]
      *    ['google-order-number']['VALUE'], <amount>);
      * Send process order : $Grequest->SendProcessOrder($data[$root]
      *    ['google-order-number']['VALUE']);
      * Send deliver order: $Grequest->SendDeliverOrder($data[$root]
      *    ['google-order-number']['VALUE'], <carrier>, <tracking-number>,
      *    <send_mail>);
      * Send archive order: $Grequest->SendArchiveOrder($data[$root]
      *    ['google-order-number']['VALUE']);
      *
      */
     switch ($root) {
         case "request-received":
             break;
         case "error":
             break;
         case "diagnosis":
             break;
         case "checkout-redirect":
             break;
         case "merchant-calculation-callback":
             // Create the results and send it
             $merchant_calc = new GoogleMerchantCalculations($currency);
             // Loop through the list of address ids from the callback
             $addresses = get_arr_result($data[$root]['calculate']['addresses']['anonymous-address']);
             foreach ($addresses as $curr_address) {
                 $curr_id = $curr_address['id'];
                 $country = $curr_address['country-code']['VALUE'];
                 $city = $curr_address['city']['VALUE'];
                 $region = $curr_address['region']['VALUE'];
                 $postal_code = $curr_address['postal-code']['VALUE'];
                 // Loop through each shipping method if merchant-calculated shipping
                 // support is to be provided
                 if (isset($data[$root]['calculate']['shipping'])) {
                     $shipping = get_arr_result($data[$root]['calculate']['shipping']['method']);
                     foreach ($shipping as $curr_ship) {
                         $name = $curr_ship['name'];
                         //Compute the price for this shipping method and address id
                         $price = 12;
                         // Modify this to get the actual price
                         $shippable = "true";
                         // Modify this as required
                         $merchant_result = new GoogleResult($curr_id);
                         $merchant_result->SetShippingDetails($name, $price, $shippable);
                         if ($data[$root]['calculate']['tax']['VALUE'] == "true") {
                             //Compute tax for this address id and shipping type
                             $amount = 15;
                             // Modify this to the actual tax value
                             $merchant_result->SetTaxDetails($amount);
                         }
                         if (isset($data[$root]['calculate']['merchant-code-strings']['merchant-code-string'])) {
                             $codes = get_arr_result($data[$root]['calculate']['merchant-code-strings']['merchant-code-string']);
                             foreach ($codes as $curr_code) {
                                 //Update this data as required to set whether the coupon is valid, the code and the amount
                                 $coupons = new GoogleCoupons("true", $curr_code['code'], 5, "test2");
                                 $merchant_result->AddCoupons($coupons);
                             }
                         }
                         $merchant_calc->AddResult($merchant_result);
                     }
                 } else {
                     $merchant_result = new GoogleResult($curr_id);
                     if ($data[$root]['calculate']['tax']['VALUE'] == "true") {
                         //Compute tax for this address id and shipping type
                         $amount = 15;
                         // Modify this to the actual tax value
                         $merchant_result->SetTaxDetails($amount);
                     }
                     $codes = get_arr_result($data[$root]['calculate']['merchant-code-strings']['merchant-code-string']);
                     foreach ($codes as $curr_code) {
                         //Update this data as required to set whether the coupon is valid, the code and the amount
                         $coupons = new GoogleCoupons("true", $curr_code['code'], 5, "test2");
                         $merchant_result->AddCoupons($coupons);
                     }
                     $merchant_calc->AddResult($merchant_result);
                 }
             }
             $Gresponse->ProcessMerchantCalculations($merchant_calc);
             break;
         case "new-order-notification":
             $Gresponse->SendAck();
             break;
         case "order-state-change-notification":
             $Gresponse->SendAck();
             $new_financial_state = $data[$root]['new-financial-order-state']['VALUE'];
             $new_fulfillment_order = $data[$root]['new-fulfillment-order-state']['VALUE'];
             $test = array('status' => $new_financial_state);
             $this->common_model->insert('test', $test);
             switch ($new_financial_state) {
                 case 'REVIEWING':
                     break;
                 case 'CHARGEABLE':
                     //$Grequest->SendProcessOrder($data[$root]['google-order-number']['VALUE']);
                     //$Grequest->SendChargeOrder($data[$root]['google-order-number']['VALUE'],'');
                     break;
                 case 'CHARGING':
                     break;
                 case 'CHARGED':
                     break;
                 case 'PAYMENT_DECLINED':
                     break;
                 case 'CANCELLED':
                     break;
                 case 'CANCELLED_BY_GOOGLE':
                     //$Grequest->SendBuyerMessage($data[$root]['google-order-number']['VALUE'],
                     //    "Sorry, your order is cancelled by Google", true);
                     break;
                 default:
                     break;
             }
             switch ($new_fulfillment_order) {
                 case 'NEW':
                     break;
                 case 'PROCESSING':
                     break;
                 case 'DELIVERED':
                     break;
                 case 'WILL_NOT_DELIVER':
                     break;
                 default:
                     break;
             }
             break;
         case "charge-amount-notification":
             //$Grequest->SendDeliverOrder($data[$root]['google-order-number']['VALUE'],
             //    <carrier>, <tracking-number>, <send-email>);
             //$Grequest->SendArchiveOrder($data[$root]['google-order-number']['VALUE'] );
             $Gresponse->SendAck();
             break;
         case "chargeback-amount-notification":
             $Gresponse->SendAck();
             break;
         case "refund-amount-notification":
             $Gresponse->SendAck();
             break;
         case "risk-information-notification":
             $Gresponse->SendAck();
             break;
         default:
             $Gresponse->SendBadRequestStatus("Invalid or not supported Message");
             break;
     }
     /* In case the XML API contains multiple open tags
     		 with the same value, then invoke this function and
     		 perform a foreach on the resultant array.
     		 This takes care of cases when there is only one unique tag
     		 or multiple tags.
     		 Examples of this are "anonymous-address", "merchant-code-string"
     		 from the merchant-calculations-callback API
     	  */
 }
示例#5
0
}
include 'includes/application_top.php';
include 'includes/modules/payment/googlecheckout.php';
//BOF - define value for languages_id//define home page  - added by colosports
$attributes = $db->Execute("select languages_id\n                                      from " . TABLE_LANGUAGES . "\n                                      where name = '" . $_SESSION['language'] . "'\n                                      ");
$languages_id = $attributes->fields['languages_id'];
//EOF - define value for languages_id//define home page  - added by colosports
//  zen_session_start();
if (isset($_SESSION['cart']) && is_object($_SESSION['cart'])) {
    $cart = $_SESSION['cart'];
    $cart->restore_contents();
} else {
    $Gresponse->SendServerErrorStatus("Shopping cart not obtained from session.");
}
$googlepayment = new googlecheckout();
$Gresponse->SetMerchantAuthentication($googlepayment->merchantid, $googlepayment->merchantkey);
// Check if is CGI install, if so .htaccess is needed
if (MODULE_PAYMENT_GOOGLECHECKOUT_CGI != 'True') {
    $Gresponse->HttpAuthentication();
}
switch ($root) {
    case "request-received":
        process_request_received_response($Gresponse);
        break;
    case "error":
        process_error_response($Gresponse);
        break;
    case "diagnosis":
        process_diagnosis_response($Gresponse);
        break;
    case "checkout-redirect":
 /**
  * Check for Google Checkout Response
  **/
 function check_googlecheckout_response()
 {
     if (isset($_GET['googleCheckoutListener']) && $_GET['googleCheckoutListener'] == '1') {
         require_once GOOGLE_CHECKOUT_LIB . 'googleresponse.php';
         require_once GOOGLE_CHECKOUT_LIB . 'googlemerchantcalculations.php';
         require_once GOOGLE_CHECKOUT_LIB . 'googleresult.php';
         require_once GOOGLE_CHECKOUT_LIB . 'googlerequest.php';
         define('RESPONSE_HANDLER_ERROR_LOG_FILE', 'googleerror.log');
         define('RESPONSE_HANDLER_LOG_FILE', 'googlemessage.log');
         $merchant_id = $this->merchant_id;
         // Your Merchant ID
         $merchant_key = $this->merchant_key;
         // Your Merchant Key
         $currency = get_option('woocommerce_currency');
         // Check if this is a test purchase
         if ($this->testmode == 'yes') {
             $server_type = "sandbox";
         } else {
             $server_type = "checkout";
         }
         $Gresponse = new GoogleResponse($merchant_id, $merchant_key);
         $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency);
         //Setup the log file
         $Gresponse->SetLogFiles('', '', L_OFF);
         //Change this to L_ON to log
         // Retrieve the XML sent in the HTTP POST request to the ResponseHandler
         $xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input");
         if (get_magic_quotes_gpc()) {
             $xml_response = stripslashes($xml_response);
         }
         list($root, $data) = $Gresponse->GetParsedXML($xml_response);
         $Gresponse->SetMerchantAuthentication($merchant_id, $merchant_key);
         $googlecheckout_return_values = array("RefNr" => $data[$root]['shopping-cart']['merchant-private-data']['cart-id']['VALUE'], "google_order_number" => $data[$root]['google-order-number']['VALUE'], "financial_order_state" => $data[$root]['financial-order-state']['VALUE']);
         switch ($root) {
             case "new-order-notification":
                 if (isset($googlecheckout_return_values['google_order_number'])) {
                     do_action("valid-googlecheckout-request", $googlecheckout_return_values);
                 }
                 $Gresponse->SendAck();
                 break;
         }
     }
 }
 function callback()
 {
     global $osC_Database, $osC_ShoppingCart;
     require_once 'ext/googlecheckout/googleresponse.php';
     require_once 'ext/googlecheckout/googlemerchantcalculations.php';
     require_once 'ext/googlecheckout/googleresult.php';
     require_once 'ext/googlecheckout/googlerequest.php';
     $fh = fopen('log.txt', 'a+');
     $merchant_id = MODULE_PAYMENT_GCHECKOUT_MERCHANT_ID;
     $merchant_key = MODULE_PAYMENT_GCHECKOUT_MERCHANT_KEY;
     $server_type = MODULE_PAYMENT_GCHECKOUT_SERVER;
     $currency = MODULE_PAYMENT_GCHECKOUT_CURRENCY;
     $Gresponse = new GoogleResponse($merchant_id, $merchant_key);
     $Gresponse->SetLogFiles('includes/logs/gerror.log', 'includes/logs/gmessage.log', L_ALL);
     // Retrieve the XML sent in the HTTP POST request to the ResponseHandler
     $xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input");
     if (get_magic_quotes_gpc()) {
         $xml_response = stripslashes($xml_response);
     }
     list($root, $data) = $Gresponse->GetParsedXML($xml_response);
     fwrite($fh, var_export($data, true));
     fclose($fh);
     $Gresponse->SetMerchantAuthentication($merchant_id, $merchant_key);
     $status = $Gresponse->HttpAuthentication();
     if (!$status) {
         exit;
     }
     switch ($root) {
         case "request-received":
             break;
         case "error":
             break;
         case "diagnosis":
             break;
         case "checkout-redirect":
             break;
         case "merchant-calculation-callback":
             break;
         case "new-order-notification":
             $serial_number = $data['new-order-notification']['serial-number'];
             $Gresponse->setSerialNumber($serial_number);
             $orders_id = $data['new-order-notification']['shopping-cart']['merchant-private-data']['orders_id']['VALUE'];
             $google_order_number = $data['new-order-notification']['google-order-number']['VALUE'];
             $osC_Database->simpleQuery("insert into " . TABLE_ORDER_GOOGLE . " (orders_id, google_order_number) values ('" . $orders_id . "','" . $google_order_number . "')");
             $Gresponse->SendAck();
             break;
         case "order-state-change-notification":
             $serial_number = $data['order-state-change-notification']['serial-number'];
             $Gresponse->setSerialNumber($serial_number);
             $Gresponse->SendAck();
             break;
         case "charge-amount-notification":
             $google_order_number = $data['charge-amount-notification']['google-order-number']['VALUE'];
             $totalcharge = $data['charge-amount-notification']['total-charge-amount']['VALUE'];
             $currency = $data['charge-amount-notification']['total-charge-amount']['currency'];
             $Qorder = $osC_Database->query('select orders_id from :table_order_google where google_order_number = :google_order_number');
             $Qorder->bindTable(':table_order_google', TABLE_ORDER_GOOGLE);
             $Qorder->bindValue(':google_order_number', $google_order_number);
             $Qorder->execute();
             $order_id = 0;
             while ($Qorder->next()) {
                 $order_id = $Qorder->valueInt('orders_id');
             }
             $Qorder->freeResult();
             $Qtotal = $osC_Database->query('select value, text from :table_orders_total where orders_id = :orders_id and class = "total" limit 1');
             $Qtotal->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
             $Qtotal->bindInt(':orders_id', $order_id);
             $Qtotal->execute();
             $total = $Qtotal->toArray();
             $neddtopay = true;
             $comment = 'Google Order Number:<strong> ' . $google_order_number . '</strong>';
             if (abs($totalcharge - $total['value']) < 0.001) {
                 $comment .= '';
                 $neddtopay = false;
             } else {
                 $topay = $total['value'] - $totalcharge;
                 $comment .= 'You have paid ' . $totalcharge . ' ' . $currency . ', and you still have to pay ' . $topay . ' ' . $currency;
             }
             $comments = 'Google Checkout Verified [' . $comment . ']';
             if ($order_id != 0) {
                 if ($neddtopay) {
                     osC_Order::process($order_id, ORDERS_STATUS_PARTLY_PAID, $comments);
                 } else {
                     osC_Order::process($order_id, $this->order_status, $comments);
                 }
             }
             $serial_number = $data['charge-amount-notification']['serial-number'];
             $Gresponse->setSerialNumber($serial_number);
             $Gresponse->SendAck();
             break;
         case "chargeback-amount-notification":
             $serial_number = $data['risk-information-notification']['serial-number'];
             $Gresponse->setSerialNumber($serial_number);
             $Gresponse->SendAck();
             break;
         case "refund-amount-notification":
             $serial_number = $data['refund-amount-notification']['serial-number'];
             $Gresponse->setSerialNumber($serial_number);
             $Gresponse->SendAck();
             break;
         case "risk-information-notification":
             $serial_number = $data['risk-information-notification']['serial-number'];
             $Gresponse->setSerialNumber($serial_number);
             $Gresponse->SendAck();
             break;
         default:
             $Gresponse->SendBadRequestStatus("Invalid or not supported Message");
             break;
     }
 }
示例#8
0
require "../../../init.php";
$whmcs->load_function("gateway");
$whmcs->load_function("invoice");
define("L_OFF", 0);
define("L_ERR", 1);
define("L_RQST", 2);
define("L_RESP", 4);
define("L_ERR_RQST", L_ERR | L_RQST);
define("L_ALL", L_ERR | L_RQST | L_RESP);
$GATEWAY = getGatewayVariables("googlecheckout");
if (!$GATEWAY['type']) {
    exit("Module Not Activated");
}
$xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input");
$Gresponse = new GoogleResponse($GATEWAY['merchantid'], $GATEWAY['merchantkey']);
$Gresponse->SetMerchantAuthentication($GATEWAY['merchantid'], $GATEWAY['merchantkey']);
$status = $Gresponse->HttpAuthentication();
if (!$status) {
    exit("authentication failed");
}
$raw_xml = $xml_response;
$Gresponse->SendAck(null, false);
if (get_magic_quotes_gpc()) {
    $xml_response = stripslashes($xml_response);
}
$xmldata = XMLtoArray($xml_response);
if (is_array($xmldata['CHARGE-AMOUNT-NOTIFICATION'])) {
    $ordernumber = $xmldata['CHARGE-AMOUNT-NOTIFICATION']['GOOGLE-ORDER-NUMBER'];
    $amount = $xmldata['CHARGE-AMOUNT-NOTIFICATION']['LATEST-CHARGE-AMOUNT'];
    $fee = $xmldata['CHARGE-AMOUNT-NOTIFICATION']['LATEST-CHARGE-FEE']['TOTAL'];
    $query = "SELECT data FROM tblgatewaylog WHERE gateway='Google Checkout' AND data LIKE '%new-order-notification%" . db_escape_string($ordernumber) . "%'";