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))
+ {!! 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') !!} -
+ +