Просмотр исходного кода

fix: :lipstick: bugfix(metodos de pagamentos) Foi ajustado os metodos de pagamentos

Ajuste nos metodos de pagamentos para a listagem não mostrar dados sensiveis, tambem efetuado a correção de um bug na parte do cadastro do provider,pois não estava atualizando

fase:dev | origin:bug
kayo henrique 3 недель назад
Родитель
Сommit
f5c281f58a

+ 2 - 1
app/Http/Controllers/ClientPaymentMethodController.php

@@ -3,6 +3,7 @@
 namespace App\Http\Controllers;
 
 use App\Http\Requests\ClientPaymentMethodRequest;
+use App\Http\Resources\CardsListResource;
 use App\Http\Resources\ClientPaymentMethodResource;
 use App\Services\ClientPaymentMethodService;
 use Illuminate\Http\JsonResponse;
@@ -18,7 +19,7 @@ class ClientPaymentMethodController extends Controller
         $paymentMethods = $this->service->getByClientId($clientId);
         
         return $this->successResponse(
-            payload: ClientPaymentMethodResource::collection($paymentMethods)
+            payload: CardsListResource::collection($paymentMethods)
         );
     }
 

+ 28 - 9
app/Http/Requests/ProviderPaymentMethodRequest.php

@@ -16,14 +16,33 @@ class ProviderPaymentMethodRequest extends FormRequest
 
     public function rules(): array
     {
-        return [
-            'provider_id' => ['required', 'exists:providers,id'],
-            'account_type' => ['required', Rule::in([AccountTypeEnum::PIX->value, AccountTypeEnum::BANK_ACCOUNT->value])],
-            'pix_key' => ['nullable', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::PIX->value)],
-            'bank_account_type' => ['nullable', Rule::in([BankAccountTypeEnum::CHECKING->value, BankAccountTypeEnum::SAVINGS->value]), Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
-            'agency' => ['nullable', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
-            'account' => ['nullable', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
-            'digit' => ['nullable', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
-        ];
+
+        if ($this->account_type == AccountTypeEnum::PIX->value) {
+
+            $rules =  [
+                'account_type' => ['sometimes', Rule::in([AccountTypeEnum::PIX->value, AccountTypeEnum::BANK_ACCOUNT->value])],
+                'pix_key' => ['required', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::PIX->value)],
+                'bank_account_type' => ['nullable', Rule::in([BankAccountTypeEnum::CHECKING->value, BankAccountTypeEnum::SAVINGS->value]), Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
+                'agency' => ['nullable', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
+                'account' => ['nullable', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
+                'digit' => ['nullable', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
+            ];
+        } else {
+            $rules =  [
+                'account_type' => ['sometimes', Rule::in([AccountTypeEnum::PIX->value, AccountTypeEnum::BANK_ACCOUNT->value])],
+                'pix_key' => ['nullable', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::PIX->value)],
+                'bank_account_type' => ['sometimes', Rule::in([BankAccountTypeEnum::CHECKING->value, BankAccountTypeEnum::SAVINGS->value]), Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
+                'agency' => ['sometimes', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
+                'account' => ['sometimes', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
+                'digit' => ['sometimes', 'string', 'max:255', Rule::requiredIf($this->account_type === AccountTypeEnum::BANK_ACCOUNT->value)],
+            ];
+        }
+
+        if ($this->isMethod('post')) {
+            $rules['provider_id'] =  ['required', 'exists:providers,id'];
+        };
+
+
+        return $rules;
     }
 }

+ 20 - 0
app/Http/Resources/CardsListResource.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace App\Http\Resources;
+
+use Illuminate\Http\Request;
+use Illuminate\Http\Resources\Json\JsonResource;
+
+class CardsListResource extends JsonResource
+{
+    public function toArray(Request $request): array
+    {
+        return [
+            'id' => $this->id,
+            'brand' => $this->brand,
+            'last_four_digits' => $this->last_four_digits,
+            'card_name' => $this->card_name,
+
+        ];
+    }
+}

+ 0 - 2
app/Http/Resources/ProviderPaymentMethodResource.php

@@ -18,8 +18,6 @@ class ProviderPaymentMethodResource extends JsonResource
             'agency' => $this->agency,
             'account' => $this->account,
             'digit' => $this->digit,
-            'created_at' => $this->created_at,
-            'updated_at' => $this->updated_at,
         ];
     }
 }

+ 7 - 1
app/Services/ClientPaymentMethodService.php

@@ -10,6 +10,12 @@ class ClientPaymentMethodService
     public function getByClientId(int $clientId): Collection
     {
         return ClientPaymentMethod::where('client_id', $clientId)
+            ->select(
+                'id',
+                'brand',
+                'last_four_digits',
+                'card_name'
+            )
             ->orderBy('is_active', 'desc')
             ->orderBy('created_at', 'desc')
             ->get();
@@ -47,7 +53,7 @@ class ClientPaymentMethodService
     private function deactivateOtherCards(int $clientId, ?int $exceptId = null): void
     {
         $query = ClientPaymentMethod::where('client_id', $clientId);
-        
+
         if ($exceptId) {
             $query->where('id', '!=', $exceptId);
         }