diff --git a/app/Http/Controllers/AccountGatewayController.php b/app/Http/Controllers/AccountGatewayController.php index e613b2047b4b..629932c567e8 100644 --- a/app/Http/Controllers/AccountGatewayController.php +++ b/app/Http/Controllers/AccountGatewayController.php @@ -295,7 +295,7 @@ class AccountGatewayController extends BaseController $config->plaidPublicKey = $oldConfig->plaidPublicKey; } - if ($gatewayId == GATEWAY_STRIPE) { + if ($gatewayId == GATEWAY_STRIPE || $gatewayId == GATEWAY_WEPAY) { $config->enableAch = boolval(Input::get('enable_ach')); } diff --git a/app/Http/routes.php b/app/Http/routes.php index 4611bb1abdd5..548fe071458d 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -669,6 +669,7 @@ if (!defined('CONTACT_EMAIL')) { define('PAYMENT_TYPE_STRIPE_CREDIT_CARD', 'PAYMENT_TYPE_STRIPE_CREDIT_CARD'); define('PAYMENT_TYPE_STRIPE_ACH', 'PAYMENT_TYPE_STRIPE_ACH'); define('PAYMENT_TYPE_BRAINTREE_PAYPAL', 'PAYMENT_TYPE_BRAINTREE_PAYPAL'); + define('PAYMENT_TYPE_WEPAY_ACH', 'PAYMENT_TYPE_WEPAY_ACH'); define('PAYMENT_TYPE_CREDIT_CARD', 'PAYMENT_TYPE_CREDIT_CARD'); define('PAYMENT_TYPE_DIRECT_DEBIT', 'PAYMENT_TYPE_DIRECT_DEBIT'); define('PAYMENT_TYPE_BITCOIN', 'PAYMENT_TYPE_BITCOIN'); diff --git a/app/Models/Account.php b/app/Models/Account.php index c489d21b180b..de1328862b71 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -379,26 +379,27 @@ class Account extends Eloquent return $format; } - public function getGatewayByType($type = PAYMENT_TYPE_ANY) + public function getGatewayByType($type = PAYMENT_TYPE_ANY, $exceptFor = null) { if ($type == PAYMENT_TYPE_STRIPE_ACH || $type == PAYMENT_TYPE_STRIPE_CREDIT_CARD) { $type = PAYMENT_TYPE_STRIPE; } - if ($type == PAYMENT_TYPE_BRAINTREE_PAYPAL) { - $gateway = $this->getGatewayConfig(GATEWAY_BRAINTREE); - - if (!$gateway || !$gateway->getPayPalEnabled()){ - return false; - } - return $gateway; - } - foreach ($this->account_gateways as $gateway) { + if ($exceptFor && ($gateway->id == $exceptFor->id)) { + continue; + } + if (!$type || $type == PAYMENT_TYPE_ANY) { return $gateway; } elseif ($gateway->isPaymentType($type)) { return $gateway; + } elseif ($type == PAYMENT_TYPE_CREDIT_CARD && $gateway->isPaymentType(PAYMENT_TYPE_STRIPE)) { + return $gateway; + } elseif ($type == PAYMENT_TYPE_DIRECT_DEBIT && $gateway->getAchEnabled()) { + return $gateway; + } elseif ($type == PAYMENT_TYPE_PAYPAL && $gateway->getPayPalEnabled()) { + return $gateway; } } @@ -1414,32 +1415,13 @@ class Account extends Eloquent } public function canAddGateway($type){ + if ($type == PAYMENT_TYPE_STRIPE) { + $type == PAYMENT_TYPE_CREDIT_CARD; + } + if($this->getGatewayByType($type)) { return false; } - if ($type == PAYMENT_TYPE_CREDIT_CARD && $this->getGatewayByType(PAYMENT_TYPE_STRIPE)) { - // Stripe is already handling credit card payments - return false; - } - - if ($type == PAYMENT_TYPE_STRIPE && $this->getGatewayByType(PAYMENT_TYPE_CREDIT_CARD)) { - // Another gateway is already handling credit card payments - return false; - } - - if ($type == PAYMENT_TYPE_DIRECT_DEBIT && $stripeGateway = $this->getGatewayByType(PAYMENT_TYPE_STRIPE)) { - if (!empty($stripeGateway->getAchEnabled())) { - // Stripe is already handling ACH payments - return false; - } - } - - if ($type == PAYMENT_TYPE_PAYPAL && $braintreeGateway = $this->getGatewayConfig(GATEWAY_BRAINTREE)) { - if (!empty($braintreeGateway->getPayPalEnabled())) { - // PayPal is already enabled - return false; - } - } return true; } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 307c37c1a152..82337d5b4f79 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -1203,7 +1203,7 @@ $LANG = array( 'ach' => 'ACH', 'enable_ach' => 'Enable ACH', 'stripe_ach_help' => 'ACH support must also be enabled at Stripe.', - 'stripe_ach_disabled' => 'Another gateway is already configured for direct debit.', + 'ach_disabled' => 'Another gateway is already configured for direct debit.', 'plaid' => 'Plaid', 'client_id' => 'Client Id', diff --git a/resources/views/accounts/account_gateway.blade.php b/resources/views/accounts/account_gateway.blade.php index fb5f674d27e7..f195d2849ab8 100644 --- a/resources/views/accounts/account_gateway.blade.php +++ b/resources/views/accounts/account_gateway.blade.php @@ -111,7 +111,7 @@ @endif @if ($gateway->id == GATEWAY_BRAINTREE) - @if ($account->getGatewayByType(PAYMENT_TYPE_PAYPAL)) + @if ($account->getGatewayByType(PAYMENT_TYPE_PAYPAL, isset($accountGateway)?$accountGateway:null)) {!! Former::checkbox('enable_paypal') ->label(trans('texts.paypal')) ->text(trans('texts.braintree_enable_paypal')) @@ -147,33 +147,49 @@ ->class('creditcard-types') ->addGroupClass('gateway-option') !!} -