Post by hknight » Tue Feb 19, 2008 11:22 pm

Hello,

I want to use the following code (from /library/cart/order.php) to place credit card information in a user's order history.  But it is not working.

The problem is that I cannot get my POST data to this line:

Code: Select all

$this->database->query($this->database->parse($sql, $order_id, ($order_status_id ? $order_status_id : $this->data['order_status_id']), strip_tags($this->cc)));
$this->cc is not passing on the POST data correctly.

Can anyone please help?
Thanks!












Code: Select all

<?php



	$cc = "Credit Card information not provided.";

	if(isset($_POST['creditcard_type'])) $creditcard_type = $_POST['creditcard_type'];

	if(isset($_POST['creditcard_number'])) $creditcard_number = $_POST['creditcard_number'];

	if(isset($_POST['cc_valid_to_month'])) $cc_valid_to_month = $_POST['cc_valid_to_month'];

	if(isset($_POST['cc_valid_to_year'])) $cc_valid_to_year = $_POST['cc_valid_to_year'];

	if(isset($_POST['creditcard_cvv'])) $creditcard_cvv = $_POST['creditcard_cvv'];

	if(isset($_POST['creditcard_type'])) $cc = "Credit Card Type: $creditcard_type<br /> Credit Card Number: $creditcard_number<br />Expiration: (month/year): $cc_valid_to_month / $cc_valid_to_year<br />CCV: $creditcard_cvv";

	define("cc", $cc);

class Order {

	var $reference = NULL;

	var $data      = array();

	var $expire    = 3600;

 	

	function __construct(&$locator) {	

		if(cc) $this->cc = cc;

		$this->config   =& $locator->get('config');

		$this->coupon   =& $locator->get('coupon');

		$this->database =& $locator->get('database');

		$this->mail     =& $locator->get('mail');

		$this->session  =& $locator->get('session');

				

		$sql = "delete from order_data where expire < '?'";

		$this->database->query($this->database->parse($sql, time()));

		

		$random    = strtoupper(uniqid());

		$reference = substr($random, 0, 5) . '-' . substr($random, 5, 5) . '-' . substr($random . rand(10, 99), 10, 5);

		

		if ($this->session->has('reference')) {

			$sql        = "select distinct * from order_data where reference = '?'";

			$order_info = $this->database->getRow($this->database->parse($sql, $this->session->get('reference')));

			

			if ($order_info) {

				$this->reference = $this->session->get('reference');

			} else {

				$this->reference = $reference;

				

				$this->session->set('reference', $reference);

			}

		} else {

			$this->reference = $reference;

			

			$this->session->set('reference', $reference);

		}	

	}

		

	function getReference() {

		return $this->reference;

	}

	

	function set($key, $value) {

		$this->data[$key] = $value;

	}

	

	function get($key) {

		return (isset($this->data[$key]) ? $this->data[$key] : NULL);

	}

		

	function load($reference) {			

		$sql        = "select distinct * from order_data where reference = '?'";

		$order_info = $this->database->getRow($this->database->parse($sql, $reference));

		

		if ($order_info) {

			$this->reference = $reference;

			$this->data      = unserialize($order_info['data']);

			

			return TRUE;

		} else {

			return FALSE;

		}

	}



	function save($reference) {

		$sql   = "select * from order_data where reference = '?'";

		$order = $this->database->getRow($this->database->parse($sql, $reference));

		

		if (!$order) {

			$sql = "insert into order_data set reference = '?', data = '?', expire = '?'";

			$this->database->query($this->database->parse($sql, $reference, serialize($this->data), time() + $this->expire));

		} else {

			$sql = "update order_data set data = '?', expire = '?' where reference = '?'";

			$this->database->query($this->database->parse($sql, serialize($this->data), time() + $this->expire, $reference));

		}

	}



