Location: PHPKode > projects > Simple PHP Shopping cart - asaancart > asaancart v-0.9/shop/receipt2.php
<?php
session_start();
/*
asaancart - easy shopping cart solution
---------------------------------------

Copyright 2009 Nasir Ahmad Khan
Email: hide@address.com

This file is part of asaancart - open source easy shopping cart solution.

asaancart is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

asaancart is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with asaancart.  If not, see <http://www.gnu.org/licenses/>.

*/


include("../config/config.php");
include("classes/functions.php");

//session_start();
if (session_id() == "") session_start();
$session_id = session_id();


include("includes/global_settings.php");

$smarty->assign('shippingTotal',shippingRate(getCartTotalAmount($session_id)));
$cartTotal  = getCartTotalAmount($session_id)+ shippingRate(getCartTotalAmount($session_id));
//end shipping cost

$smarty->assign('cartTotal',$cartTotal);

$smarty->assign('cartItems',getCartItems($session_id));
$smarty->assign('cartSubTotal', getCartTotalAmount($session_id));

$shippingTotal = shippingRate(getCartTotalAmount($session_id));
$cartSubTotal = getCartTotalAmount($session_id);


$customer_name = $_POST['customer_name'];
$_SESSION['customer_name'] = $customer_name;

$business_name = $_POST['business_name'];
$_SESSION['business_name'] = $business_name;
if($business_name==""){$business_name = " ";}
$email_address = $_POST['email_address'];
$_SESSION['email_address'] = $email_address;

$customer_mobile = $_POST['customer_mobile'];
$_SESSION['mobile'] = $customer_mobile;

$customer_phone = $_POST['customer_phone'];
$_SESSION['phone'] = $customer_phone;

$customer_state = $_POST['s_customer_state'];
$_SESSION['state'] = $customer_state;

$customer_city = $_POST['s_customer_city'];
$_SESSION['city'] = $customer_city;

$customer_suburb = $_POST['s_customer_suburb'];
$_SESSION['suburb'] = $customer_suburb;

$customer_postcode = $_POST['s_customer_postcode'];
$_SESSION['postcode'] = $customer_postcode;

$customer_address = $_POST['s_customer_address'];
$_SESSION['address'] = $customer_address;

$s_customer_country = $_POST['s_customer_country'];
$_SESSION['shipping_country'] = $s_customer_country;

$s_customer_state = $_POST['s_customer_state'];
$_SESSION['shipping_state'] = $s_customer_state;

$s_customer_city = $_POST['s_customer_city'];
$_SESSION['shipping_city'] = $s_customer_city;

$s_customer_postcode = $_POST['s_customer_postcode'];
$_SESSION['shipping_postcode'] = $s_customer_postcode;

$s_customer_suburb = $_POST['s_customer_suburb'];
$_SESSION['shipping_suburb'] = $s_customer_suburb;

$s_customer_address = $_POST['s_customer_address'];
$_SESSION['shipping_address'] = $s_customer_address;

$shipping_instructions = $_POST['shipping_instructions'];
$_SESSION['shipping_instructions'] = $shipping_instructions;

$mailing_list = $_POST['mailing_list'];
if($mailing_list!="yes"){$mailing_list = "no";}

$payment_option = "PayPal Express Checkout";//$_POST['payment_option'];

$error_msg = "";
if($customer_name==""){
$error_msg .= "Customer Name <br />";
}
if($email_address==""){
$error_msg .= "Email Address <br />";
}

$token = $_SESSION['token'];
$payer_id = $_SESSION['payer_id'];

$paymentAmount = $_SESSION['paymentAmount'];
$currCodeType = $_SESSION['currCodeType'];
$paymentType = $_SESSION['paymentType'];


