Skip to content

Commit 2a87558

Browse files
author
Liam Jackson
committed
wip
1 parent 60c8703 commit 2a87558

File tree

3 files changed

+118
-4
lines changed

3 files changed

+118
-4
lines changed

examples/retrieve-banks.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Dotenv\Dotenv;
4+
use GuzzleHttp\Exception\RequestException;
5+
use LJJackson\Volt\Exceptions\PaymentValidationException;
6+
use LJJackson\Volt\VoltApi;
7+
use LJJackson\Volt\VoltApiConfig;
8+
9+
require __DIR__ . '/../vendor/autoload.php';
10+
11+
$dotenv = Dotenv::createImmutable(__DIR__);
12+
$dotenv->load();
13+
14+
$config = new VoltApiConfig(
15+
$_ENV['VOLT_CLIENT_ID'],
16+
$_ENV['VOLT_CLIENT_SECRET'],
17+
$_ENV['VOLT_API_USERNAME'],
18+
$_ENV['VOLT_API_PASSWORD']
19+
);
20+
21+
$config->setSandbox();
22+
23+
$api = new VoltApi($config);
24+
25+
$accessToken = $api->authentication->authenticate();
26+
27+
$banks = $api->banks->retrieveAll($accessToken);
28+
29+
var_dump($banks[0]);
30+
31+
32+

src/Entities/Bank.php

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
4+
namespace LJJackson\Volt\Entities;
5+
6+
7+
class Bank
8+
{
9+
private string $id;
10+
private string $name;
11+
private string $country;
12+
private string $logo;
13+
private string $icon;
14+
private array $currencies;
15+
private array $providers;
16+
17+
public function __construct(array $response)
18+
{
19+
$this->id = $response['id'];
20+
$this->name = $response['name'];
21+
$this->country = $response['country']['id'];
22+
$this->logo = $response['logo'];
23+
$this->icon = $response['icon'];
24+
$this->currencies = $response['supportedCurrencies'];
25+
$this->providers = $response['providedBy'] ?? [];
26+
}
27+
28+
/**
29+
* @return string
30+
*/
31+
public function getId(): string
32+
{
33+
return $this->id;
34+
}
35+
36+
/**
37+
* @return string
38+
*/
39+
public function getName(): string
40+
{
41+
return $this->name;
42+
}
43+
44+
/**
45+
* @return string
46+
*/
47+
public function getCountry(): string
48+
{
49+
return $this->country;
50+
}
51+
52+
/**
53+
* @return string
54+
*/
55+
public function getLogo(): string
56+
{
57+
return $this->logo;
58+
}
59+
60+
/**
61+
* @return string
62+
*/
63+
public function getIcon(): string
64+
{
65+
return $this->icon;
66+
}
67+
68+
/**
69+
* @return string[]
70+
*/
71+
public function getCurrencies(): array
72+
{
73+
return $this->currencies;
74+
}
75+
76+
/**
77+
* @return string[]
78+
*/
79+
public function getProviders(): array
80+
{
81+
return $this->providers;
82+
}
83+
}

src/Services/BankService.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66

77
use GuzzleHttp\RequestOptions;
88
use LJJackson\Volt\Entities\AccessToken;
9+
use LJJackson\Volt\Entities\Bank;
910

1011
class BankService extends BaseService
1112
{
1213
/**
13-
* TODO Create entity.
14-
*
1514
* @param AccessToken $token
16-
* @return mixed
15+
* @return Bank[]
1716
* @throws \GuzzleHttp\Exception\GuzzleException
1817
*/
1918
public function retrieveAll(AccessToken $token)
@@ -26,6 +25,6 @@ public function retrieveAll(AccessToken $token)
2625

2726
$results = json_decode($response->getBody()->getContents(), true);
2827

29-
return $results;
28+
return array_map(fn ($bank) => new Bank($bank), $results);
3029
}
3130
}

0 commit comments

Comments
 (0)