Reply
Highlighted
Member
Posts: 1
Registered: ‎11-30-2012

Custom Shopping Cart: Paypal to Authorize.net

Hello all,  ive built a dynamically rendering custom cart for use with paypal but now need to convert if for use with authorize.net.  All the information is gathered into one form but Im having trouble itemizing and sending all information (item_id, description, price, quantity, total) for multiple products to the payment gateway using SIM.  

 

Any help would be greatly appreciated. Thanks!

 

paypal code:

 

<?php 
// Render Cart for View
$cartOutput = "";
$cartTotal = "";
$pp_checkout_btn = '';
$product_id_array = '';
if(!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
	$cartOutput = "<h2 align='center'>Your Shopping Cart is Empty</h2>";
} else {
	//Start PayPal Checkout Button
	$pp_checkout_btn .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
	<input type="hidden" name="cmd" value="_cart">
	<input type="hidden" name="upload" value="1">
	<input type="hidden" name="business" value="name@example.com">';
	//Start the For Each Loop
	$i = 0;
	foreach ($_SESSION["cart_array"] as $each_item) {
		
		$item_id = $each_item['item_id'];
		$sql = mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1");
		while ($row = mysql_fetch_array($sql)) {
			$product_name = $row["product_name"];
			$price = $row["price"];
			
		}
		$subtotal = $price * $each_item['quantity'];
		$cartTotal = $subtotal + $cartTotal;
		
		setlocale(LC_MONETARY, "en_US");
		$subtotal = money_format("%10.2n", $subtotal);
		
		// Dynamic Checkout Btn Assembly
		$x = $i + 1;
		$pp_checkout_btn .= '<input type="hidden" name="item_name_' . $x . '" value="' . $product_name . '">
		<input type="hidden" name="amount_' . $x . '" value="' . $price . '">
		<input type="hidden" name="quantity_' . $x . '" value="' . $each_item['quantity'] . '"> ';
		
		// Create the product array variable
		$product_id_array .= "$item_id-" .$each_item['quantity'].",";
		
		// Dynamic Table Row Assembly
		$cartOutput .= '<tr>';
		$cartOutput .= '<td><img src="../inventory_images/' . $item_id . '.jpg" width="100" height="66" alt="' . $product_name . '" longdesc="../inventory_images/' . $item_id . '.jpg" /></td>';
		$cartOutput .= '<td>' . $product_name . '</td>';
		$cartOutput .= '<td>$' . $price . '</td>';
		$cartOutput .= '<td><form action="Shopping_Cart.php" method="post">
		<input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" />
		<input name="adjustBtn' . $item_id . '" type="submit" value="Update"/>
		<input name="item_to_adjust" type="hidden" value="' . $item_id . '" />
		</form></td>';
		//$cartOutput .= '<td>' . $each_item['quantity'] . '</td>';
		$cartOutput .= '<td>' . $subtotal . '</td>';
		$cartOutput .= '<td><form action="Shopping_Cart.php" method="post">
		<input name="deleteBtn' . $item_id . '" type="submit" value="X"/>
		<input name="index_to_remove" type="hidden" value="' . $i . '" />
		</form></td>';
		$cartOutput .= '</tr>';
		$i++;
	}
	setlocale(LC_MONETARY, "en_US");
	$cartTotal = money_format("%10.2n", $cartTotal);
	$cartTotal = "Cart Total: " .$cartTotal;
	// Finish the PayPal Checkout Button
	$pp_checkout_btn .= '<input type="hidden" name="custom" value="' . $product_id_array . '">
						 <input type="hidden" name="notify_url" value="https://www.website/my_ipn.php">
						 <input type="hidden" name="return" value="https://www.website/checkout_complete.php">
						 <input type="hidden" name="rm" value="2">
						 <input type="hidden" name="cbt" value="Return to Store">
						 <input type="hidden" name="cancel_return" value="https://www.website/paypal_cancel.php">
						 <input type="hidden" name="lc" value="US">
						 <input type="hidden" name="currency_code" value="USD">
						 <input type="image" src="http://www.website/CheckOutBtn.gif" height="22px" width="110px" name="submit">';

}
?>

 

 

modified code in progress: (its a mess, iknow!)

 

