From fa9b0bf78b5f3a17ba712e07a0c3570228d158a6 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 13 Jul 2016 12:03:39 +0300 Subject: [PATCH] Working on buy now buttons --- app/Http/Controllers/AccountController.php | 1 + .../Controllers/OnlinePaymentController.php | 3 +- app/Http/routes.php | 1 + app/Models/Account.php | 1 + .../PaymentDrivers/BasePaymentDriver.php | 20 +++- app/Ninja/Repositories/AccountRepository.php | 1 + .../2016_07_13_083821_add_buy_now_buttons.php | 55 +++++++++ resources/lang/en/texts.php | 3 + .../views/accounts/client_portal.blade.php | 106 ++++++++++-------- resources/views/credits/edit.blade.php | 22 ++-- resources/views/expenses/edit.blade.php | 6 +- resources/views/invoices/edit.blade.php | 3 + resources/views/tasks/edit.blade.php | 6 +- 13 files changed, 167 insertions(+), 61 deletions(-) create mode 100644 database/migrations/2016_07_13_083821_add_buy_now_buttons.php diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 9e6f058c8185..17fac3e3d8ed 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -827,6 +827,7 @@ class AccountController extends BaseController $account->enable_client_portal_dashboard = !!Input::get('enable_client_portal_dashboard'); $account->enable_portal_password = !!Input::get('enable_portal_password'); $account->send_portal_password = !!Input::get('send_portal_password'); + $account->enable_buy_now_buttons = !!Input::get('enable_buy_now_buttons'); // Only allowed for pro Invoice Ninja users or white labeled self-hosted users if (Auth::user()->account->hasFeature(FEATURE_CLIENT_PORTAL_CSS)) { diff --git a/app/Http/Controllers/OnlinePaymentController.php b/app/Http/Controllers/OnlinePaymentController.php index da227f6c74bf..fded55725b66 100644 --- a/app/Http/Controllers/OnlinePaymentController.php +++ b/app/Http/Controllers/OnlinePaymentController.php @@ -214,7 +214,7 @@ class OnlinePaymentController extends BaseController $account = Account::whereAccountKey(Input::get('account_key'))->first(); $redirectUrl = Input::get('redirect_url', URL::previous()); - if ( ! $account) { + if ( ! $account || ! $account->enable_buy_now_buttons || ! $account->hasFeature(FEATURE_BUY_NOW_BUTTONS)) { return redirect()->to("{$redirectUrl}/?error=invalid account"); } @@ -237,6 +237,7 @@ class OnlinePaymentController extends BaseController } $data = [ + 'currency_id' => $account->currency_id, 'contact' => Input::all() ]; $client = $clientRepo->save($data); diff --git a/app/Http/routes.php b/app/Http/routes.php index 195b1b037442..8347210f1812 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -753,6 +753,7 @@ if (!defined('CONTACT_EMAIL')) { define('FEATURE_TASKS', 'tasks'); define('FEATURE_EXPENSES', 'expenses'); define('FEATURE_REPORTS', 'reports'); + define('FEATURE_BUY_NOW_BUTTONS', 'buy_now_buttons'); define('FEATURE_API', 'api'); define('FEATURE_CLIENT_PORTAL_PASSWORD', 'client_portal_password'); define('FEATURE_CUSTOM_URL', 'custom_url'); diff --git a/app/Models/Account.php b/app/Models/Account.php index 56c6829f243b..91dec9537d38 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -1170,6 +1170,7 @@ class Account extends Eloquent case FEATURE_MORE_INVOICE_DESIGNS: case FEATURE_QUOTES: case FEATURE_REPORTS: + case FEATURE_BUY_NOW_BUTTONS: case FEATURE_API: case FEATURE_CLIENT_PORTAL_PASSWORD: case FEATURE_CUSTOM_URL: diff --git a/app/Ninja/PaymentDrivers/BasePaymentDriver.php b/app/Ninja/PaymentDrivers/BasePaymentDriver.php index 0e906ed55853..33e9cd9b259a 100644 --- a/app/Ninja/PaymentDrivers/BasePaymentDriver.php +++ b/app/Ninja/PaymentDrivers/BasePaymentDriver.php @@ -282,19 +282,29 @@ class BasePaymentDriver private function updateClient() { - if ( ! $this->contact()->email && $this->input['email']) { - $this->contact()->email = $this->input['email']; - $this->contact()->save(); - } - if ( ! $this->isGatewayType(GATEWAY_TYPE_CREDIT_CARD)) { return; } + // update the contact info + if ( ! $this->contact()->getFullName()) { + $this->contact()->first_name = $this->input['first_name']; + $this->contact()->last_name = $this->input['last_name']; + } + + if ( ! $this->contact()->email) { + $this->contact()->email = $this->input['email']; + } + + if ($this->contact()->isDirty()) { + $this->contact()->save(); + } + if ( ! $this->accountGateway->show_address || ! $this->accountGateway->update_address) { return; } + // update the address info $client = $this->client(); $client->address1 = trim($this->input['address1']); $client->address2 = trim($this->input['address2']); diff --git a/app/Ninja/Repositories/AccountRepository.php b/app/Ninja/Repositories/AccountRepository.php index 1c6f7f30c35f..0d461d08b4b1 100644 --- a/app/Ninja/Repositories/AccountRepository.php +++ b/app/Ninja/Repositories/AccountRepository.php @@ -202,6 +202,7 @@ class AccountRepository ['new_user', '/users/create'], ['custom_fields', '/settings/invoice_settings'], ['invoice_number', '/settings/invoice_settings'], + ['buy_now_buttons', '/settings/client_portal#buyNow'] ]); $settings = array_merge(Account::$basicSettings, Account::$advancedSettings); diff --git a/database/migrations/2016_07_13_083821_add_buy_now_buttons.php b/database/migrations/2016_07_13_083821_add_buy_now_buttons.php new file mode 100644 index 000000000000..a27c0b09c504 --- /dev/null +++ b/database/migrations/2016_07_13_083821_add_buy_now_buttons.php @@ -0,0 +1,55 @@ +boolean('enable_buy_now_buttons')->default(false); + $table->dropColumn('invoice_design'); + }); + + Schema::table('datetime_formats', function($table) + { + $table->dropColumn('label'); + }); + + Schema::table('date_formats', function($table) + { + $table->dropColumn('label'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('accounts', function($table) + { + $table->dropColumn('enable_buy_now_buttons'); + $table->text('invoice_design')->nullable(); + }); + + Schema::table('datetime_formats', function($table) + { + $table->string('label'); + }); + + Schema::table('date_formats', function($table) + { + $table->string('label'); + }); + } +} diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index e8b9bae2756a..d250e07d5fc4 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2034,7 +2034,10 @@ $LANG = array( 'form' => 'Form', 'link' => 'Link', 'fields' => 'Fields', + 'dwolla' => 'Dwolla', 'buy_now_buttons_warning' => 'Note: client and invoice records are created even if the transaction isn\'t completed.', + 'buy_now_buttons_disabled' => 'This feature requires that a product is created and a payment gateway is configured.', + 'enable_buy_now_buttons_help' => 'Enable support for buy now buttons', ); diff --git a/resources/views/accounts/client_portal.blade.php b/resources/views/accounts/client_portal.blade.php index daf1efa2594e..7e9f43620ace 100644 --- a/resources/views/accounts/client_portal.blade.php +++ b/resources/views/accounts/client_portal.blade.php @@ -26,6 +26,7 @@ {!! Former::populateField('client_view_css', $client_view_css) !!} {!! Former::populateField('enable_portal_password', intval($enable_portal_password)) !!} {!! Former::populateField('send_portal_password', intval($send_portal_password)) !!} +{!! Former::populateField('enable_buy_now_buttons', intval($account->enable_buy_now_buttons)) !!} @if (!Utils::isNinja() && !Auth::user()->account->hasFeature(FEATURE_WHITE_LABEL))
@@ -83,55 +84,73 @@

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

