A Laravel package for integrating with the Wise (formerly TransferWise) API.
You can install the package via composer:
composer require lai3221/laravel-wisePublish the configuration file:
php artisan vendor:publish --tag=wise-configAdd the following environment variables to your .env file:
WISE_ENVIRONMENT=sandbox # or production
WISE_API_KEY=your_api_key_hereuse Lai3221\LaravelWise\Services\WiseService;
use Lai3221\LaravelWise\Exceptions\WiseException;
use Lai3221\LaravelWise\Exceptions\AuthenticationException;
use Lai3221\LaravelWise\Exceptions\ValidationException;
use Lai3221\LaravelWise\Exceptions\NotFoundException;
use Lai3221\LaravelWise\Exceptions\ApiException;
class WiseController extends Controller
{
protected $wiseService;
public function __construct(WiseService $wiseService)
{
$this->wiseService = $wiseService;
}
public function getBalances($profileId)
{
try {
$balances = $this->wiseService->getBalances($profileId);
return response()->json($balances);
} catch (AuthenticationException $e) {
return response()->json([
'error' => 'Authentication failed',
'message' => $e->getMessage(),
'details' => $e->getErrorResponse()
], 401);
} catch (NotFoundException $e) {
return response()->json([
'error' => 'Resource not found',
'message' => $e->getMessage(),
'details' => $e->getErrorResponse()
], 404);
} catch (ValidationException $e) {
return response()->json([
'error' => 'Validation failed',
'message' => $e->getMessage(),
'details' => $e->getErrorResponse()
], 422);
} catch (ApiException $e) {
return response()->json([
'error' => 'API error',
'message' => $e->getMessage(),
'details' => $e->getErrorResponse()
], 500);
}
}
public function getBalanceByCurrency($profileId, $currency)
{
try {
$balance = $this->wiseService->getBalanceByCurrency($profileId, $currency);
return response()->json($balance);
} catch (WiseException $e) {
return response()->json([
'error' => 'Wise API error',
'message' => $e->getMessage(),
'details' => $e->getErrorResponse()
], $e->getCode());
}
}
public function createTransfer(Request $request)
{
$data = [
'profile' => $request->profile_id,
'source_currency' => $request->source_currency,
'target_currency' => $request->target_currency,
'source_amount' => $request->amount,
'target_amount' => $request->target_amount,
'target_account' => $request->target_account,
];
return $this->wiseService->createTransfer($data);
}
}getBalances(int $profileId): arraygetBalanceByCurrency(int $profileId, string $currency): ?array
createTransfer(array $data): arraygetTransfer(int $transferId): arraycancelTransfer(int $transferId): array
The package throws the following exceptions:
WiseException: Base exception class for all Wise-related errorsAuthenticationException: Thrown when API authentication fails (401)ValidationException: Thrown when request validation fails (422)NotFoundException: Thrown when a resource is not found (404)ApiException: Thrown for general API errors (500)
All exceptions contain:
- Message: A human-readable error message
- Code: The HTTP status code
- Error Response: The full error response from the API
Example of catching specific exceptions:
try {
$balances = $wiseService->getBalances($profileId);
} catch (AuthenticationException $e) {
// Handle authentication error
$errorDetails = $e->getErrorResponse();
} catch (ValidationException $e) {
// Handle validation error
$errorDetails = $e->getErrorResponse();
} catch (WiseException $e) {
// Handle any other Wise-related error
$errorDetails = $e->getErrorResponse();
}composer testIf you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.