-
-
Save marinalohova/eb63b05ab465c672c6ae to your computer and use it in GitHub Desktop.
Google Wallet response demo handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(E_ALL); | |
require_once('library/googleresponse.php'); | |
require_once('library/googlemerchantcalculations.php'); | |
require_once('library/googleresult.php'); | |
require_once('library/googlerequest.php'); | |
define('RESPONSE_HANDLER_ERROR_LOG_FILE', 'googleerror.log'); | |
define('RESPONSE_HANDLER_LOG_FILE', 'googlemessage.log'); | |
$merchant_id = "Your Merchant ID" | |
$merchant_key = "Your Merchant Key" | |
$server_type = "sandbox"; | |
$currency = 'USD'; | |
$certificate_path = ""; | |
$Gresponse = new GoogleResponse($merchant_id, $merchant_key); | |
$Gresponse->SetLogFiles(RESPONSE_HANDLER_ERROR_LOG_FILE, | |
RESPONSE_HANDLER_LOG_FILE, L_ALL); | |
$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); | |
switch ($root) { | |
case "authorization-amount-notification": { | |
$google_order_number = $data[$root]['google-order-number']['VALUE']; | |
$GChargeRequest = new GoogleRequest($merchant_id, $merchant_key, $server_type); | |
$GChargeRequest->SendChargeAndShipOrder($google_order_number); | |
$Gresponse->sendAck($data[$root]['serial-number']); | |
break; | |
} | |
case "charge-amount-notification":{ | |
$items = get_arr_result($data[$root]['order-summary']['shopping-cart']['items']['item']); | |
$googleid = $data[$root]['google-order-number']['VALUE']; | |
foreach( $items as $item ) { | |
$userid =$item['item-name']['VALUE']; | |
if(isset($userid)){ | |
$amount = $data[$root]['total-charge-amount']['VALUE']; | |
$date = $data[$root]['timestamp']['VALUE']; | |
$tmpsql = "INSERT into orders(google_id, amount, userid) VALUES('".$googleid."', '".$amount."','".$userid . "')"; | |
if(! $sqlresult=mysql_query($tmpsql)) { | |
$Gresponse->log->LogError(mysql_error()); | |
} | |
} | |
} | |
$Gresponse->sendAck($data[$root]['serial-number']); | |
break; | |
} | |
default: | |
$Gresponse->sendAck($data[$root]['serial-number']); | |
break; | |
} | |
function get_arr_result($child_node) { | |
$result = array(); | |
if(isset($child_node)) { | |
if(is_associative_array($child_node)) { | |
$result[] = $child_node; | |
} | |
else { | |
foreach($child_node as $curr_node){ | |
$result[] = $curr_node; | |
} | |
} | |
} | |
return $result; | |
} | |
function is_associative_array( $var ) { | |
return is_array( $var ) && !is_numeric( implode( '', array_keys( $var ) ) ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment