-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphp.php
More file actions
96 lines (80 loc) · 3.59 KB
/
Copy pathphp.php
File metadata and controls
96 lines (80 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* FindBSB API — PHP examples
* https://findbsb.com.au/api
*/
define('FINDBSB_BASE_URL', 'https://findbsb.com.au/api');
// ── Single BSB lookup ────────────────────────────────────────────────────────
function lookup_bsb(string $bsb): array {
$url = FINDBSB_BASE_URL . '/bsb/' . urlencode($bsb);
$response = http_get($url);
if ($response['status'] === 404) {
throw new \Exception("BSB {$bsb} not found");
}
if ($response['status'] === 400) {
throw new \Exception("Invalid BSB format: {$bsb}");
}
return $response['body'];
}
// ── Bulk validation ──────────────────────────────────────────────────────────
function validate_bsbs(array $bsbs): array {
$response = http_post(
FINDBSB_BASE_URL . '/validate',
['bsbs' => $bsbs]
);
return $response['body'];
}
// ── Filter by bank / state / suburb / postcode ───────────────────────────────
function filter_bsbs(array $params = []): array {
$params = array_merge(['limit' => 100], $params);
$url = FINDBSB_BASE_URL . '/bsb?' . http_build_query($params);
$response = http_get($url);
return $response['body'];
}
// ── HTTP helpers ─────────────────────────────────────────────────────────────
function http_get(string $url): array {
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_USERAGENT => 'MyApp/1.0',
CURLOPT_TIMEOUT => 10,
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return ['status' => $status, 'body' => json_decode($body, true)];
}
function http_post(string $url, array $data): array {
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_USERAGENT => 'MyApp/1.0',
CURLOPT_TIMEOUT => 10,
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return ['status' => $status, 'body' => json_decode($body, true)];
}
// ── Examples ─────────────────────────────────────────────────────────────────
// Single lookup
$bsb = lookup_bsb('062-000');
echo "{$bsb['bank']} — {$bsb['branch']}, {$bsb['suburb']} {$bsb['state']}\n";
// Bulk validate
$result = validate_bsbs(['062-000', '012-003', '999-999']);
echo "Valid: {$result['valid']}, Invalid: {$result['invalid']}, Closed: {$result['closed']}\n";
foreach ($result['results'] as $r) {
$status = $r['valid'] ? '✓' : '✗';
$closed = ($r['closed'] ?? false) ? ' (CLOSED)' : '';
$bank = $r['bank'] ?? 'N/A';
echo " {$status} {$r['bsb']} — {$bank}{$closed}\n";
}
// Filter NAB branches in QLD
$result = filter_bsbs(['bank' => 'NAB', 'state' => 'QLD', 'limit' => 5]);
echo "\nNAB QLD branches ({$result['total']} total):\n";
foreach ($result['results'] as $r) {
echo " {$r['bsb']} — {$r['branch']}, {$r['suburb']}\n";
}