forked from apoloz/alfa-bank-sdk
refactor: dto, requests, connector
This commit is contained in:
33
src/Sbp/Data/Reversal/ReversalHistoryResponseData.php
Normal file
33
src/Sbp/Data/Reversal/ReversalHistoryResponseData.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Apoloz\AlfaBank\Sbp\Data\Reversal;
|
||||
|
||||
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\DataCollection;
|
||||
|
||||
class ReversalHistoryResponseData extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public int $ErrorCode,
|
||||
public string $message,
|
||||
#[DataCollectionOf(ReversalHistoryItemData::class)]
|
||||
public ?DataCollection $refunds = null,
|
||||
) {}
|
||||
}
|
||||
|
||||
class ReversalHistoryItemData extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public string $TermNo,
|
||||
public string $amount,
|
||||
public string $originalQrcId,
|
||||
public string $originalTrxId,
|
||||
public string $payerId,
|
||||
public string $status,
|
||||
public ?string $trxId = null,
|
||||
public ?string $trxDT = null,
|
||||
) {}
|
||||
}
|
||||
24
src/Sbp/Data/Webhooks/SbpPaymentNotificationData.php
Normal file
24
src/Sbp/Data/Webhooks/SbpPaymentNotificationData.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Apoloz\AlfaBank\Sbp\Data\Webhooks;
|
||||
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
class SbpPaymentNotificationData extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public string $command,
|
||||
public string $qrcId,
|
||||
public string $trxId,
|
||||
public string $status,
|
||||
public string $amount,
|
||||
public string $timestamp,
|
||||
public string $payerId,
|
||||
public string $payrrn,
|
||||
public string $TermNo,
|
||||
public ?string $kzo = null,
|
||||
public ?string $CreditDatePos = null,
|
||||
) {}
|
||||
}
|
||||
27
src/Sbp/Data/Webhooks/SbpRefundNotificationData.php
Normal file
27
src/Sbp/Data/Webhooks/SbpRefundNotificationData.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Apoloz\AlfaBank\Sbp\Data\Webhooks;
|
||||
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
class SbpRefundNotificationData extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public string $command,
|
||||
public string $TermNo,
|
||||
public string $originalQrcId,
|
||||
public string $originalTrxId,
|
||||
public string $trxId,
|
||||
public string $trxDT,
|
||||
public string $status,
|
||||
public string $amount,
|
||||
public string $ErrorCode,
|
||||
public string $message,
|
||||
public string $payerId,
|
||||
public ?string $messageID = null,
|
||||
public ?string $agentRefundRequestId = null,
|
||||
public ?string $opkcRefundRequestId = null,
|
||||
) {}
|
||||
}
|
||||
43
src/Sbp/Requests/Reversal/GetQrcReversalHistoryRequest.php
Normal file
43
src/Sbp/Requests/Reversal/GetQrcReversalHistoryRequest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Apoloz\AlfaBank\Sbp\Requests\Reversal;
|
||||
|
||||
use Apoloz\AlfaBank\Sbp\Data\Reversal\ReversalHistoryResponseData;
|
||||
use Saloon\Contracts\Body\HasBody;
|
||||
use Saloon\Enums\Method;
|
||||
use Saloon\Http\Request;
|
||||
use Saloon\Http\Response;
|
||||
use Saloon\Traits\Body\HasJsonBody;
|
||||
|
||||
class GetQrcReversalHistoryRequest extends Request implements HasBody
|
||||
{
|
||||
use HasJsonBody;
|
||||
|
||||
protected Method $method = Method::POST;
|
||||
|
||||
public function __construct(
|
||||
protected string $payrrn,
|
||||
protected string $TermNo,
|
||||
) {}
|
||||
|
||||
public function resolveEndpoint(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function defaultBody(): array
|
||||
{
|
||||
return [
|
||||
'command' => 'GetQRCreversalHistory',
|
||||
'TermNo' => $this->TermNo,
|
||||
'payrrn' => $this->payrrn,
|
||||
];
|
||||
}
|
||||
|
||||
public function createDtoFromResponse(Response $response): ReversalHistoryResponseData
|
||||
{
|
||||
return ReversalHistoryResponseData::from($response->json());
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,23 @@ class SbpConnector extends Connector implements HasPagination
|
||||
return $this->alfaConfig->baseUrl;
|
||||
}
|
||||
|
||||
protected function defaultConfig(): array
|
||||
/**
|
||||
* Parse payment notification from request body.
|
||||
*/
|
||||
public function parsePaymentNotification(array $data): \Apoloz\AlfaBank\Sbp\Data\Webhooks\SbpPaymentNotificationData
|
||||
{
|
||||
return \Apoloz\AlfaBank\Sbp\Data\Webhooks\SbpPaymentNotificationData::from($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse refund notification from request body.
|
||||
*/
|
||||
public function parseRefundNotification(array $data): \Apoloz\AlfaBank\Sbp\Data\Webhooks\SbpRefundNotificationData
|
||||
{
|
||||
return \Apoloz\AlfaBank\Sbp\Data\Webhooks\SbpRefundNotificationData::from($data);
|
||||
}
|
||||
|
||||
protected function defaultHeaders(): array
|
||||
{
|
||||
$config = [
|
||||
'cert' => $this->alfaConfig->certificatePath,
|
||||
@@ -92,6 +108,7 @@ class SbpConnector extends Connector implements HasPagination
|
||||
|
||||
// Mutate the request to add SBP-specific headers and set the exact signed body.
|
||||
$pendingRequest->headers()->add('Authorization', $signatureBase64);
|
||||
$pendingRequest->headers()->add('key-name', $this->keyNameAlias);
|
||||
// The SBP API documentation specifies this content-type for signed requests.
|
||||
$pendingRequest->headers()->add('Content-Type', 'application/x-www-form-urlencoded');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user