kaui 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +3 -3
- data/app/controllers/kaui/account_timelines_controller.rb +2 -2
- data/app/controllers/kaui/chargebacks_controller.rb +1 -1
- data/app/controllers/kaui/charges_controller.rb +1 -1
- data/app/controllers/kaui/invoice_items_controller.rb +2 -2
- data/app/controllers/kaui/invoices_controller.rb +1 -1
- data/app/controllers/kaui/payments_controller.rb +1 -1
- data/app/controllers/kaui/refunds_controller.rb +2 -2
- data/app/helpers/kaui/date_helper.rb +11 -0
- data/app/helpers/kaui/killbill_helper.rb +12 -3
- data/app/models/kaui/base.rb +1 -57
- data/app/models/kaui/rails_methods.rb +76 -0
- data/app/views/kaui/invoices/show.html.erb +3 -1
- data/config/initializers/kilbill-client-init.rb +9 -0
- data/kaui.gemspec +1 -1
- data/lib/kaui/version.rb +1 -1
- data/test/dummy/app/assets/javascripts/application.js +1 -1
- data/test/dummy/app/assets/stylesheets/application.css +1 -1
- data/test/test_helper.rb +1 -1
- metadata +7 -5
data/Gemfile.lock
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kaui (0.4.
|
4
|
+
kaui (0.4.3)
|
5
5
|
cancan (~> 1.6.10)
|
6
6
|
d3_rails (~> 3.2.8)
|
7
7
|
devise (~> 3.0.2)
|
8
8
|
jquery-rails (~> 3.0.4)
|
9
|
-
killbill-client (~> 0.3.
|
9
|
+
killbill-client (~> 0.3.3)
|
10
10
|
money-rails (~> 0.8.1)
|
11
11
|
rails (~> 3.2.14)
|
12
12
|
rest-client (~> 1.6.7)
|
@@ -60,7 +60,7 @@ GEM
|
|
60
60
|
railties (>= 3.0, < 5.0)
|
61
61
|
thor (>= 0.14, < 2.0)
|
62
62
|
json (1.8.0)
|
63
|
-
killbill-client (0.3.
|
63
|
+
killbill-client (0.3.3)
|
64
64
|
mail (2.5.4)
|
65
65
|
mime-types (~> 1.16)
|
66
66
|
treetop (~> 1.4.8)
|
@@ -27,7 +27,7 @@ class Kaui::AccountTimelinesController < Kaui::EngineController
|
|
27
27
|
@timeline.payments.each do |payment|
|
28
28
|
if payment.invoice_id.present? && payment.payment_id.present?
|
29
29
|
begin
|
30
|
-
@invoices_by_id[payment.invoice_id] = Kaui::KillbillHelper::get_invoice(payment.invoice_id, true, options_for_klient)
|
30
|
+
@invoices_by_id[payment.invoice_id] = Kaui::KillbillHelper::get_invoice(payment.invoice_id, true, "NONE", options_for_klient)
|
31
31
|
rescue => e
|
32
32
|
flash.now[:error] = "Could not get invoice information for the timeline #{@account_id}: #{as_string(e)}"
|
33
33
|
end
|
@@ -41,7 +41,7 @@ class Kaui::AccountTimelinesController < Kaui::EngineController
|
|
41
41
|
@timeline.invoices.each do |invoice|
|
42
42
|
if invoice.invoice_id.present? && !@invoices_by_id.has_key?(invoice.invoice_id)
|
43
43
|
begin
|
44
|
-
@invoices_by_id[invoice.invoice_id] = Kaui::KillbillHelper::get_invoice(invoice.invoice_id, true, options_for_klient)
|
44
|
+
@invoices_by_id[invoice.invoice_id] = Kaui::KillbillHelper::get_invoice(invoice.invoice_id, true, "NONE", options_for_klient)
|
45
45
|
rescue => e
|
46
46
|
flash.now[:error] = "Could not get invoice information for the timeline #{@account_id}: #{as_string(e)}"
|
47
47
|
end
|
@@ -26,7 +26,7 @@ class Kaui::ChargebacksController < Kaui::EngineController
|
|
26
26
|
begin
|
27
27
|
@account = Kaui::KillbillHelper::get_account(@account_id, false, false, options_for_klient)
|
28
28
|
@payment = Kaui::KillbillHelper::get_payment(@payment_id, options_for_klient)
|
29
|
-
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id, true, options_for_klient)
|
29
|
+
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id, true, "NONE", options_for_klient)
|
30
30
|
rescue => e
|
31
31
|
flash[:error] = "Error while starting a new chargeback: #{as_string(e)}"
|
32
32
|
redirect_to kaui_engine.account_timeline_path(:id => params[:account_id])
|
@@ -7,7 +7,7 @@ class Kaui::ChargesController < Kaui::EngineController
|
|
7
7
|
@account = Kaui::KillbillHelper::get_account(@account_id, false, false, options_for_klient)
|
8
8
|
|
9
9
|
if @invoice_id.present?
|
10
|
-
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id, true, options_for_klient)
|
10
|
+
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id, true, "NONE", options_for_klient)
|
11
11
|
@charge = Kaui::Charge.new("accountId" => @account_id, "invoiceId" => @invoice_id)
|
12
12
|
else
|
13
13
|
@charge = Kaui::Charge.new("accountId" => @account_id)
|
@@ -14,7 +14,7 @@ class Kaui::InvoiceItemsController < Kaui::EngineController
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def update
|
17
|
-
@invoice_item = Kaui::
|
17
|
+
@invoice_item = Kaui::KillbillHelper.new_invoice_item(params[:kill_bill_client_model_invoice_item])
|
18
18
|
begin
|
19
19
|
Kaui::KillbillHelper.adjust_invoice(@invoice_item, current_user, params[:reason], params[:comment], options_for_klient)
|
20
20
|
flash[:notice] = "Adjustment item created"
|
@@ -43,7 +43,7 @@ class Kaui::InvoiceItemsController < Kaui::EngineController
|
|
43
43
|
invoice_id = params[:invoice_id]
|
44
44
|
if invoice_item_id.present? and invoice_id.present?
|
45
45
|
begin
|
46
|
-
@invoice_item = Kaui::KillbillHelper.get_invoice_item
|
46
|
+
@invoice_item = Kaui::KillbillHelper.get_invoice_item invoice_id, invoice_item_id, options_for_klient
|
47
47
|
rescue => e
|
48
48
|
flash[:error] = "Error while trying to find the invoice item: #{as_string(e)}"
|
49
49
|
end
|
@@ -9,7 +9,7 @@ class Kaui::InvoicesController < Kaui::EngineController
|
|
9
9
|
invoice_id_or_number = params[:id]
|
10
10
|
if invoice_id_or_number.present?
|
11
11
|
begin
|
12
|
-
@invoice = Kaui::KillbillHelper.get_invoice(invoice_id_or_number, true, options_for_klient)
|
12
|
+
@invoice = Kaui::KillbillHelper.get_invoice(invoice_id_or_number, true, "FULL", options_for_klient)
|
13
13
|
if @invoice.present?
|
14
14
|
@invoice_id = @invoice.invoice_id
|
15
15
|
@account = Kaui::KillbillHelper.get_account(@invoice.account_id, false, false, options_for_klient)
|
@@ -4,7 +4,7 @@ class Kaui::PaymentsController < Kaui::EngineController
|
|
4
4
|
@account_id = params[:account_id]
|
5
5
|
@invoice_id = params[:invoice_id]
|
6
6
|
begin
|
7
|
-
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id, true, options_for_klient)
|
7
|
+
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id, true, "NONE", options_for_klient)
|
8
8
|
@account = Kaui::KillbillHelper::get_account(@account_id, false, false, options_for_klient)
|
9
9
|
rescue => e
|
10
10
|
flash[:error] = "Error while creating a new payment: #{as_string(e)}"
|
@@ -57,7 +57,7 @@ class Kaui::RefundsController < Kaui::EngineController
|
|
57
57
|
begin
|
58
58
|
@account = Kaui::KillbillHelper::get_account(@account_id, false, false, options_for_klient)
|
59
59
|
@payment = Kaui::KillbillHelper::get_payment(@payment_id, options_for_klient)
|
60
|
-
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id, true, options_for_klient)
|
60
|
+
@invoice = Kaui::KillbillHelper::get_invoice(@invoice_id, true, "NONE", options_for_klient)
|
61
61
|
rescue => e
|
62
62
|
flash[:error] = "Error while processing refund: #{as_string(e)}"
|
63
63
|
redirect_to kaui_engine.account_timeline_path(:id => params[:account_id])
|
@@ -65,7 +65,7 @@ class Kaui::RefundsController < Kaui::EngineController
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def create
|
68
|
-
invoice = Kaui::KillbillHelper::get_invoice(params[:invoice_id], true, options_for_klient)
|
68
|
+
invoice = Kaui::KillbillHelper::get_invoice(params[:invoice_id], true, "NONE", options_for_klient)
|
69
69
|
refund = Kaui::Refund.new(params[:refund])
|
70
70
|
refund.adjusted = (refund.adjustment_type != "noInvoiceAdjustment")
|
71
71
|
if refund.adjustment_type == "invoiceItemAdjustment"
|
@@ -1,6 +1,17 @@
|
|
1
1
|
module Kaui
|
2
2
|
module DateHelper
|
3
|
+
|
4
|
+
LOCAL_DATE_RE = /^\d+-\d+-\d+$/
|
5
|
+
|
3
6
|
def format_date(date, timezone="Pacific Time (US & Canada)")
|
7
|
+
|
8
|
+
# Double check this is not null
|
9
|
+
return nil if date.nil?
|
10
|
+
|
11
|
+
# If this is a local date we assume this is already in the account timezone, and so there is nothing to do
|
12
|
+
return date.to_s if LOCAL_DATE_RE.match(date.to_s)
|
13
|
+
|
14
|
+
# If not, convert into account timezone and return the date part only
|
4
15
|
parsed_date = DateTime.parse(date.to_s).in_time_zone(timezone)
|
5
16
|
parsed_date.to_s(:date_only)
|
6
17
|
end
|
@@ -232,14 +232,14 @@ module Kaui
|
|
232
232
|
|
233
233
|
############## INVOICE ##############
|
234
234
|
|
235
|
-
def self.get_invoice(id_or_number, with_items = true, options = {})
|
236
|
-
KillBillClient::Model::Invoice.find_by_id_or_number id_or_number, with_items, options
|
235
|
+
def self.get_invoice(id_or_number, with_items = true, audit = "NONE", options = {})
|
236
|
+
KillBillClient::Model::Invoice.find_by_id_or_number id_or_number, with_items, audit, options
|
237
237
|
end
|
238
238
|
|
239
239
|
def self.get_invoice_item(invoice_id, invoice_item_id, options = {})
|
240
240
|
# Find the item from the invoice
|
241
241
|
# TODO add killbill-server API
|
242
|
-
invoice = Kaui::KillbillHelper.get_invoice(invoice_id, options)
|
242
|
+
invoice = Kaui::KillbillHelper.get_invoice(invoice_id, true, "NONE", options)
|
243
243
|
if invoice.present? and invoice.items.present?
|
244
244
|
invoice.items.each do |item|
|
245
245
|
return item if item.invoice_item_id == invoice_item_id
|
@@ -248,6 +248,15 @@ module Kaui
|
|
248
248
|
nil
|
249
249
|
end
|
250
250
|
|
251
|
+
def self.new_invoice_item(invoice_item)
|
252
|
+
item = KillBillClient::Model::InvoiceItem.new
|
253
|
+
invoice_item.each do |attribute, value|
|
254
|
+
item.methods.include?("#{attribute}=".to_sym) ?
|
255
|
+
item.send("#{attribute}=".to_sym, value) : next
|
256
|
+
end
|
257
|
+
item
|
258
|
+
end
|
259
|
+
|
251
260
|
def self.get_invoice_html(invoice_id, options = {})
|
252
261
|
data = call_killbill :get, "/1.0/kb/invoices/#{invoice_id}/html", options
|
253
262
|
data[:body] if data.present?
|
data/app/models/kaui/base.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
class Kaui::Base
|
2
|
-
include
|
3
|
-
include ActiveModel::Conversion
|
4
|
-
extend ActiveModel::Naming
|
2
|
+
include Kaui::RailsMethods
|
5
3
|
|
6
4
|
attr_reader :errors
|
7
5
|
|
@@ -129,59 +127,5 @@ class Kaui::Base
|
|
129
127
|
end
|
130
128
|
end
|
131
129
|
|
132
|
-
def ==(other)
|
133
|
-
!other.nil? && self.class == other.class && self.to_hash == other.to_hash
|
134
|
-
end
|
135
|
-
|
136
|
-
def persisted?
|
137
|
-
@persisted
|
138
|
-
end
|
139
|
-
|
140
|
-
def new_record?
|
141
|
-
!persisted?
|
142
|
-
end
|
143
|
-
|
144
|
-
def to_param
|
145
|
-
# id is a string (killbill UUID)
|
146
|
-
@id
|
147
|
-
end
|
148
|
-
|
149
|
-
def read_attribute_for_validation(attr)
|
150
|
-
send(attr)
|
151
|
-
end
|
152
|
-
|
153
|
-
def self.human_attribute_name(attr, options = {})
|
154
|
-
attr
|
155
|
-
end
|
156
|
-
|
157
|
-
def self.lookup_ancestors
|
158
|
-
[self]
|
159
|
-
end
|
160
|
-
|
161
|
-
def self.all
|
162
|
-
[]
|
163
|
-
end
|
164
|
-
|
165
|
-
def self.count
|
166
|
-
all.count
|
167
|
-
end
|
168
|
-
|
169
|
-
def self.find(id)
|
170
|
-
nil
|
171
|
-
end
|
172
|
-
|
173
|
-
def save
|
174
|
-
@errors.add(:save, 'Saving this object is not yet supported')
|
175
|
-
false
|
176
|
-
end
|
177
130
|
|
178
|
-
def update_attributes(tag_definition)
|
179
|
-
@errors.add(:update, 'Updating this object is not yet supported')
|
180
|
-
false
|
181
|
-
end
|
182
|
-
|
183
|
-
def destroy
|
184
|
-
@errors.add(:destroy, 'Destroying this object is not yet supported')
|
185
|
-
false
|
186
|
-
end
|
187
131
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Kaui
|
2
|
+
module RailsMethods
|
3
|
+
|
4
|
+
# let all the rails mocks and overrides be here
|
5
|
+
def self.included(base_class)
|
6
|
+
base_class.class_eval do
|
7
|
+
extend ActiveModel::Naming
|
8
|
+
include ActiveModel::Validations
|
9
|
+
include ActiveModel::Conversion
|
10
|
+
|
11
|
+
def ==(other)
|
12
|
+
!other.nil? && self.class == other.class && self.to_hash == other.to_hash
|
13
|
+
end
|
14
|
+
|
15
|
+
def persisted?
|
16
|
+
@persisted
|
17
|
+
end
|
18
|
+
|
19
|
+
def new_record?
|
20
|
+
!persisted?
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_param
|
24
|
+
# id is a string (killbill UUID)
|
25
|
+
@id
|
26
|
+
end
|
27
|
+
|
28
|
+
def read_attribute_for_validation(attr)
|
29
|
+
send(attr)
|
30
|
+
end
|
31
|
+
|
32
|
+
def save
|
33
|
+
@errors.add(:save, 'Saving this object is not yet supported')
|
34
|
+
false
|
35
|
+
end
|
36
|
+
|
37
|
+
def update_attributes(tag_definition)
|
38
|
+
@errors.add(:update, 'Updating this object is not yet supported')
|
39
|
+
false
|
40
|
+
end
|
41
|
+
|
42
|
+
def destroy
|
43
|
+
@errors.add(:destroy, 'Destroying this object is not yet supported')
|
44
|
+
false
|
45
|
+
end
|
46
|
+
|
47
|
+
end # end instance methods
|
48
|
+
|
49
|
+
base_class.instance_eval do
|
50
|
+
def self.human_attribute_name(attr, options = {})
|
51
|
+
attr
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.lookup_ancestors
|
55
|
+
[self]
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.all
|
59
|
+
[]
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.count
|
63
|
+
all.count
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.find(id)
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
|
70
|
+
end # end class methods
|
71
|
+
|
72
|
+
end # end def included
|
73
|
+
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -36,12 +36,13 @@
|
|
36
36
|
<thead>
|
37
37
|
<tr>
|
38
38
|
<th style="width: 10%">External Key</th>
|
39
|
-
<th style="width:
|
39
|
+
<th style="width: 20%">Description</th>
|
40
40
|
<th style="width: 10%">Start date</th>
|
41
41
|
<th style="width: 10%">End date</th>
|
42
42
|
<th style="width: 10%">Charged through date</th>
|
43
43
|
<th style="width: 10%">Price list</th>
|
44
44
|
<th style="width: 10%">Amount</th>
|
45
|
+
<th style="width: 10%">Comments</th>
|
45
46
|
<th style="width: 10%"></th>
|
46
47
|
</tr>
|
47
48
|
</thead>
|
@@ -59,6 +60,7 @@
|
|
59
60
|
<td onClick="hightlightLinkedItems('<%= item.invoice_item_id %>', '<%= item.linked_invoice_item_id %>'); return false;"><%= format_date(sub.charged_through_date, @account.timezone).html_safe if sub.present? %></td>
|
60
61
|
<td onClick="hightlightLinkedItems('<%= item.invoice_item_id %>', '<%= item.linked_invoice_item_id %>'); return false;"><%= sub.price_list.downcase.capitalize if sub.present? and sub.price_list.present? %></td>
|
61
62
|
<td onClick="hightlightLinkedItems('<%= item.invoice_item_id %>', '<%= item.linked_invoice_item_id %>'); return false;"><%= humanized_money_with_symbol Kaui::Base.to_money(item.amount, item.currency) %> (<%= item.currency %>)</td>
|
63
|
+
<td onClick="hightlightLinkedItems('<%= item.invoice_item_id %>', '<%= item.linked_invoice_item_id %>'); return false;"><%= item.audit_logs.map {|log| log.comments}.compact.join('<br/>') if item.audit_logs.present? %></td>
|
62
64
|
<td>
|
63
65
|
<% if can? :item_adjust, Kaui::Invoice %>
|
64
66
|
<nobr>
|
data/kaui.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.add_dependency 'rest-client', '~> 1.6.7'
|
28
28
|
s.add_dependency 'money-rails', '~> 0.8.1'
|
29
29
|
s.add_dependency 'd3_rails', '~> 3.2.8'
|
30
|
-
s.add_dependency 'killbill-client', '~> 0.3.
|
30
|
+
s.add_dependency 'killbill-client', '~> 0.3.3'
|
31
31
|
s.add_dependency 'devise', '~> 3.0.2'
|
32
32
|
s.add_dependency 'cancan', '~> 1.6.10'
|
33
33
|
|
data/lib/kaui/version.rb
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
9
|
* compiled file, but it's generally better to create a new file per style scope.
|
10
10
|
*
|
11
|
-
*= require css/bootstrap.v2.
|
11
|
+
*= require css/bootstrap.v2.2.1.min
|
12
12
|
*= require kaui/analytics
|
13
13
|
*= require_self
|
14
14
|
*= require_tree .
|
data/test/test_helper.rb
CHANGED
@@ -62,7 +62,7 @@ module Kaui::KillbillHelper
|
|
62
62
|
find_among_fixtures(Kaui::OverdueState, account_id)
|
63
63
|
end
|
64
64
|
|
65
|
-
def self.get_invoice(invoice_id, with_items = true, options = {})
|
65
|
+
def self.get_invoice(invoice_id, with_items = true, audit= "NONE", options = {})
|
66
66
|
find_among_fixtures(Kaui::Invoice, invoice_id)
|
67
67
|
end
|
68
68
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kaui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
requirements:
|
99
99
|
- - ~>
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version: 0.3.
|
101
|
+
version: 0.3.3
|
102
102
|
type: :runtime
|
103
103
|
prerelease: false
|
104
104
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -106,7 +106,7 @@ dependencies:
|
|
106
106
|
requirements:
|
107
107
|
- - ~>
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 0.3.
|
109
|
+
version: 0.3.3
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
111
|
name: devise
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -246,6 +246,7 @@ files:
|
|
246
246
|
- app/models/kaui/payment.rb
|
247
247
|
- app/models/kaui/payment_attempt.rb
|
248
248
|
- app/models/kaui/product.rb
|
249
|
+
- app/models/kaui/rails_methods.rb
|
249
250
|
- app/models/kaui/refund.rb
|
250
251
|
- app/models/kaui/subscription.rb
|
251
252
|
- app/models/kaui/tag.rb
|
@@ -311,6 +312,7 @@ files:
|
|
311
312
|
- app/views/kaui/tags/_tags_table.html.erb
|
312
313
|
- bin/kaui
|
313
314
|
- config/initializers/devise.rb
|
315
|
+
- config/initializers/kilbill-client-init.rb
|
314
316
|
- config/initializers/killbill_authenticatable.rb
|
315
317
|
- config/initializers/time_formats.rb
|
316
318
|
- config/locales/devise.en.yml
|
@@ -435,7 +437,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
435
437
|
version: '0'
|
436
438
|
segments:
|
437
439
|
- 0
|
438
|
-
hash:
|
440
|
+
hash: 1687584771760312948
|
439
441
|
requirements: []
|
440
442
|
rubyforge_project:
|
441
443
|
rubygems_version: 1.8.25
|