cancel
Showing results for 
Search instead for 
Did you mean: 

x_line_item integration in PHP

I don't know where I found the original sample code but this is what I am using to submit payaments and generate a detailed receipt for the customer.

 

    $customer                          = (object) array();
    $customer->first_name              = tools::get_field_value("bill_first_name");
    $customer->last_name               = tools::get_field_value("bill_last_name");
    $customer->address                 = tools::get_field_value("bill_address_1");
    $customer->city                    = tools::get_field_value("bill_city");
    $customer->state                   = $this->system->get_state_code(tools::get_field_value("bill_state_id"));
    $customer->zip                     = tools::get_field_value("bill_zip_code");
    $customer->phone                   = tools::get_field_value("phone_home");
    $customer->email                   = tools::get_field_value("email_address");
    $customer->customer_ip             = tools::get_client_ip();
    $shipping_info                     = (object) array();
    $shipping_info->ship_to_first_name = tools::get_field_value("ship_first_name");
    $shipping_info->ship_to_last_name  = tools::get_field_value("ship_last_name");
    $shipping_info->ship_to_address    = tools::get_field_value("ship_address_1");
    $shipping_info->ship_to_city       = tools::get_field_value("ship_city");
    $shipping_info->ship_to_state      = $this->system->get_state_code(tools::get_field_value("ship_state_id"));
    $shipping_info->ship_to_zip        = tools::get_field_value("ship_zip_code");
    $sale                              = new AuthorizeNetAIM;
    $sale->amount                      = tools::get_field_value("order_total");
    $sale->address                     = tools::get_field_value("bill_address_1");
    $sale->zip                         = tools::get_field_value("bill_zip_code");
    $sale->card_num                    = tools::get_field_value("cc_number");
    $sale->exp_date                    = tools::get_field_value("cc_exp_month") . "/" . tools::get_field_value("cc_exp_year");
    $sale->card_code                   = tools::get_field_value("cc_cvv2");
    $sale->description                 = $company_name_no_space . "com Sales Order: " . tools::get_field_value("order_id");
    $sale->setFields($shipping_info);
    $sale->setFields($customer);
    $response = $sale->authorizeAndCapture();

 

Everything works great, but I can't find any information on how to integrate line item detail.  The x_line_item information in the AIM PDF is useless for this implementation.  Any ideas how I should go about this?

 

Thanks,

 

vijer
Member
1 ACCEPTED SOLUTION

Accepted Solutions

Well lets start with Thanks for all the help!  Oh crap I didn't get any, Thanks you Bozo's for no help.

 

Second Thanks for crappy examples and information.

 

To solve this issue I had to download the PHP SDK and review the AIM samples again.

 

First issue, there is a Precedence in the order the data is submitted.

 

Initially I was submitting the information in this order AND when submitted with ONE item it works.

 

$sale->description = "Sales Order: " . tools::get_field_value("order_id");

$sale->line_item = "1<|>Info<|>More Info<|>1<|>23.95<|>Y"

$sale->setFields($shipping_info);

$sale->setFields($customer);

$response = $sale->authorizeAndCapture();

 

Now here is the interesting part, looking through the samples it shows to submit multiple line items you have to do the item part this way;

The first line is still the same

 

$sale->line_item = "1<|>Info<|>More Info<|>1<|>23.95<|>Y"

 

But the subsequent items are done like this

 

$sale->addLineItem('2','info','more info','1','39.95','Y')

 

SERIOUSLY A DIFFERENT FORMAT!!  Not $sale->addLineItem = "2<|>Info<|>More Info<|>1<|>23.95<|>Y" HELL NO THAT WOULD ONLY MAKE SENSE.

 

Anyway so I hard coded it and tried and tried and tried, but no it kept giving me the same error; Line 1 is invalid.  So I kept looking at the sample for multiple items in the SDK and the $sale->addLineItem were all JUST BEFORE the $response = $sale->authorizeAndCapture(); so I changed my order to;

 