if($error_msg!=""){
	header("location: ReviewOrder.php?error_msg=".$error_msg."&token=".$token."&PayerID=".$payer_id."&paymentAmount=".$paymentAmount."&currencyCodeType=".$currCodeType."&paymentType=".$paymentType);
}else{

if(getCartTotalQty($session_id)>0){
	$max_order_id = getMaxOrderId();
	$new_order_id = $max_order_id + 1;
	$order_prefix = $order_prefix;
	$order_number = $order_prefix.$new_order_id;
	
	$smarty->assign('order_number', $order_number);
	$smarty->assign('customer_name', $customer_name);
	$smarty->assign('bunisess_name', $business_name);
	$smarty->assign('email_address', $email_address);
	$smarty->assign('address', $s_customer_address);
	$smarty->assign('city', $s_customer_city);
	$smarty->assign('state', $s_customer_state);
	$smarty->assign('post_code', $s_customer_postcode);
	$smarty->assign('country', $s_customer_country);
	$smarty->assign('payment_method', $payment_option);
	$smarty->assign('phone_number', $customer_phone);
	$smarty->assign('order_date', date("d-m-Y"));
	$smarty->assign('order_instructions', $shipping_instructions);
	
	$smarty->assign('payment_options_available', getDefaultPaymentOptions());
	
	
	
	
	//add user
	$sql = "INSERT INTO customers (customer_name, business_name, customer_country, customer_state, customer_city, customer_suburb, customer_postcode, customer_mobile, customer_phone, email_address, customer_address, s_customer_country, s_customer_state, s_customer_city, s_customer_suburb, s_customer_postcode, s_customer_address, mailing_list) VALUES ('$customer_name', '$business_name', '$customer_country', '$customer_state', '$customer_city', '$customer_suburb', '$customer_postcode', '$customer_mobile', '$customer_phone', '$email_address', '$customer_address', '$s_customer_country', '$s_customer_state', '$s_customer_city', '$s_customer_suburb', '$s_customer_postcode', '$s_customer_address', '$mailing_list')";
	$results = mysql_query($sql);
	//end add user
	
	//add order
	$sql = "INSERT INTO orders (order_number, customer_name, customer_email, state, city, shipping_address, postcode, country, payment_method, order_comments, order_date, order_status, order_shipping, order_subtotal) VALUES ('$order_number', '$customer_name', '$email_address', '$s_customer_state', '$s_customer_city', '$s_customer_address', '$s_customer_postcode', '$s_customer_country', '$payment_option', '$shipping_instructions', '".date("d-m-Y")."', 'pending', $shippingTotal, $cartSubTotal)";
	$results = mysql_query($sql);
	
	
	//end add order
	
	//add order items
	$sqlCart = "SELECT * FROM my_cart WHERE session_id = '$session_id' ORDER BY product_name";
		$resultsCart = mysql_query($sqlCart);
		while($rowCart = mysql_fetch_array($resultsCart) )
		{
			$product_code = $rowCart['product_code'];
			$product_id = $rowCart['product_id'];
			$product_name = $rowCart['product_name'];
			$product_name = $product_name;//."<br />".$rowCart['product_description'];
			$product_name = str_replace("'","\'",$product_name);
			$product_quantity = $rowCart['product_qty'];
			$product_price = $rowCart['product_price'];
			$sub_total = $rowCart['total'];
			$stock_ref = $rowCart['stock_ref'];
			
			$sql = "INSERT INTO order_item (order_number, product_code, product_name, product_quantity, product_price, sub_total, stock_ref, product_id) VALUES ('$order_number', '$product_code', '$product_name', $product_quantity, $product_price, $sub_total, '$stock_ref', '$product_id')";
	$results = mysql_query($sql);
	
		
	
		}
		
		
	
	//end add items

}

$smarty->assign('site_url', SITE_URL);


$results = mysql_query("DELETE FROM my_cart WHERE session_id = '$session_id'");

//session_unset();
//session_destroy();
//$_SESSION = array();





$smarty->assign('payment_options_available', getDefaultPaymentOptions());



$smarty->assign('template','exp_receipt');





/**********************************************************
DoExpressCheckoutPayment.php

This functionality is called to complete the payment with
PayPal and display the result to the buyer.

The code constructs and sends the DoExpressCheckoutPayment
request string to the PayPal server.

Called by GetExpressCheckoutDetails.php.

Calls CallerService.php and APIError.php.

**********************************************************/


///////////////
require_once 'paypal_libs/CallerService.php';
session_start();
//if (session_id() == "") session_start();
//$session_id = session_id();
/* Gather the information to make the final call to
   finalize the PayPal payment.  The variable nvpstr
   holds the name value pairs
   */
$token =urlencode( $_SESSION['token']);
$paymentAmount =urlencode ($_SESSION['paymentAmount']);
$paymentType = urlencode($_SESSION['paymentType']);
$currCodeType = urlencode($_SESSION['currCodeType']);
$payerID = urlencode($_SESSION['payer_id']);
$serverName = urlencode($_SERVER['SERVER_NAME']);

$nvpstr='&TOKEN='.$token.'&PAYERID='.$payerID.'&PAYMENTACTION='.$paymentType.'&AMT='.$paymentAmount.'&CURRENCYCODE='.$currCodeType.'&IPADDRESS='.$serverName ;

 /* Make the call to PayPal to finalize payment
    If an error occured, show the resulting errors
    */
$resArray=hash_call("DoExpressCheckoutPayment",$nvpstr);

/* Display the API response back to the browser.
   If the response from PayPal was a success, display the response parameters'
   If the response was an error, display the errors received using APIError.php.
   */
$ack = strtoupper($resArray["ACK"]);


if($ack!="SUCCESS"){
	$_SESSION['reshash']=$resArray;
	$location = "paypal_libs/APIError.php";
		 header("Location: $location");
               }


$smarty->assign('AMT', $resArray['AMT']);
$smarty->assign('TRANSACTIONID', $resArray['TRANSACTIONID']);


$smarty->display('shop/site_index.tpl');
}

?>
Return current item: Simple PHP Shopping cart - asaancart