-
+
- {!! Former::select('product') - ->onchange('updateBuyNowButtons()') - ->addOption('', '') - ->inlineHelp('buy_now_buttons_warning') - ->addGroupClass('product-select') !!} + @if (count($gateway_types) && count($products)) - {!! Former::inline_checkboxes('client_fields') - ->onchange('updateBuyNowButtons()') - ->checkboxes([ - trans('texts.first_name') => ['value' => 'first_name', 'name' => 'first_name'], - trans('texts.last_name') => ['value' => 'last_name', 'name' => 'last_name'], - trans('texts.email') => ['value' => 'email', 'name' => 'email'], - ]) !!} + {!! Former::checkbox('enable_buy_now_buttons') + ->text(trans('texts.enable')) + ->label(' ') + ->help(trans('texts.enable_buy_now_buttons_help')) !!} - {!! Former::inline_radios('landing_page') - ->onchange('showPaymentTypes();updateBuyNowButtons();') - ->radios([ - trans('texts.invoice') => ['value' => 'invoice', 'name' => 'landing_page_type'], - trans('texts.payment') => ['value' => 'payment', 'name' => 'landing_page_type'], - ])->check('invoice') !!} + @if ($account->enable_buy_now_buttons) + {!! Former::select('product') + ->onchange('updateBuyNowButtons()') + ->addOption('', '') + ->inlineHelp('buy_now_buttons_warning') + ->addGroupClass('product-select') !!} - + {!! Former::checkboxes('client_fields') + ->onchange('updateBuyNowButtons()') + ->checkboxes([ + trans('texts.first_name') => ['value' => 'first_name', 'name' => 'first_name'], + trans('texts.last_name') => ['value' => 'last_name', 'name' => 'last_name'], + trans('texts.email') => ['value' => 'email', 'name' => 'email'], + ]) !!} -

 

