besmartand-pro/bsap-account-bundle
Installation
composer require besmartand-pro/bsap-account-bundle
Register the bundle in config/app.php under providers:
BesmartandPro\BsapAccountBundle\BsapAccountBundle::class,
Publish Configuration
php artisan vendor:publish --provider="BesmartandPro\BsapAccountBundle\BsapAccountServiceProvider" --tag="config"
Edit config/bsap-account.php to set your API credentials and endpoints.
First Use Case: Fetching an Account Inject the service into a controller or command:
use BesmartandPro\BsapAccountBundle\Service\BsapAccountService;
public function __construct(private BsapAccountService $accountService) {}
public function showAccount($accountId) {
$account = $this->accountService->getAccount($accountId);
return response()->json($account);
}
client_id, client_secret, and token_endpoint in the config.api_base_url for the Bsap API.Account Management
$accounts = $this->accountService->listAccounts(['limit' => 10]);
$newAccount = $this->accountService->createAccount([
'name' => 'Test Account',
'currency' => 'EUR'
]);
Transactions
$transactions = $this->accountService->getTransactions($accountId, [
'from' => '2024-01-01',
'to' => '2024-12-31'
]);
$transfer = $this->accountService->transfer([
'from_account_id' => $sourceId,
'to_account_id' => $targetId,
'amount' => 100.50,
'currency' => 'EUR'
]);
Webhooks
config/bsap-account.php:
'webhooks' => [
'enabled' => true,
'events' => ['account.created', 'transaction.processed'],
'secret' => env('BSAP_WEBHOOK_SECRET')
],
BsapWebhookController (published with php artisan vendor:publish --tag="webhook").BsapRateLimitMiddleware in app/Http/Kernel.php if needed.'cache_enabled' => true in config and implementing BsapAccountCacheInterface.BsapLogger facade to log API interactions:
\BsapAccountBundle\Facades\BsapLogger::info('Account fetched', ['account_id' => $accountId]);
Authentication Failures
client_id and client_secret are correct and the token endpoint is reachable.$this->accountService->getAccessToken(); // Check if token is valid
Webhook Verification
BsapWebhookVerifier:
$verifier = new \BesmartandPro\BsapAccountBundle\Service\BsapWebhookVerifier($request);
if (!$verifier->isValid()) {
abort(403, 'Invalid webhook signature');
}
Deprecated Endpoints
'debug' => env('BSAP_DEBUG', false), // Logs raw API responses
BsapAccountService with a mock client:
$this->app->bind(BsapAccountService::class, function ($app) {
return new BsapAccountService(new \GuzzleHttp\Client(), new \BesmartandPro\BsapAccountBundle\Service\MockBsapClient());
});
Custom Responses
Override the default response format by extending BsapAccountService and injecting a custom BsapResponseFormatter:
class CustomBsapAccountService extends BsapAccountService {
public function __construct(BsapClient $client, BsapResponseFormatter $formatter) {
parent::__construct($client, $formatter);
}
}
Additional API Methods
Extend the BsapClient to support unsupported endpoints:
$client->addCustomMethod('get', '/custom-endpoint', function ($params) {
return $this->request('GET', '/custom-endpoint', $params);
});
Event Listeners
Subscribe to Bsap events (e.g., BsapAccountCreated) in EventServiceProvider:
protected $listen = [
\BesmartandPro\BsapAccountBundle\Events\BsapAccountCreated::class => [
\App\Listeners\LogAccountCreation::class,
],
];
BSAP_ (e.g., BSAP_API_BASE_URL).null for optional fields. Explicitly set null in your requests to override defaults.How can I help you explore Laravel packages today?