$sale->description = "Sales Order: " . tools::get_field_value("order_id");

$sale->setFields($shipping_info);

$sale->setFields($customer);

$sale->line_item = "1<|>Info<|>More Info<|>1<|>23.95<|>Y"

$sale->addLineItem(2,info,more info,1,39.95,Y)

$response = $sale->authorizeAndCapture();

 

AND BAM IT WORKS.  YA THINK THAT MIGHT BE USEFULL INFORMATION TO POINT OUT!?!?!

 

Ok so on to live data, and you have to figure this out by yourself because ALL THE EXAMPLES use hardcoded data.  Anyway here is what I came up with.  The while loop is JUST before the $response = $sale->authorizeAndCapture();.

 

Notice I have to evaluate which item is being processed so the structure is changed for the first item and then all subsequent items. 

 

NOW HERE IS ANOTHER BITCH, notice the substr($row['product_name'],0,30) well I must have submitted 10 orders and all was great, then all of a sudden I got the error Line x is invalid again.  WHAT THE HELL!!!  Well it turns out there is a limit to the length of the string Authorize.net can handle, 30 characters, if you pass a string longer than that it craps out.  YA THINK THAT IS AN IMPORTANT BIT OF INFO YOU COULD HAVE NOTED IN THE EXAMPLES?!?!?  Not to mention Authorize.net could just truncate it on their end and save everyone a lot of heart ache.

 

$result = $this->system->db->query($sql);

while ($row = mysql_fetch_array($result)) {

  if ($row['order_item_id'] == 1) {

    $sale->line_item  = $row['order_item_id'] . '<|>' . substr($row['product_name'],0,30) . '<|>' . $row['width'] . ' ' . tools::get_fraction_text($row['width_frac']) . ' x ' . $row['height'] . ' ' . tools::get_fraction_text($row['height_frac']) . '<br>Color: ' . $row['option_picklist_name'] . '<|>' . $row['quantity'] . '<|>' . $row['item_total_price'] . '<|>Y';

  }

  else {

    $sale->addLineItem($row['order_item_id'], substr($row['product_name'],0,30), $row['width'] . ' ' . tools::get_fraction_text($row['width_frac']) . ' x ' . $row['height'] . ' ' . tools::get_fraction_text($row['height_frac']) . '<br>Color: ' . $row['option_picklist_name'], $row['quantity'], $row['item_total_price'], 'Y');

   }

 }

 

Again thanks for all the help you clowns. Oh that's right I didn't get any.

 

 

 

 

 

 

View solution in original post

16 REPLIES 16

OK I figured out how to get the line item information sent but have encountered another problem.

 

I keep getting the error "Line item 1 is invalid".

 

This is the string I am sending 1<|>2&quot; Wood Blind<|><|>1<|>69.00<|>Y&

 

If I substitue &quot; with the letters 'in' then it sends fine.  Any way to get it to display with double quotes?  I would think using &quot; would work but it doesn't.

 

 

vijer
Member

Forgetting the double quote issue for the moment.  If I process an order with one item it works but with multiple items it deos not.

 

I am sending this string for a multiple line item

 

&x_line_item=1<|>2in Premier Faux Wood Blinds Painted<|>36 0.0000 x 60 0.0000<|>1<|>47.00<|>Y&x_line_item=2<|>Solid Vinyl PVC Verticals<|>36 0.0000 x 60 0.0000<|>1<|>39.00<|>Y&x_line_item=3<|>2in Designer Wood Blinds<|>36 0.0000 x 60 0.0000<|>1<|>64.00<|>Y&

 

And I have tried sending

 

1<|>2in Premier Faux Wood Blinds Painted<|>36 0.0000 x 60 0.0000<|>1<|>47.00<|>Y&2<|>Solid Vinyl PVC Verticals<|>36 0.0000 x 60 0.0000<|>1<|>39.00<|>Y&3<|>2in Designer Wood Blinds<|>36 0.0000 x 60 0.0000<|>1<|>64.00<|>Y

 

