1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Support recurring buy now buttons

This commit is contained in:
Hillel Coren 2017-01-29 17:32:59 +02:00
parent 742f07bda9
commit d62a672999
5 changed files with 71 additions and 16 deletions

View File

@ -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,

View File

@ -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();

View File

@ -1,6 +1,8 @@
<?php namespace App\Models;
use Eloquent;
use Cache;
use Str;
/**
* Class Frequency
@ -11,4 +13,16 @@ class Frequency extends Eloquent
* @var bool
*/
public $timestamps = false;
public static function selectOptions()
{
$data = [];
foreach (Cache::get('frequencies') as $frequency) {
$name = Str::snake(str_replace(' ', '_', $frequency->name));
$data[$frequency->id] = trans('texts.freq_' . $name);
}
return $data;
}
}

View File

@ -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) {

View File

@ -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) !!}
</div>
{!! 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) !!}
<div id="recurringDiv" style="display:none">
{!! Former::select('frequency_id')
->options(\App\Models\Frequency::selectOptions())
->value(FREQUENCY_MONTHLY) !!}
{!! Former::select('auto_bill')
->options([
AUTO_BILL_OFF => trans('texts.off'),
AUTO_BILL_OPT_IN => trans('texts.opt_in'),
AUTO_BILL_OPT_OUT => trans('texts.opt_out'),
AUTO_BILL_ALWAYS => trans('texts.always'),
]) !!}
</div>
<p>&nbsp;</p>
<div role="tabpanel">
@ -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 += '<input type="hidden" name="redirect_url" value="' + redirectUrl + '"/>' + "\n";
}
if (isRecurring) {
link += "&is_recurring=true&frequency_id=" + frequencyId + "&auto_bill_id=" + autoBillId;
form += '<input type="hidden" name="is_recurring" value="true"/>' + "\n"
+ '<input type="hidden" name="frequency_id" value="' + frequencyId + '"/>' + "\n"
+ '<input type="hidden" name="auto_bill_id" value="' + autoBillId + '"/>' + "\n";
}
form += '<input type="submit" value="Buy Now" name="submit"/>' + "\n" + '</form>';
}