After filling the Drupal Commerce checkout forms and proceeding to payment, I am met with:
"Status Detail: 3107 : The BillingSurname field is required.".

Is this because the name field in the Drupal Commerce form is one for the first name and last name?

I have not been able to successfully pass ANY payments through this module using 2 different accounts and as an anonymous user.

CommentFileSizeAuthor
#2 commerce_sagepay_form.module.gz7.09 KBphily245

Comments

phily245’s picture

UPDATE: I substituted the following code in on line 439 of commerce_sagepay_form.module and it worked, proving that it is an issue with the single name field.

if(!isset($address['last_name']) || $address['last_name'] == '') {
$address['last_name'] = 'AAA';
}

if(!isset($address['first_name']) || $address['first_name'] == '') {
$address['first_name'] = 'ZZZ';
}

Both $address['first_name'] and $address['last_name'] were empty, proving it was a problem with the single name field not splitting the name into two variables.

phily245’s picture

Status: Active » Closed (fixed)
StatusFileSize
new7.09 KB

UPDATE: Fixed the file by splitting the single string by whitespaces and creating 2 different name values with support for if there are no whitespaces. Here is the fix (put in on the same line as my last post):

//Explode the name into the words which comprise the name.
$name = explode(" ", $address['name_line']);

//Count the amount of words and -1 so it relates to the $name array.
$name_num_words = sizeof($name) -1;

//If there is only one name in the box, put it in both fields to ensure no SagePay malformation
if ($name_num_words == 0) {
$address['first_name'] = $address['name_line'];
$address['last_name'] = $address['name_line'];
}else{

//Create or empty the $address['first_name'] variable.
$address['first_name'] ='';

//for every word except the last, append the word to the $address['first_name'].
for($i = 0; $i < $name_num_words; ++$i) {
if ($i == $name_num_words) {
break;
}else{
$address['first_name'] = $address['first_name'] . $name[$i] . ' ';
}
}
}

//Declare $address['last_name'] is the last array item in $name.
$address['last_name'] = $name[$name_num_words];

Find the entire patched commerce_sagepay_form.module attached.

ikos’s picture

Category: bug » feature
Status: Closed (fixed) » Active

Hi,

SagePay requires the name as two variables so I added a note in the read me file about how to set up the address field.

It may be possible to check which type of name field an address is using and split the field accordingly. Do you think this would be useful? Right now we just set all sites up using a first name and last name.

Richard

phily245’s picture

Hi Richard,

I think it will be, as it covers all bases and means the module will be easier to intergrate to a site set up with just one name field. I personally thought altering the sagepay .module file was easier as the code was easier to find and I was more familiar with it as I develop more bespoke e-commerce sites using sagepay than using Drupal commerce modules.

Phil

ikos’s picture

Status: Active » Fixed

Variation of this has been committed to the latest dev version.

Status: Fixed » Closed (fixed)

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

doliveros’s picture

Status: Closed (fixed) » Needs work

Hello ikos.

I think the name variation is wrongly set on _commerce_sagepay_form_format_customer_name, line 721 of commerce_sagepay_form.module.

As you can see on:

  if (isset($name_line)) {
    $split_name = explode(' ', $name_line);

    $last_name = array_pop($split_name);
    foreach ($split_name as $n) {
      $first_name .= $n;
      $first_name .= ' ';
    }

    // Allow for a situation where only one name was entered on the name line
    $first_name = 'not set';
  }

, the first name value is always set to "Not set", even when the name line is a valid name.

The correct first name validation should be:

// Allow for a situation where only one name was entered on the name line
if (empty($first_name)) $first_name = 'not set';

Cheers.