From dcdfb4f21cf1c519d514b82f13afbfaacd0bd631 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 22 Jun 2016 20:13:45 +0300 Subject: [PATCH] Check to prevent duplicate gateways --- app/Http/Controllers/AccountGatewayController.php | 10 ++++++++++ resources/lang/en/texts.php | 1 + 2 files changed, 11 insertions(+) diff --git a/app/Http/Controllers/AccountGatewayController.php b/app/Http/Controllers/AccountGatewayController.php index e0f6ba9b5754..ccb291988429 100644 --- a/app/Http/Controllers/AccountGatewayController.php +++ b/app/Http/Controllers/AccountGatewayController.php @@ -216,6 +216,16 @@ class AccountGatewayController extends BaseController $accountGateway = AccountGateway::scope($accountGatewayPublicId)->firstOrFail(); $oldConfig = $accountGateway->getConfig(); } else { + // check they don't already have an active gateway for this provider + // TODO complete this + $accountGateway = AccountGateway::scope() + ->whereGatewayId($gatewayId) + ->first(); + if ($accountGateway) { + Session::flash('error', trans('texts.gateway_exists')); + return Redirect::to("gateways/{$accountGateway->public_id}/edit"); + } + $accountGateway = AccountGateway::createNew(); $accountGateway->gateway_id = $gatewayId; diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 918fc4b0f3c1..27ab164f530b 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -1359,6 +1359,7 @@ $LANG = array( 'bitcoin' => 'Bitcoin', 'added_on' => 'Added :date', 'failed_remove_payment_method' => 'Failed to remove the payment method', + 'gateway_exists' => 'This gateway already exists', );