<?php
require_once "../anet_php_sdk/AuthorizeNet.php"; // Render Cart for View $loginID = "1234567"; $transactionKey = "abcdefgh"; $amount = ""; $description = ""; $url = "https://secure.authorize.net/gateway/transact.dll"; if (array_key_exists("amount" ,$_REQUEST)) { $amount = $_REQUEST["amount"]; } if (array_key_exists("amount" ,$_REQUEST)) { $description = $_REQUEST["description"]; } $invoice = date(YmdHis); $sequence = rand(1, 1000); $timeStamp = time(); if( phpversion() >= '5.1.2') { $fingerprint = hash_hmac("md5", $loginID . "^" . $sequence . "^" . $timeStamp . "^" . $amount . "^", $transactionKey); } else { $fingerprint = bin2hex(mhash(MHASH_MD5, $loginID . "^" . $sequence . "^" . $timeStamp . "^" . $amount . "^", $transactionKey)); } $cartOutput = ""; $cartTotal = ""; $pp_checkout_btn = ''; $product_id_array = ''; if(!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) { $cartOutput = "<h2 align='center'>Your Shopping Cart is Empty</h2>"; } else { //Start PayPal Checkout Button**** $pp_checkout_btn .= '<form action="' . $url . '" method="post"> <input type="hidden" name="x_login" value="' . $loginID . '"> <input type="hidden" name="upload" value="1">'; //Start the For Each Loop $i = 0; foreach ($_SESSION["cart_array"] as $each_item) { $item_id = $each_item['item_id']; $sql = mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1"); while ($row = mysql_fetch_array($sql)) { $product_name = $row["product_name"]; $price = $row["price"]; } $subtotal = $price * $each_item['quantity']; $cartTotal = $subtotal + $cartTotal; setlocale(LC_MONETARY, "en_US"); $subtotal = money_format("%10.2n", $subtotal); // Dynamic Checkout Btn Assembly**** $x = $i + 1; $pp_checkout_btn .= '<input type="hidden" name="item_name_' . $x . '" value="' . $product_name . '"> <input type="hidden" name="amount_' . $x . '" value="' . $price . '"> <input type="hidden" name="quantity_' . $x . '" value="' . $each_item['quantity'] . '"> <input type="hidden" name="x_amount" value="' . $amount . '"> <input type="hidden" name="x_description" value="' . $description . '"> <input type="hidden" name="x_invoice_num" value="' . $invoice . '"> <input type="hidden" name="x_fp_sequence" value="' . $sequence . '"> <input type="hidden" name="x_fp_timestamp" value="' . $timeStamp . '"> <input type="hidden" name="x_fp_hash" value="' . $fingerprint . '"> <input type="hidden" name="x_show_form" value="PAYMENT_FORM">'; // Create the product array variable $product_id_array .= "$item_id-" .$each_item['quantity'].","; // Dynamic Table Row Assembly $cartOutput .= '<tr>'; $cartOutput .= '<td><img src="..website/inventory_images/' . $item_id . '.jpg" width="100" height="66" alt="' . $product_name . '" longdesc="..website/inventory_images/' . $item_id . '.jpg" /></td>'; $cartOutput .= '<td>' . $product_name . '</td>'; $cartOutput .= '<td>$' . $price . '</td>'; $cartOutput .= '<td><form action="Shopping_Cart.php" method="post"> <input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" /> <input name="adjustBtn' . $item_id . '" type="submit" value="Update"/> <input name="item_to_adjust" type="hidden" value="' . $item_id . '" /> </form></td>'; //$cartOutput .= '<td>' . $each_item['quantity'] . '</td>'; $cartOutput .= '<td>' . $subtotal . '</td>'; $cartOutput .= '<td><form action="Shopping_Cart.php" method="post"> <input name="deleteBtn' . $item_id . '" type="submit" value="X"/> <input name="index_to_remove" type="hidden" value="' . $i . '" /> </form></td>'; $cartOutput .= '</tr>'; $i++; } setlocale(LC_MONETARY, "en_US"); $cartTotal = money_format("%10.2n", $cartTotal); $cartTotal = "Cart Total: " .$cartTotal; // Finish the PayPal Checkout Button**** $pp_checkout_btn .= '<input type="hidden" name="custom" value="' . $product_id_array . '"> <input type="hidden" name="notify_url" value="https://www.website/my_ipn.php"> <input type="hidden" name="return" value="http://www.website/checkout_complete.php"> <input type="hidden" name="rm" value="2"> <input type="hidden" name="cbt" value="Return to Store"> <input type="hidden" name="cancel_return" value="http://www.website/paypal_cancel.php"> <input type="hidden" name="lc" value="US"> <input type="hidden" name="currency_code" value="USD"> <input type="image" src="http://www.website/CheckOutBtn.gif" height="22px" width="110px" name="submit">'; } ?>

 

 

Highlighted
Posts: 2,765
Topics: 57
Kudos: 248
Blog Posts: 67
Registered: ‎12-05-2011

Re: Custom Shopping Cart: Paypal to Authorize.net

Hello 18thandoak

It doesn't look like anyone has responded yet, but someone still may have feedback on what you're looking for. I'd recommend subscribing to this topic so that you'll be alerted via email if anyone else from the community is able to respond with any comments. To subscribe, click Topic Options at the top of this thread and then select Subscribe. You'll then receive an email once anyone replies to your post.

Thanks,

Richard

Highlighted
Member
Posts: 2
Registered: ‎12-14-2012

Re: Custom Shopping Cart: Paypal to Authorize.net

Did you get this working?

I am working on the same thing and I am not a php person so I am lost. I would appreciate it if you were able to share how you fixed this if you got it working.

Thanks