From d62a672999669c9db62e1aa78a59bbd771d329a7 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 29 Jan 2017 17:32:59 +0200 Subject: [PATCH] Support recurring buy now buttons --- app/Http/Controllers/InvoiceController.php | 10 +--- .../Controllers/OnlinePaymentController.php | 8 +++ app/Models/Frequency.php | 14 +++++ app/Ninja/Repositories/InvoiceRepository.php | 2 +- .../views/accounts/client_portal.blade.php | 53 ++++++++++++++++--- 5 files changed, 71 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index fadb5e177c..39b836fdee 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -318,15 +318,7 @@ class InvoiceController extends BaseController 'paymentTerms' => Cache::get('paymentTerms'), 'invoiceDesigns' => InvoiceDesign::getDesigns(), 'invoiceFonts' => Cache::get('fonts'), - 'frequencies' => [ - 1 => trans('texts.freq_weekly'), - 2 => trans('texts.freq_two_weeks'), - 3 => trans('texts.freq_four_weeks'), - 4 => trans('texts.freq_monthly'), - 5 => trans('texts.freq_three_months'), - 6 => trans('texts.freq_six_months'), - 7 => trans('texts.freq_annually'), - ], + 'frequencies' => \App\Models\Frequency::selectOptions(), 'recurringDueDates' => $recurringDueDates, 'recurringHelp' => $recurringHelp, 'recurringDueDateHelp' => $recurringDueDateHelp, diff --git a/app/Http/Controllers/OnlinePaymentController.php b/app/Http/Controllers/OnlinePaymentController.php index ae596b89ea..14c0d8764a 100644 --- a/app/Http/Controllers/OnlinePaymentController.php +++ b/app/Http/Controllers/OnlinePaymentController.php @@ -317,6 +317,11 @@ class OnlinePaymentController extends BaseController $data = [ 'client_id' => $client->id, + 'is_public' => true, + 'is_recurring' => filter_var(Input::get('is_recurring'), FILTER_VALIDATE_BOOLEAN), + 'frequency_id' => Input::get('frequency_id'), + 'auto_bill_id' => Input::get('auto_bill_id'), + 'start_date' => Input::get('start_date', date('Y-m-d')), 'tax_rate1' => $account->default_tax_rate ? $account->default_tax_rate->rate : 0, 'tax_name1' => $account->default_tax_rate ? $account->default_tax_rate->name : '', 'invoice_items' => [[ @@ -329,6 +334,9 @@ class OnlinePaymentController extends BaseController ]] ]; $invoice = $invoiceService->save($data); + if ($invoice->is_recurring) { + $invoice = $this->invoiceRepo->createRecurringInvoice($invoice->fresh()); + } $invitation = $invoice->invitations[0]; $link = $invitation->getLink(); diff --git a/app/Models/Frequency.php b/app/Models/Frequency.php index d4072f3b80..101e6d7c2c 100644 --- a/app/Models/Frequency.php +++ b/app/Models/Frequency.php @@ -1,6 +1,8 @@ name)); + $data[$frequency->id] = trans('texts.freq_' . $name); + } + + return $data; + } } diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index 85d9f3ac3a..c09fbd3703 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -403,7 +403,7 @@ class InvoiceRepository extends BaseRepository } $invoice->invoice_footer = (isset($data['invoice_footer']) && trim($data['invoice_footer'])) ? trim($data['invoice_footer']) : (!$publicId && $account->invoice_footer ? $account->invoice_footer : ''); - $invoice->public_notes = isset($data['public_notes']) ? trim($data['public_notes']) : null; + $invoice->public_notes = isset($data['public_notes']) ? trim($data['public_notes']) : ''; // process date variables if not recurring if(!$invoice->is_recurring) { diff --git a/resources/views/accounts/client_portal.blade.php b/resources/views/accounts/client_portal.blade.php index 10139a0a19..5ad2b0488c 100644 --- a/resources/views/accounts/client_portal.blade.php +++ b/resources/views/accounts/client_portal.blade.php @@ -236,11 +236,6 @@ ->inlineHelp('buy_now_buttons_warning') ->addGroupClass('product-select') !!} - {!! Former::text('redirect_url') - ->onchange('updateBuyNowButtons()') - ->placeholder('https://www.example.com') - ->help('redirect_url_help') !!} - {!! Former::checkboxes('client_fields') ->onchange('updateBuyNowButtons()') ->checkboxes([ @@ -262,6 +257,33 @@ ->options($gateway_types) !!} + {!! Former::text('redirect_url') + ->onchange('updateBuyNowButtons()') + ->placeholder('https://www.example.com') + ->help('redirect_url_help') !!} + + + {!! Former::checkbox('is_recurring') + ->text('enable') + ->label('recurring') + ->onchange('showRecurring();updateBuyNowButtons();') + ->value(1) !!} + + +

 

@@ -367,7 +389,16 @@ iframe.src = '{{ rtrim(SITE_URL ,'/') }}/view/' if (val == '{{ ENTITY_PAYMENT }}') { $('#paymentTypesDiv').fadeIn(); } else { - $('#paymentTypesDiv').hide(); + $('#paymentTypesDiv').fadeOut(); + } + } + + function showRecurring() { + var val = $('input[name=is_recurring]:checked').val() + if (val) { + $('#recurringDiv').fadeIn(); + } else { + $('#recurringDiv').fadeOut(); } } @@ -376,6 +407,9 @@ iframe.src = '{{ rtrim(SITE_URL ,'/') }}/view/' var landingPage = $('input[name=landing_page_type]:checked').val() var paymentType = (landingPage == 'payment') ? '/' + $('#payment_type').val() : '/'; var redirectUrl = $('#redirect_url').val(); + var isRecurring = $('#is_recurring').val(); + var frequencyId = $('#frequency_id').val(); + var autoBillId = $('#auto_bill').val(); var form = ''; var link = ''; @@ -399,6 +433,13 @@ iframe.src = '{{ rtrim(SITE_URL ,'/') }}/view/' form += '' + "\n"; } + if (isRecurring) { + link += "&is_recurring=true&frequency_id=" + frequencyId + "&auto_bill_id=" + autoBillId; + form += '' + "\n" + + '' + "\n" + + '' + "\n"; + } + form += '' + "\n" + ''; }