+ {!! Former::inline_radios('landing_page') + ->onchange('showPaymentTypes();updateBuyNowButtons();') + ->radios([ + trans('texts.invoice') => ['value' => 'invoice', 'name' => 'landing_page_type'], + trans('texts.payment') => ['value' => 'payment', 'name' => 'landing_page_type'], + ])->check('invoice') !!} -
- -
-
-
- -
- -
+ + +

 

+ +
+ +
+
+
+ +
+ +
+ + @endif + + @else + +
+ {{ trans('texts.buy_now_buttons_disabled') }} +
+ + @endif
@@ -148,7 +167,6 @@ ->label(trans('texts.custom_css')) ->rows(10) ->raw() - ->autofocus() ->maxlength(60000) ->style("min-width:100%;max-width:100%;font-family:'Roboto Mono', 'Lucida Console', Monaco, monospace;font-size:14px;'") !!}
diff --git a/resources/views/credits/edit.blade.php b/resources/views/credits/edit.blade.php index 5c8377038f21..5b4c7ae24dec 100644 --- a/resources/views/credits/edit.blade.php +++ b/resources/views/credits/edit.blade.php @@ -2,12 +2,12 @@ @section('content') - + {!! Former::open($url)->addClass('col-md-10 col-md-offset-1 warn-on-exit')->method($method)->rules(array( 'client' => 'required', - 'amount' => 'required', + 'amount' => 'required', )) !!} - +
@@ -38,23 +38,27 @@ -@stop \ No newline at end of file +@stop diff --git a/resources/views/expenses/edit.blade.php b/resources/views/expenses/edit.blade.php index dce6caafb4a6..a555ed4c09bb 100644 --- a/resources/views/expenses/edit.blade.php +++ b/resources/views/expenses/edit.blade.php @@ -257,7 +257,11 @@ var $clientSelect = $('select#client_id'); for (var i=0; i