Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/Resources/Available/Available.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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<SwiftCodeBankDetails[]>
*/
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;
}
}
34 changes: 34 additions & 0 deletions tests/Resources/Available/AvailableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}