Code snip that sends it

 

    $line_item                         = $order_item->email_item_list($order_id);
    $sale                                  = new AuthorizeNetAIM;
    $sale->amount                = tools::get_field_value("order_total");
    $sale->tax                         = tools::get_field_value("sales_tax");
    $sale->address               = tools::get_field_value("bill_address_1");
    $sale->zip                         = tools::get_field_value("bill_zip_code");
    $sale->card_num            = tools::get_field_value("cc_number");
    $sale->exp_date              = tools::get_field_value("cc_exp_month") . "/" . tools::get_field_value("cc_exp_year");
    $sale->card_code           = tools::get_field_value("cc_cvv2");
    $sale->description          = $company_name_no_space . "com Sales Order: " . tools::get_field_value("order_id");
    $sale->line_item              = $line_item;

 

For a single item if I send

 

&x_line_item=1<|>2in Premier Faux Wood Blinds Painted<|>36 0.0000 x 60 0.0000<|>1<|>47.00<|>Y

 

The receipt I get displays

 

x_line_item=1

 

And leaving it out or putting it in for multiple items doesn't help.

 

So putting that in the string isn't gettting stripped/interpreted by AIM PHP.

 

Anybody have a solution for this problem as the documentation is not very helpful.

You may find the following thread that discusses this at length helpful:

 

http://community.developer.authorize.net/t5/Integration-and-Testing/Itemized-order-info-with-AIM/td-...

 

 

Thank you,

 

Elaine

Elaine
Trusted Contributor
Trusted Contributor

No that thread wasn't useful at all, I have read it about 10 times.  For one thing why show me an example of a hardcoded array, why not show the PHP code that builds the array from the DB as I am sure that is what most sites are doing.

 

To simplify, this is the structure I am using to request authorization.

 

$sale  = new AuthorizeNetAIM;

$sale->line_item = "1<|>Some Product Info<|>More Infor<|>1<|>Y&";

$response = $sale->authorizeAndCapture();

 

This results in an approval.

 

Change line 2 to $sale->line_item = "x_line_item=1<|>Some Product Info<|>More Infor<|>1<|>Y&";

 

And the result is an approval BUT the text x_line_item=1 is displayed on the Authorize.net receipt, that is to say the whole string, not just the number 1.

 

 

Change line 2 to any of the following combinations results in an error that line 1 is invalid.

 

$sale->line_item = "x_line_item=1<|>Some Product Info<|>More Infor<|>1<|>Y&x_line_item=2<|>Another Product Info<|>More Infor<|>1<|>Y&";

 

or

 

$sale->line_item = "&x_line_item=1<|>Some Product Info<|>More Infor<|>1<|>Y&x_line_item=2<|>Another Product Info<|>More Infor<|>1<|>Y";

 

or

 

$sale->line_item = "1<|>Some Product Info<|>More Infor<|>1<|>Y&2<|>Another Product Info<|>More Infor<|>1<|>Y&";

 

or

 

$sale->line_item = "&1<|>Some Product Info<|>More Infor<|>1<|>Y&2<|>Another Product Info<|>More Infor<|>1<|>Y";

 

or even try sending each item seperately

 

$sale->line_item = "1<|>Some Product Info<|>More Infor<|>1<|>Y&";

$sale->line_item = "2<|>Another Product Info<|>More Infor<|>1<|>Y&";

$sale->line_item = "3<|>And AnotherProduct Info<|>More Infor<|>1<|>Y&";

 

even if I urlencode each string between x_line_item= and the & I still get the same error.

This is an echo of the encoded string, the structure that I believe would be generated by the code in the AIM PHP sample

 

