diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 5ce42356bf83..053d5cb66a58 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -430,7 +430,14 @@ class AccountController extends BaseController if ($count == 0) { return Redirect::to('gateways/create'); } else { + $switchToWepay = WEPAY_CLIENT_ID && !$account->getGatewayConfig(GATEWAY_WEPAY); + + if ($switchToWepay && $account->token_billing_type_id != TOKEN_BILLING_DISABLED) { + $switchToWepay = !$account->getGatewayConfig(GATEWAY_BRAINTREE) && !$account->getGatewayConfig(GATEWAY_STRIPE); + } + return View::make('accounts.payments', [ + 'showSwitchToWepay' => $switchToWepay, 'showAdd' => $count < count(Gateway::$paymentTypes), 'title' => trans('texts.online_payments') ]); diff --git a/app/Http/Controllers/AccountGatewayController.php b/app/Http/Controllers/AccountGatewayController.php index c430fb61d816..a192538480e9 100644 --- a/app/Http/Controllers/AccountGatewayController.php +++ b/app/Http/Controllers/AccountGatewayController.php @@ -410,7 +410,7 @@ class AccountGatewayController extends BaseController 'original_ip' => \Request::getClientIp(true), 'original_device' => \Request::server('HTTP_USER_AGENT'), 'tos_acceptance_time' => time(), - 'redirect_uri' => URL::to('/gateways'), + 'redirect_uri' => URL::to('gateways'), 'callback_uri' => URL::to('https://sometechie.ngrok.io/paymenthook/'.$account->account_key.'/'.GATEWAY_WEPAY), 'scope' => 'manage_accounts,collect_payments,view_user,preapprove_payments,send_money', )); @@ -437,6 +437,10 @@ class AccountGatewayController extends BaseController } } + if (($gateway = $account->getGatewayByType(PAYMENT_TYPE_CREDIT_CARD)) || ($gateway = $account->getGatewayByType(PAYMENT_TYPE_STRIPE))) { + $gateway->delete(); + } + $accountGateway = AccountGateway::createNew(); $accountGateway->gateway_id = GATEWAY_WEPAY; $accountGateway->setConfig(array( @@ -486,4 +490,18 @@ class AccountGatewayController extends BaseController return Redirect::to("gateways/{$accountGateway->public_id}/edit"); } + + public function switchToWepay() + { + $data = self::getViewModel(); + $data['url'] = 'gateways'; + $data['method'] = 'POST'; + unset($data['gateways']); + + if ( ! \Request::secure() && ! Utils::isNinjaDev()) { + Session::flash('warning', trans('texts.enable_https')); + } + + return View::make('accounts.account_gateway_switch_wepay', $data); + } } diff --git a/app/Http/routes.php b/app/Http/routes.php index 292d6128a070..2c12c215cfd3 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -243,6 +243,7 @@ Route::group([ Route::resource('gateways', 'AccountGatewayController'); Route::get('gateways/{public_id}/resend_confirmation', 'AccountGatewayController@resendConfirmation'); + Route::get('gateways/switch/wepay', 'AccountGatewayController@switchToWepay'); Route::get('api/gateways', array('as'=>'api.gateways', 'uses'=>'AccountGatewayController@getDatatable')); Route::post('account_gateways/bulk', 'AccountGatewayController@bulk'); diff --git a/app/Models/AccountGateway.php b/app/Models/AccountGateway.php index 6de95e8593cf..0c281856be66 100644 --- a/app/Models/AccountGateway.php +++ b/app/Models/AccountGateway.php @@ -77,7 +77,7 @@ class AccountGateway extends EntityModel return !empty($this->getConfigField('enableAch')); } - public function getPayPAlEnabled() + public function getPayPalEnabled() { return !empty($this->getConfigField('enablePayPal')); } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 25f9fdd6fabb..ea3ea349f31d 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -1308,7 +1308,9 @@ $LANG = array( 'manage_wepay_account' => 'Manage WePay Account', 'action_required' => 'Action Required', 'finish_setup' => 'Finish Setup', - 'created_wepay_confirmation_required' => 'Please check your email and confirm your email address with WePay.' + 'created_wepay_confirmation_required' => 'Please check your email and confirm your email address with WePay.', + 'switch_to_wepay' => 'Switch to WePay', + 'switch' => 'Switch', ); return $LANG; diff --git a/resources/views/accounts/account_gateway.blade.php b/resources/views/accounts/account_gateway.blade.php index 72acd1cff05a..49635e95db38 100644 --- a/resources/views/accounts/account_gateway.blade.php +++ b/resources/views/accounts/account_gateway.blade.php @@ -5,43 +5,8 @@ @include('accounts.nav', ['selected' => ACCOUNT_PAYMENTS]) - @if(!$accountGateway && WEPAY_CLIENT_ID) - {!! Former::open($url)->method($method)->rules(array( - 'first_name' => 'required', - 'last_name' => 'required', - 'email' => 'required', - 'description' => 'required', - 'company_name' => 'required', - 'tos_agree' => 'required', - ))->addClass('warn-on-exit') !!} - {!! Former::populateField('company_name', $account->getDisplayName()) !!} - {!! Former::populateField('first_name', $user->first_name) !!} - {!! Former::populateField('last_name', $user->last_name) !!} - {!! Former::populateField('email', $user->email) !!} -
-
-

{!! trans('texts.online_payments') !!}

-
-
- {!! Former::text('first_name') !!} - {!! Former::text('last_name') !!} - {!! Former::text('email') !!} - {!! Former::text('company_name')->help('wepay_company_name_help')->maxlength(255) !!} - {!! Former::text('description')->help('wepay_description_help') !!} - {!! Former::checkbox('tos_agree')->label(' ')->text(trans('texts.wepay_tos_agree', - ['link'=>''.trans('texts.wepay_tos_link_text').''] - ))->value('true') !!} -
- {!! Button::primary(trans('texts.sign_up_with_wepay')) - ->submit() - ->large() !!}

- {{ trans('texts.use_another_provider') }} -
-
-
- - - {!! Former::close() !!} + @if(!$accountGateway && WEPAY_CLIENT_ID && !$account->getGatewayByType(PAYMENT_TYPE_CREDIT_CARD) && !$account->getGatewayByType(PAYMENT_TYPE_STRIPE)) + @include('accounts.partials.account_gateway_wepay') @endif
diff --git a/resources/views/accounts/account_gateway_switch_wepay.blade.php b/resources/views/accounts/account_gateway_switch_wepay.blade.php new file mode 100644 index 000000000000..ae851881bed0 --- /dev/null +++ b/resources/views/accounts/account_gateway_switch_wepay.blade.php @@ -0,0 +1,7 @@ +@extends('header') + +@section('content') + @parent + @include('accounts.nav', ['selected' => ACCOUNT_PAYMENTS]) + @include('accounts.partials.account_gateway_wepay') +@stop \ No newline at end of file diff --git a/resources/views/accounts/partials/account_gateway_wepay.blade.php b/resources/views/accounts/partials/account_gateway_wepay.blade.php new file mode 100644 index 000000000000..edda271d1479 --- /dev/null +++ b/resources/views/accounts/partials/account_gateway_wepay.blade.php @@ -0,0 +1,39 @@ +{!! Former::open($url)->method($method)->rules(array( + 'first_name' => 'required', + 'last_name' => 'required', + 'email' => 'required', + 'description' => 'required', + 'company_name' => 'required', + 'tos_agree' => 'required', + ))->addClass('warn-on-exit') !!} +{!! Former::populateField('company_name', $account->getDisplayName()) !!} +{!! Former::populateField('first_name', $user->first_name) !!} +{!! Former::populateField('last_name', $user->last_name) !!} +{!! Former::populateField('email', $user->email) !!} +
+
+

{!! trans('texts.online_payments') !!}

+
+
+ {!! Former::text('first_name') !!} + {!! Former::text('last_name') !!} + {!! Former::text('email') !!} + {!! Former::text('company_name')->help('wepay_company_name_help')->maxlength(255) !!} + {!! Former::text('description')->help('wepay_description_help') !!} + {!! Former::checkbox('tos_agree')->label(' ')->text(trans('texts.wepay_tos_agree', + ['link'=>''.trans('texts.wepay_tos_link_text').''] + ))->value('true') !!} +
+ {!! Button::primary(trans('texts.sign_up_with_wepay')) + ->submit() + ->large() !!} + @if(isset($gateways)) +

+ {{ trans('texts.use_another_provider') }} + @endif +
+
+
+ + +{!! Former::close() !!} \ No newline at end of file diff --git a/resources/views/accounts/payments.blade.php b/resources/views/accounts/payments.blade.php index d2fcde895200..9907fac6ecee 100644 --- a/resources/views/accounts/payments.blade.php +++ b/resources/views/accounts/payments.blade.php @@ -4,6 +4,12 @@ @parent @include('accounts.nav', ['selected' => ACCOUNT_PAYMENTS]) + @if ($showSwitchToWepay) + {!! 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')) ->asLinkTo(URL::to('/gateways/create'))