I had an issue with a customer failing to do a payment because of the following error reported on SagePay side:

3110 : The BillingFirstnames value is too long.

The field was:

billingfirstnames=RRRRRRRRRRRRRR DDDD'DDDD

It might seem unusual but it could happen that somebody input three long names and therefore it should not represent an issue.
For obvious reasons I didn't publish the original name and just replaced it with a letter.

Comments

FrancescoUK’s picture

Issue summary: View changes
kingandy’s picture

According to the API docs, the BillingFirstnames and BillingSurname fields have a limit of 20 chars (http://www.sagepay.co.uk/file/1166/download-document/DIRECTProtocolandIn... et al). Would it be sensible to limit the address fields to match?

I'm not sure how to handle this when the address form is using a unified "name" field. Limiting to 40 characters wouldn't really help as people would be able to enter "John Isaverylongnameindeed". Maybe some form validation would be required in that case.

kingandy’s picture

Hm, actually, implementing a #maxfield may not actually help. To me it looks like the most recent versions of Addressfield cover both bases - if the addressfield widget is set to use separate first/last name fields, it helpfully populates the "name_line" field (presumably so that the widget can be switched back and forth without loss of data). Unless I'm mistaken, this looks like _commerce_sagepay_format_customer_name() will always base its transaction data off the "$name_line" variable, regardless of what is put into the first/last name fields.

kingandy’s picture

How about we just truncate the values to 20 characters before we send?

kingandy’s picture

Further to #2378145: Duplicate first name appearing in SagePay transaction listings, I'd suggest the following as a replacement to the _commerce_sagepay_format_customer_name() function:

function _commerce_sagepay_format_customer_name($name_line = '', $first_name = '', $last_name = '') {

  $name = array(
    'first_name' => empty($first_name) ? 'not set' : substr(trim($first_name), 0, 20),
    'last_name' => empty($last_name) ? 'not set' : substr(trim($last_name), 0, 20),
  );

  return $name;
}
ikos’s picture

The attached patch completely removes the need to the Commerce SagePay name splitting function as recommended by @kingandy.

It instead relies on AddressField doing the work.

I've tested this in both scenarios and it doesn't seem to cause any problems.

Can I have some reviews on this please?

many thanks

Richard

ikos’s picture

Status: Active » Needs review
willhallonline’s picture

This appears to fix the duplicate firstname issues I had (similar to https://www.drupal.org/node/2378145), using separate first and last names from addressfield.

ikos’s picture

Status: Needs review » Reviewed & tested by the community
kingandy’s picture

TBH, while this does fix the issue in #2378145, it doesn't really touch on the "too long" issue reported here.

ikos’s picture

OK,

I did combine a couple of things in this patch - including the truncation of the names to 20 chars.

Does that do the job do you think?

R

  • ikos committed eac7d2c on 7.x-1.x
    Issue #2312791 by FrancescoUK: The BillingFirstnames value is too long...
kingandy’s picture

Ah, yeah, being an idiot, I had completely missed that. Looks good!

vaccinemedia’s picture

EDIT Ignore this re-roll I've just noticed the commit

ikos’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.