diff --git a/src/Resources/Available/Available.php b/src/Resources/Available/Available.php index fcc5ad1..3922c36 100644 --- a/src/Resources/Available/Available.php +++ b/src/Resources/Available/Available.php @@ -76,6 +76,34 @@ public static function fromArray(array $data): self } } +readonly class SwiftCodeBankDetails +{ + public function __construct( + public string $id, + public string $bank, + public string $city, + public string $branch, + public string $swiftCode, + public string $swiftCodeLink, + public string $country, + public string $countrySlug + ) {} + + public static function fromArray(array $data): self + { + return new self( + id: $data['id'], + bank: $data['bank'], + city: $data['city'], + branch: $data['branch'], + swiftCode: $data['swiftCode'], + swiftCodeLink: $data['swiftCodeLink'], + country: $data['country'], + countrySlug: $data['countrySlug'] + ); + } +} + class Available { public function __construct( @@ -124,4 +152,26 @@ public function getRails(): BlindPayApiResponse return $response; } + + /* + * Get bank details for a specific swift code + * + * @param string $swift The swift code to get bank details for + * @return BlindPayApiResponse + */ + public function getSwiftCodeBankDetails(string $swift): BlindPayApiResponse + { + $response = $this->client->get("available/swift/{$swift}"); + + if ($response->isSuccess() && is_array($response->data)) { + $swiftCodeBankDetails = array_map( + fn (array $item) => SwiftCodeBankDetails::fromArray($item), + $response->data + ); + + return BlindPayApiResponse::success($swiftCodeBankDetails); + } + + return $response; + } } diff --git a/tests/Resources/Available/AvailableTest.php b/tests/Resources/Available/AvailableTest.php index ec2db72..4303610 100644 --- a/tests/Resources/Available/AvailableTest.php +++ b/tests/Resources/Available/AvailableTest.php @@ -174,4 +174,38 @@ public function it_gets_available_rails(): void $this->assertEquals('rtp', $response->data[7]->value); $this->assertEquals('US', $response->data[7]->country); } + + #[Test] + public function it_get_bank_details_of_a_swift_code(): void + { + $mockedBankDetails = [ + [ + 'id' => '416', + 'bank' => 'BANK OF AMERICA, N.A.', + 'city' => 'NEW JERSEY', + 'branch' => 'LENDING SERVICES AND OPERATIONS (LSOP)', + 'swiftCode' => 'BOFAUS3NLMA', + 'swiftCodeLink' => 'https://bank.codes/swift-code/united-states/bofaus3nlma/', + 'country' => 'United States', + 'countrySlug' => 'united-states', + ], + ]; + + $this->mockResponse($mockedBankDetails); + + $response = $this->blindpay->available->getSwiftCodeBankDetails('BOFAUS3NLMA'); + + $this->assertTrue($response->isSuccess()); + $this->assertNull($response->error); + $this->assertIsArray($response->data); + $this->assertCount(1, $response->data); + $this->assertEquals('416', $response->data[0]->id); + $this->assertEquals('BANK OF AMERICA, N.A.', $response->data[0]->bank); + $this->assertEquals('NEW JERSEY', $response->data[0]->city); + $this->assertEquals('LENDING SERVICES AND OPERATIONS (LSOP)', $response->data[0]->branch); + $this->assertEquals('BOFAUS3NLMA', $response->data[0]->swiftCode); + $this->assertEquals('https://bank.codes/swift-code/united-states/bofaus3nlma/', $response->data[0]->swiftCodeLink); + $this->assertEquals('United States', $response->data[0]->country); + $this->assertEquals('united-states', $response->data[0]->countrySlug); + } }