kaui 3.0.3 → 3.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/kaui/account_timelines_controller.rb +117 -0
  3. data/app/controllers/kaui/accounts_controller.rb +50 -7
  4. data/app/controllers/kaui/audit_logs_controller.rb +37 -0
  5. data/app/controllers/kaui/bundles_controller.rb +5 -1
  6. data/app/controllers/kaui/engine_controller.rb +3 -28
  7. data/app/controllers/kaui/engine_controller_util.rb +8 -2
  8. data/app/controllers/kaui/invoices_controller.rb +54 -29
  9. data/app/controllers/kaui/payments_controller.rb +69 -9
  10. data/app/controllers/kaui/sessions_controller.rb +7 -0
  11. data/app/helpers/kaui/exception_helper.rb +25 -0
  12. data/app/helpers/kaui/subscription_helper.rb +5 -1
  13. data/app/models/kaui/account.rb +9 -0
  14. data/app/models/kaui/invoice.rb +2 -0
  15. data/app/models/kaui/payment.rb +7 -0
  16. data/app/views/kaui/account_timelines/_multi_functions_bar.html.erb +155 -0
  17. data/app/views/kaui/account_timelines/show.html.erb +2 -0
  18. data/app/views/kaui/accounts/_account_info.html.erb +7 -0
  19. data/app/views/kaui/accounts/_multi_functions_bar.html.erb +329 -0
  20. data/app/views/kaui/accounts/index.html.erb +32 -18
  21. data/app/views/kaui/audit_logs/_multi_functions_bar.html.erb +189 -0
  22. data/app/views/kaui/audit_logs/index.html.erb +8 -0
  23. data/app/views/kaui/bundles/index.html.erb +34 -0
  24. data/app/views/kaui/errors/500.html.erb +29 -0
  25. data/app/views/kaui/invoices/_multi_functions_bar.html.erb +322 -0
  26. data/app/views/kaui/invoices/index.html.erb +49 -24
  27. data/app/views/kaui/payments/_multi_functions_bar.html.erb +323 -0
  28. data/app/views/kaui/payments/index.html.erb +73 -30
  29. data/config/locales/en.yml +3 -0
  30. data/config/routes.rb +7 -0
  31. data/lib/kaui/error_handler.rb +37 -0
  32. data/lib/kaui/version.rb +1 -1
  33. data/lib/kaui.rb +117 -30
  34. metadata +13 -19
@@ -1,14 +1,11 @@
1
1
  <div class="search">
2
-
3
2
  <div class="column-block">
4
-
5
3
  <h1>Invoices</h1>
6
-
7
- <table id="invoices-table" class="table table-condensed mobile-data">
4
+ <%= render :partial => 'multi_functions_bar' %>
5
+ <table id="invoices-table" class="table table-condensed mobile-data" style="width:100%">
8
6
  <thead>
9
7
  <tr>
10
- <th>Number</th>
11
- <% (@account.account_id.blank? ? Kaui.invoice_search_columns : Kaui.account_invoices_columns).call()[0].each do |title| %>
8
+ <% Kaui.account_invoices_columns.call[0].each do |title| %>
12
9
  <th><%= title %></th>
13
10
  <% end %>
14
11
  </tr>
@@ -19,30 +16,44 @@
19
16
  </tr>
20
17
  </tbody>
21
18
  </table>
22
-
23
19
  </div>
24
-
25
20
  </div>
26
21
 
22
+ <style>
23
+ #invoices-table td, #invoices-table tr {
24
+ white-space: nowrap;
25
+ }
26
+ </style>
27
+
27
28
  <%= javascript_tag do %>
