Working on buy now buttons

This commit is contained in:
Hillel Coren 2016-07-13 12:03:39 +03:00
parent 401851e212
commit fa9b0bf78b
13 changed files with 167 additions and 61 deletions

View File

@ -827,6 +827,7 @@ class AccountController extends BaseController
$account->enable_client_portal_dashboard = !!Input::get('enable_client_portal_dashboard'); $account->enable_client_portal_dashboard = !!Input::get('enable_client_portal_dashboard');
$account->enable_portal_password = !!Input::get('enable_portal_password'); $account->enable_portal_password = !!Input::get('enable_portal_password');
$account->send_portal_password = !!Input::get('send_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 // Only allowed for pro Invoice Ninja users or white labeled self-hosted users
if (Auth::user()->account->hasFeature(FEATURE_CLIENT_PORTAL_CSS)) { if (Auth::user()->account->hasFeature(FEATURE_CLIENT_PORTAL_CSS)) {

View File

@ -214,7 +214,7 @@ class OnlinePaymentController extends BaseController
$account = Account::whereAccountKey(Input::get('account_key'))->first(); $account = Account::whereAccountKey(Input::get('account_key'))->first();
$redirectUrl = Input::get('redirect_url', URL::previous()); $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"); return redirect()->to("{$redirectUrl}/?error=invalid account");
} }
@ -237,6 +237,7 @@ class OnlinePaymentController extends BaseController
} }
$data = [ $data = [
'currency_id' => $account->currency_id,
'contact' => Input::all() 'contact' => Input::all()
]; ];
$client = $clientRepo->save($data); $client = $clientRepo->save($data);

View File

@ -753,6 +753,7 @@ if (!defined('CONTACT_EMAIL')) {
define('FEATURE_TASKS', 'tasks'); define('FEATURE_TASKS', 'tasks');
define('FEATURE_EXPENSES', 'expenses'); define('FEATURE_EXPENSES', 'expenses');
define('FEATURE_REPORTS', 'reports'); define('FEATURE_REPORTS', 'reports');
define('FEATURE_BUY_NOW_BUTTONS', 'buy_now_buttons');
define('FEATURE_API', 'api'); define('FEATURE_API', 'api');
define('FEATURE_CLIENT_PORTAL_PASSWORD', 'client_portal_password'); define('FEATURE_CLIENT_PORTAL_PASSWORD', 'client_portal_password');
define('FEATURE_CUSTOM_URL', 'custom_url'); define('FEATURE_CUSTOM_URL', 'custom_url');

View File

@ -1170,6 +1170,7 @@ class Account extends Eloquent
case FEATURE_MORE_INVOICE_DESIGNS: case FEATURE_MORE_INVOICE_DESIGNS:
case FEATURE_QUOTES: case FEATURE_QUOTES:
case FEATURE_REPORTS: case FEATURE_REPORTS:
case FEATURE_BUY_NOW_BUTTONS:
case FEATURE_API: case FEATURE_API:
case FEATURE_CLIENT_PORTAL_PASSWORD: case FEATURE_CLIENT_PORTAL_PASSWORD:
case FEATURE_CUSTOM_URL: case FEATURE_CUSTOM_URL:

View File

@ -282,19 +282,29 @@ class BasePaymentDriver
private function updateClient() 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)) { if ( ! $this->isGatewayType(GATEWAY_TYPE_CREDIT_CARD)) {
return; 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) { if ( ! $this->accountGateway->show_address || ! $this->accountGateway->update_address) {
return; return;
} }
// update the address info
$client = $this->client(); $client = $this->client();
$client->address1 = trim($this->input['address1']); $client->address1 = trim($this->input['address1']);
$client->address2 = trim($this->input['address2']); $client->address2 = trim($this->input['address2']);

View File

@ -202,6 +202,7 @@ class AccountRepository
['new_user', '/users/create'], ['new_user', '/users/create'],
['custom_fields', '/settings/invoice_settings'], ['custom_fields', '/settings/invoice_settings'],
['invoice_number', '/settings/invoice_settings'], ['invoice_number', '/settings/invoice_settings'],
['buy_now_buttons', '/settings/client_portal#buyNow']
]); ]);
$settings = array_merge(Account::$basicSettings, Account::$advancedSettings); $settings = array_merge(Account::$basicSettings, Account::$advancedSettings);

View File

@ -0,0 +1,55 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddBuyNowButtons extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('accounts', function($table)
{
$table->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');
});
}
}

View File

@ -2034,7 +2034,10 @@ $LANG = array(
'form' => 'Form', 'form' => 'Form',
'link' => 'Link', 'link' => 'Link',
'fields' => 'Fields', '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_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',
); );

View File

