45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Enums\Order\TransactionStatus;
|
|
use App\Models\Customer\Customer;
|
|
use App\Models\Payment\Transaction;
|
|
use App\Models\User;
|
|
use Illuminate\Auth\Access\Response;
|
|
|
|
class TransactionPolicy extends Policy
|
|
{
|
|
/**
|
|
* Can a user order things ?
|
|
*
|
|
* ! Only owner customer or a Bo user
|
|
* ! + a validated transaction.
|
|
*
|
|
* @param \App\Models\Customer\Customer|\App\Models\User|null $user
|
|
* @param \App\Models\Payment\Transaction|null $transaction
|
|
*
|
|
* @return \Illuminate\Auth\Access\Response
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
*/
|
|
public function download(
|
|
$user = null,
|
|
Transaction $transaction = null
|
|
): Response {
|
|
if (!$transaction or !$transaction->status->equals(TransactionStatus::validated())) {
|
|
return Response::deny();
|
|
}
|
|
if ($user and $user instanceof User) {
|
|
return Response::allow();
|
|
}
|
|
if (
|
|
$user and $user instanceof Customer and
|
|
$transaction->order->customer and
|
|
!\is_null($user->hashcode) and
|
|
$transaction->order->customer->hashcode === $user->hashcode
|
|
) {
|
|
return Response::allow();
|
|
}
|
|
return Response::deny();
|
|
}
|
|
}
|