Skip to content

Commit

Permalink
Merge pull request #27 from wedevBr/refactor/PixCashoutRefactor
Browse files Browse the repository at this point in the history
[Refactor] Refactoring PixCashout with correctly rules and validation
  • Loading branch information
adeildo-jr authored Oct 11, 2023
2 parents a2081e6 + 00d9051 commit c2e4d0a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/Clients/CelcoinBAASPIX.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace WeDevBr\Celcoin\Clients;

use Illuminate\Http\Client\RequestException;
use Illuminate\Support\Facades\Validator;
use WeDevBr\Celcoin\Common\CelcoinBaseApi;
use WeDevBr\Celcoin\Rules\BAAS\PixCashOut as BAASPixCashOut;
Expand Down Expand Up @@ -29,9 +30,12 @@ class CelcoinBAASPIX extends CelcoinBaseApi
const REFUND_PIX_ENDPOINT = '/baas-wallet-transactions-webservice/v1/pix/reverse';
const STATUS_REFUND_PIX_ENDPOINT = '/baas-wallet-transactions-webservice/v1/pix/reverse/status';

/**
* @throws RequestException
*/
public function cashOut(PixCashOut $data)
{
$body = Validator::validate($data->toArray(), BAASPixCashOut::rules());
$body = Validator::validate($data->toArray(), BAASPixCashOut::rules($data->initiationType->value));
return $this->post(
self::CASH_OUT_ENDPOINT,
$body
Expand Down
7 changes: 4 additions & 3 deletions src/Rules/BAAS/PixCashOut.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ class PixCashOut
/**
* @see https://developers.celcoin.com.br/docs/realizar-um-pix-cash-out-por-chaves-pix
* @see https://developers.celcoin.com.br/docs/realizar-um-pix-cash-out
* @param string $initiationTypeEnum
* @return array
*/
public static function rules(): array
public static function rules(string $initiationTypeEnum): array
{

return match (request()->initiationType) {
return match ($initiationTypeEnum) {
InitiationTypeEnum::PAYMENT_MANUAL->value => self::manual(),
InitiationTypeEnum::PAYMENT_DICT->value => self::dict(),
InitiationTypeEnum::PAYMENT_STATIC_BRCODE->value => self::static(),
Expand Down Expand Up @@ -76,7 +77,7 @@ private static function dict(): array
[
'transactionIdentification' => ['prohibited'],
'endToEndId' => ['required'],
'creditParty.*' => ['required', 'array'],
'creditParty' => ['required', 'array'],
'creditParty.key' => ['required'],
]
);
Expand Down
1 change: 0 additions & 1 deletion tests/Integration/BAAS/PixCashOut/BAASPIXCashOutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ final public function testSuccess(): void
new PixCashOut([
"amount" => 5.55,
"clientCode" => "1234ab",
"transactionIdentification" => fake()->uuid(),
"endToEndId" => "E1393589320230724213001637810511",
"initiationType" => "DICT",
"paymentType" => "IMMEDIATE",
Expand Down

0 comments on commit c2e4d0a

Please sign in to comment.