@ -26,6 +26,7 @@
{!! Former::populateField('client_view_css', $client_view_css) !!} {!! Former::populateField('client_view_css', $client_view_css) !!}
{!! Former::populateField('enable_portal_password', intval($enable_portal_password)) !!} {!! Former::populateField('enable_portal_password', intval($enable_portal_password)) !!}
{!! Former::populateField('send_portal_password', intval($send_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)) @if (!Utils::isNinja() && !Auth::user()->account->hasFeature(FEATURE_WHITE_LABEL))
<div class="alert alert-warning" style="font-size:larger;"> <div class="alert alert-warning" style="font-size:larger;">
@ -83,15 +84,23 @@
<h3 class="panel-title">{!! trans('texts.buy_now_buttons') !!}</h3> <h3 class="panel-title">{!! trans('texts.buy_now_buttons') !!}</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<div class="col-md-10 col-md-offset-1"> <div class="col-md-10 col-md-offset-1" id="buyNow">
@if (count($gateway_types) && count($products))
{!! Former::checkbox('enable_buy_now_buttons')
->text(trans('texts.enable'))
->label(' ')
->help(trans('texts.enable_buy_now_buttons_help')) !!}
@if ($account->enable_buy_now_buttons)
{!! Former::select('product') {!! Former::select('product')
->onchange('updateBuyNowButtons()') ->onchange('updateBuyNowButtons()')
->addOption('', '') ->addOption('', '')
->inlineHelp('buy_now_buttons_warning') ->inlineHelp('buy_now_buttons_warning')
->addGroupClass('product-select') !!} ->addGroupClass('product-select') !!}
{!! Former::inline_checkboxes('client_fields') {!! Former::checkboxes('client_fields')
->onchange('updateBuyNowButtons()') ->onchange('updateBuyNowButtons()')
->checkboxes([ ->checkboxes([
trans('texts.first_name') => ['value' => 'first_name', 'name' => 'first_name'], trans('texts.first_name') => ['value' => 'first_name', 'name' => 'first_name'],
@ -133,6 +142,16 @@
</div> </div>
</div> </div>
@endif
@else
<center style="font-size:16px;color:#888888;">
{{ trans('texts.buy_now_buttons_disabled') }}
</center>
@endif
</div> </div>
</div> </div>
</div> </div>
@ -148,7 +167,6 @@
->label(trans('texts.custom_css')) ->label(trans('texts.custom_css'))
->rows(10) ->rows(10)
->raw() ->raw()
->autofocus()
->maxlength(60000) ->maxlength(60000)
->style("min-width:100%;max-width:100%;font-family:'Roboto Mono', 'Lucida Console', Monaco, monospace;font-size:14px;'") !!} ->style("min-width:100%;max-width:100%;font-family:'Roboto Mono', 'Lucida Console', Monaco, monospace;font-size:14px;'") !!}
</div> </div>

View File

@ -46,7 +46,11 @@
var $clientSelect = $('select#client'); var $clientSelect = $('select#client');
for (var i=0; i<clients.length; i++) { for (var i=0; i<clients.length; i++) {
var client = clients[i]; var client = clients[i];
$clientSelect.append(new Option(getClientDisplayName(client), client.public_id)); var clientName = getClientDisplayName(client);
if (!clientName) {
continue;
}
$clientSelect.append(new Option(clientName, client.public_id));
} }
if ({{ $clientPublicId ? 'true' : 'false' }}) { if ({{ $clientPublicId ? 'true' : 'false' }}) {

View File

@ -257,7 +257,11 @@
var $clientSelect = $('select#client_id'); var $clientSelect = $('select#client_id');
for (var i=0; i<clients.length; i++) { for (var i=0; i<clients.length; i++) {
var client = clients[i]; var client = clients[i];
$clientSelect.append(new Option(getClientDisplayName(client), client.public_id)); var clientName = getClientDisplayName(client);
if (!clientName) {
continue;
}
$clientSelect.append(new Option(clientName, client.public_id));
} }
$clientSelect.combobox().change(function() { $clientSelect.combobox().change(function() {
onClientChange(); onClientChange();

View File

@ -789,6 +789,9 @@
for (var i=0; i<clients.length; i++) { for (var i=0; i<clients.length; i++) {
var client = clients[i]; var client = clients[i];
var clientName = getClientDisplayName(client); var clientName = getClientDisplayName(client);
if (!clientName) {
continue;
}
for (var j=0; j<client.contacts.length; j++) { for (var j=0; j<client.contacts.length; j++) {
var contact = client.contacts[j]; var contact = client.contacts[j];
var contactName = getContactDisplayName(contact); var contactName = getContactDisplayName(contact);

View File

@ -408,7 +408,11 @@
var $clientSelect = $('select#client'); var $clientSelect = $('select#client');
for (var i=0; i<clients.length; i++) { for (var i=0; i<clients.length; i++) {
var client = clients[i]; var client = clients[i];
$clientSelect.append(new Option(getClientDisplayName(client), client.public_id)); var clientName = getClientDisplayName(client);
if (!clientName) {
continue;
}
$clientSelect.append(new Option(clientName, client.public_id));
} }
if ({{ $clientPublicId ? 'true' : 'false' }}) { if ({{ $clientPublicId ? 'true' : 'false' }}) {