Reputation: 199
My Sagepay implementation has been working fine now for some time, however lately users that have a %27 character (') have been returning with the error:
'Invalid:3035 : The VendorTxCode format is invalid.'
Currently I am URLEncoding the surname before sending it to my createVendorTxCode function:
$encodedSurname = urlencode(Input::get('BillingSurname'));
// Create a custom VendorTxCode. This must be unique every time.
$VendorTxCode = $this->createVendorTxCode($encodedSurname, $ids);
...
public function createVendorTxCode($lastName, $ids) {
$lesson_ids = str_replace(',', '-', $ids);
$VendorTxCode = $lastName;
$VendorTxCode .= date("-YmdHis-");
$VendorTxCode .= rand(0,32000)*rand(0,32000);
return $VendorTxCode;
}
With a name such as O'Neil this now returns the surname as O%27Neil, which I think is what is causing the problems (all other users without this character work). After building the rest of the URL and sending it to my requestPost function (shown below), Sagepay returns with the Invalid error started above
public function requestPost($url, $data){
set_time_limit(60);
$output = array();
$curlSession = curl_init();
curl_setopt ($curlSession, CURLOPT_URL, $url);
curl_setopt ($curlSession, CURLOPT_HEADER, 0);
curl_setopt ($curlSession, CURLOPT_POST, 1);
curl_setopt ($curlSession, CURLOPT_POSTFIELDS, $data);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curlSession, CURLOPT_TIMEOUT,30);
curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curlSession, CURLOPT_SSL_VERIFYHOST, 2);
$rawresponse = curl_exec($curlSession);
$_SESSION["rawresponse"]=$rawresponse;
$response = explode(chr(10), $rawresponse);
// Check that a connection was made
if (curl_error($curlSession)){
$output['Status'] = "FAIL";
$output['StatusDetail'] = curl_error($curlSession);
}
curl_close ($curlSession);
for ($i=0; $i<count($response); $i++){
$splitAt = strpos($response[$i], "=");
$output[trim(substr($response[$i], 0, $splitAt))] = trim(substr($response[$i], ($splitAt+1)));
}
return $output;
}
Here is the output from the response:
array(3) { ["VPSProtocol"]=> string(4) "2.23" ["Status"]=> string(7) "INVALID" ["StatusDetail"]=> string(42) "3035 : The VendorTxCode format is invalid." }
As I have said, this works fine with every other surname, just not any with that particular character in it.
Any help or insight would be greatly appreciated. Thanks.
Upvotes: 0
Views: 268
Reputation: 1149
The vendorTxCode field only allows a-z A-Z - _ . (max length 40 characters), so is failing on the ' character. The peril of embedding a surname in the vendorTxCode, I'm afraid.
Upvotes: 1