28
29
  $(document).ready(function() {
30
+ var stateKey = 'DataTables_invoices-table';
31
+ var state = JSON.parse(localStorage.getItem(stateKey));
32
+ if (state) {
33
+ state.start = <%= @offset %>;
34
+ state.search = { search: "<%= @search_query %>" };
35
+ localStorage.setItem(stateKey, JSON.stringify(state));
36
+ }
37
+
29
38
  var table = $('#invoices-table').DataTable({
30
- <% if @account.account_id.blank? %>
31
- "dom": "<'row'r>t<'row'<'col-md-6'i><'col-md-6'p>>",
32
- "pagingType": <% if @max_nb_records.nil? -%>"simple"<% else -%>"full_numbers"<% end -%>,
33
- "language": {
34
- <!-- See DefaultPaginationSqlDaoHelper.java -->
35
- "info": <% if @max_nb_records.nil? -%>"Showing _START_ to _END_ of <%= number_with_delimiter(Kaui::EngineControllerUtil::SIMPLE_PAGINATION_THRESHOLD) -%>+ entries"<% else -%>"Showing _START_ to _END_ of _TOTAL_ entries"<% end -%>
36
- },
37
- "pageLength": <%= @limit %>,
38
- "displayStart": <%= @offset %>,
39
- "ajax": "<%= invoices_pagination_path(:ordering => @ordering, :format => :json) %>",
40
- <% else %>
41
- // No paging for per-account listings
42
- "dom": "t",
43
- "paging": false,
44
- "ajax": "<%= invoices_pagination_path :format => :json %>",
45
- <% end %>
39
+ "colReorder": {
40
+ "enable": false
41
+ },
42
+ "stateSave": true,
43
+ "stateSaveCallback": function(settings, data) {
44
+ localStorage.setItem('DataTables_invoices-table', JSON.stringify(data));
45
+ },
46
+ "stateLoadCallback": function(settings) {
47
+ return JSON.parse(localStorage.getItem('DataTables_invoices-table'));
48
+ },
49
+ "scrollX": true,
50
+ "dom": "<'row'r>t<'row'<'col-md-6'i><'col-md-6'p>>",
51
+ "pagingType": <% if @max_nb_records.nil? -%>"simple"<% else -%>"full_numbers"<% end -%>,
52
+ "language": {
53
+ "info": <% if @max_nb_records.nil? -%>"Showing _START_ to _END_ of <%= number_with_delimiter(Kaui::EngineControllerUtil::SIMPLE_PAGINATION_THRESHOLD) -%>+ entries"<% else -%>"Showing _START_ to _END_ of _TOTAL_ entries"<% end -%>
54
+ },
55
+ "pageLength": <%= @limit %>,
56
+ "displayStart": <%= @offset %>,
46
57
  <% if @search_query.blank? %>
47
58
  "ordering": false,
48
59
  <% elsif !@ordering.blank? %>
@@ -51,6 +62,20 @@ $(document).ready(function() {
51
62
  "processing": true,
52
63
  "serverSide": true,
53
64
  "search": {"search": "<%= @search_query %>"},
65
+ "ajax": {
66
+ url: "<%= invoices_pagination_path(:ordering => @ordering, :format => :json) %>",
67
+ dataSrc: function(json) {
68
+ var colOrder = table.colReorder.order();
69
+ var reorderedData = json.data.map(function(row) {
70
+ var newRow = [];
71
+ for (var i = 0; i < colOrder.length; i++) {
72
+ newRow.push(row[colOrder[i]]);
73
+ }
74
+ return newRow;
75
+ });
76
+ return reorderedData;
77
+ }
78
+ }
54
79
  });
55
80
 
56
81
  <!-- When we don't know the total number of pages, we need to hide the legend and next button manually -->
@@ -0,0 +1,323 @@
1
+ <div class="dropdown-container">
2
+ <button class="btn btn-default download-button-right" type="button" id="modalDownloadButton">
3
+ <i class="glyphicon glyphicon-download-alt"></i>
4
+ <strong>Download CSV</strong>
5
+ </button>
6
+ <div class="dropdown">
7
+ <button class="btn btn-default dropdown-toggle toggle-button-right" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
8
+ <i class="glyphicon glyphicon-cog"></i>
9
+ <strong>Edit Columns</strong>
10
+ </button>
11
+ <ul class="dropdown-menu" id="column-visibility" aria-labelledby="v">
12
+ <% Kaui.account_payments_columns.call()[0].each_with_index do |title, index| %>
13
+ <li class="list-group-item-manual" data-id="<%= index %>">
14
+ <label class="label-group-item-manual">
15
+ <input type="checkbox" class="column-toggle" draggable="true" data-column="<%= index %>" checked> <%= title %>
16
+ <span class="glyphicon glyphicon-option-vertical icon-drag" aria-hidden="true"></span>
17
+ </label>
18
+ </li>
19
+ <% end %>
20
+ </ul>
21
+ </div>
22
+ </div>
23
+
24
+ <div class="modal fade" id="downloadCsvModal" tabindex="-1" role="dialog" aria-labelledby="downloadCsvModalLabel" aria-hidden="true">
25
+ <div class="modal-dialog" role="document">
26
+ <div class="modal-content">
27
+ <div class="modal-header">
28
+ <h3 class="modal-title" id="downloadCsvModalLabel">Download</h3>
29
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close">
30
+ <span aria-hidden="true">&times;</span>
31
+ </button>
32
+ </div>
33
+ <div class="modal-body">
34
+ <form id="downloadCsvForm">
35
+ <div class="row">
36
+ <div class="col-md-6">
37
+ <div class="form-group">
38
+ <label for="startDate">Payment Date From:</label>
39
+ <input type="text" class="form-control" id="startDate" name="startDate">
40
+ </div>
41
+ </div>
42
+ <div class="col-md-6">
43
+ <div class="form-group">
44
+ <label for="endDate">To:</label>
45
+ <input type="text" class="form-control" id="endDate" name="endDate">
46
+ </div>
47
+ </div>
48
+ </div>
49
+ <div class="row">
50
+ <div class="col-md-6">
51
+ <div class="form-check">
52
+ <div>
53
+ <input type="radio" id="customDate" name="download_option" value="customDate">
54
+ <label for="customDate">Custom date</label>
55
+ </div>
56
+ <div>
57
+ <input type="radio" id="allData" name="download_option" value="all">
58
+ <label for="allData">All payments</label>
59
+ </div>
60
+ <div>
61
+ <input type="radio" id="thisWeek" name="download_option" value="thisWeek">
62
+ <label for="thisWeek">This week</label>
63
+ </div>
64
+ <div>
65
+ <input type="radio" id="thisMonth" name="download_option" value="thisMonth">
66
+ <label for="thisMonth">This month</label>
67
+ </div>
68
+ <div>
69
+ <input type="radio" id="thisYear" name="download_option" value="thisYear">
70
+ <label for="thisYear">This year</label>
71
+ </div>
72
+ </div>
73
+ </div>
74
+ </div>
75
+ <div class="row">
76
+ <div class="col-md-12">
77
+ <h5>Additional Options</h5>
78
+ </div>
79
+ </div>
80
+ <div class="row">
81
+ <div class="col-md-6">
82
+ <div class="form-check">
83
+ <input type="checkbox" class="form-check-input" id="allFields" name="allFields">
84
+ <label class="form-check-label" for="allFields">All fields</label>
85
+ </div>
86
+ </div>
87
+ </div>
88
+ </form>
89
+ </div>
90
+ <div class="modal-footer">
91
+ <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
92
+ <button type="button" class="btn btn-primary" id="downloadButton">Download</button>
93
+ </div>
94
+ </div>
95
+ </div>
96
+ </div>
97
+
98
+ <style>
99
+ .dropdown-menu#column-visibility {
100
+ max-height: 300px;
101
+ width: 220px;
102
+ overflow-y: auto;
103
+ }
104
+
105
+ .dropdown-menu {
106
+ padding: 5px;
107
+ }
108
+
109
+ .dropdown-menu#column-visibility::before {
110
+ content: 'Drag to reorder columns';
111
+ display: block;
112
+ height: 30px;
113
+ text-align: center;
114
+ color: darkgrey;
115
+ padding-top: 5px;
116
+ }
117
+
118
+ .toggle-button-right {
119
+ float: right;
120
+ margin-bottom: 10px;
121
+ margin-left: 10px;
122
+ background-color: white;
123
+ color: black;
124
+ text-transform: none;
125
+ border: 1px solid #ccc;
126
+ padding: 8px 15px;
127
+ }
128
+
129
+ .download-button-right {
130
+ float: right;
131
+ margin-bottom: 10px;
132
+ margin-left: 10px;
133
+ background-color: white;
134
+ color: black;
135
+ text-transform: none;
136
+ border: 1px solid #ccc;
137
+ padding: 8px 15px;
138
+ }
139
+
140
+ .icon-drag {
141
+ float: right;
142
+ padding: 5px;
143
+ }
144
+
145
+ .dropdown-container {
146
+ display: flex;
147
+ justify-content: flex-end;
148
+ }
149
+
150
+ .label-group-item-manual {
151
+ margin: 5px;
152
+ width: -webkit-fill-available;
153
+ cursor: grab;
154
+ }
155
+ .label-group-item-manual:active {
156
+ cursor: grabbing;
157
+ }
158
+ </style>
159
+
160
+ <%= javascript_tag do %>
161
+ $(document).ready(function() {
162
+ $('.dropdown-menu').on('click', 'input[type="checkbox"], label', function(event) {
163
+ event.stopPropagation();
164
+ });
165
+
166
+ $('#modalDownloadButton').click(function() {
167
+ $('#downloadCsvModal').modal('show');
168
+ });
169
+
170
+ $('#startDate, #endDate').datepicker({
171
+ dateFormat: 'yy-mm-dd'
172
+ });
173
+
174
+ $('#downloadCsvModal').on('show.bs.modal', function (e) {
175
+ $('#allData').prop('checked', true);
176
+ $('#startDate, #endDate').prop('disabled', true);
177
+ $('#startDate').val(null);
178
+ $('#endDate').val(null);
179
+ });
180
+
181
+ $('#allData').change(function() {
182
+ $('#startDate').val(null);
183
+ $('#endDate').val(null);
184
+ $('#startDate, #endDate').prop('disabled', true);
185
+ });
186
+
187
+ $('#thisWeek').change(function() {
188
+ if ($(this).is(':checked')) {
189
+ setDateRange("week");
190
+ }
191
+ });
192
+
193
+ $('#thisMonth').change(function() {
194
+ if ($(this).is(':checked')) {
195
+ setDateRange("month");
196
+ }
197
+ });
198
+
199
+ $('#thisYear').change(function() {
200
+ if ($(this).is(':checked')) {
201
+ setDateRange("year");
202
+ }
203
+ });
204
+
205
+ $('#customDate').change(function() {
206
+ if ($(this).is(':checked')) {
207
+ setDateRange("day");
208
+ $('#startDate, #endDate').prop('disabled', false);
209
+ }
210
+ });
211
+
212
+ var downloadButton = document.getElementById('downloadButton');
213
+ if (downloadButton) {
214
+ downloadButton.addEventListener('click', function() {
215
+ event.preventDefault();
216
+
217
+ var allFieldsChecked = document.getElementById('allFields').checked;
218
+ var startDate = $('#startDate').val();
219
+ var endDate = $('#endDate').val();
220
+ var downloadAll = $('#allData').is(':checked');
221
+ var thElements = document.querySelectorAll('#payments-table th');
222
+ var columnTitles = Array.from(thElements).map(function(th) {
223
+ return th.textContent.trim();
224
+ });
225
+ var columnsString = columnTitles.join(',')
226
+
227
+ var url = new URL("<%= download_payments_path %>", window.location.origin);
228
+ var params = new URLSearchParams();
229
+ params.append('account_id', "<%=@account.account_id%>");
230
+ params.append('columnsString', columnsString);
231
+ if (!downloadAll) {
232
+ params.append('startDate', startDate);
233
+ params.append('endDate', endDate);
234
+ }
235
+ params.append('allFieldsChecked', allFieldsChecked);
236
+ url.search = params.toString();
237
+ console.log(url.toString());
238
+ window.open(url.toString(), '_blank');
239
+ });
240
+ }
241
+
242
+ updateDropdownOrder();
243
+
244
+ function loadState() {
245
+ var state = JSON.parse(localStorage.getItem('DataTables_payments-table'));
246
+ return state || { columns: [], columnOrder: [] };
247
+ }
248
+
249
+ function updateDropdownOrder() {
250
+ var state = loadState();
251
+ var columnOrder = state.ColReorder;
252
+ var $list = $('#column-visibility');
253
+ var thElements = document.querySelectorAll('#payments-table th');
254
+ var $columnTitles = Array.from(thElements).map(function(th) {
255
+ return th.textContent.trim();
256
+ });
257
+ if (columnOrder !== undefined) {
258
+ $list.empty();
259
+ columnOrder.forEach(function(colIdx, index) {
260
+ var $item = $('<li>', { class: "list-group-item-manual", "data-id": index });
261
+ var column = state.columns[colIdx];
262
+ var col_name = $columnTitles[colIdx];
263
+ var $label = $('<label>', {
264
+ class: "label-group-item-manual",
265
+ });
266
+ var $checkbox = $("<input>", {
267
+ type: "checkbox",
268
+ value: colIdx,
269
+ checked: column.visible,
270
+ "data-column": colIdx,
271
+ class: "column-toggle"
272
+ });
273
+ $label.append($checkbox).append(" " + col_name);
274
+ var $icon = $("<span>", { class: "glyphicon glyphicon-option-vertical icon-drag"});
275
+ $label.append($icon);
276
+ $item.append($label);
277
+ $list.append($item);
278
+ });
279
+ }
280
+ resetDataColumn();
281
+ resetDataId();
282
+ }
283
+
284
+ $("#column-visibility").sortable({
285
+ axis: "y",
286
+ containment: "parent",
287
+ stop: function(event, ui) {
288
+ var order = $("#column-visibility").sortable('toArray', {attribute: 'data-id'});
289
+ reorderTableColumns(order);
290
+ }
291
+ });
292
+ $("#column-visibility").disableSelection();
293
+
294
+ function reorderTableColumns(order) {
295
+ var table = $('#payments-table').DataTable();
296
+ var columnIndexes = order.map(Number);
297
+ console.log('New column order:', columnIndexes);
298
+ table.colReorder.order(columnIndexes);
299
+ resetDataColumn();
300
+ resetDataId();
301
+ }
302
+
303
+ function resetDataId() {
304
+ var elements = document.querySelectorAll('.list-group-item-manual');
305
+ elements.forEach(function(element, index) {
306
+ element.setAttribute('data-id', index);
307
+ });
308
+ }
309
+
310
+ function resetDataColumn() {
311
+ var elements = document.querySelectorAll('.column-toggle');
312
+ elements.forEach(function(element, index) {
313
+ element.setAttribute('data-column', index);
314
+ });
315
+ }
316
+
317
+ $('.column-toggle').on('change', function() {
318
+ var table = $('#payments-table').DataTable();
319
+ var column = table.column($(this).attr('data-column'));
320
+ column.visible(!column.visible());
321
+ });
322
+ });
323
+ <% end %>
@@ -1,20 +1,14 @@
1
1
  <div class="search">
2
-
3
2
  <div class="column-block">
4
-
5
3
  <h1><%= I18n.translate('payments') %></h1>
6
-
7
- <table id="payments-table" class="table table-condensed mobile-data">
4
+ <%= render :partial => 'multi_functions_bar' %>
5
+ <table id="payments-table" class="table table-condensed mobile-data" style="width:100%">
8
6
  <thead>
9
- <tr>
10
- <th><%= I18n.translate('number') %></th>
11
- <th><%= I18n.translate('date') %></th>
12
- <th><%= I18n.translate('auth_amount') %></th>
13
- <th><%= I18n.translate('capture_amount') %></th>
14
- <th><%= I18n.translate('refund_amount') %></th>
15
- <th><%= I18n.translate('last_transaction_status') %></th>
16
- <th><%= I18n.translate('external_key') %></th>
17
- </tr>
7
+ <tr>
8
+ <% Kaui.account_payments_columns.call()[0].each do |title| %>
9
+ <th><%= title %></th>
10
+ <% end %>
11
+ </tr>
18
12
  </thead>
19
13
  <tbody>
20
14
  <tr>
@@ -22,34 +16,83 @@
22
16
  </tr>
23
17
  </tbody>
24
18
  </table>
25
-
26
19
  </div>
27
-
28
20
  </div>
29
21
 
22
+ <style>
23
+ #payments-table td, #payments-table tr {
24
+ white-space: nowrap;
25
+ }
26
+ </style>
27
+
30
28
  <%= javascript_tag do %>
31
29
  $(document).ready(function() {
30
+ var stateKey = 'DataTables_payments-table';
31
+ var state = JSON.parse(localStorage.getItem(stateKey));
32
+ if (state) {
33
+ state.start = <%= @offset %>;
34
+ state.search = { search: "<%= @search_query %>" };
35
+ localStorage.setItem(stateKey, JSON.stringify(state));
36
+ }
37
+
32
38
  var table = $('#payments-table').DataTable({
39
+ "colReorder": {
40
+ "enable": false
41
+ },
42
+ "stateSave": true,
43
+ "stateSaveCallback": function(settings, data) {
44
+ localStorage.setItem('DataTables_payments-table', JSON.stringify(data));
45
+ },
46
+ "stateLoadCallback": function(settings) {
47
+ return JSON.parse(localStorage.getItem('DataTables_payments-table'));
48
+ },
49
+ "scrollX": true,
33
50
  <% if @account.account_id.blank? %>
34
- "dom": "<'row'r>t<'row'<'col-md-6'i><'col-md-6'p>>",
35
- "pagingType": <% if @max_nb_records.nil? -%>"simple"<% else -%>"full_numbers"<% end -%>,
36
- "language": {
37
- <!-- See DefaultPaginationSqlDaoHelper.java -->
38
- "info": <% if @max_nb_records.nil? -%>"Showing _START_ to _END_ of <%= number_with_delimiter(Kaui::EngineControllerUtil::SIMPLE_PAGINATION_THRESHOLD) -%>+ entries"<% else -%>"Showing _START_ to _END_ of _TOTAL_ entries"<% end -%>
39
- },
40
- "pageLength": <%= @limit %>,
41
- "displayStart": <%= @offset %>,
42
- "ajax": "<%= payments_pagination_path(:ordering => @ordering, :format => :json) %>",
51
+ "dom": "<'row'r>t<'row'<'col-md-6'i><'col-md-6'p>>",
52
+ "pagingType": <% if @max_nb_records.nil? -%>"simple"<% else -%>"full_numbers"<% end -%>,
53
+ "language": {
54
+ <!-- See DefaultPaginationSqlDaoHelper.java -->
55
+ "info": <% if @max_nb_records.nil? -%>"Showing _START_ to _END_ of <%= number_with_delimiter(Kaui::EngineControllerUtil::SIMPLE_PAGINATION_THRESHOLD) -%>+ entries"<% else -%>"Showing _START_ to _END_ of _TOTAL_ entries"<% end -%>
56
+ },
57
+ "pageLength": <%= @limit %>,
58
+ "displayStart": <%= @offset %>,
59
+ "ajax": {
60
+ url: "<%= payments_pagination_path(:ordering => @ordering, :format => :json) %>",
61
+ dataSrc: function(json) {
62
+ var colOrder = $('#payments-table').DataTable().colReorder.order();
63
+ var reorderedData = json.data.map(function(row) {
64
+ var newRow = [];
65
+ for (var i = 0; i < colOrder.length; i++) {
66
+ newRow.push(row[colOrder[i]]);
67
+ }
68
+ return newRow;
69
+ });
70
+ return reorderedData;
71
+ }
72
+ },
43
73
  <% else %>
44
- // No paging for per-account listings
45
- "dom": "t",
46
- "paging": false,
47
- "ajax": "<%= payments_pagination_path :format => :json %>",
74
+ // No paging for per-account listings
75
+ "dom": "t",
76
+ "paging": false,
77
+ "ajax": {
78
+ url: "<%= payments_pagination_path(:format => :json) %>",
79
+ dataSrc: function(json) {
80
+ var colOrder = $('#payments-table').DataTable().colReorder.order();
81
+ var reorderedData = json.data.map(function(row) {
82
+ var newRow = [];
83
+ for (var i = 0; i < colOrder.length; i++) {
84
+ newRow.push(row[colOrder[i]]);
85
+ }
86
+ return newRow;
87
+ });
88
+ return reorderedData;
89
+ }
90
+ },
48
91
  <% end %>
49
92
  <% if @search_query.blank? %>
50
- "ordering": false,
93
+ "ordering": false,
51
94
  <% elsif !@ordering.blank? %>
52
- "order": [[ 0, "<%= @ordering %>" ]],
95
+ "order": [[ 0, "<%= @ordering %>" ]],
53
96
  <% end %>
54
97
  "processing": true,
55
98
  "serverSide": true,
@@ -63,6 +63,9 @@ en:
63
63
  invalid_xml: "Invalid XML: %{error}"
64
64
  invalid_min_date: "Invalid min date format"
65
65
  invalid_max_date: "Invalid max date format"
66
+ unable_to_connect_database: "Unable to connect to the database."
67
+ unable_to_connect_killbill: "Unable to connect to the Kill Bill server."
68
+ error_communicating_killbill: "Error while communicating with the Kill Bill server."
66
69
  views:
67
70
  subscriptions:
68
71
  requested_date_for_billing_notice: <ul>
data/config/routes.rb CHANGED
@@ -22,10 +22,13 @@ Kaui::Engine.routes.draw do
22
22
  controllers: { sessions: 'kaui/sessions', registrations: 'kaui/registrations' }
23
23
 
24
24
  root to: 'home#index', as: 'kaui'
25
+ get '/500', to: 'errors#show', code: 500
25
26
 
26
27
  scope '/accounts' do
27
28
  match '/pagination' => 'accounts#pagination', :via => :get, :as => 'accounts_pagination'
28
29
  match '/validate_external_key' => 'accounts#validate_external_key', :via => :get, :as => 'accounts_validate_external_key'
30
+ match '/download' => 'accounts#download', :via => :get, :as => 'download_accounts'
31
+ get '/export/:account_id', to: 'accounts#export_account', as: 'export_account'
29
32
 
30
33
  scope '/email_notifications' do
31
34
  match '/' => 'accounts#set_email_notifications_configuration', :via => :post, :as => 'email_notifications_configuration'
@@ -53,6 +56,7 @@ Kaui::Engine.routes.draw do
53
56
  end
54
57
  scope '/timeline' do
55
58
  match '/' => 'account_timelines#show', :via => :get, :as => 'account_timeline'
59
+ match '/download' => 'account_timelines#download', :via => :get, :as => 'download_account_timeline'
56
60
  end
57
61
  scope '/custom_fields' do
58
62
  match '/' => 'account_custom_fields#index', :via => :get, :as => 'account_custom_fields'
@@ -63,6 +67,7 @@ Kaui::Engine.routes.draw do
63
67
  end
64
68
  scope '/audit_logs' do
65
69
  match '/history' => 'audit_logs#history', :via => :get, :as => 'audit_logs_history'
70
+ match '/download' => 'audit_logs#download', :via => :get, :as => 'download_audit_logs'
66
71
  end
67
72
  end
68
73
  end
@@ -97,6 +102,7 @@ Kaui::Engine.routes.draw do
97
102
 
98
103
  scope '/invoices' do
99
104
  match '/pagination' => 'invoices#pagination', :via => :get, :as => 'invoices_pagination'
105
+ match '/download' => 'invoices#download', :via => :get, :as => 'download_invoices'
100
106
  match '/:id/show_html' => 'invoices#show_html', :via => :get, :as => 'show_html_invoice'
101
107
  match '/:number' => 'invoices#restful_show_by_number', :via => :get, :constraints => { number: /\d+/ }
102
108
  match '/:id' => 'invoices#restful_show', :via => :get, :as => 'invoice'
@@ -112,6 +118,7 @@ Kaui::Engine.routes.draw do
112
118
 
113
119
  scope '/payments' do
114
120
  match '/pagination' => 'payments#pagination', :via => :get, :as => 'payments_pagination'
121
+ match '/download' => 'payments#download', :via => :get, :as => 'download_payments'
115
122
  match '/:id' => 'payments#restful_show', :via => :get, :as => 'payment'
116
123
  match '/:id/cancel_scheduled_payment' => 'payments#cancel_scheduled_payment', :via => :delete, :as => 'payment_cancel_scheduled_payment'
117
124
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kaui
4
+ module ErrorHandler
5
+ extend ActiveSupport::Concern
6
+ include Kaui::EngineControllerUtil
7
+
8
+ included do
9
+ rescue_from(StandardError) do |error|
10
+ flash[:error] = "Error: #{as_string(error)}"
11
+ try_to_redirect_to_account_path = !params[:controller].ends_with?('accounts')
12
+ perform_redirect_after_error(redirect: try_to_redirect_to_account_path)
13
+ end
14
+
15
+ rescue_from(ActionController::ParameterMissing) do |parameter_missing_exception|
16
+ log_rescue_error parameter_missing_exception
17
+ flash[:error] = "Required parameter missing: #{parameter_missing_exception.param}"
18
+ perform_redirect_after_error
19
+ end
20
+
21
+ rescue_from(KillBillClient::API::ResponseError) do |killbill_exception|
22
+ flash[:error] = "Error while communicating with the Kill Bill server: #{as_string(killbill_exception)}"
23
+ try_to_redirect_to_account_path = !killbill_exception.is_a?(KillBillClient::API::Unauthorized) && !(killbill_exception.is_a?(KillBillClient::API::NotFound) && params[:controller].ends_with?('accounts'))
24
+ perform_redirect_after_error(redirect: try_to_redirect_to_account_path)
25
+ end
26
+ end
27
+
28
+ def perform_redirect_after_error(redirect: true)
29
+ account_id = nested_hash_value(params.permit!.to_h, :account_id)
30
+ if redirect && account_id.present?
31
+ redirect_to kaui_engine.account_path(account_id)
32
+ else
33
+ redirect_to kaui_engine.home_path
34
+ end
35
+ end
36
+ end
37
+ end
data/lib/kaui/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kaui
4
- VERSION = '3.0.3'
4
+ VERSION = '3.0.5'
5
5
  end