Category: >> PHP Code >> Accept Payments with Google Checkout Bookmark and Share

<< lastnext >>

Snippet Name: Accept Payments with Google Checkout

Description: Google Checkout is an online checkout process that you integrate with your website, which enables your customers to buy from you quickly, easily and securely, using only one account and a single username and password for purchases. Once a customer purchases something, you can use Google Checkout to charge the amount, process their orders, and receive payments to your personal or business bank account.

Also see:
» PayPal Instant Payment Notificatio...
» Standard PayPal Payment Integration
» CyberCash payment class
» Add dashes to credit card numbers
» Validate credit card numbers
» Active Processes (DBA)
» Automatically process email
» Delete by wildcard

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 28th, 2012

require_once ('google/ResponseHandlerAPIFunctions.php');
$googleMode = 1;//0 for sandbox and 1 for live mode
$GCheckout = new gCart($merchant_id,$mercant_key);
$varcounter =2;// total products
$shop_items[0]= new gItem('first product name','its description','2','2220');//product name, description, quantity, amount
$shop_items[1]= new gItem('second product name','its description','2','2120');//product name, description, quantity, amount
$shop_items[$varcounter]= new gItem("Shipping","Amount for shipping","1",'20');//20 is the shipping amount
$shop_items[$varcounter+1]= new gItem("Tax","Tax amount","1",'110');//110 is the tax amounr
$shop_items[$varcounter+2]= new gItem("Discount","Coupon discount","1",'-25');//25 is the discount amount
$newvar = $GCheckout->getCart();
//echo  $newvar;exit;
$newvar1 = strstr($newvar, '</merchant-checkout-flow-support>');
$firstpartlen=strlen($newvar)-strlen($newvar1);//getting the length diff
//echo  $final_xml;exit;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Google Checkout</title>
<script language="javascript" type="text/javaScript">
function submitForm()
<body   onload="submitForm();">
<?PHP if($googleMode == 0){?><form  method="post" action="<?php echo $merchant_id; ?>/checkout"  name="confirmation" accept-charset="utf-8">
<?PHP }else {?><form method="POST" action="<?php echo $merchant_id; ?>/checkout"  name="confirmation" accept-charset="utf-8"><?PHP } ?>
<input type="hidden" name="cart" value="<?php echo base64_encode($final_xml);?>"/>
<input type="hidden" name="_charset_"/>
<input type="hidden" name="signature" value="<?php echo base64_encode($GCheckout->getSignature($final_xml));?>" />
Need to set the call back url in the merchant’s account page.
Please refer the following link :
The callback page will run in the backend. You will all the return values from here including transaction id, customer values etc. You can update the database from here.
Call back page
//you can check the return value from here by sending a mail to your email id.
foreach($HTTP_POST_VARS as $key=>$value)
$privatedata.=$key."=".$value."<br />";
$header 	 = "From:Google checkout call back<>\n";
$header    .= 'MIME-Version: 1.0' . "\r\n";
$header    .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
@mail("","Comment From google checkout",$privatedata,$header); 
// check your mail for return values and you can update the database using the reutnr value
		$returnid=trim($_REQUEST['shopping-cart_items_item-1_merchant-private-item-data']);// this is the custom id which we have passed
	//firstly check whether the google order number is already in your database. if it is not in your database , firstly you have o charge the order.. (or it can be done by the merchant from his account itself.)
	///For charging the order
	$objGoogle = new GoogleRequest($merchant_id, $mercant_key, 'sandbox', 'USD');
// For charging and refund
//you can charge the order from you site itself. (or it can be done by the merchant from his account itself.)
///For charging the order
$objGoogle = new GoogleRequest($merchant_id, $mercant_key, 'sandbox', 'USD');
// for refund order
$objGoogle = new GoogleRequest($merchant_id, $mercant_key, 'sandbox', 'USD');
$refund_status=$objGoogle->SendRefundOrder($transaction_id, $refund_amount, '', '');
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© | users online: 9