--- uc_authorizenet.module.bak 2011-03-30 16:38:10.000000000 -0400 +++ uc_authorizenet.module 2011-04-01 11:17:18.000000000 -0400 @@ -449,10 +449,10 @@ global $user; // Build a description of the order for logging in Auth.Net. - $description = array(); - foreach ((array) $order->products as $product) { - $description[] = $product->qty .'x '. $product->model; - } +// $description = array(); +// foreach ((array) $order->products as $product) { +// $description[] = $product->qty .'x '. $product->model; +// } $billing_country = uc_get_country_data(array('country_id' => $order->billing_country)); $delivery_country = uc_get_country_data(array('country_id' => $order->delivery_country)); @@ -467,6 +467,62 @@ 'dec' => '.', ); +// Build a description of the order for logging in Auth.Net. + $description = array(); + foreach ((array) $order->products as $product) { + /* + * lineitems cause the data back from quickbooks to be more useful + * they need to be dealt with outside of the normal $submit_data routine as the standard + * is for several items. I did think about making them an array but I also wanted to handle the + * length (mostly because the title field is only 31 & there is a high chance of fields being that long & + * being blown out over it when url_encode is done - ie a space becomes 3 characers not one) using the function tidyStringforXML but didn't know if that would be 'approved' + */ + + /* + * A.net fields + * x_line_item=item1<|>title<|><|>2<|>18.95<|>Y&x_line_item= + * item2<|>golf bag<|>Wilson golf carry bag, red<|>1<|>39.99<|>Y& + * x_line_item=item3<|>book<|>Golf for Dummies<|>1<|>21.99<|>Y& + * + * Item ID<|> Up to 31 characters The ID assigned to an item. + * item name<|>Up to 31 characters A short description of an item. + * item description<|>Up to 255 characters A detailed description of an item. + * itemX quantity<|>Up to two decimal places Must be a positive number The quantity of an item. + * item price (unit cost)<|>Up to two decimal places Must be a positive number Cost of an item per unit, excluding tax, freight, and duty.The dollar sign ($) is not allowed when submitting delimited information. + * itemX taxable + */ + $lineitems .= "&x_line_item="._uc_authorize_tidyStringforXML($product->model,31) + ."<|>"._uc_authorize_tidyStringforXML($product->title,31) + ."<|>" ._uc_authorize_tidyStringforXML($product->title,255) + ."<|>".uc_price($product->qty, $context, $options) + ."<|>".uc_price($product->price, $context, $options)."<|>" + ."N";//it seems taxes are always listed @ the end not included in line item + $description[] = $product->qty .'x '. $product->model; + } +/* + if($order->line_items[1]['amount'] > 0){ + $lineitems .= "&x_line_item=uc_add_donation" + ."<|>donation" + ."<|>donation" + ."<|>1" + ."<|>".$order->line_items[1]['amount']."<|>" + ."N";//it seems taxes are always listed @ the end not included in line item + $description[] = 'Donation'; + } + if($order->line_items[2]['amount'] > 0){ + $lineitems .= "&x_line_item=Shipping" + ."<|>". _uc_authorize_tidyStringforXML("Shipping: ".$order->line_items[2]['title'],31) + ."<|>". _uc_authorize_tidyStringforXML("Shipping: ".$order->line_items[2]['title'],31) + ."<|>1" + ."<|>".$order->line_items[2]['amount']."<|>" + ."N";//it seems taxes are always listed @ the end not included in line item + $description[] = 'shipping'; + } +*/ + + + + // Build the POST data for the transaction. $submit_data = array( // Merchant Information @@ -544,13 +600,13 @@ foreach ($submit_data as $key => $value) { $post_fields[] = $key .'='. urlencode($value); } - // Setup the cURL request. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $post_url); curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $post_fields)); + curl_setopt($ch, CURLOPT_POSTFIELDS, implode('&', $post_fields) . $lineitems); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_NOPROGRESS, 1); @@ -1238,3 +1294,21 @@ return $data; } + +/* + * helper function to encode to url while ensuring string length is correct + * the xml is posted to a url so must not contain spaces etc. It also needs to be cut off at a certain + * length to match the processor's field length. The cut needs to be made after spaces etc are + * transformed but must not include a partial transformed character e.g. %20 must be in or out not half-way + */ + + function _uc_authorize_tidyStringforXML($value,$fieldlength) + { + $xmlString = substr(rawurlencode($value),0,$fieldlength); + $lastPercent = strrpos($xmlString,'%'); + if ($lastPercent > $fieldlength- 3) { + $xmlString = substr($xmlString,0,$lastPercent); + } + return $xmlString; + } +