Jump to content
Sign in to follow this  
gtilflm

Updating another database when order is placed

Recommended Posts

Hello all. I'm installing a modification in which I need to insert data into a table based on if the order_status is paid or not. I'm working with checkout_process.php

 

After:

 

// load the after_process function from the payment modules
 $payment_modules->after_process();
 $cart->reset(true);

I have:

 

 


//Begin code for determining if a VBC product has been purchased and handling orders that are paid vs. orders that are to be paid later

// 1.) Get order ID for order.
//$insert_id     This is the orders_id.


// 2.) Get customer's data for entering into the bridge.  Using information that's already on this page.


// 3.) Use order ID to get products assoacited with that order
	// $order->products[$i]['id']	Contains product information for this order.



// 4.) Generate the security token
	//BOF Security token function
	function new_token($length) {
		return substr(_new_token(), 0, $length);
	}

	function _new_token() {
		$rand_bits = '';

		// Linux platform
		$fp = @fopen('/dev/urandom', 'rb');
		if ($fp !== FALSE) {
			$rand_bits .= @fread($fp, 16);
			@fclose($fp);
		}

		// Windows platform
		if (@class_exists('COM')) {
			try {
				$CAPI_Util = new COM('CAPICOM.Utilities.1');
				$rand_bits .= $CAPI_Util->GetRandom(16, 0); // 0 - base64 encoding
			} catch (Exception $ex) {
				// Fail silently; see OWASP 2007 A6
			}
		}

		// If both above fail, fall back to a default method
		if (strlen($rand_bits) < 16) {
			$rand_bits .= substr(session_id(), 0, 8) . rand() . rand();
		}

		return sha1($rand_bits);
	}

	//echo new_token(30);

	$token = new_token(30);
//EOF Security token function


// 5.)
	// a.) Is products_id one of the VBC products? 
	foreach ($order->products as $product) {
		if (in_array($product['id'], array(85, 86, 89, 90, 91, 92, 93, 94, 95))) {		

			if ($order->info['order_status'] == 3) { 
			//If the status is paid...

				// Write necessary info. to table.
				$sql_data_array = array(
						'token' => $token,
						'orders_id' => $insert_id,
						'products_id' => $product['id'],
						'customer_firstname' => $order->customer['firstname'],
						'customer_lastname' => $order->customer['lastname'],
						'customer_email' => $order->customer['email_address'],
						'date_added' => 'now()'
				);
				tep_db_perform('VBC_table', $sql_data_array);	

			} else {

			// The order hasn't been paid for yet... 

				// Write preliminary info. to table.
				$sql_data_array = array(
						// Uncomment if the autoincrement isn't being added  'id' => 'null',
						'token' => '',
						'orders_id' => $insert_id,
						'products_id' => $product['id'],
						'customer_firstname' => $order->customer['firstname'],
						'customer_lastname' => $order->customer['lastname'],
						'customer_email' => $order->customer['email_address'],
						'date_added' => 'now()'
				);
				tep_db_perform('VBC_table', $sql_data_array);
			}

		}

	}		



//End code for determining if a VBC product has been purchased and handling orders that are paid vs. orders that are to be paid later (John)

 

 

Currently, orders that are not yet paid for are having the preliminary data entered into the table and everything is fine. However, when paying by PayPal (with a successful payment), apparently I've done something wrong because I placed an order and an entry was not recorded in the VBC_table. It appears that the check at step 5:

 

			if ($order->info['order_status'] == 3) { 

 

is failing.

 

 

 

Any ideas? Thanks!

Share this post


Link to post
Share on other sites

Bump. Anyone with an idea? Please?

 

Hello all. I'm installing a modification in which I need to insert data into a table based on if the order_status is paid or not. I'm working with checkout_process.php

 

After:

 

// load the after_process function from the payment modules
 $payment_modules->after_process();
 $cart->reset(true);

I have:

 

 


//Begin code for determining if a VBC product has been purchased and handling orders that are paid vs. orders that are to be paid later

// 1.) Get order ID for order.
//$insert_id     This is the orders_id.


// 2.) Get customer's data for entering into the bridge.  Using information that's already on this page.


// 3.) Use order ID to get products assoacited with that order
	// $order->products[$i]['id']	Contains product information for this order.



// 4.) Generate the security token
	//BOF Security token function
	function new_token($length) {
		return substr(_new_token(), 0, $length);
	}

	function _new_token() {
		$rand_bits = '';

		// Linux platform
		$fp = @fopen('/dev/urandom', 'rb');
		if ($fp !== FALSE) {
			$rand_bits .= @fread($fp, 16);
			@fclose($fp);
		}

		// Windows platform
		if (@class_exists('COM')) {
			try {
				$CAPI_Util = new COM('CAPICOM.Utilities.1');
				$rand_bits .= $CAPI_Util->GetRandom(16, 0); // 0 - base64 encoding
			} catch (Exception $ex) {
				// Fail silently; see OWASP 2007 A6
			}
		}

		// If both above fail, fall back to a default method
		if (strlen($rand_bits) < 16) {
			$rand_bits .= substr(session_id(), 0, 8) . rand() . rand();
		}

		return sha1($rand_bits);
	}

	//echo new_token(30);

	$token = new_token(30);
//EOF Security token function


// 5.)
	// a.) Is products_id one of the VBC products? 
	foreach ($order->products as $product) {
		if (in_array($product['id'], array(85, 86, 89, 90, 91, 92, 93, 94, 95))) {		

			if ($order->info['order_status'] == 3) { 
			//If the status is paid...

				// Write necessary info. to table.
				$sql_data_array = array(
						'token' => $token,
						'orders_id' => $insert_id,
						'products_id' => $product['id'],
						'customer_firstname' => $order->customer['firstname'],
						'customer_lastname' => $order->customer['lastname'],
						'customer_email' => $order->customer['email_address'],
						'date_added' => 'now()'
				);
				tep_db_perform('VBC_table', $sql_data_array);	

			} else {

			// The order hasn't been paid for yet... 

				// Write preliminary info. to table.
				$sql_data_array = array(
						// Uncomment if the autoincrement isn't being added  'id' => 'null',
						'token' => '',
						'orders_id' => $insert_id,
						'products_id' => $product['id'],
						'customer_firstname' => $order->customer['firstname'],
						'customer_lastname' => $order->customer['lastname'],
						'customer_email' => $order->customer['email_address'],
						'date_added' => 'now()'
				);
				tep_db_perform('VBC_table', $sql_data_array);
			}

		}

	}		



//End code for determining if a VBC product has been purchased and handling orders that are paid vs. orders that are to be paid later (John)

 

 

Currently, orders that are not yet paid for are having the preliminary data entered into the table and everything is fine. However, when paying by PayPal (with a successful payment), apparently I've done something wrong because I placed an order and an entry was not recorded in the VBC_table. It appears that the check at step 5:

 

			if ($order->info['order_status'] == 3) { 

 

is failing.

 

 

 

Any ideas? Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×