Offline payment delete method check transaction.

This commit is contained in:
Cüneyt Şentürk
2020-09-22 01:35:11 +03:00
parent 9abda76d22
commit 3ca586a72f
4 changed files with 47 additions and 11 deletions

View File

@ -4,6 +4,7 @@ namespace Modules\OfflinePayments\Jobs;
use App\Abstracts\Job;
use App\Utilities\Modules;
use App\Models\Banking\Transaction;
class DeletePaymentMethod extends Job
{
@ -26,6 +27,8 @@ class DeletePaymentMethod extends Job
*/
public function handle()
{
$this->authorize();
$methods = json_decode(setting('offline-payments.methods'), true);
$payment_method = [];
@ -50,4 +53,31 @@ class DeletePaymentMethod extends Job
return $payment_method;
}
/**
* Determine if this action is applicable.
*
* @return void
*/
public function authorize()
{
if ($relationships = $this->getRelationships()) {
$message = trans('messages.warning.deleted', ['name' => $this->request->get('code'), 'text' => implode(', ', $relationships)]);
throw new \Exception($message);
}
}
public function getRelationships()
{
$counter = [];
if (!$c = Transaction::where('payment_method', $this->request->get('code'))->get()->count()) {
return [];
}
$counter[] = $c . ' ' . strtolower(trans_choice('general.transactions', ($c > 1) ? 2 : 1));
return $counter;
}
}