From 86f50eed6a215a873a3f223b0670e1544c2c2a67 Mon Sep 17 00:00:00 2001 From: Anatoliy Poloz Date: Mon, 26 Jan 2026 15:36:42 +0300 Subject: [PATCH] feat: update BaaS flow example and connector OAuth implementation - Updated 01_baas_flow.php example to properly initialize BaaS with auth credentials - Removed unused GetTokenRequest import from AlfaBankConnector - Removed OAuth2Api interface implementation from AlfaBankConnector - Renamed resolveOauth2Config method to defaultOauthConfig in AlfaBankConnector Co-authored-by: Qwen-Coder --- examples/01_baas_flow.php | 21 +++++++++++++-------- src/Core/AlfaBankConnector.php | 6 ++---- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/examples/01_baas_flow.php b/examples/01_baas_flow.php index 76e1214..008c7a9 100644 --- a/examples/01_baas_flow.php +++ b/examples/01_baas_flow.php @@ -31,18 +31,23 @@ try { // METHOD B: Authorization Code Flow (H2H) (REQUIRED for Nominal Accounts) // See examples/13_h2h_auth_service.php for the full setup - $auth = \Apoloz\AlfaBank\AlfaBank::auth( - clientId: 'your-client-id', - clientSecret: 'your-client-secret', - redirectUri: 'https://...', + + // We re-initialize with auth credentials if we didn't pass them initially + $baas = AlfaBank::baas( certificatePath: __DIR__ . '/certs/client.cer', privateKeyPath: __DIR__ . '/certs/private.key', - environment: Environment::SANDBOX + environment: Environment::SANDBOX, + clientId: 'your-client-id', + clientSecret: 'your-client-secret', + redirectUri: 'https://...' ); - // Assuming you have a saved refresh token: - // $auth->refreshToken('saved_refresh_token'); + + // Now you can use OAuth methods: + // $url = $baas->getAuthorizationUrl(); + // or + // $baas->refreshAccessToken('saved_refresh_token'); - echo "Authentication Successful!\n"; + echo "Authentication Configured!\n"; // 2. Create a Beneficiary (Counterparty) echo "Creating Beneficiary...\n"; diff --git a/src/Core/AlfaBankConnector.php b/src/Core/AlfaBankConnector.php index 89ee393..5aa1c6c 100644 --- a/src/Core/AlfaBankConnector.php +++ b/src/Core/AlfaBankConnector.php @@ -9,7 +9,6 @@ namespace Apoloz\AlfaBank\Core; use Apoloz\AlfaBank\Contracts\SignerInterface; use Apoloz\AlfaBank\Http\Middleware\RequestIdMiddleware; use Apoloz\AlfaBank\Http\Pagination\AlfaOffsetPaginator; -use Apoloz\AlfaBank\Requests\Auth\GetTokenRequest; // Will be removed use Apoloz\AlfaBank\Traits\HasAlfaErrorHandling; use Saloon\Helpers\OAuth2\OAuthConfig; use Saloon\Http\Connector; @@ -19,11 +18,10 @@ use Saloon\PaginationPlugin\OffsetPaginator; use Saloon\Traits\Plugins\AlwaysThrowOnErrors; use Saloon\Traits\RequestProperties\HasTries; use Saloon\Traits\Plugins\HasTimeout; -use Saloon\Contracts\OAuth2\OAuth2Api; use Saloon\Traits\OAuth2\AuthorizationCodeGrant; use Apoloz\AlfaBank\Enums\Environment; -class AlfaBankConnector extends Connector implements HasPagination, OAuth2Api +class AlfaBankConnector extends Connector implements HasPagination { use HasTimeout; use HasTries; @@ -44,7 +42,7 @@ class AlfaBankConnector extends Connector implements HasPagination, OAuth2Api return $this->alfaConfig->baseUrl; } - protected function resolveOauth2Config(): OAuthConfig + protected function defaultOauthConfig(): OAuthConfig { $idUrl = $this->alfaConfig->baseUrl === Environment::PRODUCTION->value ? Environment::ID_PRODUCTION->value