Skip to content

Commit

Permalink
Fix payment update
Browse files Browse the repository at this point in the history
  • Loading branch information
daVitekPL committed Aug 7, 2024
1 parent 57a7972 commit 66b17bf
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
4 changes: 3 additions & 1 deletion app/Http/Middleware/IsAppPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Enums\ExceptionsEnums\Exceptions;
use App\Exceptions\ClientException;
use App\Models\App;
use App\Models\Payment;
use Closure;
use Illuminate\Http\Request;
Expand All @@ -16,7 +17,8 @@ public function handle(Request $request, Closure $next): mixed
/** @var Payment $payment */
$payment = $request->route('payment');

if ($payment->paymentMethod?->app_id !== Auth::id()) {
// @phpstan-ignore-next-line
if (Auth::user() instanceof App && $payment->paymentMethod?->app_id !== Auth::id()) {
throw new ClientException(Exceptions::CLIENT_NO_ACCESS);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Domain/Organization/Resources/OrganizationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function base(Request $request): array
'client_id' => $this->resource->client_id,
'billing_email' => $this->resource->billing_email,
'billing_address' => AddressResource::make($this->resource->address),
'sales_channel' => SalesChannelResource::make($this->resource->salesChannel),
'sales_channel' => SalesChannelResource::make($this->resource->salesChannel)->baseOnly(),
];
}

Expand Down
1 change: 0 additions & 1 deletion src/Domain/Organization/Services/OrganizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ public function myOrganization(): Organization
*/
public function myOrganizationEdit(OrganizationPublicUpdateDto $dto): Organization
{
// TODO dodać consents
return $this->organizationRepository->myUpdate($this->myOrganization(), $dto);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,9 @@ public function testUpdate(): void
]);
}

public function testUpdateSuccessful(): void
public function testUpdateAsUser(): void
{
$this->appUser->givePermissionTo('payments.edit');
$this->user->givePermissionTo('payments.edit');
$paymentMethod = PaymentMethod::factory()->create([
'name' => 'test',
'app_id' => $this->appUser->getKey(),
Expand All @@ -638,7 +638,7 @@ public function testUpdateSuccessful(): void
'amount' => 100,
]);

$this->actingAs($this->appUser)->json('PATCH', '/payments/id:' . $payment->getKey(), [
$this->actingAs($this->user)->json('PATCH', '/payments/id:' . $payment->getKey(), [
'status' => PaymentStatus::SUCCESSFUL,
])
->assertOk()
Expand Down

0 comments on commit 66b17bf

Please sign in to comment.