forked from apoloz/alfa-bank-sdk
fix(formating)
This commit is contained in:
@@ -9,9 +9,9 @@ namespace Apoloz\AlfaBank;
|
||||
use Apoloz\AlfaBank\Core\AlfaBankConnector;
|
||||
use Apoloz\AlfaBank\Core\AlfaConfig;
|
||||
use Apoloz\AlfaBank\Enums\Environment;
|
||||
use Apoloz\AlfaBank\Services\OpenSslCmsSigner;
|
||||
use Apoloz\AlfaBank\Sbp\SbpConnector;
|
||||
use Apoloz\AlfaBank\Requests\Accounts\GetAccountsRequest;
|
||||
use Apoloz\AlfaBank\Sbp\SbpConnector;
|
||||
use Apoloz\AlfaBank\Services\OpenSslCmsSigner;
|
||||
|
||||
class AlfaBank
|
||||
{
|
||||
@@ -29,7 +29,8 @@ class AlfaBank
|
||||
): bool {
|
||||
$baas = self::baas($certificatePath, $privateKeyPath, $environment, $caBundlePath);
|
||||
$baas->login($clientId, $clientSecret);
|
||||
$baas->send(new GetAccountsRequest());
|
||||
$baas->send(new GetAccountsRequest);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -76,8 +77,8 @@ class AlfaBank
|
||||
?string $signingCertificatePath = null,
|
||||
?string $signingPrivateKeyPath = null
|
||||
): SbpConnector {
|
||||
$baseUrl = $environment === Environment::PRODUCTION
|
||||
? Environment::SBP_PRODUCTION->value
|
||||
$baseUrl = $environment === Environment::PRODUCTION
|
||||
? Environment::SBP_PRODUCTION->value
|
||||
: Environment::SBP_SANDBOX->value;
|
||||
|
||||
$config = new AlfaConfig(
|
||||
@@ -92,4 +93,4 @@ class AlfaBank
|
||||
return new SbpConnector($config, $keyNameAlias);
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Apoloz\AlfaBank\Core;
|
||||
// <SECTION name="module_imports" intent="Import necessary contracts, services, and base framework components for the connector's operation.">
|
||||
// <BELIEF_STATE "Saloon's plugin architecture requires importing traits for features like retries and timeouts. Local contracts (SignerInterface) are imported for dependency injection.">
|
||||
use Apoloz\AlfaBank\Contracts\SignerInterface;
|
||||
use Apoloz\AlfaBank\Enums\Environment;
|
||||
use Apoloz\AlfaBank\Http\Middleware\RequestIdMiddleware;
|
||||
use Apoloz\AlfaBank\Http\Pagination\AlfaOffsetPaginator;
|
||||
use Apoloz\AlfaBank\Traits\HasAlfaErrorHandling;
|
||||
@@ -15,19 +16,18 @@ use Saloon\Http\Connector;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\PaginationPlugin\Contracts\HasPagination;
|
||||
use Saloon\PaginationPlugin\OffsetPaginator;
|
||||
use Saloon\Traits\Plugins\AlwaysThrowOnErrors;
|
||||
use Saloon\Traits\RequestProperties\HasTries;
|
||||
use Saloon\Traits\Plugins\HasTimeout;
|
||||
use Saloon\Traits\OAuth2\AuthorizationCodeGrant;
|
||||
use Apoloz\AlfaBank\Enums\Environment;
|
||||
use Saloon\Traits\Plugins\AlwaysThrowOnErrors;
|
||||
use Saloon\Traits\Plugins\HasTimeout;
|
||||
use Saloon\Traits\RequestProperties\HasTries;
|
||||
|
||||
class AlfaBankConnector extends Connector implements HasPagination
|
||||
{
|
||||
use AlwaysThrowOnErrors;
|
||||
use AuthorizationCodeGrant;
|
||||
use HasAlfaErrorHandling;
|
||||
use HasTimeout;
|
||||
use HasTries;
|
||||
use AlwaysThrowOnErrors;
|
||||
use HasAlfaErrorHandling;
|
||||
use AuthorizationCodeGrant;
|
||||
|
||||
public function __construct(
|
||||
protected AlfaConfig $alfaConfig,
|
||||
@@ -42,6 +42,79 @@ class AlfaBankConnector extends Connector implements HasPagination
|
||||
return $this->alfaConfig->baseUrl;
|
||||
}
|
||||
|
||||
public function boot(\Saloon\Http\PendingRequest $pendingRequest): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function paginate(Request $request): OffsetPaginator
|
||||
{
|
||||
return new AlfaOffsetPaginator($this, $request);
|
||||
}
|
||||
|
||||
// login() kept for ClientCredentials compatibility (legacy/simple flow)
|
||||
public function login(?string $clientId = null, ?string $clientSecret = null, array $scopes = []): static
|
||||
{
|
||||
$oauthConfig = $this->oauthConfig();
|
||||
|
||||
// Allow overriding credentials via method arguments
|
||||
if ($clientId) {
|
||||
$oauthConfig->setClientId($clientId);
|
||||
}
|
||||
if ($clientSecret) {
|
||||
$oauthConfig->setClientSecret($clientSecret);
|
||||
}
|
||||
|
||||
if (empty($oauthConfig->getClientId()) || empty($oauthConfig->getClientSecret())) {
|
||||
throw new \RuntimeException('Client ID/Secret not configured.');
|
||||
}
|
||||
|
||||
$request = new \Saloon\Http\OAuth2\GetClientCredentialsTokenRequest($oauthConfig, $scopes);
|
||||
|
||||
$response = $this->send($request);
|
||||
|
||||
// Use the trait's helper to parse the token
|
||||
$authenticator = $this->createOAuthAuthenticatorFromResponse($response);
|
||||
|
||||
$this->authenticate($authenticator);
|
||||
|
||||
return $this;
|
||||
}
|
||||
// </SECTION>
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="signer_accessor" intent="Provide access to the configured signing service for requests that require a digital signature.">
|
||||
// <BELIEF_STATE "Requests should not instantiate their own signing logic. The connector acts as a service locator, providing the globally-configured Signer service. This ensures that all signatures are generated consistently.">
|
||||
public function getSigner(): SignerInterface
|
||||
{
|
||||
if (! $this->signer) {
|
||||
throw new \RuntimeException('No signer configured for this connector.');
|
||||
}
|
||||
|
||||
return $this->signer;
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="logging_mutator" intent="Allow attaching a PSR-3 logger to the connector for debugging.">
|
||||
// <BELIEF_STATE "Logging should be an optional, opt-in feature. This method provides a fluent interface to attach a logging middleware, which will automatically sanitize sensitive data before output.">
|
||||
public function withLogging(\Psr\Log\LoggerInterface $logger): static
|
||||
{
|
||||
$this->middleware()->onRequest(new \Apoloz\AlfaBank\Http\Middleware\LoggingRequestMiddleware($logger));
|
||||
$this->middleware()->onResponse(new \Apoloz\AlfaBank\Http\Middleware\LoggingResponseMiddleware($logger));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable automated JWS response verification and decoding.
|
||||
*/
|
||||
public function withJwsVerification(string $publicKeyPem): static
|
||||
{
|
||||
$this->middleware()->onResponse(new \Apoloz\AlfaBank\Http\Middleware\VerifyJwsResponseMiddleware($publicKeyPem));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function defaultOauthConfig(): OAuthConfig
|
||||
{
|
||||
$idUrl = $this->alfaConfig->baseUrl === Environment::PRODUCTION->value
|
||||
@@ -83,80 +156,8 @@ class AlfaBankConnector extends Connector implements HasPagination
|
||||
protected function defaultMiddleware(): array
|
||||
{
|
||||
return [
|
||||
new RequestIdMiddleware(),
|
||||
new RequestIdMiddleware,
|
||||
];
|
||||
}
|
||||
|
||||
public function boot(\Saloon\Http\PendingRequest $pendingRequest): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function paginate(Request $request): OffsetPaginator
|
||||
{
|
||||
return new AlfaOffsetPaginator($this, $request);
|
||||
}
|
||||
|
||||
// login() kept for ClientCredentials compatibility (legacy/simple flow)
|
||||
public function login(?string $clientId = null, ?string $clientSecret = null, array $scopes = []): static
|
||||
{
|
||||
$oauthConfig = $this->oauthConfig();
|
||||
|
||||
// Allow overriding credentials via method arguments
|
||||
if ($clientId) {
|
||||
$oauthConfig->setClientId($clientId);
|
||||
}
|
||||
if ($clientSecret) {
|
||||
$oauthConfig->setClientSecret($clientSecret);
|
||||
}
|
||||
|
||||
if (empty($oauthConfig->getClientId()) || empty($oauthConfig->getClientSecret())) {
|
||||
throw new \RuntimeException("Client ID/Secret not configured.");
|
||||
}
|
||||
|
||||
$request = new \Saloon\Http\OAuth2\GetClientCredentialsTokenRequest($oauthConfig, $scopes);
|
||||
|
||||
$response = $this->send($request);
|
||||
|
||||
// Use the trait's helper to parse the token
|
||||
$authenticator = $this->createOAuthAuthenticatorFromResponse($response);
|
||||
|
||||
$this->authenticate($authenticator);
|
||||
|
||||
return $this;
|
||||
}
|
||||
// </SECTION>
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="signer_accessor" intent="Provide access to the configured signing service for requests that require a digital signature.">
|
||||
// <BELIEF_STATE "Requests should not instantiate their own signing logic. The connector acts as a service locator, providing the globally-configured Signer service. This ensures that all signatures are generated consistently.">
|
||||
public function getSigner(): SignerInterface
|
||||
{
|
||||
if (!$this->signer) {
|
||||
throw new \RuntimeException("No signer configured for this connector.");
|
||||
}
|
||||
return $this->signer;
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="logging_mutator" intent="Allow attaching a PSR-3 logger to the connector for debugging.">
|
||||
// <BELIEF_STATE "Logging should be an optional, opt-in feature. This method provides a fluent interface to attach a logging middleware, which will automatically sanitize sensitive data before output.">
|
||||
public function withLogging(\Psr\Log\LoggerInterface $logger): static
|
||||
{
|
||||
$this->middleware()->onRequest(new \Apoloz\AlfaBank\Http\Middleware\LoggingRequestMiddleware($logger));
|
||||
$this->middleware()->onResponse(new \Apoloz\AlfaBank\Http\Middleware\LoggingResponseMiddleware($logger));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable automated JWS response verification and decoding.
|
||||
*/
|
||||
public function withJwsVerification(string $publicKeyPem): static
|
||||
{
|
||||
$this->middleware()->onResponse(new \Apoloz\AlfaBank\Http\Middleware\VerifyJwsResponseMiddleware($publicKeyPem));
|
||||
|
||||
return $this;
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,17 +41,17 @@ readonly class AlfaConfig
|
||||
public ?string $signingPrivateKeyPath = null,
|
||||
) {
|
||||
// <BELIEF_STATE "This runtime check ensures that the provided certificate and key paths are not just valid strings, but point to actual, accessible files on the filesystem. This prevents configuration errors that would otherwise only surface during an HTTP request.">
|
||||
if (!file_exists($this->certificatePath)) {
|
||||
if (! file_exists($this->certificatePath)) {
|
||||
throw new \InvalidArgumentException("Certificate not found: {$this->certificatePath}");
|
||||
}
|
||||
if (!file_exists($this->privateKeyPath)) {
|
||||
if (! file_exists($this->privateKeyPath)) {
|
||||
throw new \InvalidArgumentException("Private key not found: {$this->privateKeyPath}");
|
||||
}
|
||||
if ($this->signingCertificatePath && !file_exists($this->signingCertificatePath)) {
|
||||
throw new \InvalidArgumentException("Signing certificate not found: {$this->signingCertificatePath}");
|
||||
if ($this->signingCertificatePath && ! file_exists($this->signingCertificatePath)) {
|
||||
throw new \InvalidArgumentException("Signing certificate not found: {$this->signingCertificatePath}");
|
||||
}
|
||||
if ($this->signingPrivateKeyPath && !file_exists($this->signingPrivateKeyPath)) {
|
||||
throw new \InvalidArgumentException("Signing private key not found: {$this->signingPrivateKeyPath}");
|
||||
if ($this->signingPrivateKeyPath && ! file_exists($this->signingPrivateKeyPath)) {
|
||||
throw new \InvalidArgumentException("Signing private key not found: {$this->signingPrivateKeyPath}");
|
||||
}
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
@@ -13,6 +13,6 @@ class AccountData extends Data
|
||||
public string $openDate,
|
||||
public string $type,
|
||||
public ?string $mnemonic = null,
|
||||
public ?array $balance = null,
|
||||
public ?array $balance = null,
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\Auth;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for OAuth 2.0 token responses.">
|
||||
|
||||
@@ -17,6 +17,7 @@ use Apoloz\AlfaBank\Data\PaginationData;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for a collection of client consents.">
|
||||
|
||||
@@ -14,9 +14,10 @@ namespace Apoloz\AlfaBank\Data\Auth\UserInfo;
|
||||
// <SECTION name="module_imports" intent="Import necessary DTOs and Spatie Laravel Data components.">
|
||||
// <BELIEF_STATE "This DTO represents a single consent entry. The `PaginationData` import here is likely due to prior usage or template, but not directly used within this single DTO.">
|
||||
use Apoloz\AlfaBank\Data\PaginationData; // This import is likely extraneous for a single DTO, but kept for context consistency.
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf; // This is also likely extraneous for a single DTO.
|
||||
// This is also likely extraneous for a single DTO.
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection; // This is also likely extraneous for a single DTO.
|
||||
|
||||
// This is also likely extraneous for a single DTO.
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for a single client consent.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\Auth\UserInfo;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for OpenID Connect UserInfo claims.">
|
||||
|
||||
@@ -4,9 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Apoloz\AlfaBank\Data\B2C;
|
||||
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
class B2CPaymentResponseData extends Data
|
||||
{
|
||||
|
||||
@@ -14,4 +14,4 @@ class CertificateData extends Data
|
||||
public string $status,
|
||||
public ?string $thumbprint = null,
|
||||
) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Apoloz\AlfaBank\Data\FileExchange;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for file download response data.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\FileExchange;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for file link details.">
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Apoloz\AlfaBank\Data\FileExchange;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for file upload response data.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for address details.">
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for a beneficiary's balance details.">
|
||||
|
||||
@@ -17,6 +17,7 @@ use Apoloz\AlfaBank\Data\PaginationData;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define the paginated collection for beneficiary transactions.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie\LaravelData class.">
|
||||
// <BELIEF_STATE "This class extends `Spatie\LaravelData\Data` to leverage its robust data mapping and type safety, ensuring consistent and predictable handling of individual transaction payloads.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define the beneficiary transaction data structure.">
|
||||
|
||||
@@ -20,6 +20,7 @@ use Spatie\LaravelData\Attributes\Validation\Email;
|
||||
use Spatie\LaravelData\Attributes\Validation\Numeric;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for creating a new beneficiary.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for the response of creating a beneficiary.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for an identification document.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for personal identification details.">
|
||||
|
||||
@@ -18,6 +18,7 @@ use Apoloz\AlfaBank\Traits\SignableData;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for creating a new requisite.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries\Requisites;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for a single payment requisite.">
|
||||
|
||||
@@ -16,9 +16,9 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries\Requisites;
|
||||
use Apoloz\AlfaBank\Data\NominalAccounts\Payouts\DigestSignatureData;
|
||||
use Apoloz\AlfaBank\Traits\SignableData;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Attributes\Validation\Numeric;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for updating an existing requisite.">
|
||||
|
||||
@@ -20,6 +20,7 @@ use Spatie\LaravelData\Attributes\Validation\Email;
|
||||
use Spatie\LaravelData\Attributes\Validation\Numeric;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for updating an existing beneficiary.">
|
||||
@@ -39,3 +40,23 @@ class UpdateBeneficiaryRequestData extends Data
|
||||
public ?DataCollection $addresses = null,
|
||||
public ?string $accountNumber = null,
|
||||
public ?bool $taxResidentUS = null,
|
||||
public ?bool $foreignTaxResident = null,
|
||||
public ?bool $financialActivities = null,
|
||||
public ?string $name = null,
|
||||
public ?string $registrationDate = null,
|
||||
#[Numeric]
|
||||
public ?string $inn = null,
|
||||
#[Numeric]
|
||||
public ?string $kpp = null,
|
||||
#[Numeric]
|
||||
public ?string $ogrn = null,
|
||||
public ?PersonalInformationData $personalInformation = null,
|
||||
public ?string $phoneNumber = null,
|
||||
#[Email]
|
||||
public ?string $email = null,
|
||||
#[DataCollectionOf(DocumentData::class)]
|
||||
public ?DataCollection $documents = null,
|
||||
) {}
|
||||
// </SECTION>
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for a specific wallet's balance.">
|
||||
|
||||
@@ -17,6 +17,7 @@ use Apoloz\AlfaBank\Data\PaginationData;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for a collection of beneficiaries.">
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts;
|
||||
use Apoloz\AlfaBank\Data\PaginationData; // This import might be misleading for a single DTO, but kept for context consistency.
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for a single beneficiary's details.">
|
||||
@@ -45,4 +45,4 @@ class BeneficiaryData extends Data
|
||||
public ?bool $isVpr = null,
|
||||
) {}
|
||||
// </SECTION>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for the status of a counterparty request.">
|
||||
|
||||
@@ -17,6 +17,7 @@ use Apoloz\AlfaBank\Data\PaginationData;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for a collection of deals.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Deals;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for a single deal's details.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Deals;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for a payoff associated with a deal.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Deals;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for the status of a deal request.">
|
||||
|
||||
@@ -18,6 +18,7 @@ use Apoloz\AlfaBank\Traits\SignableData;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for performing an action on a deal contractor.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Deals\Steps;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for an amount allocated to a contractor's wallet.">
|
||||
|
||||
@@ -18,6 +18,7 @@ use Apoloz\AlfaBank\Traits\SignableData;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for performing an action on a deal step.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Deals\Steps;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for the response of a step action request.">
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Deals\Steps;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for a contractor in a deal step.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Deals\Steps;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for a single deal step.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Deals;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for the response of a deal validation.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Identification;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for distributing amounts to beneficiaries.">
|
||||
|
||||
@@ -18,6 +18,7 @@ use Apoloz\AlfaBank\Traits\SignableData;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for identifying a transaction.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Identification;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for the response of an identification request.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Identification;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for payer details.">
|
||||
|
||||
@@ -18,6 +18,7 @@ use Apoloz\AlfaBank\Traits\SignableData;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for refunding an unidentified transaction.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Identification;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for the response of a refund request.">
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Identification;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for a collection of unidentified transactions.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Identification;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for an unidentified transaction.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for a nominal account.">
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Payouts;
|
||||
use Apoloz\AlfaBank\Data\Shared\PayerInfoData;
|
||||
use Apoloz\AlfaBank\Data\Shared\RecipientInfoData;
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for detailed payoff records.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Payouts;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for cryptographic digest signatures.">
|
||||
|
||||
@@ -21,6 +21,7 @@ use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Attributes\Validation\Numeric;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for creating a new payoff request.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Payouts;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for the response of a payoff request.">
|
||||
@@ -28,4 +29,4 @@ class PayoffResponseData extends Data
|
||||
public ?string $description = null,
|
||||
) {}
|
||||
// </SECTION>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Payouts;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for payout requisite details.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Payouts;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for recipient details.">
|
||||
|
||||
@@ -14,10 +14,10 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Payouts;
|
||||
// <SECTION name="module_imports" intent="Import necessary classes for cryptographic signatures, data collection, and Laravel Data.">
|
||||
// <BELIEF_STATE "These imports are essential for constructing a secure and structured tax refund request. `DigestSignatureData` ensures the integrity and authenticity of the request, `DataCollectionOf` and `DataCollection` facilitate handling multiple signatures, and `Data` provides the foundational capabilities for data object mapping and validation.">
|
||||
use Apoloz\AlfaBank\Traits\SignableData;
|
||||
use Apoloz\AlfaBank\Data\NominalAccounts\Payouts\DigestSignatureData;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define the tax refund request data structure.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\Payouts;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie\LaravelData class.">
|
||||
// <BELIEF_STATE "This class extends `Spatie\LaravelData\Data` to leverage its robust data mapping and type safety, ensuring consistent and predictable handling of tax refund response payloads.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define the tax refund response data structure.">
|
||||
|
||||
@@ -16,9 +16,9 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\UniversalRecipients;
|
||||
use Apoloz\AlfaBank\Data\NominalAccounts\Payouts\DigestSignatureData;
|
||||
use Apoloz\AlfaBank\Traits\SignableData;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Attributes\Validation\Numeric;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for creating a universal recipient.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\UniversalRecipients;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for a single universal recipient's details.">
|
||||
|
||||
@@ -14,7 +14,8 @@ namespace Apoloz\AlfaBank\Data\NominalAccounts\UniversalRecipients;
|
||||
// <SECTION name="module_imports" intent="Import the base response DTO.">
|
||||
// <BELIEF_STATE "This DTO reuses `CreateBeneficiaryResponseData` as its base, indicating that the response structure for creating universal recipients is identical to that for beneficiaries. This promotes consistency and reduces code duplication.">
|
||||
use Apoloz\AlfaBank\Data\NominalAccounts\Beneficiaries\CreateBeneficiaryResponseData;
|
||||
use Spatie\LaravelData\Data; // Included for clarity, though inherited from base DTO.
|
||||
|
||||
// Included for clarity, though inherited from base DTO.
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for the response of creating a universal recipient.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for pagination metadata.">
|
||||
|
||||
@@ -17,59 +17,59 @@ class PaymentData extends Data
|
||||
public function __construct(
|
||||
#[MapOutputName('Amount')]
|
||||
public float $amount,
|
||||
|
||||
|
||||
#[MapOutputName('DocDate')]
|
||||
public string $date,
|
||||
|
||||
|
||||
#[MapOutputName('DocNo')]
|
||||
public string $externalId,
|
||||
|
||||
|
||||
#[MapOutputName('OperationCode')]
|
||||
public string $operationCode,
|
||||
|
||||
|
||||
#[MapOutputName('PayeeAccount')]
|
||||
public string $payeeAccount,
|
||||
|
||||
|
||||
#[MapOutputName('PayeeBankBic'), Numeric, Size(9)]
|
||||
public string $payeeBankBic,
|
||||
|
||||
|
||||
#[MapOutputName('PayeeName')]
|
||||
public string $payeeName,
|
||||
|
||||
|
||||
#[MapOutputName('PayerAccount')]
|
||||
public string $payerAccount,
|
||||
|
||||
|
||||
#[MapOutputName('PayerBankBic'), Numeric, Size(9)]
|
||||
public string $payerBankBic,
|
||||
|
||||
|
||||
#[MapOutputName('PayerBankCorrAccount')]
|
||||
public string $payerBankCorrAccount,
|
||||
|
||||
|
||||
#[MapOutputName('PayerInn'), Numeric]
|
||||
public string $payerInn,
|
||||
|
||||
|
||||
#[MapOutputName('PayerName')]
|
||||
public string $payerName,
|
||||
|
||||
|
||||
#[MapOutputName('Priority')]
|
||||
public string $priority,
|
||||
|
||||
|
||||
#[MapOutputName('Purpose')]
|
||||
public string $purpose,
|
||||
|
||||
|
||||
#[MapOutputName('Number')]
|
||||
public ?string $number = null,
|
||||
|
||||
|
||||
#[MapOutputName('PayeeKpp')]
|
||||
public ?string $payeeKpp = null,
|
||||
|
||||
|
||||
#[MapOutputName('PayeeBankCorrAccount')]
|
||||
public ?string $payeeBankCorrAccount = null,
|
||||
|
||||
|
||||
#[MapOutputName('PaymentType')]
|
||||
public ?string $paymentType = null,
|
||||
|
||||
|
||||
#[MapOutputName('DigestSignatures'), DataCollectionOf(DigestSignatureData::class)]
|
||||
public ?DataCollection $digestSignatures = null,
|
||||
) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ use Apoloz\AlfaBank\Traits\SignableData;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for creating a sandbox RUB payment.">
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Apoloz\AlfaBank\Data\Shared;
|
||||
use Spatie\LaravelData\Attributes\Validation\Numeric;
|
||||
use Spatie\LaravelData\Attributes\Validation\Size;
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for payer information.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\Statement;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for monetary amount data.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\Statement;
|
||||
// <SECTION name="module_imports" intent="Import the base Spatie Laravel Data class.">
|
||||
// <BELIEF_STATE "Extending `Spatie\LaravelData\Data` enables automatic casting from JSON and provides other DTO benefits.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for Russian Ruble transfer details.">
|
||||
|
||||
@@ -17,6 +17,7 @@ use Apoloz\AlfaBank\Data\PaginationData;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for a collection of account transactions.">
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Data\Statement;
|
||||
// <SECTION name="module_imports" intent="Import necessary DTOs and Spatie Laravel Data components.">
|
||||
// <BELIEF_STATE "This DTO includes nested `AmountData` for monetary values and `RurTransferData` for detailed transfer information.">
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a DTO for a single account transaction.">
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace Apoloz\AlfaBank\Data;
|
||||
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
class WebhookCollectionData extends Data
|
||||
|
||||
@@ -20,4 +20,4 @@ class BaasWebhookData extends BaseWebhookData
|
||||
organizationId: $organizationId
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,4 +14,4 @@ class BaseWebhookData extends Data
|
||||
public ?string $eventTime = null,
|
||||
public ?string $organizationId = null,
|
||||
) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,4 +20,4 @@ class SbpWebhookData extends BaseWebhookData
|
||||
organizationId: $organizationId
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Apoloz\AlfaBank\Exceptions;
|
||||
// <SECTION name="module_imports" intent="Import the base Saloon Response class.">
|
||||
// <BELIEF_STATE "The custom exception needs to hold the original Saloon `Response` object to give developers full access to the raw HTTP response for debugging purposes.">
|
||||
use Saloon\Http\Response;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a custom exception that extends PHP's base Exception class.">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
// MODULE_CONTRACT: Provides a Saloon middleware to standardize error handling for Alfa Bank API responses.
|
||||
// RESPONSIBILITY: To intercept API responses, identify various error formats (BaaS, SBP, or generic HTTP), and throw a consistent `AlfaBankException`, thereby centralizing error reporting and simplifying error management in the SDK.
|
||||
@@ -13,6 +14,7 @@ namespace Apoloz\AlfaBank\Http\Middleware;
|
||||
// <BELIEF_STATE "These imports are crucial for the middleware's functionality. `AlfaBankException` provides a standardized way to signal API errors within the SDK, while `Response` from Saloon is the object that the middleware processes.">
|
||||
use Apoloz\AlfaBank\Exceptions\AlfaBankException;
|
||||
use Saloon\Http\Response;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define the Alfa Bank API response error handling middleware.">
|
||||
@@ -24,7 +26,7 @@ class AlfaResponseMiddleware
|
||||
public function __invoke(Response $response): void
|
||||
{
|
||||
$contentType = $response->header('Content-Type') ?? '';
|
||||
|
||||
|
||||
if (str_contains($contentType, 'application/json')) {
|
||||
$data = $response->json();
|
||||
|
||||
@@ -38,10 +40,10 @@ class AlfaResponseMiddleware
|
||||
}
|
||||
|
||||
// 2. Handle SBP specific errors
|
||||
if (isset($data['ErrorCode']) && (string)$data['ErrorCode'] !== '0') {
|
||||
if (isset($data['ErrorCode']) && (string) $data['ErrorCode'] !== '0') {
|
||||
throw new AlfaBankException(
|
||||
$response,
|
||||
(string)$data['ErrorCode'],
|
||||
(string) $data['ErrorCode'],
|
||||
$data['message'] ?? 'No message'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ class LoggingMiddleware implements RequestMiddleware, ResponseMiddleware
|
||||
if (isset($headers['Authorization'])) {
|
||||
$headers['Authorization'] = 'Bearer *****';
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
// </SECTION>
|
||||
@@ -53,7 +54,9 @@ class LoggingMiddleware implements RequestMiddleware, ResponseMiddleware
|
||||
// <BELIEF_STATE "This protected recursive helper method inspects the request or response body for predefined sensitive keys (e.g., `pan`, `client_secret`). If a sensitive key is found, its value is replaced with a mask. The method recursively processes nested arrays, ensuring that sensitive data is masked even within complex JSON structures, thereby enhancing log security.">
|
||||
protected function maskBody(mixed $body): mixed
|
||||
{
|
||||
if (!is_array($body)) return $body;
|
||||
if (! is_array($body)) {
|
||||
return $body;
|
||||
}
|
||||
|
||||
$sensitiveKeys = ['pan', 'cvc', 'digestSignatures', 'client_secret', 'refresh_token', 'access_token'];
|
||||
|
||||
@@ -64,6 +67,7 @@ class LoggingMiddleware implements RequestMiddleware, ResponseMiddleware
|
||||
$body[$key] = $this->maskBody($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
@@ -25,12 +25,15 @@ class LoggingRequestMiddleware implements RequestMiddleware
|
||||
if (isset($headers['Authorization'])) {
|
||||
$headers['Authorization'] = 'Bearer *****';
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
protected function maskBody(mixed $body): mixed
|
||||
{
|
||||
if (!is_array($body)) return $body;
|
||||
if (! is_array($body)) {
|
||||
return $body;
|
||||
}
|
||||
|
||||
$sensitiveKeys = ['pan', 'cvc', 'digestSignatures', 'client_secret', 'refresh_token', 'access_token'];
|
||||
|
||||
@@ -41,6 +44,7 @@ class LoggingRequestMiddleware implements RequestMiddleware
|
||||
$body[$key] = $this->maskBody($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ class LoggingResponseMiddleware implements ResponseMiddleware
|
||||
|
||||
protected function maskBody(mixed $body): mixed
|
||||
{
|
||||
if (!is_array($body)) return $body;
|
||||
if (! is_array($body)) {
|
||||
return $body;
|
||||
}
|
||||
|
||||
$sensitiveKeys = ['pan', 'cvc', 'digestSignatures', 'client_secret', 'refresh_token', 'access_token'];
|
||||
|
||||
@@ -32,6 +34,7 @@ class LoggingResponseMiddleware implements ResponseMiddleware
|
||||
$body[$key] = $this->maskBody($value);
|
||||
}
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class RequestIdMiddleware implements RequestMiddleware
|
||||
{
|
||||
public function __invoke(PendingRequest $pendingRequest): void
|
||||
{
|
||||
if (!$pendingRequest->headers()->get('X-Request-ID')) {
|
||||
if (! $pendingRequest->headers()->get('X-Request-ID')) {
|
||||
$pendingRequest->headers()->add('X-Request-ID', Uuid::v4());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ class VerifyJwsResponseMiddleware
|
||||
{
|
||||
$contentType = $response->header('Content-Type');
|
||||
|
||||
if (str_contains((string)$contentType, 'application/jose')) {
|
||||
if (!$this->publicKey) {
|
||||
if (str_contains((string) $contentType, 'application/jose')) {
|
||||
if (! $this->publicKey) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
@@ -26,12 +26,12 @@ class VerifyJwsResponseMiddleware
|
||||
$decoded = JwsSigner::verify($jws, $this->publicKey);
|
||||
|
||||
if ($decoded) {
|
||||
// In Saloon v3, we can't easily "fake" an existing response object in a type-safe way
|
||||
// In Saloon v3, we can't easily "fake" an existing response object in a type-safe way
|
||||
// without internal access. We will wrap the data and the user should use $response->json().
|
||||
// However, for the sake of PHPStan and clean architecture, we should use the response's
|
||||
// internal body repository if we really need to overwrite it, or better -
|
||||
// However, for the sake of PHPStan and clean architecture, we should use the response's
|
||||
// internal body repository if we really need to overwrite it, or better -
|
||||
// let the user handle the decoded data from a custom DTO.
|
||||
// To fix the immediate error, we'll return the response as is,
|
||||
// To fix the immediate error, we'll return the response as is,
|
||||
// but JWS verification is still performed.
|
||||
return $response;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class AlfaOffsetPaginator extends OffsetPaginator
|
||||
protected function isLastPage(Response $response): bool
|
||||
{
|
||||
$items = $this->getPageItems($response, $this->request);
|
||||
|
||||
|
||||
return count($items) < $this->perPageLimit;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class AlfaOffsetPaginator extends OffsetPaginator
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// Fallback to raw json if DTO fails
|
||||
echo "DTO Error: " . $e->getMessage() . "\n";
|
||||
echo 'DTO Error: ' . $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,13 +52,21 @@ class AlfaOffsetPaginator extends OffsetPaginator
|
||||
$json = $response->json();
|
||||
|
||||
// Common keys in Alfa API
|
||||
if (isset($json['transactions'])) return $json['transactions'];
|
||||
if (isset($json['payments'])) return $json['payments'];
|
||||
if (isset($json['accounts'])) return $json['accounts'];
|
||||
|
||||
if (isset($json['transactions'])) {
|
||||
return $json['transactions'];
|
||||
}
|
||||
if (isset($json['payments'])) {
|
||||
return $json['payments'];
|
||||
}
|
||||
if (isset($json['accounts'])) {
|
||||
return $json['accounts'];
|
||||
}
|
||||
|
||||
// If it's a direct array (some endpoints)
|
||||
if (array_is_list($json)) return $json;
|
||||
if (array_is_list($json)) {
|
||||
return $json;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,14 @@ use Apoloz\AlfaBank\Contracts\SignerInterface;
|
||||
use Apoloz\AlfaBank\Core\AlfaBankConnector;
|
||||
use Apoloz\AlfaBank\Core\AlfaConfig;
|
||||
use Apoloz\AlfaBank\Enums\Environment;
|
||||
use Apoloz\AlfaBank\Laravel\Http\Controllers\AlfaWebhookController;
|
||||
use Apoloz\AlfaBank\Laravel\Middleware\VerifyAlfaWebhook;
|
||||
use Apoloz\AlfaBank\Sbp\SbpConnector;
|
||||
use Apoloz\AlfaBank\Services\OpenSslCmsSigner;
|
||||
use Apoloz\AlfaBank\Services\PhpseclibCardEncryptor;
|
||||
use Apoloz\AlfaBank\Sbp\SbpConnector;
|
||||
use Apoloz\AlfaBank\Laravel\Middleware\VerifyAlfaWebhook;
|
||||
use Apoloz\AlfaBank\Laravel\Http\Controllers\AlfaWebhookController;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
class AlfaBankServiceProvider extends ServiceProvider
|
||||
@@ -37,6 +38,7 @@ class AlfaBankServiceProvider extends ServiceProvider
|
||||
|
||||
$this->app->singleton('alfa.baas.config', function ($app) {
|
||||
$conf = $app['config']['alfa-bank.baas'];
|
||||
|
||||
return new AlfaConfig(
|
||||
baseUrl: $conf['environment'] === 'production' ? Environment::PRODUCTION->value : Environment::SANDBOX->value,
|
||||
certificatePath: $conf['certificate_path'],
|
||||
@@ -55,13 +57,14 @@ class AlfaBankServiceProvider extends ServiceProvider
|
||||
$config = $app->make('alfa.baas.config');
|
||||
$cert = $config->signingCertificatePath ?: $config->certificatePath;
|
||||
$key = $config->signingPrivateKeyPath ?: $config->privateKeyPath;
|
||||
|
||||
|
||||
return new OpenSslCmsSigner($cert, $key);
|
||||
});
|
||||
|
||||
|
||||
$this->app->bind(EncryptorInterface::class, function ($app) {
|
||||
$key = $app['config']['alfa-bank.encryption.card_public_key'] ?? '';
|
||||
return new PhpseclibCardEncryptor($key);
|
||||
|
||||
return new PhpseclibCardEncryptor($key);
|
||||
});
|
||||
|
||||
$this->app->singleton(AlfaBankConnector::class, function ($app) {
|
||||
@@ -74,6 +77,7 @@ class AlfaBankServiceProvider extends ServiceProvider
|
||||
|
||||
$this->app->singleton('alfa.sbp.config', function ($app) {
|
||||
$conf = $app['config']['alfa-bank.sbp'];
|
||||
|
||||
return new AlfaConfig(
|
||||
baseUrl: $conf['environment'] === 'production' ? Environment::SBP_PRODUCTION->value : Environment::SBP_SANDBOX->value,
|
||||
certificatePath: $conf['certificate_path'],
|
||||
@@ -86,6 +90,7 @@ class AlfaBankServiceProvider extends ServiceProvider
|
||||
|
||||
$this->app->singleton(SbpConnector::class, function ($app) {
|
||||
$config = $app['config']['alfa-bank.sbp'];
|
||||
|
||||
return new SbpConnector(
|
||||
alfaConfig: $app->make('alfa.sbp.config'),
|
||||
keyNameAlias: $config['key_name_alias'] ?? null
|
||||
@@ -112,7 +117,7 @@ class AlfaBankServiceProvider extends ServiceProvider
|
||||
if ($this->app->bound('router')) {
|
||||
$router = $this->app->make('router');
|
||||
$router->aliasMiddleware('alfa.webhook', VerifyAlfaWebhook::class);
|
||||
|
||||
|
||||
Route::macro('alfaWebhooks', function (string $url) {
|
||||
return Route::post($url, AlfaWebhookController::class)
|
||||
->name('alfa.webhooks')
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace Apoloz\AlfaBank\Laravel\Commands;
|
||||
use Apoloz\AlfaBank\Core\AlfaBankConnector;
|
||||
use Apoloz\AlfaBank\Sbp\SbpConnector;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define the Alfa Bank SDK connection check Artisan command.">
|
||||
@@ -25,6 +26,7 @@ class CheckConnectionCommand extends Command
|
||||
// <SECTION name="command_signature_and_description" intent="Define the command's name and description.">
|
||||
// <BELIEF_STATE "The `$signature` property (`alfa:check`) makes the command executable via Artisan. The `$description` provides a clear summary of the command's purpose, aiding in user understanding when viewing `php artisan list`.">
|
||||
protected $signature = 'alfa:check';
|
||||
|
||||
protected $description = 'Verify Alfa Bank SDK configuration and mTLS certificates';
|
||||
// </SECTION>
|
||||
|
||||
@@ -50,61 +52,68 @@ class CheckConnectionCommand extends Command
|
||||
$keyPath = (string) config("{$configKey}.private_key_path");
|
||||
|
||||
// 1. Check Files
|
||||
if (!file_exists($certPath)) {
|
||||
if (! file_exists($certPath)) {
|
||||
$this->error("❌ Certificate not found at: {$certPath}");
|
||||
|
||||
return;
|
||||
} else {
|
||||
$this->comment("✅ Certificate found");
|
||||
$this->comment('✅ Certificate found');
|
||||
}
|
||||
|
||||
if (!file_exists($keyPath)) {
|
||||
if (! file_exists($keyPath)) {
|
||||
$this->error("❌ Private Key not found at: {$keyPath}");
|
||||
|
||||
return;
|
||||
} else {
|
||||
$this->comment("✅ Private Key found");
|
||||
$this->comment('✅ Private Key found');
|
||||
}
|
||||
|
||||
// 2. Validate Cert Expiry
|
||||
$certContent = (string) file_get_contents($certPath);
|
||||
$certInfo = openssl_x509_parse($certContent);
|
||||
|
||||
|
||||
if ($certInfo && isset($certInfo['validTo_time_t'])) {
|
||||
$validTo = new \DateTimeImmutable('@' . $certInfo['validTo_time_t']);
|
||||
$now = new \DateTimeImmutable();
|
||||
$now = new \DateTimeImmutable;
|
||||
if ($validTo < $now) {
|
||||
$this->error("❌ Certificate EXPIRED on: " . $validTo->format('Y-m-d H:i:s'));
|
||||
$this->error('❌ Certificate EXPIRED on: ' . $validTo->format('Y-m-d H:i:s'));
|
||||
} else {
|
||||
$diff = $now->diff($validTo);
|
||||
$days = $diff->days;
|
||||
$this->comment("✅ Certificate valid until: " . $validTo->format('Y-m-d') . " ({$days} days remaining)");
|
||||
$this->comment('✅ Certificate valid until: ' . $validTo->format('Y-m-d') . " ({$days} days remaining)");
|
||||
}
|
||||
} else {
|
||||
$this->warn("⚠️ Could not parse certificate date.");
|
||||
$this->warn('⚠️ Could not parse certificate date.');
|
||||
}
|
||||
|
||||
// 3. Attempt Connection (Ping)
|
||||
$this->comment("Attempting TLS Handshake...");
|
||||
|
||||
$this->comment('Attempting TLS Handshake...');
|
||||
|
||||
try {
|
||||
// We resolve the connector from container to use the config
|
||||
$connector = $name === 'BaaS (Nominal Accounts)'
|
||||
? app(AlfaBankConnector::class)
|
||||
$connector = $name === 'BaaS (Nominal Accounts)'
|
||||
? app(AlfaBankConnector::class)
|
||||
: app(SbpConnector::class);
|
||||
|
||||
// Simple GET to the base URL (or a health endpoint) just to test SSL handshake
|
||||
// We don't need a valid token, we just want to see if we get a 401/403 instead of a connection error
|
||||
$connector->send(new class extends \Saloon\Http\Request {
|
||||
$connector->send(new class extends \Saloon\Http\Request
|
||||
{
|
||||
protected \Saloon\Enums\Method $method = \Saloon\Enums\Method::GET;
|
||||
public function resolveEndpoint(): string { return '/'; }
|
||||
|
||||
public function resolveEndpoint(): string
|
||||
{
|
||||
return '/';
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// If we are here, SSL worked!
|
||||
$this->info("✅ Connection Successful! (Handshake completed)");
|
||||
$this->info('✅ Connection Successful! (Handshake completed)');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Check if it's an SSL error
|
||||
if (str_contains($e->getMessage(), 'certificate') || str_contains($e->getMessage(), 'SSL')) {
|
||||
$this->error("❌ SSL/TLS Error: " . $e->getMessage());
|
||||
$this->error('❌ SSL/TLS Error: ' . $e->getMessage());
|
||||
} else {
|
||||
// Other errors (like 404/401) mean SSL worked but endpoint failed, which is GOOD for this check
|
||||
$this->info("✅ Connection Successful! (Server responded: {$e->getMessage()})");
|
||||
|
||||
@@ -15,4 +15,4 @@ class AlfaWebhookReceived
|
||||
public function __construct(
|
||||
public BaseWebhookData $webhook
|
||||
) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Apoloz\AlfaBank\Laravel\Facades;
|
||||
|
||||
use Apoloz\AlfaBank\Core\AlfaBankConnector;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Apoloz\AlfaBank\Laravel\Facades;
|
||||
|
||||
use Apoloz\AlfaBank\Sbp\SbpConnector;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,7 +33,7 @@ class AlfaWebhookController extends Controller
|
||||
protected function processEvent(array $payload): void
|
||||
{
|
||||
$webhookDto = WebhookFactory::create($payload);
|
||||
|
||||
|
||||
AlfaWebhookReceived::dispatch($webhookDto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,16 +29,16 @@ class VerifyAlfaWebhook
|
||||
$publicKeyPath = config('alfa-bank.webhook.alfa_public_key');
|
||||
if ($publicKeyPath && file_exists($publicKeyPath)) {
|
||||
$signature = $request->header('x-jws-signature') ?: $request->getContent();
|
||||
|
||||
|
||||
// If content is a JWS string (3 parts separated by dot)
|
||||
if (is_string($signature) && count(explode('.', $signature)) === 3) {
|
||||
$publicKey = file_get_contents($publicKeyPath);
|
||||
$verified = \Apoloz\AlfaBank\Utils\JwsSigner::verify($signature, $publicKey);
|
||||
|
||||
if (!$verified) {
|
||||
|
||||
if (! $verified) {
|
||||
return response()->json(['error' => 'Invalid Webhook Signature'], 401);
|
||||
}
|
||||
|
||||
|
||||
// Replace request content with verified payload
|
||||
$request->merge($verified);
|
||||
}
|
||||
|
||||
@@ -31,13 +31,13 @@ class GetAccountsRequest extends Request implements Paginatable
|
||||
return '/api/pp/v1/accounts';
|
||||
}
|
||||
|
||||
protected function defaultQuery(): array
|
||||
{
|
||||
return $this->getPaginationQuery();
|
||||
}
|
||||
|
||||
public function createDtoFromResponse(Response $response): DataCollection
|
||||
{
|
||||
return AccountData::collect($response->json('accounts'), DataCollection::class);
|
||||
}
|
||||
}
|
||||
|
||||
protected function defaultQuery(): array
|
||||
{
|
||||
return $this->getPaginationQuery();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ class CheckComplianceRequest extends Request
|
||||
return '/api/aff/jp/v1/creditors/compliance';
|
||||
}
|
||||
|
||||
public function createDtoFromResponse(Response $response): AffResponseData
|
||||
{
|
||||
return AffResponseData::from($response->json());
|
||||
}
|
||||
|
||||
protected function defaultQuery(): array
|
||||
{
|
||||
return [
|
||||
@@ -30,9 +35,4 @@ class CheckComplianceRequest extends Request
|
||||
'name' => $this->name,
|
||||
];
|
||||
}
|
||||
|
||||
public function createDtoFromResponse(Response $response): AffResponseData
|
||||
{
|
||||
return AffResponseData::from($response->json());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,13 +27,13 @@ class CreateRegisterRequest extends Request implements HasBody
|
||||
return '/api/aff/jp/v1/registers';
|
||||
}
|
||||
|
||||
protected function defaultBody(): array
|
||||
{
|
||||
return $this->data->toArray();
|
||||
}
|
||||
|
||||
public function createDtoFromResponse(Response $response): AffResponseData
|
||||
{
|
||||
return AffResponseData::from($response->json());
|
||||
}
|
||||
}
|
||||
|
||||
protected function defaultBody(): array
|
||||
{
|
||||
return $this->data->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,4 +29,4 @@ class DownloadRegisterDocumentsRequest extends Request
|
||||
'size' => strlen($response->body()),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,4 +26,4 @@ class GetPaymentStatusRequest extends Request
|
||||
{
|
||||
return AffResponseData::from($response->json());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,15 +27,15 @@ class SignRegisterRequest extends Request implements HasBody
|
||||
return '/api/aff/jp/v1/registers/sign';
|
||||
}
|
||||
|
||||
protected function defaultBody(): array
|
||||
{
|
||||
return $this->data->toArray();
|
||||
}
|
||||
|
||||
public function createDtoFromResponse(Response $response): GeneralStatusData
|
||||
{
|
||||
return GeneralStatusData::from([
|
||||
'success' => $response->successful(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function defaultBody(): array
|
||||
{
|
||||
return $this->data->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\Http\Response;
|
||||
use Saloon\Traits\Body\HasFormBody;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a class for the OAuth 2.0 token endpoint request.">
|
||||
@@ -55,6 +56,14 @@ class GetTokenRequest extends Request implements HasBody
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="response_dto_caster" intent="Transform the raw JSON response into a structured TokenData DTO.">
|
||||
// <BELIEF_STATE "Automatically casting the JSON token response into a `TokenData` DTO provides type safety and a clean, object-oriented way to access token properties like `access_token` and `expires_in`.">
|
||||
public function createDtoFromResponse(Response $response): TokenData
|
||||
{
|
||||
return TokenData::from($response->json());
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="request_body_builder" intent="Construct the form-urlencoded body for the token request.">
|
||||
// <BELIEF_STATE "This method builds the request body array. It correctly maps the class properties to the `snake_case` parameter names expected by the OAuth 2.0 standard.">
|
||||
protected function defaultBody(): array
|
||||
@@ -64,7 +73,7 @@ class GetTokenRequest extends Request implements HasBody
|
||||
'client_id' => $this->clientId,
|
||||
'client_secret' => $this->clientSecret,
|
||||
];
|
||||
|
||||
|
||||
if ($this->grantType === 'authorization_code') {
|
||||
$body['code'] = $this->code;
|
||||
$body['redirect_uri'] = $this->redirectUri;
|
||||
@@ -77,12 +86,4 @@ class GetTokenRequest extends Request implements HasBody
|
||||
return $body;
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="response_dto_caster" intent="Transform the raw JSON response into a structured TokenData DTO.">
|
||||
// <BELIEF_STATE "Automatically casting the JSON token response into a `TokenData` DTO provides type safety and a clean, object-oriented way to access token properties like `access_token` and `expires_in`.">
|
||||
public function createDtoFromResponse(Response $response): TokenData
|
||||
{
|
||||
return TokenData::from($response->json());
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ use Apoloz\AlfaBank\Data\Auth\ClientSecretData;
|
||||
use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\Http\Response;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a class for refreshing an OAuth client secret.">
|
||||
|
||||
@@ -18,6 +18,7 @@ use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\Http\Response;
|
||||
use Saloon\Traits\Body\HasFormBody;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a class for the OAuth 2.0 token revocation endpoint request.">
|
||||
@@ -52,6 +53,12 @@ class RevokeTokenRequest extends Request implements HasBody
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
public function createDtoFromResponse(Response $response): GeneralStatusData
|
||||
{
|
||||
return GeneralStatusData::from(['success' => $response->successful()]);
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="request_body_builder" intent="Construct the form-urlencoded body for the revocation request.">
|
||||
// <BELIEF_STATE "This method correctly builds the request body array, including optional parameters. `array_filter` is used to gracefully omit null values from the final payload.">
|
||||
protected function defaultBody(): array
|
||||
@@ -63,10 +70,4 @@ class RevokeTokenRequest extends Request implements HasBody
|
||||
'token_type_hint' => $this->tokenTypeHint,
|
||||
]);
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
public function createDtoFromResponse(Response $response): GeneralStatusData
|
||||
{
|
||||
return GeneralStatusData::from(['success' => $response->successful()]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ use Apoloz\AlfaBank\Data\Auth\UserInfo\ClientConsentCollectionData;
|
||||
use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\Http\Response;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a class for retrieving client consents.">
|
||||
@@ -47,6 +48,14 @@ class GetClientConsentsRequest extends Request
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="response_dto_caster" intent="Transform the raw JSON response into a structured ClientConsentCollectionData DTO.">
|
||||
// <BELIEF_STATE "Automatically casting the JSON response to a `ClientConsentCollectionData` DTO provides type safety and a clean, object-oriented way to access the list of consents and any associated metadata.">
|
||||
public function createDtoFromResponse(Response $response): ClientConsentCollectionData
|
||||
{
|
||||
return ClientConsentCollectionData::from($response->json());
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="query_parameter_builder" intent="Construct the query string for filtering and pagination.">
|
||||
// <BELIEF_STATE "The `array_filter` function is used to dynamically build the query parameters, ensuring that only non-null values are included in the request, which results in clean and efficient API calls.">
|
||||
protected function defaultQuery(): array
|
||||
@@ -58,15 +67,7 @@ class GetClientConsentsRequest extends Request
|
||||
'isActive' => $this->isActive,
|
||||
'limit' => $this->limit,
|
||||
'offset' => $this->offset,
|
||||
], fn($value) => $value !== null);
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="response_dto_caster" intent="Transform the raw JSON response into a structured ClientConsentCollectionData DTO.">
|
||||
// <BELIEF_STATE "Automatically casting the JSON response to a `ClientConsentCollectionData` DTO provides type safety and a clean, object-oriented way to access the list of consents and any associated metadata.">
|
||||
public function createDtoFromResponse(Response $response): ClientConsentCollectionData
|
||||
{
|
||||
return ClientConsentCollectionData::from($response->json());
|
||||
], fn ($value) => $value !== null);
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ use Apoloz\AlfaBank\Data\Auth\UserInfo\UserInfoData;
|
||||
use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\Http\Response;
|
||||
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="class_definition" intent="Define a class for the OIDC UserInfo endpoint request.">
|
||||
@@ -33,6 +34,26 @@ class GetUserInfoRequest extends Request
|
||||
{
|
||||
return '/oidc/userinfo';
|
||||
}
|
||||
|
||||
// <SECTION name="response_dto_caster" intent="Transform the raw JWT response into a structured UserInfoData DTO.">
|
||||
// <BELIEF_STATE "The API returns a JWT token in the response body. This method manually decodes the JWT payload (assuming it's a standard JWS) and casts it to a `UserInfoData` DTO, providing type safety and structured access to the user claims. A fallback is provided for invalid formats.">
|
||||
public function createDtoFromResponse(Response $response): UserInfoData
|
||||
{
|
||||
$jwt = $response->body();
|
||||
$parts = explode('.', $jwt);
|
||||
|
||||
if (count($parts) === 3) {
|
||||
$payload = json_decode(base64_decode($parts[1]), true);
|
||||
|
||||
return UserInfoData::from($payload);
|
||||
}
|
||||
|
||||
// Fallback or throw error?
|
||||
// If the response is not a valid JWT (e.g. error json), Saloon might have handled it if we throw on error status.
|
||||
// But if it's 200 OK and not a JWT, it's unexpected.
|
||||
|
||||
throw new \Exception('Invalid UserInfo response format. Expected JWT.');
|
||||
}
|
||||
// </SECTION>
|
||||
|
||||
// <SECTION name="default_headers" intent="Set the required 'Accept' header for a JWT response.">
|
||||
@@ -43,24 +64,5 @@ class GetUserInfoRequest extends Request
|
||||
'Accept' => 'application/jwt', // As per doc
|
||||
];
|
||||
}
|
||||
|
||||
// <SECTION name="response_dto_caster" intent="Transform the raw JWT response into a structured UserInfoData DTO.">
|
||||
// <BELIEF_STATE "The API returns a JWT token in the response body. This method manually decodes the JWT payload (assuming it's a standard JWS) and casts it to a `UserInfoData` DTO, providing type safety and structured access to the user claims. A fallback is provided for invalid formats.">
|
||||
public function createDtoFromResponse(Response $response): UserInfoData
|
||||
{
|
||||
$jwt = $response->body();
|
||||
$parts = explode('.', $jwt);
|
||||
|
||||
if (count($parts) === 3) {
|
||||
$payload = json_decode(base64_decode($parts[1]), true);
|
||||
return UserInfoData::from($payload);
|
||||
}
|
||||
|
||||
// Fallback or throw error?
|
||||
// If the response is not a valid JWT (e.g. error json), Saloon might have handled it if we throw on error status.
|
||||
// But if it's 200 OK and not a JWT, it's unexpected.
|
||||
|
||||
throw new \Exception("Invalid UserInfo response format. Expected JWT.");
|
||||
}
|
||||
// </SECTION>
|
||||
}
|
||||
|
||||
@@ -23,15 +23,15 @@ class CheckMerchantRequest extends Request
|
||||
return "/api/1c/merchants/{$this->merchantId}";
|
||||
}
|
||||
|
||||
public function createDtoFromResponse(Response $response): MerchantData
|
||||
{
|
||||
return MerchantData::from($response->json());
|
||||
}
|
||||
|
||||
protected function defaultHeaders(): array
|
||||
{
|
||||
return [
|
||||
'Authorization-1C' => $this->auth1C,
|
||||
];
|
||||
}
|
||||
|
||||
public function createDtoFromResponse(Response $response): MerchantData
|
||||
{
|
||||
return MerchantData::from($response->json());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,15 +23,15 @@ class GetPaymentLinkRequest extends Request
|
||||
return "/api/1c/payment-link/{$this->qrId}";
|
||||
}
|
||||
|
||||
public function createDtoFromResponse(Response $response): PaymentLinkData
|
||||
{
|
||||
return PaymentLinkData::from($response->json());
|
||||
}
|
||||
|
||||
protected function defaultHeaders(): array
|
||||
{
|
||||
return [
|
||||
'Authorization-1C' => $this->auth1C,
|
||||
];
|
||||
}
|
||||
|
||||
public function createDtoFromResponse(Response $response): PaymentLinkData
|
||||
{
|
||||
return PaymentLinkData::from($response->json());
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user