Compare commits

...

2 Commits

Author SHA1 Message Date
ca3f14485a feat: Add optional redirectUri and keyNameAlias parameters with null defaults
- Make keyNameAlias parameter optional in SbpConnector with null default
- Add redirectUri parameter to AlfaBankServiceProvider configuration
- Make keyNameAlias optional in service provider with null coalescing operator
- Add conditional check for caBundlePath to allow disabling SSL verification

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-01-26 15:48:22 +03:00
86f50eed6a 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 <qwen-coder@alibabacloud.com>
2026-01-26 15:36:42 +03:00
4 changed files with 19 additions and 15 deletions

View File

@@ -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";

View File

@@ -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
@@ -67,7 +65,7 @@ class AlfaBankConnector extends Connector implements HasPagination, OAuth2Api
];
if ($this->alfaConfig->caBundlePath) {
$config['verify'] = $this->alfaConfig->caBundlePath;
$config['verify'] = $this->alfaConfig->caBundlePath === 'false' ? false : $this->alfaConfig->caBundlePath;
}
return $config;

View File

@@ -44,6 +44,7 @@ class AlfaBankServiceProvider extends ServiceProvider
caBundlePath: $conf['ca_bundle'] ?? null,
clientId: $conf['client_id'],
clientSecret: $conf['client_secret'],
redirectUri: $conf['redirect_uri'] ?? null,
signingCertificatePath: $conf['signing_certificate_path'] ?? null,
signingPrivateKeyPath: $conf['signing_private_key_path'] ?? null,
);
@@ -87,7 +88,7 @@ class AlfaBankServiceProvider extends ServiceProvider
$config = $app['config']['alfa-bank.sbp'];
return new SbpConnector(
alfaConfig: $app->make('alfa.sbp.config'),
keyNameAlias: $config['key_name_alias']
keyNameAlias: $config['key_name_alias'] ?? null
);
});
$this->app->alias(SbpConnector::class, 'alfa.sbp');

View File

@@ -27,7 +27,7 @@ class SbpConnector extends Connector implements HasPagination
public function __construct(
protected AlfaConfig $alfaConfig,
protected string $keyNameAlias
protected ?string $keyNameAlias = null
) {
$this->tries = 3;
$this->retryInterval = 500;