/** * This method is handles the response that will be invoked (from extern/googleNotify) every time * a notification or request is sent by the Google Server. * */ static function main($xml_response) { require_once 'Google/library/googleresponse.php'; require_once 'Google/library/googlerequest.php'; require_once 'Google/library/googlemerchantcalculations.php'; require_once 'Google/library/googleresult.php'; require_once 'Google/library/xml-processing/gc_xmlparser.php'; $config = CRM_Core_Config::singleton(); // Retrieve the XML sent in the HTTP POST request to the ResponseHandler if (get_magic_quotes_gpc()) { $xml_response = stripslashes($xml_response); } $headers = CRM_Utils_System::getAllHeaders(); if (GOOGLE_DEBUG_PP) { CRM_Core_Error::debug_var('RESPONSE', $xml_response, TRUE, TRUE, 'Google'); } // Retrieve the root and data from the xml response $response = new GoogleResponse(); list($root, $data) = $response->GetParsedXML($xml_response); // lets retrieve the private-data & order-no $privateData = NULL; if (array_key_exists('shopping-cart', $data[$root])) { $privateData = $data[$root]['shopping-cart']['merchant-private-data']['VALUE']; } if (empty($privateData) && array_key_exists('order-summary', $data[$root]) && array_key_exists('shopping-cart', $data[$root]['order-summary'])) { $privateData = $data[$root]['order-summary']['shopping-cart']['merchant-private-data']['VALUE']; } $privateData = $privateData ? self::stringToArray($privateData) : ''; $orderNo = $data[$root]['google-order-number']['VALUE']; $serial = $data[$root]['serial-number']; // a dummy object to call get context and a parent function inside it. $ipn = new CRM_Core_Payment_GoogleIPN('live', $dummyProcessor); list($mode, $module, $paymentProcessorID) = $ipn->getContext($privateData, $orderNo, $root, $response, $serial); $mode = $mode ? 'test' : 'live'; $paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($paymentProcessorID, $mode); $merchant_id = $paymentProcessor['user_name']; $merchant_key = $paymentProcessor['password']; $response->SetMerchantAuthentication($merchant_id, $merchant_key); $server_type = $mode == 'test' ? 'sandbox' : 'production'; $request = new GoogleRequest($merchant_id, $merchant_key, $server_type); $ipn = self::singleton($mode, $module, $paymentProcessor); if (GOOGLE_DEBUG_PP) { CRM_Core_Error::debug_var('RESPONSE-ROOT', $response->root, TRUE, TRUE, 'Google'); } //Check status and take appropriate action $status = $response->HttpAuthentication($headers); switch ($root) { case "request-received": case "error": case "diagnosis": case "checkout-redirect": case "merchant-calculation-callback": break; case "new-order-notification": $response->SendAck($serial, FALSE); $ipn->newOrderNotify($data[$root], $privateData, $module); break; case "order-state-change-notification": $response->SendAck($serial, FALSE); $new_financial_state = $data[$root]['new-financial-order-state']['VALUE']; $new_fulfillment_order = $data[$root]['new-fulfillment-order-state']['VALUE']; switch ($new_financial_state) { case 'CHARGEABLE': break; case 'CHARGED': case 'PAYMENT_DECLINED': case 'CANCELLED': case 'CANCELLED_BY_GOOGLE': $ipn->orderStateChange($new_financial_state, $data[$root], $privateData, $module); break; case 'REVIEWING': case 'CHARGING': break; default: break; } break; case "authorization-amount-notification": $response->SendAck($serial, FALSE); $new_financial_state = $data[$root]['order-summary']['financial-order-state']['VALUE']; $new_fulfillment_order = $data[$root]['order-summary']['fulfillment-order-state']['VALUE']; switch ($new_financial_state) { case 'CHARGEABLE': // For google-handled subscriptions chargeorder needn't be initiated, // assuming auto-charging is turned on. //$request->SendProcessOrder($data[$root]['google-order-number']['VALUE']); //$request->SendChargeOrder($data[$root]['google-order-number']['VALUE'],''); break; case 'CHARGED': case 'PAYMENT_DECLINED': case 'CANCELLED': break; case 'REVIEWING': case 'CHARGING': case 'CANCELLED_BY_GOOGLE': break; default: break; } break; case "charge-amount-notification": case "chargeback-amount-notification": case "refund-amount-notification": case "risk-information-notification": $response->SendAck($serial); break; default: break; } }
function nzsc_googleResponse() { global $wpdb, $user_ID; $merchant_id = get_option('google_id'); $merchant_key = get_option('google_key'); $server_type = get_option('google_server_type'); $currency = get_option('google_cur'); define('RESPONSE_HANDLER_ERROR_LOG_FILE', 'library/googleerror.log'); define('RESPONSE_HANDLER_LOG_FILE', 'library/googlemessage.log'); if (stristr($_SERVER['HTTP_USER_AGENT'], "Google Checkout Notification Agent")) { $Gresponse = new GoogleResponse($merchant_id, $merchant_key); $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); $message = "<pre>" . print_r($user_marketing_preference, 1) . "</pre>"; $sessionid = mt_rand(100, 999) . time(); if ($root == "new-order-notification") { $_SESSION['nzshpcrt_cart'] = ''; $cart_items = $data['new-order-notification']['shopping-cart']['items']; $user_marketing_preference = $data['new-order-notification']['buyer-marketing-preferences']['email-allowed']['VALUE']; $shipping_name = $data['new-order-notification']['buyer-shipping-address']['contact-name']['VALUE']; $shipping_name = explode(" ", $shipping_name); $shipping_firstname = $shipping_name[0]; $shipping_lastname = $shipping_name[count($shipping_name) - 1]; $shipping_country = $data['new-order-notification']['buyer-shipping-address']['country-code']['VALUE']; $shipping_address1 = $data['new-order-notification']['buyer-shipping-address']['address1']['VALUE']; $shipping_address2 = $data['new-order-notification']['buyer-shipping-address']['address2']['VALUE']; $shipping_city = $data['new-order-notification']['buyer-shipping-address']['city']['VALUE']; $shipping_region = $data['new-order-notification']['buyer-shipping-address']['region']['VALUE']; $billing_name = $data['new-order-notification']['buyer-billing-address']['contact-name']['VALUE']; $billing_name = explode(" ", $shipping_name); $billing_firstname = $shipping_name[0]; $billing_lastname = $shipping_name[count($shipping_name) - 1]; $billing_region = $data['new-order-notification']['buyer-billing-address']['region']['VALUE']; $billing_country = $data['new-order-notification']['buyer-billing-address']['country-code']['VALUE']; $total_price = $data['new-order-notification']['order-total']['VALUE']; $billing_email = $data['new-order-notification']['buyer-billing-address']['email']['VALUE']; $billing_phone = $data['new-order-notification']['buyer-billing-address']['phone']['VALUE']; $billing_address = $data['new-order-notification']['buyer-billing-address']['address1']['VALUE']; $billing_address .= " " . $data['new-order-notification']['buyer-billing-address']['address2']['VALUE']; $billing_address .= " " . $data['new-order-notification']['buyer-billing-address']['city']['VALUE']; $billing_city = $data['new-order-notification']['buyer-billing-address']['city']['VALUE']; $google_order_number = $data['new-order-notification']['google-order-number']['VALUE']; $pnp = $data['new-order-notification']['order-adjustment']['shipping']['flat-rate-shipping-adjustment']['shipping-cost']['VALUE']; $affiliate_id = $data['new-order-notification']['shopping-cart']['merchant-private-data']; $affiliate_id = explode('=', $affiliate_id); if ($affiliate_id[0] == 'affiliate_id') { if ($affiliate_id[1] == '') { $affiliate_id = null; } else { $affiliate_id = $affiliate_id[1]; } } //$tax = $data['new-order-notification']['order-adjustment'][]; $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); $result = $Grequest->SendProcessOrder($google_order_number); $region_number = $wpdb->get_var("SELECT id FROM " . WPSC_TABLE_REGION_TAX . "` WHERE code ='" . $billing_region . "'"); $sql = "INSERT INTO `" . WPSC_TABLE_PURCHASE_LOGS . "` ( `totalprice` , `sessionid` , `date`, `billing_country`, `shipping_country`,`base_shipping`,`shipping_region`, `user_ID`, `discount_value`,`gateway`, `google_order_number`, `google_user_marketing_preference`, `affiliate_id`) VALUES ( '" . $total_price . "', '" . $sessionid . "', '" . time() . "', '" . $billing_country . "', '" . $shipping_country . "', '" . $pnp . "','" . $region_number . "' , '" . $user_ID . "' , '" . $_SESSION['wpsc_discount'] . "','" . get_option('payment_gateway') . "','" . $google_order_number . "','" . $user_marketing_preference . "', '" . $affiliate_id . "')"; // mail('*****@*****.**',"",$sql); $wpdb->query($sql); $log_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` IN('" . $sessionid . "') LIMIT 1"); $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET firstname='" . $shipping_firstname . "', lastname='" . $shipping_lastname . "', email='" . $billing_email . "', phone='" . $billing_phone . "' WHERE id='" . $log_id . "'"; $wpdb->query($sql); if (array_key_exists(0, $cart_items['item'])) { $cart_items = $cart_items['item']; } //logging to submited_form_data $billing_fname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='first_name' LIMIT 1"); $sql = "INSERT INTO `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` (log_id, form_id, value) VALUES ('" . $log_id . "','" . $billing_fname_id . "','" . $billing_firstname . "')"; //$wpdb->query($sql) ; $billing_lname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='last_name' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_lname_id . "','" . $billing_lastname . "')"; $billing_address_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='address' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_address_id . "','" . $billing_address . "')"; $billing_city_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='city' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_city_id . "','" . $billing_city . "')"; $billing_country_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='country' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_country_id . "','" . $billing_country . "')"; $billing_state_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='state' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_state_id . "','" . $billing_region . "')"; $shipping_fname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_first_name' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_fname_id . "','" . $shipping_firstname . "')"; $shipping_lname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_last_name' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_lname_id . "','" . $shipping_lastname . "')"; $shipping_address_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_address' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_address_id . "','" . $shipping_address1 . " " . $shipping_address2 . "')"; $shipping_city_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_city' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_city_id . "','" . $shipping_city . "')"; $shipping_state_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_state' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_state_id . "','" . $shipping_region . "')"; $shipping_country_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_country' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_country_id . "','" . $shipping_country . "')"; $wpdb->query($sql); //$variations = $cart_item->product_variations; foreach ($cart_items as $cart_item) { $product_id = $cart_item['merchant-item-id']['VALUE']; $item_name = $cart_item['item-name']['VALUE']; $item_desc = $cart_item['item-description']['VALUE']; $item_unit_price = $cart_item['unit-price']['VALUE']; $item_quantity = $cart_item['quantity']['VALUE']; $product_info = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE id='" . $product_id . "' LIMIT 1", ARRAY_A); $product_info = $product_info[0]; //mail("*****@*****.**","",print_r($product_info,1)); if ($product_info['notax'] != 1) { //$price = nzshpcrt_calculate_tax($item_unit_price, $billing_country, $region_number); if (get_option('base_country') == $billing_country) { $country_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode` IN('" . get_option('base_country') . "') LIMIT 1", ARRAY_A); if ($country_data['has_regions'] == 1) { if (get_option('base_region') == $region_number) { $region_data = $wpdb->get_row("SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `" . WPSC_TABLE_REGION_TAX . "`.`country_id` IN('" . $country_data['id'] . "') AND `" . WPSC_TABLE_REGION_TAX . "`.`id` IN('" . get_option('base_region') . "') ", ARRAY_A); } $gst = $region_data['tax']; } else { $gst = $country_data['tax']; } } else { $gst = 0; } } else { $gst = 0; } if ($product_info['no_shipping'] == '0') { if ($shipping_country == get_option('base_country')) { $pnp = $product_info['pnp']; } else { $pnp = $product_info['international_pnp']; } } else { $pnp = 0; } $cartsql = "INSERT INTO `" . WPSC_TABLE_CART_CONTENTS . "` ( `prodid` , `purchaseid`, `price`, `pnp`, `gst`, `quantity`, `donation`, `no_shipping` ) VALUES ('" . $product_id . "', '" . $log_id . "','" . $item_unit_price . "','" . $pnp . "', '" . $gst . "','" . $item_quantity . "', '" . $product_info['donation'] . "', '" . $product_info['no_shipping'] . "')"; $wpdb->query($cartsql); } } if ($root == "order-state-change-notification") { $google_order_number = $data['order-state-change-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number='" . $google_order_number . "'"); $google_status = unserialize($google_status); if ($google_status[0] != 'Partially Charged' && $google_status[0] != 'Partially Refunded') { $google_status[0] = $data['order-state-change-notification']['new-financial-order-state']['VALUE']; $google_status[1] = $data['order-state-change-notification']['new-fulfillment-order-state']['VALUE']; } $google_status = serialize($google_status); $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET google_status='" . $google_status . "' WHERE google_order_number='" . $google_order_number . "'"; $wpdb->query($sql); if ($data['order-state-change-notification']['new-financial-order-state']['VALUE'] == 'CHARGEABLE' && get_option('google_auto_charge') == '1') { $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); $result = $Grequest->SendChargeOrder($google_order_number); $_SESSION['nzshpcrt_cart'] = ''; unset($_SESSION['coupon_num'], $_SESSION['google_session']); $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET processed='2' WHERE google_order_number='" . $google_order_number . "'"; $wpdb->query($sql); } } if ($root == "charge-amount-notification") { $google_order_number = $data['charge-amount-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number='" . $google_order_number . "'"); $google_status = unserialize($google_status); $total_charged = $data['charge-amount-notification']['total-charge-amount']['VALUE']; $google_status['partial_charge_amount'] = $total_charged; $totalprice = $wpdb->get_var("SELECT totalprice FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number='" . $google_order_number . "'"); if ($totalprice > $total_charged) { $google_status[0] = 'Partially Charged'; } else { if ($totalprice = $total_charged) { $google_status[0] = 'CHARGED'; } } $google_status = serialize($google_status); $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET google_status='" . $google_status . "' WHERE google_order_number='" . $google_order_number . "'"; $wpdb->query($sql); } if ($root == "refund-amount-notification") { $google_order_number = $data['refund-amount-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number='" . $google_order_number . "'"); $google_status = unserialize($google_status); $total_charged = $data['refund-amount-notification']['total-refund-amount']['VALUE']; $google_status['partial_refund_amount'] = $total_charged; $totalprice = $wpdb->get_var("SELECT totalprice FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number='" . $google_order_number . "'"); if ($totalprice > $total_charged) { $google_status[0] = 'Partially refunded'; } else { if ($totalprice = $total_charged) { $google_status[0] = 'REFUNDED'; } } $google_status = serialize($google_status); $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET google_status='" . $google_status . "' WHERE google_order_number='" . $google_order_number . "'"; $wpdb->query($sql); } // <avs-response>Y</avs-response> // <cvn-response>M</cvn-response> if ($root == "risk-information-notification") { $google_order_number = $data['risk-information-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number='" . $google_order_number . "'"); $google_status = unserialize($google_status); $google_status['cvn'] = $data['risk-information-notification']['risk-information']['cvn-response']['VALUE']; $google_status['avs'] = $data['risk-information-notification']['risk-information']['avs-response']['VALUE']; $google_status['protection'] = $data['risk-information-notification']['risk-information']['eligible-for-protection']['VALUE']; $google_status = serialize($google_status); $google_status = $wpdb->query("UPDATE " . WPSC_TABLE_PURCHASE_LOGS . " SET google_status='" . $google_status . "' WHERE google_order_number='" . $google_order_number . "'"); if ($data['risk-information-notification']['risk-information']['cvn-response']['VALUE'] == 'E') { $google_risk = 'cvn'; } if (in_array($data['risk-information-notification']['risk-information']['avs-response']['VALUE'], array('N', 'U'))) { if (isset($google_risk)) { $google_risk = 'cvn+avs'; } else { $google_risk = 'avs'; } } if (isset($google_risk)) { $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET google_risk='" . $google_risk . "' WHERE google_order_number='" . $google_order_number . "'"; $wpdb->query($sql); } } if ($root == "order-state-change-notification") { $google_order_number = $data['order-state-change-notification']['google-order-number']['VALUE']; if ($data['order-state-change-notification']['new-financial-order-state']['VALUE'] == "CANCELLED_BY_GOOGLE") { $google_status = $wpdb->get_var("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number='" . $google_order_number . "'"); $google_status = unserialize($google_status); $google_status[0] = "CANCELLED_BY_GOOGLE"; $wpdb->get_var("UPDATE " . WPSC_TABLE_PURCHASE_LOGS . " SET google_status='" . serialize($google_status) . "' WHERE google_order_number='" . $google_order_number . "'"); } } // mail('*****@*****.**',"",$root . " <pre>". print_r($data,1)."</pre>"); exit; } }
define('GC_STATE_SHIPPED', 102); define('GC_STATE_REFUNDED', 103); define('GC_STATE_SHIPPED_REFUNDED', 104); define('GC_STATE_CANCELED', 105); chdir('./..'); $curr_dir = getcwd(); define('API_CALLBACK_ERROR_LOG', $curr_dir . "/googlecheckout/logs/response_error.log"); define('API_CALLBACK_MESSAGE_LOG', $curr_dir . "/googlecheckout/logs/response_message.log"); require_once $curr_dir . '/googlecheckout/library/googlemerchantcalculations.php'; require_once $curr_dir . '/googlecheckout/library/googleresult.php'; require_once $curr_dir . '/googlecheckout/library/googlerequest.php'; require_once $curr_dir . '/googlecheckout/library/googleresponse.php'; require_once $curr_dir . '/googlecheckout/library/configuration/google_configuration.php'; require_once $curr_dir . '/googlecheckout/library/configuration/google_configuration_keys.php'; $config = new GoogleConfigurationKeys(); $google_response = new GoogleResponse(); // Set up the log files. $google_response->SetLogFiles(API_CALLBACK_ERROR_LOG, API_CALLBACK_MESSAGE_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, $gc_data) = $google_response->GetParsedXML($xml_response); // Session variables. if (isset($gc_data[$root]['shopping-cart']['merchant-private-data']['session-data']['VALUE'])) { list($sess_id, $sess_name) = explode(";", $gc_data[$root]['shopping-cart']['merchant-private-data']['session-data']['VALUE']); // If session management is supported by this PHP version. if (function_exists('session_id')) { session_id($sess_id); }
$application = Engine_Api::getInstance()->getApplication(); //$application = Engine_Api::getInstance()->getApplication(); $application->getBootstrap()->bootstrap('frontcontroller'); $application->getBootstrap()->bootstrap('cache'); $application->getBootstrap()->bootstrap('db'); $application->getBootstrap()->bootstrap('translate'); $application->getBootstrap()->bootstrap('frontcontrollermodules'); $application->getBootstrap()->bootstrap('session'); $application->getBootstrap()->bootstrap('manifest'); $application->getBootstrap()->bootstrap('router'); $application->getBootstrap()->bootstrap('view'); $application->getBootstrap()->bootstrap('layout'); $application->getBootstrap()->bootstrap('modules'); function getLog($filename = 'store.notify.log') { $writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/temporary/log/' . $filename); return new Zend_Log($writer); } require_once APPLICATION_PATH . '/application/modules/Socialstore/externals/scripts/library/googlemerchantcalculations.php'; require_once APPLICATION_PATH . '/application/modules/Socialstore/externals/scripts/library/googleresult.php'; require_once APPLICATION_PATH . '/application/modules/Socialstore/externals/scripts/library/googlerequest.php'; require_once APPLICATION_PATH . '/application/modules/Socialstore/externals/scripts/library/googleresponse.php'; $Gresponse = new GoogleResponse(); $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); } $response = $Gresponse->GetParsedXML($xml_response); getLog('store.response.log')->log(var_dump($response, true), Zend_Log::DEBUG); ?>
<?php require_once dirname(__FILE__) . '/../../config/config.inc.php'; require_once dirname(__FILE__) . '/gcheckout.php'; require_once dirname(__FILE__) . '/library/googleresponse.php'; require_once dirname(__FILE__) . '/library/googlemerchantcalculations.php'; require_once dirname(__FILE__) . '/library/googleresult.php'; require_once dirname(__FILE__) . '/library/googlerequest.php'; $gcheckout = new GCheckout(); $merchant_id = Configuration::get('GCHECKOUT_MERCHANT_ID'); $merchant_key = Configuration::get('GCHECKOUT_MERCHANT_KEY'); $server_type = Configuration::get('GCHECKOUT_MODE'); $currency = $gcheckout->getCurrency(); $Gresponse = new GoogleResponse($merchant_id, $merchant_key); $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); //Setup the log file if (Configuration::get('GCHECKOUT_LOGS')) { $Gresponse->SetLogFiles('googleerror.log', 'googlemessage.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); $Gresponse->SetMerchantAuthentication($merchant_id, $merchant_key); $status = $Gresponse->HttpAuthentication(); if (!$status) { die('authentication failed'); } /* Commands to send the various order processing APIs
/** * This method is handles the response that will be invoked (from extern/googleNotify) every time * a notification or request is sent by the Google Server. * */ static function main($xml_response) { require_once 'Google/library/googleresponse.php'; require_once 'Google/library/googlemerchantcalculations.php'; require_once 'Google/library/googleresult.php'; require_once 'Google/library/xml-processing/xmlparser.php'; $config = CRM_Core_Config::singleton(); // Retrieve the XML sent in the HTTP POST request to the ResponseHandler if (get_magic_quotes_gpc()) { $xml_response = stripslashes($xml_response); } require_once 'CRM/Utils/System.php'; $headers = CRM_Utils_System::getAllHeaders(); if (GOOGLE_DEBUG_PP) { CRM_Core_Error::debug_var('RESPONSE', $xml_response, TRUE, TRUE, 'Google'); } // Retrieve the root and data from the xml response $xmlParser = new XmlParser($xml_response); $root = $xmlParser->GetRoot(); $data = $xmlParser->GetData(); $orderNo = $data[$root]['google-order-number']['VALUE']; // lets retrieve the private-data $privateData = $data[$root]['shopping-cart']['merchant-private-data']['VALUE']; $privateData = $privateData ? self::stringToArray($privateData) : ''; list($mode, $module, $paymentProcessorID) = self::getContext($xml_response, $privateData, $orderNo, $root); $mode = $mode ? 'test' : 'live'; require_once 'CRM/Financial/BAO/PaymentProcessor.php'; $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID, $mode); $ipn =& self::singleton($mode, $module, $paymentProcessor); // Create new response object $merchant_id = $paymentProcessor['user_name']; $merchant_key = $paymentProcessor['password']; $server_type = $mode == 'test' ? "sandbox" : ''; $response = new GoogleResponse($merchant_id, $merchant_key, $xml_response, $server_type); if (GOOGLE_DEBUG_PP) { CRM_Core_Error::debug_var('RESPONSE-ROOT', $response->root, TRUE, TRUE, 'Google'); } //Check status and take appropriate action $status = $response->HttpAuthentication($headers); switch ($root) { case "request-received": case "error": case "diagnosis": case "checkout-redirect": case "merchant-calculation-callback": break; case "new-order-notification": $response->SendAck(); $ipn->newOrderNotify($data[$root], $privateData, $module); break; case "order-state-change-notification": $response->SendAck(); $new_financial_state = $data[$root]['new-financial-order-state']['VALUE']; $new_fulfillment_order = $data[$root]['new-fulfillment-order-state']['VALUE']; switch ($new_financial_state) { case 'CHARGEABLE': $amount = $ipn->getAmount($orderNo); if ($amount) { $response->SendChargeOrder($data[$root]['google-order-number']['VALUE'], $amount, $message_log); $response->SendProcessOrder($data[$root]['google-order-number']['VALUE'], $message_log); } break; case 'CHARGED': case 'PAYMENT_DECLINED': case 'CANCELLED': $ipn->orderStateChange($new_financial_state, $data[$root], $module); break; case 'REVIEWING': case 'CHARGING': case 'CANCELLED_BY_GOOGLE': break; default: break; } case "charge-amount-notification": case "chargeback-amount-notification": case "refund-amount-notification": case "risk-information-notification": $response->SendAck(); break; default: 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; } }
function callback($in, &$paymentId, &$money, &$message) { ##chdir(".."); define('RESPONSE_HANDLER_LOG_FILE', 'googlemessage.log'); //Setup the log file if (!($message_log = fopen(RESPONSE_HANDLER_LOG_FILE, "a"))) { $message = "Cannot open " . RESPONSE_HANDLER_LOG_FILE . " file."; return PAY_ERROR; } // Retrieve the XML sent in the HTTP POST request to the ResponseHandler $xml_response = $HTTP_RAW_POST_DATA; if (get_magic_quotes_gpc()) { $xml_response = stripslashes($xml_response); } $headers = getallheaders(); fwrite($message_log, sprintf("\n\r%s:- %s\n", date("D M j G:i:s T Y"), $xml_response)); $merchant_key = $this->getConf($in["M_OrderId"], 'PrivateKey'); //todo支付号没有 // Create new response object //$merchant_id = ""; //Your Merchant ID //$merchant_key = ""; //Your Merchant Key $server_type = "checkout"; $response = new GoogleResponse($merchant_id, $merchant_key, $xml_response, $server_type); $root = $response->root; $data = $response->data; fwrite($message_log, sprintf("\n\r%s:- %s\n", date("D M j G:i:s T Y"), $response->root)); //Use the following two lines to log the associative array storing the XML data //$result = print_r($data,true); //fwrite($message_log, sprintf("\n\r%s:- %s\n",date("D M j G:i:s T Y"),$result)); //Check status and take appropriate action $status = $response->HttpAuthentication($headers); /* Commands to send the various order processing APIs * Send charge order : $response->SendChargeOrder($data[$root] * ['google-order-number']['VALUE'], <amount>, $message_log); * Send proces order : $response->SendProcessOrder($data[$root] * ['google-order-number']['VALUE'], $message_log); * Send deliver order: $response->SendDeliverOrder($data[$root] * ['google-order-number']['VALUE'], <carrier>, <tracking-number>, * <send_mail>, $message_log); * Send archive order: $response->SendArchiveOrder($data[$root] * ['google-order-number']['VALUE'], $message_log); * */ 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(); // Loop through the list of address ids from the callback $addresses = $this->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['region']['VALUE']; // Loop through each shipping method if merchant-calculated shipping // support is to be provided if (isset($data[$root]['calculate']['shipping'])) { $shipping = $this->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 = 10; // Modify this to get the actual price $shippable = "true"; // Modify this as required $merchant_result = new GoogleResult($curr_id); $merchant_result->SetShippingDetails($name, $price, "USD", $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, "USD"); } $codes = $this->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, "USD", "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, "USD"); } $codes = $this->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, "USD", "test2"); $merchant_result->AddCoupons($coupons); } $merchant_calc->AddResult($merchant_result); } } fwrite($message_log, sprintf("\n\r%s:- %s\n", date("D M j G:i:s T Y"), $merchant_calc->GetXML())); $response->ProcessMerchantCalculations($merchant_calc); break; case "new-order-notification": $response->SendAck(); break; case "order-state-change-notification": $response->SendAck(); $new_financial_state = $data[$root]['new-financial-order-state']['VALUE']; $new_fulfillment_order = $data[$root]['new-fulfillment-order-state']['VALUE']; switch ($new_financial_state) { case 'REVIEWING': break; case 'CHARGEABLE': //$response->SendProcessOrder($data[$root]['google-order-number']['VALUE'], // $message_log); //$response->SendChargeOrder($data[$root]['google-order-number']['VALUE'], // '', $message_log); break; case 'CHARGING': break; case 'CHARGED': break; case 'PAYMENT_DECLINED': break; case 'CANCELLED': break; case 'CANCELLED_BY_GOOGLE': //$response->SendBuyerMessage($data[$root]['google-order-number']['VALUE'], // "Sorry, your order is cancelled by Google", true, $message_log); break; default: break; } switch ($new_fulfillment_order) { case 'NEW': break; case 'PROCESSING': break; case 'DELIVERED': break; case 'WILL_NOT_DELIVER': break; default: break; } case "charge-amount-notification": $response->SendAck(); //$response->SendDeliverOrder($data[$root]['google-order-number']['VALUE'], // <carrier>, <tracking-number>, <send-email>, $message_log); //$response->SendArchiveOrder($data[$root]['google-order-number']['VALUE'], // $message_log); break; case "chargeback-amount-notification": $response->SendAck(); break; case "refund-amount-notification": $response->SendAck(); break; case "risk-information-notification": $response->SendAck(); break; default: break; } return PAY_SUCCESS; ## }
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 */ }
function nzsc_googleResponse() { global $wpdb, $user_ID; $merchant_id = get_option('google_id'); $merchant_key = get_option('google_key'); $server_type = get_option('google_server_type'); $currency = get_option('google_cur'); $xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input"); define('RESPONSE_HANDLER_ERROR_LOG_FILE', 'library/googleerror.log'); define('RESPONSE_HANDLER_LOG_FILE', 'library/googlemessage.log'); if (stristr($_SERVER['HTTP_USER_AGENT'], "Google Checkout Notification Agent")) { $Gresponse = new GoogleResponse($merchant_id, $merchant_key); $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); $message = "<pre>" . print_r($user_marketing_preference, 1) . "</pre>"; $sessionid = mt_rand(100, 999) . time(); if ($root == "new-order-notification") { $_SESSION['nzshpcrt_cart'] = ''; $cart_items = $data['new-order-notification']['shopping-cart']['items']; $user_marketing_preference = $data['new-order-notification']['buyer-marketing-preferences']['email-allowed']['VALUE']; $shipping_name = $data['new-order-notification']['buyer-shipping-address']['contact-name']['VALUE']; $shipping_name = explode(" ", $shipping_name); $shipping_firstname = $shipping_name[0]; $shipping_lastname = $shipping_name[count($shipping_name) - 1]; $shipping_country = $data['new-order-notification']['buyer-shipping-address']['country-code']['VALUE']; $shipping_address1 = $data['new-order-notification']['buyer-shipping-address']['address1']['VALUE']; $shipping_address2 = $data['new-order-notification']['buyer-shipping-address']['address2']['VALUE']; $shipping_city = $data['new-order-notification']['buyer-shipping-address']['city']['VALUE']; $shipping_region = $data['new-order-notification']['buyer-shipping-address']['region']['VALUE']; $billing_name = $data['new-order-notification']['buyer-billing-address']['contact-name']['VALUE']; $billing_name = explode(" ", $shipping_name); $billing_firstname = $shipping_name[0]; $billing_lastname = $shipping_name[count($shipping_name) - 1]; $billing_region = $data['new-order-notification']['buyer-billing-address']['region']['VALUE']; $billing_country = $data['new-order-notification']['buyer-billing-address']['country-code']['VALUE']; $total_price = $data['new-order-notification']['order-total']['VALUE']; $billing_email = $data['new-order-notification']['buyer-billing-address']['email']['VALUE']; $billing_phone = $data['new-order-notification']['buyer-billing-address']['phone']['VALUE']; $billing_address = $data['new-order-notification']['buyer-billing-address']['address1']['VALUE']; $billing_address .= " " . $data['new-order-notification']['buyer-billing-address']['address2']['VALUE']; $billing_address .= " " . $data['new-order-notification']['buyer-billing-address']['city']['VALUE']; $billing_city = $data['new-order-notification']['buyer-billing-address']['city']['VALUE']; $google_order_number = $data['new-order-notification']['google-order-number']['VALUE']; $pnp = $data['new-order-notification']['order-adjustment']['shipping']['flat-rate-shipping-adjustment']['shipping-cost']['VALUE']; $affiliate_id = $data['new-order-notification']['shopping-cart']['merchant-private-data']; $affiliate_id = explode('=', $affiliate_id); if ($affiliate_id[0] == 'affiliate_id') { if ($affiliate_id[1] == '') { $affiliate_id = null; } else { $affiliate_id = $affiliate_id[1]; } } $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); $result = $Grequest->SendProcessOrder($google_order_number); $region_number = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . WPSC_TABLE_REGION_TAX . "` WHERE code = %s", $billing_region)); $wpdb->insert(WPSC_TABLE_PURCHASE_LOGS, array('totalprice' => $total_price, 'sessionid' => $sessionid, 'date' => time(), 'billing_country' => $billing_country, 'shipping_country' => $shipping_country, 'base_shipping' => $pnp, 'shipping_region' => $region_number, 'user_ID' => $user_ID, 'discount_value' => $_SESSION['wpsc_discount'], 'gateway' => get_option('payment_gateway'), 'google_order_number' => $google_order_number, 'google_user_marketing_preference' => $user_marketing_preference, 'affiliate_id' => $affiliate_id), array('%f', '%s', '%s', '%s', '%s', '%f', '%s', '%d', '%f', '%s', '%s', '%s', '%s')); $log_id = $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` IN(%s) LIMIT 1", $sessionid)); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('firstname' => $shipping_firstname, 'lastname' => $shipping_lastname, 'email' => $billing_email, 'phone' => $billing_phone), array('id' => $log_id), '%s', '%d'); if (array_key_exists(0, $cart_items['item'])) { $cart_items = $cart_items['item']; } //logging to submited_form_data $billing_fname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='first_name' LIMIT 1"); $sql = "INSERT INTO `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` (log_id, form_id, value) VALUES ('" . $log_id . "','" . $billing_fname_id . "','" . esc_sql($billing_firstname) . "')"; $billing_lname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='last_name' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_lname_id . "','" . esc_sql($billing_lastname) . "')"; $billing_address_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='address' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_address_id . "','" . esc_sql($billing_address) . "')"; $billing_city_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='city' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_city_id . "','" . esc_sql($billing_city) . "')"; $billing_country_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='country' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_country_id . "','" . esc_sql($billing_country) . "')"; $billing_state_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='state' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_state_id . "','" . esc_sql($billing_region) . "')"; $shipping_fname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_first_name' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_fname_id . "','" . esc_sql($shipping_firstname) . "')"; $shipping_lname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_last_name' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_lname_id . "','" . esc_sql($shipping_lastname) . "')"; $shipping_address_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_address' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_address_id . "','" . esc_sql($shipping_address1) . " " . esc_sql($shipping_address2) . "')"; $shipping_city_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_city' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_city_id . "','" . esc_sql($shipping_city) . "')"; $shipping_state_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_state' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_state_id . "','" . esc_sql($shipping_region) . "')"; $shipping_country_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_country' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_country_id . "','" . esc_sql($shipping_country) . "')"; $wpdb->query($sql); foreach ($cart_items as $cart_item) { $product_id = $cart_item['merchant-item-id']['VALUE']; $item_name = $cart_item['item-name']['VALUE']; $item_desc = $cart_item['item-description']['VALUE']; $item_unit_price = $cart_item['unit-price']['VALUE']; $item_quantity = $cart_item['quantity']['VALUE']; $product_info = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . $wpdb->posts . "` WHERE id= %d LIMIT 1", $product_id), ARRAY_A); $product_info = $product_info[0]; if ($product_info['notax'] != 1) { if (get_option('base_country') == $billing_country) { $country_data = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode` IN(%s) LIMIT 1", get_option('base_country')), ARRAY_A); if ($country_data['has_regions'] == 1) { if (get_option('base_region') == $region_number) { $region_data = $wpdb->get_row($wpdb->prepare("SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `" . WPSC_TABLE_REGION_TAX . "`.`country_id` IN(%d) AND `" . WPSC_TABLE_REGION_TAX . "`.`id` IN(%d)", $country_data['id'], get_option('base_region')), ARRAY_A); } $gst = $region_data['tax']; } else { $gst = $country_data['tax']; } } else { $gst = 0; } } else { $gst = 0; } if ($product_info['no_shipping'] == '0') { if ($shipping_country == get_option('base_country')) { $pnp = $product_info['pnp']; } else { $pnp = $product_info['international_pnp']; } } else { $pnp = 0; } $wpdb->insert(WPSC_TABLE_CART_CONTENTS, array('prodid' => $product_id, 'purchaseid' => $log_id, 'price' => $item_unit_price, 'pnp' => $pnp, 'gst' => $gst, 'quantity' => $item_quantity, 'donation' => $product_info['donation'], 'no_shipping' => $product_info['no_shipping']), array('%d', '%d', '%s', '%f', '%f', '%d', '%s', '%s')); } } if ($root == "order-state-change-notification") { $google_order_number = $data['order-state-change-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var($wpdb->prepare("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number = %s", $google_order_number)); $google_status = unserialize($google_status); if ($google_status[0] != 'Partially Charged' && $google_status[0] != 'Partially Refunded') { $google_status[0] = $data['order-state-change-notification']['new-financial-order-state']['VALUE']; $google_status[1] = $data['order-state-change-notification']['new-fulfillment-order-state']['VALUE']; } $google_status = serialize($google_status); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('google_status' => $google_status), array('google_order_number' => $google_order_number)); if ($data['order-state-change-notification']['new-financial-order-state']['VALUE'] == 'CHARGEABLE' && get_option('google_auto_charge') == '1') { $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); $result = $Grequest->SendChargeOrder($google_order_number); $_SESSION['nzshpcrt_cart'] = ''; unset($_SESSION['coupon_num'], $_SESSION['google_session']); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('processed' => '3'), array('google_order_number' => $google_order_number)); } } if ($root == "charge-amount-notification") { $google_order_number = $data['charge-amount-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var($wpdb->prepare("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number = %s", $google_order_number)); $google_status = unserialize($google_status); $total_charged = $data['charge-amount-notification']['total-charge-amount']['VALUE']; $google_status['partial_charge_amount'] = $total_charged; $totalprice = $wpdb->get_var($wpdb->prepare("SELECT totalprice FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number = %s", $google_order_number)); if ($totalprice > $total_charged) { $google_status[0] = 'Partially Charged'; } else { if ($totalprice = $total_charged) { $google_status[0] = 'CHARGED'; } } $google_status = serialize($google_status); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('google_status' => $google_status), array('google_order_number' => $google_order_number)); } if ($root == "refund-amount-notification") { $google_order_number = $data['refund-amount-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var($wpdb->prepare("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number= %s", $google_order_number)); $google_status = unserialize($google_status); $total_charged = $data['refund-amount-notification']['total-refund-amount']['VALUE']; $google_status['partial_refund_amount'] = $total_charged; $totalprice = $wpdb->get_var($wpdb->prepare("SELECT totalprice FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number = %s", $google_order_number)); if ($totalprice > $total_charged) { $google_status[0] = 'Partially refunded'; } else { if ($totalprice = $total_charged) { $google_status[0] = 'REFUNDED'; } } $google_status = serialize($google_status); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('google_status' => $google_status), array('google_order_number' => $google_order_number)); } if ($root == "risk-information-notification") { $google_order_number = $data['risk-information-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var($wpdb->prepare("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number = %s", $google_order_number)); $google_status = unserialize($google_status); $google_status['cvn'] = $data['risk-information-notification']['risk-information']['cvn-response']['VALUE']; $google_status['avs'] = $data['risk-information-notification']['risk-information']['avs-response']['VALUE']; $google_status['protection'] = $data['risk-information-notification']['risk-information']['eligible-for-protection']['VALUE']; $google_status = serialize($google_status); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('google_status' => $google_status), array('google_order_number' => $google_order_number)); if ($data['risk-information-notification']['risk-information']['cvn-response']['VALUE'] == 'E') { $google_risk = 'cvn'; } if (in_array($data['risk-information-notification']['risk-information']['avs-response']['VALUE'], array('N', 'U'))) { if (isset($google_risk)) { $google_risk = 'cvn+avs'; } else { $google_risk = 'avs'; } } if (isset($google_risk)) { $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('google_risk' => $google_risk), array('google_order_number' => $google_order_number)); } } if ($root == "order-state-change-notification") { $google_order_number = $data['order-state-change-notification']['google-order-number']['VALUE']; if ($data['order-state-change-notification']['new-financial-order-state']['VALUE'] == "CANCELLED_BY_GOOGLE") { $google_status = $wpdb->get_var($wpdb->prepare("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number = %s", $google_order_number)); $google_status = unserialize($google_status); $google_status[0] = "CANCELLED_BY_GOOGLE"; $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('google_status' => serialize($google_status)), array('google_order_number' => $google_order_number)); } } exit; } }
public function validateIpn($arr_notifications) { try { parent::validateIpn($arr_notifications); $this->payment_result->transaction = $arr_notifications['new-order-notification']['google-order-number']['VALUE']; $arr_lastchange = end($arr_notifications['order-state-change-notification']); switch ($arr_lastchange['new-financial-order-state']['VALUE']) { case "CHARGED": $this->payment_result->confirmed = 1; break; default: $this->payment_result->confirmed = 0; break; } $Gresponse = new GoogleResponse($this->arr_settings['account'], $this->arr_settings['secret']); $ack_response = $Gresponse->SendAck($arr_notifications['serial-number'], false); } catch (Exception $e) { $this->payment_result->log .= "CATCH" . print_r($e, true); $this->payment_result->error = 01; $this->payment_result->confirmed = 0; } return $this->payment_result; }
/** * 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; } } }
require_once 'library/googlemerchantcalculations.php'; require_once 'library/googlerequest.php'; require_once 'library/googlenotificationhistory.php'; define('RESPONSE_HANDLER_ERROR_LOG_FILE', 'googleerror.log'); define('RESPONSE_HANDLER_LOG_FILE', 'googlemessage.log'); //Definitions $merchant_id = ""; // Your Merchant ID $merchant_key = ""; // Your Merchant Key $server_type = "sandbox"; // change this to go live $currency = 'USD'; // set to GBP if in the UK //Create the response object $Gresponse = new GoogleResponse($merchant_id, $merchant_key); //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 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) {
include_once "classes/ConnectionFactory.php"; include_once "classes/DiamondPurchasedHistory.php"; include_once "classes/User.php"; include_once "classes/InAppHttpRequest.php"; include_once "properties/constants.php"; define('RESPONSE_HANDLER_ERROR_LOG_FILE', 'logs/googleerror.log'); define('RESPONSE_HANDLER_LOG_FILE', 'logs/googlemessage.log'); $merchant_id = MERCHANT_ID; // Your Merchant ID $merchant_key = MERCHANT_KEY; // Your Merchant Key $server_type = CHECKOUT_SERVER_TYPE; // change this to go live $currency = CHECKOUT_CURRENCY; // 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'); } switch ($root) {
$fp = fopen($config_file, "r"); while (!feof($fp)) { $line = trim(fgets($fp)); if ($line && !ereg("^{$comment}", $line)) { $pieces = explode("=", $line); $option = trim($pieces[0]); $value = trim($pieces[1]); $config_values[$option] = $value; } } fclose($fp); $merchant_id = $config_values['CONFIG_MERCHANT_ID']; $merchant_key = $config_values['CONFIG_MERCHANT_KEY']; $server_type = $config_values['CONFIG_SERVER_TYPE']; $currency = $config_values['CONFIG_CURRENCY']; $Gresponse = new GoogleResponse($merchant_id, $merchant_key); $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); //serial-number //Setup the log file $Gresponse->SetLogFiles(RESPONSE_HANDLER_ERROR_LOG_FILE, RESPONSE_HANDLER_LOG_FILE, L_ALL); $Grequest->SetLogFiles(RESPONSE_HANDLER_ERROR_LOG_FILE, RESPONSE_HANDLER_LOG_FILE, L_ALL); //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
/** * * This method calls on the notify url of the Google checkout and performed the task accordingly * */ function _process() { require_once dirname(__FILE__) . "/{$this->_element}/library/googleresponse.php"; require_once dirname(__FILE__) . "/{$this->_element}/library/googleresult.php"; require_once dirname(__FILE__) . "/{$this->_element}/library/googlerequest.php"; $response = new GoogleResponse($this->_getParam('merchant_id'), $this->_getParam('merchant_key')); // setup the log files if ($this->_isLog) { $path = JPATH_ROOT . '/cache'; $response->SetLogFiles($path . '/google_error.log', $path . '/google_message.log', L_ALL); $this->_logObj = $response->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 (!$xml_response) { die('No response received'); } if (get_magic_quotes_gpc()) { $xml_response = stripslashes($xml_response); } list($root, $data) = $response->GetParsedXML($xml_response); // TODO Need to Check the Header Information of the request for Authentication // // validate the data (comment for testing) // $response->SetMerchantAuthentication($this->_getParam('merchant_id'), $this->_getParam('merchant_key')); // if ( ! $response->HttpAuthentication()) { // $this->_log('Authentication failed', 'error'); // die('Authentication failed'); // } // prepare the payment data $data = $data[$root]; $payment_details = $this->_getFormattedPaymentDetails($xml_response); // process the payment $error = ''; // svae the goggole orderid in the transaction id if ($root == 'new-order-notification') { $payment_error = $this->_saveTransaction($data, $error); } if ($root == 'order-state-change-notification') { // it's amount charged if ($data['new-financial-order-state']['VALUE'] == 'CHARGED') { $payment_error = $this->_processSale($data, $error, $payment_details); $serial = isset($data) ? $data[$this->root]['serial-number'] : null; $response->SendAck($serial); } } $error = 'processed'; return $error; }
exit(1); } // Retrieve the XML sent in the HTTP POST request to the ResponseHandler $xml_response = $HTTP_RAW_POST_DATA; if (get_magic_quotes_gpc()) { $xml_response = stripslashes($xml_response); } $headers = getallheaders(); fwrite($message_log, sprintf("\n\r%s:- %s\n", date("D M j G:i:s T Y"), $xml_response)); // Create new response object $merchant_id = ""; //Your Merchant ID $merchant_key = ""; //Your Merchant Key $server_type = "sandbox"; $response = new GoogleResponse($merchant_id, $merchant_key, $xml_response, $server_type); $root = $response->root; $data = $response->data; fwrite($message_log, sprintf("\n\r%s:- %s\n", date("D M j G:i:s T Y"), $response->root)); //Use the following two lines to log the associative array storing the XML data //$result = print_r($data,true); //fwrite($message_log, sprintf("\n\r%s:- %s\n",date("D M j G:i:s T Y"),$result)); //Check status and take appropriate action $status = $response->HttpAuthentication($headers); /* Commands to send the various order processing APIs * Send charge order : $response->SendChargeOrder($data[$root] * ['google-order-number']['VALUE'], <amount>, $message_log); * Send proces order : $response->SendProcessOrder($data[$root] * ['google-order-number']['VALUE'], $message_log); * Send deliver order: $response->SendDeliverOrder($data[$root] * ['google-order-number']['VALUE'], <carrier>, <tracking-number>,
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; } }
$application->getBootstrap()->bootstrap('session'); $application->getBootstrap()->bootstrap('manifest'); $application->getBootstrap()->bootstrap('router'); $application->getBootstrap()->bootstrap('view'); $application->getBootstrap()->bootstrap('layout'); $application->getBootstrap()->bootstrap('modules'); function getLog($filename = 'store.notify.log') { $writer = new Zend_Log_Writer_Stream(APPLICATION_PATH . '/temporary/log/' . $filename); return new Zend_Log($writer); } require_once APPLICATION_PATH . '/application/modules/Ynevent/externals/scripts/library/googlemerchantcalculations.php'; require_once APPLICATION_PATH . '/application/modules/Ynevent/externals/scripts/library/googleresult.php'; require_once APPLICATION_PATH . '/application/modules/Ynevent/externals/scripts/library/googlerequest.php'; require_once APPLICATION_PATH . '/application/modules/Ynevent/externals/scripts/library/googleresponse.php'; $Gresponse = new GoogleResponse(); $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); $response = $data; switch ($root) { case "request-received": //process_request_received_response($Gresponse); getLog('store.response.log')->log(print_r('1', true), Zend_Log::DEBUG); break; case "error": //process_error_response($Gresponse); getLog('store.response.log')->log(print_r('2', true), Zend_Log::DEBUG); break;
} 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'];