Reply
Highlighted
Member
Posts: 2
Registered: ‎09-27-2011

Re: Resolved

Um .. I understand that there is an interface and sample API files. I am mainly saying that you have to possibly filter your Item names and descriptions so they have the correct string length and no special characters. Thank you for your 2 cents though.

Highlighted
Posts: 1,609
Topics: 15
Kudos: 201
Solutions: 121
Registered: ‎06-23-2011

Re: Resolved

Well, that's one way to address the problem, but the most efficient way in my opinion is to avoid it entirely by using the API and letting it deal with any XML formatting issues. Why anyone would want to mess with XML when there's a nice clean API layer on top, I don't know.

Highlighted
Contributor
Posts: 37
Registered: ‎05-09-2011

Re: Resolved

can someone paste the addLineItem() function code? I see it in the markdown file but i can't find it in the class itself... What the heck is the function doing?

Highlighted
Posts: 1,609
Topics: 15
Kudos: 201
Solutions: 121
Registered: ‎06-23-2011

Re: Resolved

Took me about 5 seconds to find it in the AuthorizeNetAIM.php file in the lib folder:

 

    public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable)
    {
        $line_item = "";
        $delimiter = "";
        foreach (func_get_args() as $key => $value) {
            $line_item .= $delimiter . $value;
            $delimiter = "<|>";
        }
        $this->_additional_line_items[] = $line_item;
    }

 This is a rather inefficient way to say that you want to put together id, name, descriptioon, quantity, price, taxable, separated by <|>. Then those are in turn added to the post string as follows:

 

foreach ($this->_additional_line_items as $key => $value) {
    $this->_post_string .= "x_line_item=" . urlencode($value) . "&";
}

 

Highlighted
Member
Posts: 2
Registered: ‎12-19-2011

Re: Resolved

[ Edited ]

Use something like this:

 

	private function _authN_addLineItem(&$to,$item) {
	
		//wrapper for authNet's crappy addLineItem
		
		for ($i=0,$c=count($item);$i<$c;$i++) {
			$item[$i] = substr($item[$i],0,30);
		}
		
		if (empty($to->line_item)) $to->line_item = implode('<|>',$item);
		else {
			list ($item_id, $item_name, $item_desc, $item_quantity, $item_unit_price, $item_taxable) = $item;
			$to->addLineItem($item_id, $item_name, $item_desc, $item_quantity, $item_unit_price, $item_taxable);
		}
	
	}

 

It'll cover the dumb $auth->line_item format and strip your strings to 30 chars.

Highlighted
Member
Posts: 2
Registered: ‎12-19-2011

Re: Resolved

That empty() won't work. Do this instead:

 

private function _authN_addLineItem(&$to,$item) {

	//wrapper for authNet's crappy addLineItem
	
	if (!isset($this->_authN_addLineItem_hash)) $this->_authN_addLineItem_hash = array();

	for ($i=0,$c=count($item);$i<$c;$i++) {
		$item[$i] = substr($item[$i],0,30);
	}
	
	$id = spl_object_hash($to);
	if (empty($this->_authN_addLineItem_hash[$id])) {
		$to->line_item = implode('<|>',$item);
		$this->_authN_addLineItem_hash[$id] = true;
	} else {
		list ($item_id, $item_name, $item_desc, $item_quantity, $item_unit_price, $item_taxable) = $item;
		$to->addLineItem($item_id, $item_name, $item_desc, $item_quantity, $item_unit_price, $item_taxable);
	}

}

 

Highlighted
Member
Posts: 1
Registered: ‎09-05-2013

Re: Resolved

Thanks for posting the answer to this issue.  I was having the same problems and your post was just what I needed! Thanks again