&x_line_item=1%3C%7C%3E1%2F2in+Single+Cell+Honeycomb%3C%7C%3E36+0.0000+x+60+0.0000%3C%7C%3E1%3C%7C%3E101.00%3C%7C%3EY&x_line_item=2%3C%7C%3EWoven+Wood+Shades+-+Series+100%3C%7C%3E36+0.0000+x+60+0.0000%3C%7C%3E1%3C%7C%3E67.00%3C%7C%3EY&x_line_item=3%3C%7C%3E2in+Express+Faux+Wood+Blinds%3C%7C%3E36+0.0000+x+60+0.0000%3C%7C%3E1%3C%7C%3E38.00%3C%7C%3EY

 

and echo of the unencoded string

 

&x_line_item=1<|>1/2in Single Cell Honeycomb<|>36 0.0000 x 60 0.0000<|>1<|>101.00<|>Y&x_line_item=2<|>Woven Wood Shades - Series 100<|>36 0.0000 x 60 0.0000<|>1<|>67.00<|>Y&x_line_item=3<|>2in Express Faux Wood Blinds<|>36 0.0000 x 60 0.0000<|>1<|>38.00<|>Y

 

 

Well lets start with Thanks for all the help!  Oh crap I didn't get any, Thanks you Bozo's for no help.

 

Second Thanks for crappy examples and information.

 

To solve this issue I had to download the PHP SDK and review the AIM samples again.

 

First issue, there is a Precedence in the order the data is submitted.

 

Initially I was submitting the information in this order AND when submitted with ONE item it works.

 

$sale->description = "Sales Order: " . tools::get_field_value("order_id");

$sale->line_item = "1<|>Info<|>More Info<|>1<|>23.95<|>Y"

$sale->setFields($shipping_info);

$sale->setFields($customer);

$response = $sale->authorizeAndCapture();

 

Now here is the interesting part, looking through the samples it shows to submit multiple line items you have to do the item part this way;

The first line is still the same

 

$sale->line_item = "1<|>Info<|>More Info<|>1<|>23.95<|>Y"

 

But the subsequent items are done like this

 

$sale->addLineItem('2','info','more info','1','39.95','Y')

 

SERIOUSLY A DIFFERENT FORMAT!!  Not $sale->addLineItem = "2<|>Info<|>More Info<|>1<|>23.95<|>Y" HELL NO THAT WOULD ONLY MAKE SENSE.

 

Anyway so I hard coded it and tried and tried and tried, but no it kept giving me the same error; Line 1 is invalid.  So I kept looking at the sample for multiple items in the SDK and the $sale->addLineItem were all JUST BEFORE the $response = $sale->authorizeAndCapture(); so I changed my order to;

 

$sale->description = "Sales Order: " . tools::get_field_value("order_id");

$sale->setFields($shipping_info);

$sale->setFields($customer);

$sale->line_item = "1<|>Info<|>More Info<|>1<|>23.95<|>Y"

$sale->addLineItem(2,info,more info,1,39.95,Y)

$response = $sale->authorizeAndCapture();

 

AND BAM IT WORKS.  YA THINK THAT MIGHT BE USEFULL INFORMATION TO POINT OUT!?!?!

 

Ok so on to live data, and you have to figure this out by yourself because ALL THE EXAMPLES use hardcoded data.  Anyway here is what I came up with.  The while loop is JUST before the $response = $sale->authorizeAndCapture();.

 

Notice I have to evaluate which item is being processed so the structure is changed for the first item and then all subsequent items. 

 

NOW HERE IS ANOTHER BITCH, notice the substr($row['product_name'],0,30) well I must have submitted 10 orders and all was great, then all of a sudden I got the error Line x is invalid again.  WHAT THE HELL!!!  Well it turns out there is a limit to the length of the string Authorize.net can handle, 30 characters, if you pass a string longer than that it craps out.  YA THINK THAT IS AN IMPORTANT BIT OF INFO YOU COULD HAVE NOTED IN THE EXAMPLES?!?!?  Not to mention Authorize.net could just truncate it on their end and save everyone a lot of heart ache.

 

$result = $this->system->db->query($sql);

