diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 053d5cb66a58..bf047ded36c3 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -1,5 +1,6 @@ account; $account->load('account_gateways'); $count = count($account->account_gateways); + $trashedCount = AccountGateway::scope($account->id)->withTrashed()->count(); if ($accountGateway = $account->getGatewayConfig(GATEWAY_STRIPE)) { if (! $accountGateway->getPublishableStripeKey()) { @@ -427,7 +429,7 @@ class AccountController extends BaseController } } - if ($count == 0) { + if ($trashedCount == 0) { return Redirect::to('gateways/create'); } else { $switchToWepay = WEPAY_CLIENT_ID && !$account->getGatewayConfig(GATEWAY_WEPAY); diff --git a/app/Http/Controllers/AccountGatewayController.php b/app/Http/Controllers/AccountGatewayController.php index 27d3d54464d2..9a12ca11c5f9 100644 --- a/app/Http/Controllers/AccountGatewayController.php +++ b/app/Http/Controllers/AccountGatewayController.php @@ -45,10 +45,6 @@ class AccountGatewayController extends BaseController $accountGateway = AccountGateway::scope($publicId)->firstOrFail(); $config = $accountGateway->getConfig(); - if ($accountGateway->gateway_id == GATEWAY_WEPAY) { - return Redirect::to('gateways'); - } - foreach ($config as $field => $value) { $config->$field = str_repeat('*', strlen($value)); } @@ -109,31 +105,7 @@ class AccountGatewayController extends BaseController $paymentTypes = []; foreach (Gateway::$paymentTypes as $type) { - if ($accountGateway || !$account->getGatewayByType($type)) { - if ($type == PAYMENT_TYPE_CREDIT_CARD && $account->getGatewayByType(PAYMENT_TYPE_STRIPE)) { - // Stripe is already handling credit card payments - continue; - } - - if ($type == PAYMENT_TYPE_STRIPE && $account->getGatewayByType(PAYMENT_TYPE_CREDIT_CARD)) { - // Another gateway is already handling credit card payments - continue; - } - - if ($type == PAYMENT_TYPE_DIRECT_DEBIT && $stripeGateway = $account->getGatewayByType(PAYMENT_TYPE_STRIPE)) { - if (!empty($stripeGateway->getAchEnabled())) { - // Stripe is already handling ACH payments - continue; - } - } - - if ($type == PAYMENT_TYPE_PAYPAL && $braintreeGateway = $account->getGatewayConfig(GATEWAY_BRAINTREE)) { - if (!empty($braintreeGateway->getPayPalEnabled())) { - // PayPal is already enabled - continue; - } - } - + if ($accountGateway || $account->canAddGateway($type)) { $paymentTypes[$type] = $type == PAYMENT_TYPE_CREDIT_CARD ? trans('texts.other_providers'): trans('texts.'.strtolower($type)); if ($type == PAYMENT_TYPE_BITCOIN) { @@ -162,7 +134,7 @@ class AccountGatewayController extends BaseController foreach ($gateways as $gateway) { $fields = $gateway->getFields(); asort($fields); - $gateway->fields = $fields; + $gateway->fields = $gateway->id == GATEWAY_WEPAY ? [] : $fields; if ($accountGateway && $accountGateway->gateway_id == $gateway->id) { $accountGateway->fields = $gateway->fields; } @@ -193,7 +165,7 @@ class AccountGatewayController extends BaseController $ids = Input::get('bulk_public_id'); $count = $this->accountGatewayService->bulk($ids, $action); - Session::flash('message', trans('texts.archived_account_gateway')); + Session::flash('message', trans("texts.{$action}d_account_gateway")); return Redirect::to('settings/' . ACCOUNT_PAYMENTS); } @@ -208,10 +180,6 @@ class AccountGatewayController extends BaseController $paymentType = Input::get('payment_type_id'); $gatewayId = Input::get('gateway_id'); - if ($gatewayId == GATEWAY_WEPAY) { - return $this->setupWePay(); - } - if ($paymentType == PAYMENT_TYPE_PAYPAL) { $gatewayId = GATEWAY_PAYPAL_EXPRESS; } elseif ($paymentType == PAYMENT_TYPE_BITCOIN) { @@ -245,14 +213,16 @@ class AccountGatewayController extends BaseController } } - foreach ($fields as $field => $details) { - if (!in_array($field, $optional)) { - if (strtolower($gateway->name) == 'beanstream') { - if (in_array($field, ['merchant_id', 'passCode'])) { - $rules[$gateway->id.'_'.$field] = 'required'; + if ($gatewayId != GATEWAY_WEPAY) { + foreach ($fields as $field => $details) { + if (!in_array($field, $optional)) { + if (strtolower($gateway->name) == 'beanstream') { + if (in_array($field, ['merchant_id', 'passCode'])) { + $rules[$gateway->id . '_' . $field] = 'required'; + } + } else { + $rules[$gateway->id . '_' . $field] = 'required'; } - } else { - $rules[$gateway->id.'_'.$field] = 'required'; } } } @@ -274,20 +244,29 @@ class AccountGatewayController extends BaseController } else { $accountGateway = AccountGateway::createNew(); $accountGateway->gateway_id = $gatewayId; + + if ($gatewayId == GATEWAY_WEPAY && !$this->setupWePay($accountGateway, $wepayResponse)) { + return $wepayResponse; + } } $config = new stdClass(); - foreach ($fields as $field => $details) { - $value = trim(Input::get($gateway->id.'_'.$field)); - // if the new value is masked use the original value - if ($oldConfig && $value && $value === str_repeat('*', strlen($value))) { - $value = $oldConfig->$field; - } - if (!$value && ($field == 'testMode' || $field == 'developerMode')) { - // do nothing - } else { - $config->$field = $value; + + if ($gatewayId != GATEWAY_WEPAY) { + foreach ($fields as $field => $details) { + $value = trim(Input::get($gateway->id . '_' . $field)); + // if the new value is masked use the original value + if ($oldConfig && $value && $value === str_repeat('*', strlen($value))) { + $value = $oldConfig->$field; + } + if (!$value && ($field == 'testMode' || $field == 'developerMode')) { + // do nothing + } else { + $config->$field = $value; + } } + } else { + $config = clone $oldConfig; } $publishableKey = Input::get('publishable_key'); @@ -349,15 +328,18 @@ class AccountGatewayController extends BaseController $account->save(); } - if ($accountGatewayPublicId) { - $message = trans('texts.updated_gateway'); + if(isset($wepayResponse)) { + return $wepayResponse; } else { - $message = trans('texts.created_gateway'); + if ($accountGatewayPublicId) { + $message = trans('texts.updated_gateway'); + } else { + $message = trans('texts.created_gateway'); + } + + Session::flash('message', $message); + return Redirect::to("gateways/{$accountGateway->public_id}/edit"); } - - Session::flash('message', $message); - - return Redirect::to("gateways/{$accountGateway->public_id}/edit"); } } @@ -378,7 +360,7 @@ class AccountGatewayController extends BaseController return $update_uri_data->uri; } - protected function setupWePay() + protected function setupWePay($accountGateway, &$response) { $user = Auth::user(); $account = $user->account; @@ -441,7 +423,6 @@ class AccountGatewayController extends BaseController $gateway->delete(); } - $accountGateway = AccountGateway::createNew(); $accountGateway->gateway_id = GATEWAY_WEPAY; $accountGateway->setConfig(array( 'userId' => $wepayUser->user_id, @@ -451,7 +432,6 @@ class AccountGatewayController extends BaseController 'accountId' => $wepayAccount->account_id, 'testMode' => WEPAY_ENVIRONMENT == WEPAY_STAGE, )); - $account->account_gateways()->save($accountGateway); if ($confirmationRequired) { Session::flash('message', trans('texts.created_wepay_confirmation_required')); @@ -461,14 +441,17 @@ class AccountGatewayController extends BaseController 'redirect_uri' => URL::to('gateways'), )); - return Redirect::to($updateUri->uri); + $response = Redirect::to($updateUri->uri); + return true; } - return Redirect::to("gateways"); + $response = Redirect::to("gateways/{$accountGateway->public_id}/edit"); + return true; } catch (\WePayException $e) { Session::flash('error', $e->getMessage()); - return Redirect::to('gateways/create') + $response = Redirect::to('gateways/create') ->withInput(); + return false; } } diff --git a/app/Models/Account.php b/app/Models/Account.php index fb2c39b951db..c489d21b180b 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -1412,6 +1412,37 @@ class Account extends Eloquent public function getFontFolders(){ return array_map(function($item){return $item['folder'];}, $this->getFontsData()); } + + public function canAddGateway($type){ + 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; + } } Account::updated(function ($account) { diff --git a/app/Ninja/Repositories/AccountGatewayRepository.php b/app/Ninja/Repositories/AccountGatewayRepository.php index b011ebda765b..286c8416a21a 100644 --- a/app/Ninja/Repositories/AccountGatewayRepository.php +++ b/app/Ninja/Repositories/AccountGatewayRepository.php @@ -15,10 +15,14 @@ class AccountGatewayRepository extends BaseRepository public function find($accountId) { - return DB::table('account_gateways') + $query = DB::table('account_gateways') ->join('gateways', 'gateways.id', '=', 'account_gateways.gateway_id') - ->where('account_gateways.deleted_at', '=', null) - ->where('account_gateways.account_id', '=', $accountId) - ->select('account_gateways.id', 'account_gateways.public_id', 'gateways.name', 'account_gateways.deleted_at', 'account_gateways.gateway_id'); + ->where('account_gateways.account_id', '=', $accountId); + + if (!\Session::get('show_trash:gateway')) { + $query->where('account_gateways.deleted_at', '=', null); + } + + return $query->select('account_gateways.id', 'account_gateways.public_id', 'gateways.name', 'account_gateways.deleted_at', 'account_gateways.gateway_id'); } } diff --git a/app/Services/AccountGatewayService.php b/app/Services/AccountGatewayService.php index fe5427b966bb..a992da5c82c9 100644 --- a/app/Services/AccountGatewayService.php +++ b/app/Services/AccountGatewayService.php @@ -42,7 +42,9 @@ class AccountGatewayService extends BaseService [ 'name', function ($model) { - if ($model->gateway_id != GATEWAY_WEPAY) { + if ($model->deleted_at) { + return $model->name; + } elseif ($model->gateway_id != GATEWAY_WEPAY) { return link_to("gateways/{$model->public_id}/edit", $model->name)->toHtml(); } else { $accountGateway = AccountGateway::find($model->id); @@ -89,20 +91,12 @@ class AccountGatewayService extends BaseService { return [ [ - uctrans('texts.edit_gateway'), - function ($model) { - return URL::to("gateways/{$model->public_id}/edit"); - }, - function($model) { - return $model->gateway_id != GATEWAY_WEPAY; - } - ], [ uctrans('texts.resend_confirmation_email'), function ($model) { return $model->resendConfirmationUrl; }, function($model) { - return $model->gateway_id == GATEWAY_WEPAY && !empty($model->resendConfirmationUrl); + return !$model->deleted_at && $model->gateway_id == GATEWAY_WEPAY && !empty($model->resendConfirmationUrl); } ], [ uctrans('texts.finish_setup'), @@ -110,9 +104,17 @@ class AccountGatewayService extends BaseService return $model->setupUrl; }, function($model) { - return $model->gateway_id == GATEWAY_WEPAY && !empty($model->setupUrl); + return !$model->deleted_at && $model->gateway_id == GATEWAY_WEPAY && !empty($model->setupUrl); } ] , [ + uctrans('texts.edit_gateway'), + function ($model) { + return URL::to("gateways/{$model->public_id}/edit"); + }, + function($model) { + return !$model->deleted_at; + } + ], [ uctrans('texts.manage_wepay_account'), function ($model) { $accountGateway = AccountGateway::find($model->id); @@ -123,7 +125,7 @@ class AccountGatewayService extends BaseService ); }, function($model) { - return $model->gateway_id == GATEWAY_WEPAY; + return !$model->deleted_at && $model->gateway_id == GATEWAY_WEPAY; } ] ]; diff --git a/app/Services/DatatableService.php b/app/Services/DatatableService.php index 222a7b4d7cb6..df4c9d93d55d 100644 --- a/app/Services/DatatableService.php +++ b/app/Services/DatatableService.php @@ -60,11 +60,7 @@ class DatatableService $str .= '
'; } - $str .= ' '; + if (!empty($dropdown_contents)) { + $str .= ' '; }); } diff --git a/public/built.js b/public/built.js index 14f82399435f..06790ce1e6ed 100644 --- a/public/built.js +++ b/public/built.js @@ -30933,7 +30933,7 @@ function truncate(string, length){ // Show/hide the 'Select' option in the datalists function actionListHandler() { - $('tbody tr').mouseover(function() { + $('tbody tr .tr-action').closest('tr').mouseover(function() { $(this).closest('tr').find('.tr-action').show(); $(this).closest('tr').find('.tr-status').hide(); }).mouseout(function() { diff --git a/public/js/script.js b/public/js/script.js index a76e6d37cd0e..a66c48768bb6 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -1042,7 +1042,7 @@ function truncate(string, length){ // Show/hide the 'Select' option in the datalists function actionListHandler() { - $('tbody tr').mouseover(function() { + $('tbody tr .tr-action').closest('tr').mouseover(function() { $(this).closest('tr').find('.tr-action').show(); $(this).closest('tr').find('.tr-status').hide(); }).mouseout(function() { diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index ea3ea349f31d..f1adcabadaa3 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -1311,6 +1311,8 @@ $LANG = array( 'created_wepay_confirmation_required' => 'Please check your email and confirm your email address with WePay.', 'switch_to_wepay' => 'Switch to WePay', 'switch' => 'Switch', + 'restore_account_gateway' => 'Restore Gateway', + 'restored_account_gateway' => 'Successfully restored gateway', ); return $LANG; diff --git a/resources/views/accounts/account_gateway.blade.php b/resources/views/accounts/account_gateway.blade.php index 49635e95db38..4bcbc1cc0fb6 100644 --- a/resources/views/accounts/account_gateway.blade.php +++ b/resources/views/accounts/account_gateway.blade.php @@ -94,7 +94,7 @@ {!! Former::text('publishable_key') !!} @endif - @if ($gateway->id == GATEWAY_STRIPE || $gateway->id == GATEWAY_BRAINTREE) + @if ($gateway->id == GATEWAY_STRIPE || $gateway->id == GATEWAY_BRAINTREE || $gateway->id == GATEWAY_WEPAY) {!! Former::select('token_billing_type_id') ->options($tokenBillingOptions) ->help(trans('texts.token_billing_help')) !!} diff --git a/resources/views/accounts/payments.blade.php b/resources/views/accounts/payments.blade.php index 9907fac6ecee..997190ec4f0a 100644 --- a/resources/views/accounts/payments.blade.php +++ b/resources/views/accounts/payments.blade.php @@ -8,7 +8,12 @@ {!! Button::success(trans('texts.switch_to_wepay')) ->asLinkTo(URL::to('/gateways/switch/wepay')) ->appendIcon(Icon::create('circle-arrow-up')) !!} + @endif + @if ($showAdd) {!! Button::primary(trans('texts.add_gateway')) @@ -34,6 +39,14 @@ @stop \ No newline at end of file diff --git a/resources/views/list.blade.php b/resources/views/list.blade.php index 93588fba9806..02faad273954 100644 --- a/resources/views/list.blade.php +++ b/resources/views/list.blade.php @@ -26,7 +26,7 @@ + -onli '; + } + + return $str.'