Files
alfa-bank-sdk/src/Requests/NominalAccounts/Payouts/PayoffAcceptRequest.php

64 lines
2.8 KiB
PHP

<?php
/*
// MODULE_CONTRACT: Represents the API call to accept or reject a pending payoff.
// RESPONSIBILITY: To define the PATCH request for changing the status of a payoff (approve/decline).
// INPUTS: Payoff ID (string) and a boolean indicating acceptance.
// OUTPUTS: Boolean (true if successful, false otherwise).
*/
namespace Apoloz\AlfaBank\Requests\NominalAccounts\Payouts;
// <SECTION name="module_imports" intent="Import Saloon components for a JSON body request.">
// <BELIEF_STATE "This PATCH request requires body-handling traits because it sends a JSON payload.">
use Saloon\Contracts\Body\HasBody;
use Saloon\Enums\Method;
use Saloon\Http\Request;
use Saloon\Http\Response;
use Saloon\Traits\Body\HasJsonBody;
// </SECTION>
// <SECTION name="class_definition" intent="Define the request to accept a payoff.">
// <BELIEF_STATE "This class encapsulates a critical state-changing operation on a payment.">
class PayoffAcceptRequest extends Request implements HasBody
{
use HasJsonBody;
// <SECTION name="http_method" intent="Declare the HTTP verb.">
// <BELIEF_STATE "PATCH is the appropriate verb for partially modifying an existing resource's state, such as accepting or rejecting a payoff.">
protected Method $method = Method::PATCH;
// </SECTION>
// <SECTION name="constructor" intent="Inject the payoff ID and the acceptance flag.">
// <BELIEF_STATE "The constructor requires the `payoffId` to target the specific payment and an `accept` flag to indicate the desired action. The default `true` simplifies the most common use case (accept).">
public function __construct(
protected string $payoffId,
protected bool $accept = true
) {}
// </SECTION>
// <SECTION name="endpoint_resolver" intent="Construct the request URI for accepting a payoff.">
// <BELIEF_STATE "The endpoint is specific to the `/accept` action on a given payoff resource.">
public function resolveEndpoint(): string
{
return "/api/na/jp/v1/payoffs/{$this->payoffId}/accept";
}
// </SECTION>
// <SECTION name="body_builder" intent="Construct the JSON body for the request.">
// <BELIEF_STATE "The request body is simple, containing only the `accept` boolean flag.">
protected function defaultBody(): array
{
return [
'accept' => $this->accept,
];
}
// </SECTION>
// <SECTION name="response_caster" intent="Extract the boolean result from the JSON response.">
// <BELIEF_STATE "The API returns a JSON object, but the relevant information is a boolean status. This method extracts that boolean, providing a direct, simple result to the user.">
public function createDtoFromResponse(Response $response): bool
{
return (bool)($response->json('result') ?? false);
}
// </SECTION>
}