Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Storing Authcodes into database with orders


vipes

Recommended Posts

Posted

Hi,

 

I'm using Beanstream payment module, and when a transaction is completed, it returns a bunch of values. One of the values is authCode, which I want to insert into the database along with the order, just for easy lookup of orders if a customer called in with the authcode. Also, authcodes are supposed to be provided to the customer after they checkout.

 

This if statement basically reads the results sent back from the server, and if trnApproved=1 then it forwards them to checkout_process where the order is entered into the database. How do I cary the variable $authorization_number over to checkout_process and into the orders database? :blink:

 

I have tried puting it into the url but I'm not sure how to call it?

 

--

if(substr($txResult, 0, 13)=="trnApproved=1") {

$authorization_number = $aryResult['authCode'];

header("location:" . tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', true) . "?authorization_number=" . $aryResult['authCode'] . $osCsession);

--

 

Does anyone know how?

 

Thanks,

Mark

Posted

Your code should work, as far as I can see, though it could be a little cleaner:

 

if(substr($txResult, 0, 13)=="trnApproved=1") {
header("location:" . tep_href_link(FILENAME_CHECKOUT_PROCESS, 'authorization_number=' . $aryResult['authCode'] . $osCsession, 'SSL', true) ); 
}

 

I'm not familiar with this payment gateway/module, but I find it odd that you need to do a substr() to get important information. Are you sure your code is getting past the if statement?

Contributions

 

Discount Coupon Codes

Donations

Posted
Your code should work, as far as I can see, though it could be a little cleaner:

 

if(substr($txResult, 0, 13)=="trnApproved=1") {
header("location:" . tep_href_link(FILENAME_CHECKOUT_PROCESS, 'authorization_number=' . $aryResult['authCode'] . $osCsession, 'SSL', true) ); 
}

 

I'm not familiar with this payment gateway/module, but I find it odd that you need to do a substr() to get important information. Are you sure your code is getting past the if statement?

 

 

Yeah it does get past the if statement, I tested that by making it echoing it as a link instead of the header.

 

This is where it takes the response from beanstream. The response is a long line of different variables seperated by & signs.

// Now POST the transaction. $txResult will contain Beanstream's response
$txResult = curl_exec( $ch );

foreach (split("&", $txResult) as $value) {
$aryElement = split("=", $value);
eval('$aryResult["' . $aryElement[0] . '"] = "' . $aryElement[1] . '";');
}


//echo $txResult;

//IF APPROVED TRANSACTION:
if($aryResult['trnApproved'] == 1) {
			//echo tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', true) . "" . $osCsession);
$authcode = $aryResult['authCode'];
global $authcode;
header("location:" . tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', true) . "" . $osCsession);

 

--

 

What if I took the authcode out of the url and stored it into a cookie? How do you store variables into cookies and then call them in other pages?

Posted

If you're sure the authcode is being sent to the checkout_process page, then you know you're in business. How are you handling it in checkout_process? If the variable is in the URL for the header redirect, then checkout_process.php should have access to it. More likely the problem exists in checkout_process.

 

The problem with a cookie is that I think some browsers won't set a cookie when they're being sent a redirect header. Not 100% sure on that though.

 

Set a cookie with setcookie():

 

http://us2.php.net/manual/en/function.setcookie.php

 

Call a cookie:

 

$_COOKIE['cookiename'];

Contributions

 

Discount Coupon Codes

Donations

Posted
If you're sure the authcode is being sent to the checkout_process page, then you know you're in business. How are you handling it in checkout_process? If the variable is in the URL for the header redirect, then checkout_process.php should have access to it. More likely the problem exists in checkout_process.

 

The problem with a cookie is that I think some browsers won't set a cookie when they're being sent a redirect header. Not 100% sure on that though.

 

Set a cookie with setcookie():

 

http://us2.php.net/manual/en/function.setcookie.php

 

Call a cookie:

 

$_COOKIE['cookiename'];

 

I guess the URL way is the best way to go then. I actually just tried it and it still doesnt insert it into the database, it still comes up blank.

 

in checkout_process i added a line right before require order.php

 

$authcode = $HTTP_GET_VARS['authcode'];
//	tep_output_string_protected($authcod['authorization_number']);

 require(DIR_WS_CLASSES . 'order.php');
 $order = new order;

 

Is that the correct way of taking the variable from the url?

 

Then in order.php

 

	  $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID,
					  'currency' => $currency,
					  'currency_value' => $currencies->currencies[$currency]['value'],
					  'payment_method' => $payment,
			  'authcode' => $authcode,
					  'cc_type' => (isset($GLOBALS['cc_type']) ? $GLOBALS['cc_type'] : ''),
					  'cc_owner' => (isset($GLOBALS['cc_owner']) ? $GLOBALS['cc_owner'] : ''),
					  'cc_number' => (isset($GLOBALS['cc_number']) ? $GLOBALS['cc_number'] : ''),
					  'cc_expires' => (isset($GLOBALS['cc_expires']) ? $GLOBALS['cc_expires'] : ''),
					  'shipping_method' => $shipping['title'],
					  'shipping_cost' => $shipping['cost'],
					  'subtotal' => 0,
					  'tax' => 0,
					  'tax_groups' => array(),
					  'comments' => (isset($GLOBALS['comments']) ? $GLOBALS['comments'] : ''));

 

I also of course, added authcode to the db query right after payment_method.

 

Thanks again!

Posted
$authcode = $HTTP_GET_VARS['authcode'];

 

In the first post, you named the GET variable 'authorization_number':

 

 header("location:" . tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', true) . "?authorization_number=" . $aryResult['authCode'] . $osCsession);

 

You then need to access this variable as

 

$HTTP_GET_VARS['authorization_number'];

 

And in the second block of code you posted, I don't see where you append the authcode to the URL anymore:

 

//IF APPROVED TRANSACTION:
if($aryResult['trnApproved'] == 1) {
//echo tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', true) . "" . $osCsession);
$authcode = $aryResult['authCode'];
global $authcode;
header("location:" . tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL', true) . "" . $osCsession);

 

As far as the code for order.php, no that won't work. $authcode won't be written to the database there. Order.php is to read orders. You need to insert authcode into the db in checkout_process.php. If this isn't standard, you will need to create a field in the beanstream table (if there is one) or alter the orders table (avoid this if the first method is available).

 

Lastly to read $authcode in order.php, you would need to declare it as a global variable in order.php.

Contributions

 

Discount Coupon Codes

Donations

Posted

Doh, I just read the last sentence of your post. Ignore the last part of mine.

 

Okay, so the first step is to make sure your variable is accessible where you insert it into the database. As I said, I don't think you're getting anything, which is one reason why nothing's going in the db. Don't bother with order.php until you've gotten the value to insert into the db.

Contributions

 

Discount Coupon Codes

Donations

Posted
Doh, I just read the last sentence of your post. Ignore the last part of mine.

 

Okay, so the first step is to make sure your variable is accessible where you insert it into the database. As I said, I don't think you're getting anything, which is one reason why nothing's going in the db. Don't bother with order.php until you've gotten the value to insert into the db.

 

 

I'm really confused with payment_process.php. I'm trying to find where I would insert it into the database. I already created a new column in the Orders table that is right after payment_method.

 

in checkout_process

 

  $sql_data_array = array('customers_id' => $customer_id,
					  'customers_name' => $order->customer['firstname'] . ' ' . $order->customer['lastname'],
					  'customers_company' => $order->customer['company'],
					  'customers_street_address' => $order->customer['street_address'],
					  'customers_suburb' => $order->customer['suburb'],
					  'customers_city' => $order->customer['city'],
					  'customers_postcode' => $order->customer['postcode'], 
					  'customers_state' => $order->customer['state'], 
					  'customers_country' => $order->customer['country']['title'], 
					  'customers_telephone' => $order->customer['telephone'], 
					  'customers_email_address' => $order->customer['email_address'],
					  'customers_address_format_id' => $order->customer['format_id'], 
					  'delivery_name' => $order->delivery['firstname'] . ' ' . $order->delivery['lastname'], 
					  'delivery_company' => $order->delivery['company'],
					  'delivery_street_address' => $order->delivery['street_address'], 
					  'delivery_suburb' => $order->delivery['suburb'], 
					  'delivery_city' => $order->delivery['city'], 
					  'delivery_postcode' => $order->delivery['postcode'], 
					  'delivery_state' => $order->delivery['state'], 
					  'delivery_country' => $order->delivery['country']['title'], 
					  'delivery_address_format_id' => $order->delivery['format_id'], 
					  'billing_name' => $order->billing['firstname'] . ' ' . $order->billing['lastname'], 
					  'billing_company' => $order->billing['company'],
					  'billing_street_address' => $order->billing['street_address'], 
					  'billing_suburb' => $order->billing['suburb'], 
					  'billing_city' => $order->billing['city'], 
					  'billing_postcode' => $order->billing['postcode'], 
					  'billing_state' => $order->billing['state'], 
					  'billing_country' => $order->billing['country']['title'], 
					  'billing_address_format_id' => $order->billing['format_id'], 
					  'payment_method' => $order->info['payment_method'], 
		  'authcode' => $authcode,
					  'cc_type' => $order->info['cc_type'], 
					  'cc_owner' => $order->info['cc_owner'], 
					  'cc_number' => $order->info['cc_number'], 
					  'cc_expires' => $order->info['cc_expires'], 
					  'date_purchased' => 'now()', 
					  'orders_status' => $order->info['order_status'], 
					  'currency' => $order->info['currency'], 
					  'currency_value' => $order->info['currency_value']);

 

Thats wrong right? lol. I inserted it around line 93. I must be missing a step. How does this work?

 

Btw, I changed every instance of authorization_number to just plain authcode.

Posted

I made it echo $authcode in checkout_process and commented out the tep_redirect so that I could see it. It does take the auth code from the url. So now it is just how to insert it into the database along with the order...

 

EDIT:

 

It works now! Now whenever I process an order it sends the authorization number to the database! YES!! Thanks very much for your help!!

 

Mark :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...