Offline payment delete method check transaction.
This commit is contained in:
parent
9abda76d22
commit
3ca586a72f
@ -102,17 +102,22 @@ class Settings extends Controller
|
||||
*/
|
||||
public function destroy(DRequest $request)
|
||||
{
|
||||
$payment_method = $this->dispatch(new DeletePaymentMethod($request));
|
||||
$response = $this->ajaxDispatch(new DeletePaymentMethod($request));
|
||||
|
||||
$message = trans('messages.success.deleted', ['type' => $payment_method['name']]);
|
||||
if ($response['success']) {
|
||||
//$response['redirect'] = route('offline-payments.settings.edit');
|
||||
|
||||
//flash($message)->success();
|
||||
$response['message'] = trans('messages.success.deleted', ['type' => $response['data']['name']]);
|
||||
|
||||
return response()->json([
|
||||
'errors' => false,
|
||||
'success' => true,
|
||||
'message' => $message,
|
||||
'redirect' => route('offline-payments.settings.edit'),
|
||||
]);
|
||||
//flash($message)->success();
|
||||
} else {
|
||||
//$response['redirect'] = route('offline-payments.settings.edit');
|
||||
|
||||
$message = $response['message'];
|
||||
|
||||
//flash($message)->error();
|
||||
}
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -100,9 +100,10 @@ const app = new Vue({
|
||||
|
||||
document.getElementById('method-' + this.confirm.code).remove();
|
||||
|
||||
this.confirm.show = false;
|
||||
}
|
||||
|
||||
this.confirm.show = false;
|
||||
|
||||
this.$notify({
|
||||
message: response.data.message,
|
||||
timeout: 5000,
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user