<?php
namespace App\Classes;
use App\Bank\Payment;
class StoreKyc
{
private $store = null;
public function __construct($store)
{
$this->store = $store;
}
public function checkStoreKYC($amount)
{
if ($this->validateAmount($amount)) return response()->json(['message' => 'Montante invalido'], 400);
if ($this->checkPayment()) return response()->json(['message' => ' Pagamento indisponivel na loja ' . '\'' . $this->store->name . '\''], 400);
if ($this->checkNrTransactions()) return response()->json(['message' => $this->store->name . ' atingiu o limite diário de transacoes por dia.'], 400);
if ($this->checkMinAmount($amount)) return response()->json(['message' => 'O valor informado é inferior ao valor permitido pela loja ' . '\'' . $this->store->name . '\''], 400);
if ($this->checkMaxAmount($amount)) return response()->json(['message' => 'O valor informado é superior ao valor permitido pela loja ' . '\'' . $this->store->name . '\''], 400);
if ($this->checkMaxBalance($amount)) return response()->json(['message' => 'A Loja ' . '\'' . $this->store->name . '\'' . ' atingiu o limite de saldo. '], 400);
return response()->json(['message' => 'All test done successfuly!!!'], 200);
}
/**
* Retorna o numero total de transacoes do dia,
* efectuados pelo utilizador. Dependendo do nivel de KYC.
*/
private function getNrTransactions()
{
$payMent = Payment::query()
->where('payments.store_id', $this->store->id)
->whereDate('payments.created_at', 'LIKE', "%" . date('Y-m-d') . "%")
->get()->count();
return $payMent;
}
private function checkNrTransactions()
{
if ($this->getNrTransactions() >= $this->store->nr_transaction) return true;
return false;
}
private function checkMaxBalance($amount)
{
$total_amount = $amount + $this->store->balance;
if ($total_amount > $this->store->max_balance) return true;
return false;
}
private function checkMinAmount($amount)
{
if ($amount < $this->store->min_amount) return true;
return false;
}
private function checkMaxAmount($amount)
{
if ($amount > $this->store->max_amount) return true;
return false;
}
private function checkPayment()
{
if (!$this->store->accept_payment) return true;
return false;
}
private function validateAmount($amount)
{
if (!is_numeric($amount)) return true;
if ($amount <= 0) return true;
return false;
}
}