Skip to content

Commit a5544a6

Browse files
committed
Added UK Bank Validation
1 parent 687a128 commit a5544a6

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
namespace Dfcplc\PostcodeAnywhere\BankValidation;
3+
4+
class Validate
5+
{
6+
7+
//Now includes faster payments and CHAPs availability information.
8+
//Credit: Thanks to Stuart Sillitoe (http://stu.so/me) for the original PHP that these samples are based on.
9+
10+
private $Key; //The key to use to authenticate to the service.
11+
private $AccountNumber; //The bank account number to validate.
12+
private $SortCode; //The branch sort code for the account number.
13+
private $Data; //Holds the results of the query
14+
15+
public function __construct($Key, $AccountNumber, $SortCode)
16+
{
17+
$this->Key = $Key;
18+
$this->AccountNumber = $AccountNumber;
19+
$this->SortCode = $SortCode;
20+
}
21+
22+
public function MakeRequest()
23+
{
24+
$url = "http://services.postcodeanywhere.co.uk/BankAccountValidation/Interactive/Validate/v2.00/xmla.ws?";
25+
$url .= "&Key=" . urlencode($this->Key);
26+
$url .= "&AccountNumber=" . urlencode($this->AccountNumber);
27+
$url .= "&SortCode=" . urlencode($this->SortCode);
28+
29+
//Make the request to Postcode Anywhere and parse the XML returned
30+
$file = simplexml_load_file($url);
31+
32+
//Check for an error, if there is one then throw an exception
33+
if ($file->Columns->Column->attributes()->Name == "Error")
34+
{
35+
throw new Exception("[ID] " . $file->Rows->Row->attributes()->Error . " [DESCRIPTION] " . $file->Rows->Row->attributes()->Description . " [CAUSE] " . $file->Rows->Row->attributes()->Cause . " [RESOLUTION] " . $file->Rows->Row->attributes()->Resolution);
36+
}
37+
38+
//Copy the data
39+
if ( !empty($file->Rows) )
40+
{
41+
foreach ($file->Rows->Row as $item)
42+
{
43+
$this->Data[] = array(
44+
'IsCorrect'=>$item->attributes()->IsCorrect,
45+
'IsDirectDebitCapable'=>$item->attributes()->IsDirectDebitCapable,
46+
'StatusInformation'=>$item->attributes()->StatusInformation,
47+
'CorrectedSortCode'=>$item->attributes()->CorrectedSortCode,
48+
'CorrectedAccountNumber'=>$item->attributes()->CorrectedAccountNumber,
49+
'IBAN'=>$item->attributes()->IBAN,
50+
'Bank'=>$item->attributes()->Bank,
51+
'BankBIC'=>$item->attributes()->BankBIC,
52+
'Branch'=>$item->attributes()->Branch,
53+
'BranchBIC'=>$item->attributes()->BranchBIC,
54+
'ContactAddressLine1'=>$item->attributes()->ContactAddressLine1,
55+
'ContactAddressLine2'=>$item->attributes()->ContactAddressLine2,
56+
'ContactPostTown'=>$item->attributes()->ContactPostTown,
57+
'ContactPostcode'=>$item->attributes()->ContactPostcode,
58+
'ContactPhone'=>$item->attributes()->ContactPhone,
59+
'ContactFax'=>$item->attributes()->ContactFax,
60+
'FasterPaymentsSupported'=>$item->attributes()->FasterPaymentsSupported,
61+
'CHAPSSupported'=>$item->attributes()->CHAPSSupported
62+
);
63+
}
64+
}
65+
}
66+
67+
public function HasData()
68+
{
69+
if (!empty($this->Data))
70+
{
71+
return $this->Data;
72+
}
73+
return false;
74+
}
75+
76+
}

0 commit comments

Comments
 (0)