From e905b295105c1a326ec375fff54591ee7538411f Mon Sep 17 00:00:00 2001 From: Joshua Dwire Date: Tue, 17 May 2016 14:09:39 -0400 Subject: [PATCH] Partial WePay ACH support --- .../Controllers/AccountGatewayController.php | 2 +- .../Controllers/PublicClientController.php | 19 +++--- app/Http/routes.php | 1 + app/Models/Account.php | 48 +++++---------- resources/lang/en/texts.php | 2 +- .../views/accounts/account_gateway.blade.php | 58 ++++++++++++------- .../partials/account_gateway_wepay.blade.php | 12 ++++ .../payments/add_paymentmethod.blade.php | 2 +- .../payments/paymentmethods_list.blade.php | 24 ++++++++ 9 files changed, 103 insertions(+), 65 deletions(-) diff --git a/app/Http/Controllers/AccountGatewayController.php b/app/Http/Controllers/AccountGatewayController.php index 9b02bfe56a24..202e3f35fcf2 100644 --- a/app/Http/Controllers/AccountGatewayController.php +++ b/app/Http/Controllers/AccountGatewayController.php @@ -301,7 +301,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/Controllers/PublicClientController.php b/app/Http/Controllers/PublicClientController.php index bf12d808fa31..29d67135e953 100644 --- a/app/Http/Controllers/PublicClientController.php +++ b/app/Http/Controllers/PublicClientController.php @@ -293,6 +293,7 @@ class PublicClientController extends BaseController 'color' => $color, 'account' => $account, 'client' => $client, + 'contact' => $invitation->contact, 'clientFontUrl' => $account->getFontsUrl(), 'gateway' => $account->getTokenGateway(), 'paymentMethods' => $this->paymentService->getClientPaymentMethods($client), @@ -757,6 +758,7 @@ class PublicClientController extends BaseController 'account' => $account, 'color' => $account->primary_color ? $account->primary_color : '#0b4d78', 'client' => $client, + 'contact' => $invitation->contact, 'clientViewCSS' => $account->clientViewCSS(), 'clientFontUrl' => $account->getFontsUrl(), 'paymentMethods' => $paymentMethods, @@ -828,20 +830,21 @@ class PublicClientController extends BaseController $accountGateway = $invoice->client->account->getTokenGateway(); $gateway = $accountGateway->gateway; - if ($token && $paymentType == PAYMENT_TYPE_BRAINTREE_PAYPAL) { - $sourceReference = $this->paymentService->createToken($this->paymentService->createGateway($accountGateway), array('token'=>$token), $accountGateway, $client, $invitation->contact_id); + if ($token) { + if ($paymentType == PAYMENT_TYPE_BRAINTREE_PAYPAL) { + $sourceReference = $this->paymentService->createToken($this->paymentService->createGateway($accountGateway), array('token' => $token), $accountGateway, $client, $invitation->contact_id); - if(empty($sourceReference)) { - $this->paymentMethodError('Token-No-Ref', $this->paymentService->lastError, $accountGateway); - } else { - Session::flash('message', trans('texts.payment_method_added')); + if (empty($sourceReference)) { + $this->paymentMethodError('Token-No-Ref', $this->paymentService->lastError, $accountGateway); + } else { + Session::flash('message', trans('texts.payment_method_added')); + } + return redirect()->to($account->enable_client_portal ? '/client/dashboard' : '/client/paymentmethods/'); } - return redirect()->to($account->enable_client_portal?'/client/dashboard':'/client/paymentmethods/'); } $acceptedCreditCardTypes = $accountGateway->getCreditcardTypes(); - $data = [ 'showBreadcrumbs' => false, 'client' => $client, diff --git a/app/Http/routes.php b/app/Http/routes.php index 46fe5cea836b..3b210671725e 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -665,6 +665,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 e766e13afbc0..1edde462a025 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -1219,7 +1219,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 155ef6579f69..f019edce93dc 100644 --- a/resources/views/accounts/account_gateway.blade.php +++ b/resources/views/accounts/account_gateway.blade.php @@ -113,7 +113,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')) @@ -149,33 +149,49 @@ ->class('creditcard-types') ->addGroupClass('gateway-option') !!} -
- @if ($account->getGatewayByType(PAYMENT_TYPE_DIRECT_DEBIT)) + @if(isset($accountGateway) && $accountGateway->gateway_id == GATEWAY_WEPAY) + @if ($account->getGatewayByType(PAYMENT_TYPE_DIRECT_DEBIT, $accountGateway)) {!! Former::checkbox('enable_ach') ->label(trans('texts.ach')) ->text(trans('texts.enable_ach')) ->value(null) ->disabled(true) - ->help(trans('texts.stripe_ach_disabled')) !!} + ->help(trans('texts.ach_disabled')) !!} @else - {!! Former::checkbox('enable_ach') - ->label(trans('texts.ach')) - ->text(trans('texts.enable_ach')) - ->help(trans('texts.stripe_ach_help')) !!} -
-
-
-

{{trans('texts.plaid')}}

-
{{trans('texts.plaid_optional')}}
-
-
- {!! Former::text('plaid_client_id')->label(trans('texts.client_id')) !!} - {!! Former::text('plaid_secret')->label(trans('texts.secret')) !!} - {!! Former::text('plaid_public_key')->label(trans('texts.public_key')) - ->help(trans('texts.plaid_environment_help')) !!} -
+ {!! Former::checkbox('enable_ach') + ->label(trans('texts.ach')) + ->text(trans('texts.enable_ach')) !!} @endif -
+ + @elseif(!isset($accountGateway) || $accountGateway->gateway_id == GATEWAY_STRIPE) +
+ @if ($account->getGatewayByType(PAYMENT_TYPE_DIRECT_DEBIT, isset($accountGateway)?$accountGateway:null)) + {!! Former::checkbox('enable_ach') + ->label(trans('texts.ach')) + ->text(trans('texts.enable_ach')) + ->value(null) + ->disabled(true) + ->help(trans('texts.ach_disabled')) !!} + @else + {!! Former::checkbox('enable_ach') + ->label(trans('texts.ach')) + ->text(trans('texts.enable_ach')) + ->help(trans('texts.stripe_ach_help')) !!} +
+
+
+

{{trans('texts.plaid')}}

+
{{trans('texts.plaid_optional')}}
+
+
+ {!! Former::text('plaid_client_id')->label(trans('texts.client_id')) !!} + {!! Former::text('plaid_secret')->label(trans('texts.secret')) !!} + {!! Former::text('plaid_public_key')->label(trans('texts.public_key')) + ->help(trans('texts.plaid_environment_help')) !!} +
+ @endif +
+ @endif diff --git a/resources/views/accounts/partials/account_gateway_wepay.blade.php b/resources/views/accounts/partials/account_gateway_wepay.blade.php index a5ccd7f01abc..0ccce3deded0 100644 --- a/resources/views/accounts/partials/account_gateway_wepay.blade.php +++ b/resources/views/accounts/partials/account_gateway_wepay.blade.php @@ -53,6 +53,18 @@ ->label('Accepted Credit Cards') ->checkboxes($creditCardTypes) ->class('creditcard-types') !!} + @if ($account->getGatewayByType(PAYMENT_TYPE_DIRECT_DEBIT)) + {!! Former::checkbox('enable_ach') + ->label(trans('texts.ach')) + ->text(trans('texts.enable_ach')) + ->value(null) + ->disabled(true) + ->help(trans('texts.ach_disabled')) !!} + @else + {!! Former::checkbox('enable_ach') + ->label(trans('texts.ach')) + ->text(trans('texts.enable_ach')) !!} + @endif {!! Former::checkbox('tos_agree')->label(' ')->text(trans('texts.wepay_tos_agree', ['link'=>''.trans('texts.wepay_tos_link_text').''] ))->value('true') !!} diff --git a/resources/views/payments/add_paymentmethod.blade.php b/resources/views/payments/add_paymentmethod.blade.php index c5a5b1eab36c..f0ecfbbed58d 100644 --- a/resources/views/payments/add_paymentmethod.blade.php +++ b/resources/views/payments/add_paymentmethod.blade.php @@ -124,7 +124,7 @@

 
 

- @if($paymentType != PAYMENT_TYPE_STRIPE_ACH && $paymentType != PAYMENT_TYPE_BRAINTREE_PAYPAL) + @if($paymentType != PAYMENT_TYPE_STRIPE_ACH && $paymentType != PAYMENT_TYPE_BRAINTREE_PAYPAL && $paymentType != PAYMENT_TYPE_WEPAY_ACH)

{{ trans('texts.contact_information') }}

diff --git a/resources/views/payments/paymentmethods_list.blade.php b/resources/views/payments/paymentmethods_list.blade.php index 6c068b5f915a..77789b8f5c83 100644 --- a/resources/views/payments/paymentmethods_list.blade.php +++ b/resources/views/payments/paymentmethods_list.blade.php @@ -48,6 +48,24 @@ }) }); +@elseif($gateway->gateway_id == GATEWAY_WEPAY && $gateway->getAchEnabled()) + + + @endif @if(!empty($paymentMethods)) @foreach ($paymentMethods as $paymentMethod) @@ -88,8 +106,14 @@ ->asLinkTo(URL::to('/client/paymentmethods/add/'.($gateway->getPaymentType() == PAYMENT_TYPE_STRIPE ? 'stripe_credit_card' : 'credit_card'))) !!} @if($gateway->getACHEnabled())   + @if($gateway->gateway_id == GATEWAY_STRIPE) {!! Button::success(strtoupper(trans('texts.add_bank_account'))) ->asLinkTo(URL::to('/client/paymentmethods/add/stripe_ach')) !!} + @elseif($gateway->gateway_id == GATEWAY_WEPAY) + {!! Button::success(strtoupper(trans('texts.add_bank_account'))) + ->withAttributes(['id'=>'add-ach']) + ->asLinkTo(URL::to('/client/paymentmethods/add/wepay_ach')) !!} + @endif @endif @if($gateway->getPayPalEnabled())