diff --git a/app/Http/Controllers/AccountGatewayController.php b/app/Http/Controllers/AccountGatewayController.php index 09a17ede065e..e4b907d33dbe 100644 --- a/app/Http/Controllers/AccountGatewayController.php +++ b/app/Http/Controllers/AccountGatewayController.php @@ -119,9 +119,9 @@ class AccountGatewayController extends BaseController $creditCards = []; foreach ($creditCardsArray as $card => $name) { if ($selectedCards > 0 && ($selectedCards & $card) == $card) { - $creditCards[$name['text']] = ['value' => $card, 'data-imageUrl' => asset($name['card']), 'checked' => 'checked']; + $creditCards['
' . $name['text'] . '
'] = ['value' => $card, 'data-imageUrl' => asset($name['card']), 'checked' => 'checked']; } else { - $creditCards[$name['text']] = ['value' => $card, 'data-imageUrl' => asset($name['card'])]; + $creditCards['
' . $name['text'] . '
'] = ['value' => $card, 'data-imageUrl' => asset($name['card'])]; } } @@ -316,6 +316,7 @@ class AccountGatewayController extends BaseController $accountGateway->accepted_credit_cards = $cardCount; $accountGateway->show_address = Input::get('show_address') ? true : false; + $accountGateway->show_shipping_address = Input::get('show_shipping_address') ? true : false; $accountGateway->update_address = Input::get('update_address') ? true : false; $accountGateway->setConfig($config); diff --git a/app/Ninja/PaymentDrivers/BasePaymentDriver.php b/app/Ninja/PaymentDrivers/BasePaymentDriver.php index 43092b1a194b..71c704b0bcca 100644 --- a/app/Ninja/PaymentDrivers/BasePaymentDriver.php +++ b/app/Ninja/PaymentDrivers/BasePaymentDriver.php @@ -173,7 +173,6 @@ class BasePaymentDriver 'accountGateway' => $this->accountGateway, 'acceptedCreditCardTypes' => $this->accountGateway->getCreditcardTypes(), 'gateway' => $gateway, - 'showAddress' => $this->accountGateway->show_address, 'showBreadcrumbs' => false, 'url' => $url, 'amount' => $this->invoice()->getRequestedAmount(), @@ -407,18 +406,32 @@ class BasePaymentDriver $this->contact()->save(); } + // update the address info + if ($this->accountGateway->update_address) { + $client = $this->client(); + if ($this->accountGateway->show_address) { + $client->address1 = trim($this->input['address1']); + $client->address2 = trim($this->input['address2']); + $client->city = trim($this->input['city']); + $client->state = trim($this->input['state']); + $client->postal_code = trim($this->input['postal_code']); + $client->country_id = trim($this->input['country_id']); + } + if ($this->accountGateway->show_shipping_address) { + $client->shipping_address1 = trim($this->input['shipping_address1']); + $client->shipping_address2 = trim($this->input['shipping_address2']); + $client->shipping_city = trim($this->input['shipping_city']); + $client->shipping_state = trim($this->input['shipping_state']); + $client->shipping_postal_code = trim($this->input['shipping_postal_code']); + $client->shipping_country_id = trim($this->input['shipping_country_id']); + } + } + 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']); - $client->city = trim($this->input['city']); - $client->state = trim($this->input['state']); - $client->postal_code = trim($this->input['postal_code']); - $client->country_id = trim($this->input['country_id']); + $client->save(); } diff --git a/database/migrations/2017_11_15_114422_add_subdomain_to_lookups.php b/database/migrations/2017_11_15_114422_add_subdomain_to_lookups.php index 23522d925241..3469fa0ff5e5 100644 --- a/database/migrations/2017_11_15_114422_add_subdomain_to_lookups.php +++ b/database/migrations/2017_11_15_114422_add_subdomain_to_lookups.php @@ -36,7 +36,11 @@ class AddSubdomainToLookups extends Migration }); Schema::table('clients', function ($table) { - $table->foreign('shipping_country_id')->references('id')->on('currencies'); + $table->foreign('shipping_country_id')->references('id')->on('countries'); + }); + + Schema::table('account_gateways', function ($table) { + $table->boolean('show_shipping_address')->default(false)->nullable(); }); } @@ -65,5 +69,9 @@ class AddSubdomainToLookups extends Migration $table->dropColumn('shipping_postal_code'); $table->dropColumn('shipping_country_id'); }); + + Schema::table('account_gateways', function ($table) { + $table->dropColumn('show_shipping_address'); + }); } } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index bc9818114bf6..8663234cccc9 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2541,6 +2541,8 @@ $LANG = array( 'shipping_postal_code' => 'Shipping Postal Code', 'shipping_country' => 'Shipping Country', 'classify' => 'Classify', + 'show_shipping_address_help' => 'Require client to provide their shipping address', + 'ship_to_billing_address' => 'Ship to billing address', ); diff --git a/resources/views/accounts/account_gateway.blade.php b/resources/views/accounts/account_gateway.blade.php index 18c34f0fd819..6b6150027a9b 100644 --- a/resources/views/accounts/account_gateway.blade.php +++ b/resources/views/accounts/account_gateway.blade.php @@ -1,5 +1,20 @@ @extends('header') +@section('head') + @parent + + +@stop + + @section('top-right') @if (env('WEPAY_CLIENT_ID') && isset($accountGatewaysIds) && ! count($accountGatewaysIds)) {!! Button::primary(trans('texts.sign_up_with_wepay')) @@ -23,6 +38,7 @@ {!! Former::populateField('primary_gateway_id', $accountGateway->gateway_id) !!} {!! Former::populateField('recommendedGateway_id', $accountGateway->gateway_id) !!} {!! Former::populateField('show_address', intval($accountGateway->show_address)) !!} + {!! Former::populateField('show_shipping_address', intval($accountGateway->show_shipping_address)) !!} {!! Former::populateField('update_address', intval($accountGateway->update_address)) !!} {!! Former::populateField('publishable_key', $accountGateway->getPublishableStripeKey() ? str_repeat('*', strlen($accountGateway->getPublishableStripeKey())) : '') !!} {!! Former::populateField('enable_ach', $accountGateway->getAchEnabled() ? 1 : 0) !!} @@ -142,6 +158,12 @@ ->addGroupClass('gateway-option') ->value(1) !!} + {!! Former::checkbox('show_shipping_address') + ->label(trans('texts.shipping_address')) + ->text(trans('texts.show_shipping_address_help')) + ->addGroupClass('gateway-option') + ->value(1) !!} + {!! Former::checkbox('update_address') ->label(' ') ->text(trans('texts.update_address_help')) @@ -153,8 +175,10 @@ ->checkboxes($creditCardTypes) ->class('creditcard-types') ->addGroupClass('gateway-option') + ->inline() ->value(1) !!} +
@if (!$accountGateway || $accountGateway->gateway_id == GATEWAY_STRIPE) @@ -279,14 +303,9 @@ } function enableUpdateAddress(event) { - var disabled = !$('#show_address').is(':checked'); + var disabled = ! $('#show_address').is(':checked') && ! $('#show_shipping_address').is(':checked'); $('#update_address').prop('disabled', disabled); $('label[for=update_address]').css('color', disabled ? '#888' : '#000'); - if (disabled) { - $('#update_address').prop('checked', false); - } else if (event) { - $('#update_address').prop('checked', true); - } } function updateWebhookShown() { @@ -306,7 +325,7 @@ setFieldsShown(); updateWebhookShown(); - $('#show_address').change(enableUpdateAddress); + $('#show_address, #show_shipping_address').change(enableUpdateAddress); enableUpdateAddress(); $('#enable_ach').change(updateWebhookShown); diff --git a/resources/views/clients/edit.blade.php b/resources/views/clients/edit.blade.php index 29e23538e033..e15227c357a4 100644 --- a/resources/views/clients/edit.blade.php +++ b/resources/views/clients/edit.blade.php @@ -39,7 +39,7 @@
-

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

+

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

diff --git a/resources/views/clients/show.blade.php b/resources/views/clients/show.blade.php index d2c882ba8c38..cb376b938145 100644 --- a/resources/views/clients/show.blade.php +++ b/resources/views/clients/show.blade.php @@ -98,11 +98,6 @@

{{ trans('texts.vat_number').': '.$client->vat_number }}

@endif - {!! $client->present()->address(ADDRESS_BILLING) !!} - {!! $client->present()->address(ADDRESS_SHIPPING) !!} - -
- @if ($client->account->custom_client_label1 && $client->custom_value1) {{ $client->account->custom_client_label1 . ': ' . $client->custom_value1 }}
@endif @@ -144,6 +139,14 @@

{{ $client->present()->paymentTerms }}

+
+

{{ trans('texts.address') }}

+ + {!! $client->present()->address(ADDRESS_BILLING) !!}
+ {!! $client->present()->address(ADDRESS_SHIPPING) !!} + +
+

{{ trans('texts.contacts') }}

@foreach ($client->contacts as $contact) @@ -173,7 +176,7 @@ @endforeach
-
+

{{ trans('texts.standing') }} diff --git a/resources/views/payments/credit_card.blade.php b/resources/views/payments/credit_card.blade.php index 19af5a9e48de..e73e716f44bd 100644 --- a/resources/views/payments/credit_card.blade.php +++ b/resources/views/payments/credit_card.blade.php @@ -24,6 +24,32 @@ return true; }); + $('#shipToBillingAddress').click(function() { + var checked = $('#shipToBillingAddress').is(':checked'); + var fields = [ + 'address1', + 'address2', + 'city', + 'state', + 'postal_code', + 'country_id', + ] + $.each(fields, function(i, field) { + if (checked) { + $('#shipping_' + field).val($('#' + field).val()); + } else { + $('#shipping_' + field).val(''); + } + }) + if (checked) { + $('#shipping_country_id').combobox('refresh'); + } else { + $('#shipping_country_id').combobox('toggle'); + $('#shipping_address1').focus(); + } + + }) + @if ($accountGateway->gateway_id != GATEWAY_BRAINTREE) var card = new Card({ form: 'form#payment-form', // *required* @@ -91,6 +117,11 @@ 'routing_number' => 'required', 'account_holder_name' => 'required', 'account_holder_type' => 'required', + 'shipping_address1' => 'required', + 'shipping_city' => 'required', + 'shipping_state' => 'required', + 'shipping_postal_code' => 'required', + 'shipping_country_id' => 'required', )) !!} @@ -101,6 +132,7 @@ {{ Former::populateField('email', $contact->email) }} @if (!$client->country_id && $client->account->country_id) {{ Former::populateField('country_id', $client->account->country_id) }} + {{ Former::populateField('shipping_country_id', $client->account->country_id) }} @endif @if (!$client->currency_id && $client->account->currency_id) {{ Former::populateField('currency_id', $client->account->currency_id) }} @@ -153,8 +185,8 @@

 
 

- @if (!empty($showAddress)) -

{{ trans('texts.billing_address') }} {{ trans('texts.payment_footer1') }}

+ @if (!empty($accountGateway->show_address)) +

{{ trans('texts.billing_address') }}    {{ trans('texts.payment_footer1') }}

{!! Former::text('address1') @@ -202,6 +234,62 @@

 
 

@endif + @if (!empty($accountGateway->show_shipping_address)) +

{{ trans('texts.shipping_address') }}    + + + +

+
+
+ {!! Former::text('shipping_address1') + ->autocomplete('shipping address-line1') + ->placeholder(trans('texts.address1')) + ->label('') !!} +
+
+ {!! Former::text('shipping_address2') + ->autocomplete('shipping address-line2') + ->placeholder(trans('texts.address2')) + ->label('') !!} +
+
+
+
+ {!! Former::text('shipping_city') + ->autocomplete('shipping address-level2') + ->placeholder(trans('texts.city')) + ->label('') !!} +
+
+ {!! Former::text('shipping_state') + ->autocomplete('shipping address-level1') + ->placeholder(trans('texts.state')) + ->label('') !!} +
+
+
+
+ {!! Former::text('shipping_postal_code') + ->autocomplete('shipping postal-code') + ->placeholder(trans('texts.postal_code')) + ->label('') !!} +
+
+ {!! Former::select('shipping_country_id') + ->placeholder(trans('texts.country_id')) + ->fromQuery($countries, 'name', 'id') + ->addGroupClass('shipping-country-select') + ->label('') !!} +
+
+ +

 
 

+ @endif + @if ($accountGateway->isGateway(GATEWAY_WEPAY) && $account->token_billing_type_id == TOKEN_BILLING_DISABLED) {{--- do nothing ---}} @else diff --git a/resources/views/payments/payment_method.blade.php b/resources/views/payments/payment_method.blade.php index a05f983638fd..e3a4f5eaa47d 100644 --- a/resources/views/payments/payment_method.blade.php +++ b/resources/views/payments/payment_method.blade.php @@ -67,7 +67,7 @@ $(this).css({color:'#444444'}); }); - $('#country_id').combobox(); + $('#country_id, #shipping_country_id').combobox(); $('#currency_id').combobox(); $('#first_name').focus(); });