|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DevinPearson\BinList; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* A sample class. |
|
7
|
|
|
* |
|
8
|
|
|
* Use this section to define what this class is doing, the PHPDocumentator will use this |
|
9
|
|
|
* to automatically generate an API documentation using this information. |
|
10
|
|
|
* |
|
11
|
|
|
* @author Devin Pearson |
|
12
|
|
|
*/ |
|
13
|
|
|
class BinList |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var BinListConnector handling the calls to binlist |
|
17
|
|
|
*/ |
|
18
|
|
|
private $connector; |
|
19
|
|
|
|
|
20
|
12 |
|
public function __construct($connector = null) |
|
21
|
|
|
{ |
|
22
|
12 |
|
if (!$connector instanceof BinListConnector) { |
|
23
|
9 |
|
$connector = new BinListConnector(); |
|
24
|
|
|
} |
|
25
|
12 |
|
$this->connector = $connector; |
|
26
|
12 |
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Check method. |
|
30
|
|
|
* |
|
31
|
|
|
* Checks the bin number against binlists db, |
|
32
|
|
|
* returns a BinList object |
|
33
|
|
|
* |
|
34
|
|
|
* @param string $binNumber bin number being searched for |
|
35
|
|
|
* |
|
36
|
|
|
* @return BinResult |
|
37
|
|
|
*/ |
|
38
|
3 |
|
public function check($binNumber) |
|
39
|
|
|
{ |
|
40
|
3 |
|
$binResult = $this->formatResponse($this->connector->check($binNumber)); |
|
41
|
|
|
|
|
42
|
3 |
|
return $binResult; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Takes the json response and converts it in to a BinResult object set. |
|
47
|
|
|
* |
|
48
|
|
|
* @param $json |
|
49
|
|
|
* |
|
50
|
|
|
* @return BinResult |
|
51
|
|
|
*/ |
|
52
|
3 |
|
private function formatResponse($json) |
|
53
|
|
|
{ |
|
54
|
3 |
|
$result = json_decode($json); |
|
55
|
3 |
|
$bank = new BinBank( |
|
56
|
3 |
|
$result->bank->name ?? '', |
|
57
|
3 |
|
$result->bank->url ?? '', |
|
58
|
3 |
|
$result->bank->phone ?? '', |
|
59
|
3 |
|
$result->bank->city ?? '' |
|
60
|
|
|
); |
|
61
|
3 |
|
$country = new BinCountry( |
|
62
|
3 |
|
$result->country->numeric ?? '', |
|
63
|
3 |
|
$result->country->alpha2 ?? '', |
|
64
|
3 |
|
$result->country->name ?? '', |
|
65
|
3 |
|
$result->country->emoji ?? '', |
|
66
|
3 |
|
$result->country->currency ?? '', |
|
67
|
3 |
|
$result->country->latitude ?? 0, |
|
68
|
3 |
|
$result->country->longitude ?? 0 |
|
69
|
|
|
); |
|
70
|
3 |
|
$binResult = new BinResult( |
|
71
|
3 |
|
$result->scheme ?? '', |
|
72
|
3 |
|
$result->type ?? '', |
|
73
|
3 |
|
$result->brand ?? '', |
|
74
|
3 |
|
$result->prepaid ?? false, |
|
75
|
3 |
|
$country, |
|
76
|
3 |
|
$bank |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
3 |
|
return $binResult; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|