while ($row = mysql_fetch_array($result)) {

  if ($row['order_item_id'] == 1) {

    $sale->line_item  = $row['order_item_id'] . '<|>' . substr($row['product_name'],0,30) . '<|>' . $row['width'] . ' ' . tools::get_fraction_text($row['width_frac']) . ' x ' . $row['height'] . ' ' . tools::get_fraction_text($row['height_frac']) . '<br>Color: ' . $row['option_picklist_name'] . '<|>' . $row['quantity'] . '<|>' . $row['item_total_price'] . '<|>Y';

  }

  else {

    $sale->addLineItem($row['order_item_id'], substr($row['product_name'],0,30), $row['width'] . ' ' . tools::get_fraction_text($row['width_frac']) . ' x ' . $row['height'] . ' ' . tools::get_fraction_text($row['height_frac']) . '<br>Color: ' . $row['option_picklist_name'], $row['quantity'], $row['item_total_price'], 'Y');

   }

 }

 

Again thanks for all the help you clowns. Oh that's right I didn't get any.

 

 

 

 

 

 

Hey Vince, I hope you're still subcribed to this....I am pulling my hair out with this issue. If you could please email me chris @ dowden . com I will love you forever.

 

Thanks.

Ok.. So I just did the x_line_item integration and it took me forever to figure it out, but I hope that this post here is helpful to others.

 

first the format:

x_line_item=1<|>2in Premier Faux Wood Blinds Painted<|>36 0.0000 x 60 0.0000<|>1<|>47.00<|>Y&x_line_item=2<|>Solid Vinyl PVC Verticals<|>36 0.0000 x 60 0.0000<|>1<|>39.00<|>Y&x_line_item=3<|>2in Designer Wood Blinds<|>36 0.0000 x 60 0.0000<|>1<|>64.00<|>Y&

 

This submit format is correct, but... yes, there is a but

 

Structure:

x_line_item=Item ID<|>item name<|>item description<|>itemX quantity<|>item price (unit cost)<|>itemX taxable

 

Notes:

Item ID: This should be a running number integer in a sequence starting with 1 then 2 then 3, etc. So you get item 1, 2, 3 ... etc.

 

item name: This can't be longer than 30 characters! If it is it will not work! You have to do some string modification:

substr(str_replace($item_name,0,30)

Also be sure to replace or filter out any special characters like ™ , ®, &, etc. Oh yes.. also remove all commas!

 

item description: This can't be longer than 255 characters! Again, all special characters need to be stripped out and replaced, and remove all commas. That is what worked for me. With commas.. no workie.. without commas.. works like a charm.

 

itemX quantity: that should be an integer

 

item price: that should the just the number, no $ sign!    9.99 for example, or 5.45

 

itemX taxable: that should be either Y for yes or N for no, or you can write it out Yes or No.

 

Once you build that item string and add it to the rest of your processing string you still have to urlencode the actual x_line_item values like this:

 

x_line_item=urlencode("1<|>2in Premier Faux Wood Blinds Painted<|>36 0.0000 x 60 0.0000<|>1<|>47.00<|>Y")&x_line_item=urlencode("2<|>Solid Vinyl PVC Verticals<|>36 0.0000 x 60 0.0000<|>1<|>39.00<|>Y")&x_line_item=urlencode("3<|>2in Designer Wood Blinds<|>36 0.0000 x 60 0.0000<|>1<|>64.00<|>Y")&

 

If your x_line_item(s) are at the end of your string or in general don't forget to remove the last & before submitting!

 

 

That's it. I hope that this will help someone.

 

Martin

Um, there's an interface for adding line items. From the AIM.markdown file in the PHP SDK:

 

// To add itemized order information use the addLineItem method:

$auth->addLineItem(
  'item1', // Item Id
  'Golf tees', // Item Name
  'Blue tees', // Item Description
  '2', // Item Quantity
  '5.00', // Item Unit Price
  'N' // Item taxable
);