billing 0.0.4b → 0.0.4c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/models/billing/{account.rb → bill.rb} +34 -28
- data/app/models/billing/charge.rb +25 -11
- data/app/models/billing/modifier.rb +5 -5
- data/app/models/billing/origin.rb +2 -2
- data/app/models/billing/payment.rb +6 -10
- data/app/models/billing/payment_with_type.rb +1 -1
- data/app/models/billing/report.rb +13 -11
- data/app/models/concerns/billing/{account_item.rb → bill_item.rb} +5 -6
- data/app/models/concerns/billing/bill_text_parser.rb +18 -0
- data/config/initializers/money.rb +67 -0
- data/config/routes.rb +1 -6
- data/db/migrate/20140803073707_rename_billing_account_to_bill.rb +8 -0
- data/db/migrate/20140804065726_add_qty_to_billing_charge.rb +5 -0
- data/db/migrate/20140804070517_add_tax_ratio_to_billing_charge.rb +5 -0
- data/lib/billing.rb +0 -2
- data/lib/billing/billable.rb +3 -3
- data/lib/billing/engine.rb +3 -0
- data/lib/billing/version.rb +1 -1
- data/lib/collection_proxy_wild.rb +9 -0
- data/test/dummy/config/routes.rb +1 -3
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +18 -16
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +4810 -0
- data/test/dummy/log/test.log +64325 -0
- data/test/fixtures/billing/{accounts.yml → bills.yml} +0 -0
- data/test/fixtures/billing/charges.yml +2 -2
- data/test/fixtures/billing/modifiers.yml +2 -2
- data/test/fixtures/billing/payments.yml +2 -2
- data/test/models/billing/bill_test.rb +76 -0
- data/test/models/billing/charge_test.rb +13 -6
- data/test/models/billing/modifier_test.rb +2 -2
- data/test/models/billing/payment_test.rb +12 -12
- metadata +15 -56
- data/app/assets/javascripts/billing/accounts.js +0 -2
- data/app/assets/javascripts/billing/application.js +0 -13
- data/app/assets/javascripts/billing/charges.js +0 -2
- data/app/assets/javascripts/billing/modifiers.js +0 -2
- data/app/assets/stylesheets/billing/accounts.css +0 -4
- data/app/assets/stylesheets/billing/application.css +0 -15
- data/app/assets/stylesheets/billing/charges.css +0 -4
- data/app/assets/stylesheets/billing/modifiers.css +0 -4
- data/app/assets/stylesheets/billing/payments.css +0 -4
- data/app/controllers/billing/accounts_controller.rb +0 -29
- data/app/controllers/billing/application_controller.rb +0 -22
- data/app/controllers/billing/charges_controller.rb +0 -29
- data/app/controllers/billing/modifiers_controller.rb +0 -29
- data/app/controllers/billing/payments_controller.rb +0 -29
- data/app/helpers/billing/accounts_helper.rb +0 -4
- data/app/helpers/billing/application_helper.rb +0 -4
- data/app/helpers/billing/charges_helper.rb +0 -4
- data/app/helpers/billing/modifiers_helper.rb +0 -4
- data/app/helpers/billing/payments_helper.rb +0 -4
- data/app/views/billing/accounts/index.html.erb +0 -7
- data/app/views/billing/accounts/new.html.erb +0 -8
- data/app/views/billing/accounts/show.html.erb +0 -29
- data/app/views/billing/application/index.html.erb +0 -3
- data/app/views/billing/charges/new.html.erb +0 -12
- data/app/views/billing/modifiers/new.html.erb +0 -18
- data/app/views/billing/payments/new.html.erb +0 -11
- data/app/views/layouts/billing/application.html.erb +0 -14
- data/lib/billing/mapping.rb +0 -32
- data/lib/billing/routes.rb +0 -16
- data/test/controllers/billing/accounts_controller_test.rb +0 -19
- data/test/controllers/billing/charges_controller_test.rb +0 -16
- data/test/controllers/billing/modifiers_controller_test.rb +0 -16
- data/test/controllers/billing/payments_controller_test.rb +0 -16
- data/test/helpers/billing/accounts_helper_test.rb +0 -6
- data/test/helpers/billing/charges_helper_test.rb +0 -6
- data/test/helpers/billing/modifiers_helper_test.rb +0 -6
- data/test/helpers/billing/payments_helper_test.rb +0 -6
- data/test/integration/navigation_test.rb +0 -10
- data/test/models/billing/account_test.rb +0 -56
@@ -1,22 +0,0 @@
|
|
1
|
-
module Billing
|
2
|
-
class ApplicationController < ActionController::Base
|
3
|
-
prepend_before_filter :include_extra_module
|
4
|
-
helper_method :billable
|
5
|
-
|
6
|
-
def index
|
7
|
-
end
|
8
|
-
|
9
|
-
def billable
|
10
|
-
@billable ||= billing_mapping.i_klass.find_by(billing_mapping.i_find_key => params[billing_mapping.i_param])
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
def billing_mapping
|
15
|
-
@billing_mapping ||= Billing::Mapping.find(request.fullpath)
|
16
|
-
end
|
17
|
-
|
18
|
-
def include_extra_module
|
19
|
-
self.class.send(:include, billing_mapping.i_extra_module) if billing_mapping.i_extra_module.present?
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require_dependency "billing/application_controller"
|
2
|
-
|
3
|
-
module Billing
|
4
|
-
class ChargesController < ApplicationController
|
5
|
-
before_action :set_account
|
6
|
-
|
7
|
-
def new
|
8
|
-
@charge = @account.charges.new
|
9
|
-
end
|
10
|
-
|
11
|
-
def create
|
12
|
-
@charge = @account.charges.new(charge_params)
|
13
|
-
if @charge.save
|
14
|
-
redirect_to @account
|
15
|
-
else
|
16
|
-
render action: :new
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
def set_account
|
22
|
-
@account = billable.billing_accounts.find(params[:account_id])
|
23
|
-
end
|
24
|
-
|
25
|
-
def charge_params
|
26
|
-
params.require(:charge).permit(:price)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require_dependency "billing/application_controller"
|
2
|
-
|
3
|
-
module Billing
|
4
|
-
class ModifiersController < ApplicationController
|
5
|
-
before_action :set_account
|
6
|
-
|
7
|
-
def new
|
8
|
-
@modifier = @account.modifiers.new
|
9
|
-
end
|
10
|
-
|
11
|
-
def create
|
12
|
-
@modifier = @account.modifiers.new(modifier_params)
|
13
|
-
if @modifier.save
|
14
|
-
redirect_to @account
|
15
|
-
else
|
16
|
-
render action: :new
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
def set_account
|
22
|
-
@account = billable.billing_accounts.find(params[:account_id])
|
23
|
-
end
|
24
|
-
|
25
|
-
def modifier_params
|
26
|
-
params.require(:modifier).permit(:percent_ratio, :fixed_value, :charge_id)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require_dependency "billing/application_controller"
|
2
|
-
|
3
|
-
module Billing
|
4
|
-
class PaymentsController < ApplicationController
|
5
|
-
before_action :set_account
|
6
|
-
|
7
|
-
def new
|
8
|
-
@payment = @account.payments.new(value: @account.total)
|
9
|
-
end
|
10
|
-
|
11
|
-
def create
|
12
|
-
@payment = @account.payments.new(payment_params)
|
13
|
-
if @payment.save
|
14
|
-
redirect_to @account
|
15
|
-
else
|
16
|
-
render action: :new
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
def set_account
|
22
|
-
@account = billable.billing_accounts.find(params[:account_id])
|
23
|
-
end
|
24
|
-
|
25
|
-
def payment_params
|
26
|
-
params.require(:payment).permit(:value)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
<%= @account.inspect %>
|
2
|
-
<h2>
|
3
|
-
total: <%= @account.total %>
|
4
|
-
<br />
|
5
|
-
balance: <%= @account.balance %>
|
6
|
-
</h2>
|
7
|
-
<hr />
|
8
|
-
Charges:<br />
|
9
|
-
<% @account.charges.each do |charge| %>
|
10
|
-
<%= charge.inspect %>
|
11
|
-
<% end %>
|
12
|
-
<%= link_to :charge, [:new, @account, :charge] %>
|
13
|
-
<hr />
|
14
|
-
Modifiers:<br />
|
15
|
-
<% @account.modifiers.each do |modifier| %>
|
16
|
-
<%= modifier.inspect %>
|
17
|
-
<% end %>
|
18
|
-
<%= link_to :modifier, [:new, @account, :modifier] %>
|
19
|
-
<div>
|
20
|
-
<% @account.modifier_items.each do |mi| %>
|
21
|
-
<%= mi.inspect %><br />
|
22
|
-
<% end %>
|
23
|
-
</div>
|
24
|
-
<hr />
|
25
|
-
Payments:<br />
|
26
|
-
<% @account.payments.each do |payment| %>
|
27
|
-
<%= payment.inspect %>
|
28
|
-
<% end %>
|
29
|
-
<%= link_to :pay, [:new, @account, :payment] %>
|
@@ -1,18 +0,0 @@
|
|
1
|
-
<h1>
|
2
|
-
New Modifier
|
3
|
-
<small><%= @account %></small>
|
4
|
-
</h1>
|
5
|
-
<div>
|
6
|
-
<%= @modifier.errors.full_messages.join(', ') %>
|
7
|
-
</div>
|
8
|
-
<%= form_for [@account, @modifier] do |f| %>
|
9
|
-
<%= @modifier.inspect %>
|
10
|
-
<br />
|
11
|
-
percent ratio <%= f.number_field :percent_ratio, step: 0.001 %>
|
12
|
-
<br />
|
13
|
-
fixed value <%= f.number_field :fixed_value, step: 0.01 %>
|
14
|
-
<br />
|
15
|
-
<%= f.select :charge_id, @account.charges.collect(&:id), { include_blank: true } %>
|
16
|
-
<br />
|
17
|
-
<%= f.submit %>
|
18
|
-
<% end %>
|
@@ -1,14 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>Billing</title>
|
5
|
-
<%= stylesheet_link_tag "billing/application", media: "all" %>
|
6
|
-
<%= javascript_include_tag "billing/application" %>
|
7
|
-
<%= csrf_meta_tags %>
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
|
11
|
-
<%= yield %>
|
12
|
-
|
13
|
-
</body>
|
14
|
-
</html>
|
data/lib/billing/mapping.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
module Billing
|
2
|
-
class Mapping
|
3
|
-
attr_reader :name, :i_klass, :i_param, :i_find_key, :i_extra_module
|
4
|
-
def initialize(resource, options)
|
5
|
-
@name = (options[:as] || resource).to_s
|
6
|
-
|
7
|
-
@i_klass = (options[:billable_type] || name.to_s.classify).to_s.constantize
|
8
|
-
|
9
|
-
@i_param = options[:billable_param] || "#{name.singularize}_id" #default #{resource}_id
|
10
|
-
|
11
|
-
# key to find interfaceable in controller, when
|
12
|
-
# :uuid then find_by! :uuid => params[:uuid]
|
13
|
-
# :shop_uuid then find_by! :uuid => params[:shop_uuid]
|
14
|
-
# :shop_id then find_by! :id => params[:shop_id]
|
15
|
-
@i_find_key = @i_param[/^(#{resource}_|)(\w+)/,2]
|
16
|
-
# FIXME not before schema load
|
17
|
-
#raise "#{@i_klass.name} has no method #{@i_find_key}" unless @i_klass.new.respond_to? @i_find_key
|
18
|
-
#raise "Did you forget to add 'has_extface_devices' in #{@i_klass.name} ?" unless @i_klass.new.respond_to? :extface_devices
|
19
|
-
@i_extra_module = options[:controller_include].to_s.constantize if options[:controller_include].present?
|
20
|
-
end
|
21
|
-
|
22
|
-
def mount_point
|
23
|
-
"#{name}_billing"
|
24
|
-
end
|
25
|
-
|
26
|
-
class << self
|
27
|
-
def find(fullpath)
|
28
|
-
Billing.mappings[fullpath[%r{/(\w+)_billing\/}, 1]]
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/lib/billing/routes.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
module ActionDispatch::Routing
|
2
|
-
class Mapper
|
3
|
-
def billing_for(resource, options = {})
|
4
|
-
mapping = Billing.add_mapping(resource, options)
|
5
|
-
mount Billing::Engine, at: mapping.mount_point, as: [options[:as],:billing].compact.join('_')
|
6
|
-
get "#{mapping.mount_point}/accounts", to: "billing/accounts#index", as: options[:as] ? options[:as].to_s.pluralize.intern : :billing_accounts
|
7
|
-
get "#{mapping.mount_point}/accounts/:account_id", to: "billing/accounts#show", as: options[:as] ? options[:as].to_s.singularize.intern : :billing_account
|
8
|
-
get "#{mapping.mount_point}/accounts/:account_id/charges", to: "billing/charges#index", as: options[:as] ? "#{options[:as].to_s.singularize.intern}_charges" : :billing_account_charges
|
9
|
-
get "#{mapping.mount_point}/accounts/:account_id/charges/new", to: "billing/charges#new", as: options[:as] ? "#{options[:as].to_s.singularize.intern}_new_charge" : :billing_account_new_charge
|
10
|
-
get "#{mapping.mount_point}/accounts/:account_id/charges/:charge_id", to: "billing/charges#show", as: options[:as] ? "#{options[:as].to_s.singularize.intern}_charge" : :billing_account_charge
|
11
|
-
get "#{mapping.mount_point}/accounts/:account_id/payments", to: "billing/payments#index", as: options[:as] ? "#{options[:as].to_s.singularize.intern}_payments" : :billing_account_payments
|
12
|
-
get "#{mapping.mount_point}/accounts/:account_id/payments/new", to: "billing/payments#new", as: options[:as] ? "#{options[:as].to_s.singularize.intern}_new_payment" : :billing_account_new_payment
|
13
|
-
get "#{mapping.mount_point}/accounts/:account_id/payments/:payment_id", to: "billing/payments#show", as: options[:as] ? "#{options[:as].to_s.singularize.intern}_payment" : :billing_account_payment
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Billing
|
4
|
-
class AccountsControllerTest < ActionController::TestCase
|
5
|
-
setup do
|
6
|
-
@account = billing_accounts(:one)
|
7
|
-
end
|
8
|
-
|
9
|
-
test "should get index" do
|
10
|
-
get :index
|
11
|
-
assert_response :success
|
12
|
-
end
|
13
|
-
|
14
|
-
test "new" do
|
15
|
-
get :new
|
16
|
-
assert_response :success
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Billing
|
4
|
-
class ChargesControllerTest < ActionController::TestCase
|
5
|
-
setup do
|
6
|
-
@charge = billing_charges(:one)
|
7
|
-
@account = @charge.account
|
8
|
-
end
|
9
|
-
|
10
|
-
test "should get new" do
|
11
|
-
get :new, account_id: @account
|
12
|
-
assert_response :success
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Billing
|
4
|
-
class ModifiersControllerTest < ActionController::TestCase
|
5
|
-
setup do
|
6
|
-
@modifier = billing_modifiers(:one)
|
7
|
-
@account = @modifier.account
|
8
|
-
end
|
9
|
-
|
10
|
-
test "should get new" do
|
11
|
-
get :new, account_id: @account
|
12
|
-
assert_response :success
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Billing
|
4
|
-
class PaymentsControllerTest < ActionController::TestCase
|
5
|
-
setup do
|
6
|
-
@payment = billing_payments(:one)
|
7
|
-
@account = @payment.account
|
8
|
-
end
|
9
|
-
|
10
|
-
test "should get new" do
|
11
|
-
get :new, account_id: @account
|
12
|
-
assert_response :success
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Billing
|
4
|
-
class AccountTest < ActiveSupport::TestCase
|
5
|
-
setup do
|
6
|
-
@account = billing_accounts(:one)
|
7
|
-
@account.save! # force summary calculation
|
8
|
-
end
|
9
|
-
|
10
|
-
test "charge" do
|
11
|
-
charge = @account.charge 3
|
12
|
-
assert charge.try(:persisted?)
|
13
|
-
assert_equal '13 USD'.to_money, @account.total # (1 + 3) + 100% + $1
|
14
|
-
end
|
15
|
-
|
16
|
-
test "discount" do
|
17
|
-
discount = @account.modify(-1.00, charge: billing_charges(:two))
|
18
|
-
assert discount.try(:persisted?)
|
19
|
-
assert_equal '6 USD'.to_money, @account.total
|
20
|
-
end
|
21
|
-
|
22
|
-
test "surcharge" do
|
23
|
-
surcharge = @account.modify(1.00, charge: billing_charges(:two))
|
24
|
-
assert surcharge.try(:persisted?)
|
25
|
-
assert_equal '8 USD'.to_money, @account.total
|
26
|
-
end
|
27
|
-
|
28
|
-
test "pay" do
|
29
|
-
payment = @account.pay billing_payment_types(:one)
|
30
|
-
assert @account.balance.zero?, @account.errors.full_messages.join(', ')
|
31
|
-
assert_equal '7 USD'.to_money, @account.payments_sum
|
32
|
-
end
|
33
|
-
|
34
|
-
test "validate positive total" do
|
35
|
-
assert @account.save
|
36
|
-
@account.modify(-500)
|
37
|
-
assert @account.errors.messages[:total]
|
38
|
-
assert_raise ActiveRecord::RecordInvalid do
|
39
|
-
@account.save!
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
test "account with payments should have origin" do
|
44
|
-
assert @account.origin
|
45
|
-
assert @account.payments.any?
|
46
|
-
@account.origin = nil
|
47
|
-
assert_equal false, @account.save
|
48
|
-
assert @account.errors.messages[:origin]
|
49
|
-
end
|
50
|
-
|
51
|
-
test "autofin" do
|
52
|
-
assert @account.pay billing_payment_types(:one)
|
53
|
-
assert @account.finalized_at
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|