	function process($order_status_id = NULL) {

		if ($this->data) {

			$sql = "insert into `order` set customer_id = '?', reference = '?', firstname = '?', lastname = '?', email = '?', telephone = '?', fax = '?',  order_status_id = '?', total = '?', currency = '?', value = '?', ip = '?', shipping_firstname = '?', shipping_lastname = '?', shipping_company = '?', shipping_address_1 = '?', shipping_address_2 = '?', shipping_city = '?', shipping_postcode = '?', shipping_zone = '?', shipping_country = '?', shipping_address_format = '?', shipping_method = '?', payment_firstname = '?', payment_lastname = '?', payment_company = '?', payment_address_1 = '?', payment_address_2 = '?', payment_city = '?', payment_postcode = '?', payment_zone = '?', payment_country = '?', payment_address_format = '?', payment_method = '?', date_modified = now(), date_added = now()";

			$this->database->query($this->database->parse($sql, $this->data['customer_id'], $this->reference, $this->data['firstname'], $this->data['lastname'], $this->data['email'], $this->data['telephone'], $this->data['fax'], ($order_status_id ? $order_status_id : $this->data['order_status_id']), $this->data['total'], $this->data['currency'], $this->data['value'], $this->data['ip'], $this->data['shipping_firstname'], $this->data['shipping_lastname'], $this->data['shipping_company'], $this->data['shipping_address_1'], $this->data['shipping_address_2'], $this->data['shipping_city'], $this->data['shipping_postcode'], $this->data['shipping_zone'], $this->data['shipping_country'], $this->data['shipping_address_format'], $this->data['shipping_method'], $this->data['payment_firstname'], $this->data['payment_lastname'], $this->data['payment_company'], $this->data['payment_address_1'], $this->data['payment_address_2'], $this->data['payment_city'], $this->data['payment_postcode'], $this->data['payment_zone'], $this->data['payment_country'], $this->data['payment_address_format'], $this->data['payment_method']));



			$order_id = $this->database->getLastId();



			foreach ($this->data['products'] as $product) {

				$sql = "insert into order_product set order_id = '?', name = '?', model = '?', price = '?', discount = '?', total = '?', tax = '?', quantity = '?'";

				$this->database->query($this->database->parse($sql, $order_id, $product['name'], $product['model'], $product['price'], $product['discount'], $product['total'], $product['tax'], $product['quantity']));

 

				$order_product_id = $this->database->getLastId();



				foreach ($product['option'] as $option) {

					$sql = "insert into order_option set order_id = '?', order_product_id = '?', name = '?', `value` = '?', price = '?', prefix = '?'";

					$this->database->query($this->database->parse($sql, $order_id, $order_product_id, $option['name'], $option['value'], $product['price'], $option['prefix']));

				}

				

				foreach ($product['download'] as $download) {

					$sql = "insert into order_download set order_id = '?', order_product_id = '?', name = '?', filename = '?', mask = '?', remaining = '?'";

					$this->database->query($this->database->parse($sql, $order_id, $order_product_id, $download['name'], $download['filename'], $download['mask'], $download['remaining'] * $product['quantity']));

				}	

				

				if ($this->config->get('config_stock_subtract')) {

					$this->database->query("update product set quantity = (quantity - " . (int)$product['quantity'] . ") where product_id = '" . (int)$product['product_id'] . "'");

				}

			}



			$sql = "insert into order_history set order_id = '?', order_status_id = '?', date_added = now(), notify = '1', comment = '?'";

			$this->database->query($this->database->parse($sql, $order_id, ($order_status_id ? $order_status_id : $this->data['order_status_id']), strip_tags($this->data['comment'])));



			$sql = "insert into order_history set order_id = '?', order_status_id = '?', date_added = now(), notify = '0', comment = '?'";

			$this->database->query($this->database->parse($sql, $order_id, ($order_status_id ? $order_status_id : $this->data['order_status_id']), strip_tags($this->cc)));



			foreach ($this->data['totals'] as $total) {

				$sql = "insert into order_total set order_id = '?', title = '?', text = '?', `value` = '?', sort_order = '?'";

				$this->database->query($this->database->parse($sql, $order_id, $total['title'], $total['text'], $total['value'], $total['sort_order']));

			}

			

			if ($this->data['coupon_id']) {

				$this->coupon->redeem($this->data['coupon_id'], $this->data['customer_id'], $order_id);

			}

			 

			if ($this->config->get('config_email_send')) {

				$this->mail->setTo($this->data['email']);

				$this->mail->setFrom($this->config->get('config_email'));

				$this->mail->setSender($this->config->get('config_store'));

				$this->mail->setSubject($this->data['email_subject']);

				$this->mail->setText($this->data['email_text']);

				$this->mail->setHtml($this->data['email_html']);

				$this->mail->send();

			}

		

			$this->database->query("update customer set cart = '' where customer_id = '" . (int)$this->data['customer_id'] . "'");

			

			$this->data = array();

			

			$sql = "delete from order_data where reference = '?'";

			$this->database->query($this->database->parse($sql, $this->reference));

		}

	}

}

?>

Newbie

Posts

Joined
Sat Oct 20, 2007 12:36 am

Post by ally3762002 » Wed Feb 20, 2008 6:20 am

Hi! I am also trying to create a way to process credit cards manually. I am a total noobie when it comes to major coding, I can do some mod but not the base coding itself. Most of my work comes down to guess work and trial and error. Needless to say I am totally lost as to where I would stick the form to accept the credit card information to begin with. I wish I could help with your issue  :-\ but could you point me in the right direction?

Any help you could be able to give me would be greatly appreciated!!!  :D

Newbie

Posts

Joined
Wed Feb 20, 2008 6:15 am
Who is online

Users browsing this forum: No registered users and 3 guests