billing 0.0.0 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/billing/accounts.js +2 -0
- data/app/assets/javascripts/billing/charges.js +2 -0
- data/app/assets/javascripts/billing/modifiers.js +2 -0
- data/app/assets/javascripts/billing/payments.js +2 -0
- data/app/assets/stylesheets/billing/accounts.css +4 -0
- data/app/assets/stylesheets/billing/charges.css +4 -0
- data/app/assets/stylesheets/billing/modifiers.css +4 -0
- data/app/assets/stylesheets/billing/payments.css +4 -0
- data/app/controllers/billing/accounts_controller.rb +29 -0
- data/app/controllers/billing/application_controller.rb +18 -0
- data/app/controllers/billing/charges_controller.rb +29 -0
- data/app/controllers/billing/modifiers_controller.rb +29 -0
- data/app/controllers/billing/payments_controller.rb +29 -0
- data/app/helpers/billing/accounts_helper.rb +4 -0
- data/app/helpers/billing/charges_helper.rb +4 -0
- data/app/helpers/billing/modifiers_helper.rb +4 -0
- data/app/helpers/billing/payments_helper.rb +4 -0
- data/app/models/billing/account.rb +66 -0
- data/app/models/billing/account_item.rb +15 -0
- data/app/models/billing/charge.rb +21 -0
- data/app/models/billing/modifier.rb +32 -0
- data/app/models/billing/modifier_items.rb +11 -0
- data/app/models/billing/origin.rb +4 -0
- data/app/models/billing/payment.rb +39 -0
- data/app/models/billing/payment_type.rb +6 -0
- data/app/models/billing/payment_with_type.rb +14 -0
- data/app/models/billing/plu.rb +4 -0
- data/app/models/billing/profile.rb +4 -0
- data/app/models/billing/tax_group.rb +4 -0
- data/app/views/billing/accounts/index.html.erb +7 -0
- data/app/views/billing/accounts/new.html.erb +8 -0
- data/app/views/billing/accounts/show.html.erb +29 -0
- data/app/views/billing/application/index.html.erb +3 -0
- data/app/views/billing/charges/new.html.erb +12 -0
- data/app/views/billing/modifiers/new.html.erb +18 -0
- data/app/views/billing/payments/new.html.erb +11 -0
- data/config/routes.rb +6 -0
- data/db/migrate/20140717180443_create_billing_accounts.rb +9 -0
- data/db/migrate/20140717181134_create_billing_charges.rb +11 -0
- data/db/migrate/20140717181406_create_billing_discounts.rb +11 -0
- data/db/migrate/20140717183129_create_billing_payments.rb +10 -0
- data/db/migrate/20140717202527_create_billing_origins.rb +9 -0
- data/db/migrate/20140718164841_add_sumaries_to_billing_account.rb +11 -0
- data/db/migrate/20140718210349_add_fixed_value_to_billing_discount.rb +7 -0
- data/db/migrate/20140718212116_create_billing_payment_types.rb +11 -0
- data/db/migrate/20140719094023_create_billing_tax_groups.rb +9 -0
- data/db/migrate/20140719094033_create_billing_plus.rb +9 -0
- data/db/migrate/20140719094418_create_billing_profiles.rb +9 -0
- data/db/migrate/20140719103621_rename_billing_discounts_to_modifiers.rb +5 -0
- data/db/migrate/20140719110412_add_surcharges_sum_to_billing_account.rb +7 -0
- data/db/migrate/20140720110811_add_type_to_billing_payment.rb +6 -0
- data/db/migrate/20140720132559_add_type_to_billing_payment_type.rb +5 -0
- data/lib/billing.rb +16 -0
- data/lib/billing/billable.rb +34 -0
- data/lib/billing/engine.rb +1 -0
- data/lib/billing/mapping.rb +32 -0
- data/lib/billing/routes.rb +16 -0
- data/lib/billing/version.rb +1 -1
- data/lib/tasks/billing.rake +7 -0
- data/test/controllers/billing/accounts_controller_test.rb +19 -0
- data/test/controllers/billing/charges_controller_test.rb +16 -0
- data/test/controllers/billing/modifiers_controller_test.rb +16 -0
- data/test/controllers/billing/payments_controller_test.rb +16 -0
- data/test/dummy/app/models/profile.rb +3 -0
- data/test/dummy/config/routes.rb +3 -2
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20140718104656_create_profiles.rb +8 -0
- data/test/dummy/db/schema.rb +112 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +1602 -0
- data/test/dummy/log/test.log +52069 -0
- data/test/dummy/test/fixtures/profiles.yml +11 -0
- data/test/dummy/test/models/profile_test.rb +7 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/02adf8ace512aefc4ef19b35aebc07f7 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/0cab887466527f5353fd43adab72769b +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/25b7c6efcbd128f109577104af58d084 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/2f52090f9e08ac02cd453b04af0df887 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/35a523ac3c33d6409a69faead4b2a882 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/3f4fc67be1dd91962f5a0026848dca77 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/43b3cc0ac6f63c0e1a3ab61fec84519d +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/59435066fc40e1ef5b45b0fd2c0eacf9 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/69cb965e6031d8099c185256f6fa8f90 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/6d34e4addaf3495d1d96306d164feb97 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/79316f9f3f5ebcec9b368d92d2e97e23 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/7ffc7e805e3fc08bae6a93e027a3e911 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/82ae0f4fbceb673c729b9bcb54a1161c +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/9509747efe602f6a81d50d9744f385f2 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/971b6b8d6c7a57e72d235e55537a2c44 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/b68d1e1a967e74abe3e10f643756ae67 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/cab3eca4515d1263ea8db2ff58df151d +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/cac68bb014ecc482b8f85312e49baa6f +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d3ab844c61f1c211ed5fad5407cd18ef +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d6d844128e4910cf773d1c48dd147e3b +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/e62907e54633a2adb53c33c1f59b79bf +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/e96b4e8fe0ebcceb51d202c8af7826ea +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/eb95e26896c1c6788657c4ef68a7e9e1 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/efaa0abeb4ad44b0ef8df996631f3997 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f393277b28dd79320611f18a379dbea7 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/fbf1489a0c3d66a329f070c10cd77a03 +0 -0
- data/test/fixtures/billing/accounts.yml +11 -0
- data/test/fixtures/billing/charges.yml +15 -0
- data/test/fixtures/billing/modifiers.yml +14 -0
- data/test/fixtures/billing/origins.yml +7 -0
- data/test/fixtures/billing/payment_types.yml +11 -0
- data/test/fixtures/billing/payments.yml +15 -0
- data/test/fixtures/billing/plus.yml +7 -0
- data/test/fixtures/billing/profiles.yml +7 -0
- data/test/fixtures/billing/tax_groups.yml +7 -0
- data/test/fixtures/profiles.yml +1 -0
- data/test/helpers/billing/accounts_helper_test.rb +6 -0
- data/test/helpers/billing/charges_helper_test.rb +6 -0
- data/test/helpers/billing/modifiers_helper_test.rb +6 -0
- data/test/helpers/billing/payments_helper_test.rb +6 -0
- data/test/models/billing/account_test.rb +43 -0
- data/test/models/billing/charge_test.rb +17 -0
- data/test/models/billing/modifier_test.rb +19 -0
- data/test/models/billing/origin_test.rb +9 -0
- data/test/models/billing/payment_test.rb +17 -0
- data/test/models/billing/payment_type_test.rb +9 -0
- data/test/models/billing/plu_test.rb +9 -0
- data/test/models/billing/profile_test.rb +9 -0
- data/test/models/billing/tax_group_test.rb +9 -0
- data/test/test_helper.rb +28 -2
- metadata +199 -7
@@ -0,0 +1,29 @@
|
|
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] %>
|
@@ -0,0 +1,18 @@
|
|
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 %>
|
data/config/routes.rb
CHANGED
data/lib/billing.rb
CHANGED
@@ -1,4 +1,20 @@
|
|
1
1
|
require "billing/engine"
|
2
|
+
require "billing/billable"
|
3
|
+
require "billing/mapping"
|
4
|
+
require "billing/routes"
|
2
5
|
|
3
6
|
module Billing
|
7
|
+
mattr_reader :mappings
|
8
|
+
@@mappings = ActiveSupport::OrderedHash.new
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def setup
|
12
|
+
yield self
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_mapping(resource, options)
|
16
|
+
mapping = Billing::Mapping.new(resource, options)
|
17
|
+
@@mappings[mapping.name] = mapping
|
18
|
+
end
|
19
|
+
end
|
4
20
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Billing
|
2
|
+
module Billable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
def composite_id
|
6
|
+
"#{(self.class.try(:base_class) || self.class).send(:name)}##{self.id}"
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def has_billing(options={})
|
11
|
+
payment_types_scope = options.delete(:payment_types)
|
12
|
+
has_many :billing_accounts, options.merge(as: :billable).reverse_merge(class_name: 'Billing::Account')
|
13
|
+
provide_billing_items(:billing_accounts)
|
14
|
+
if options[:as]
|
15
|
+
has_many options[:as], options.merge(as: :billable).reverse_merge(class_name: 'Billing::Account')
|
16
|
+
provide_billing_items(options[:as])
|
17
|
+
end
|
18
|
+
if payment_types_scope.present?
|
19
|
+
define_method :billing_payment_types do
|
20
|
+
payment_types_scope
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def provide_billing_items(association_name)
|
27
|
+
has_many "#{association_name}_charges".intern, class_name: 'Billing::Charge', through: association_name, source: :charges
|
28
|
+
has_many "#{association_name}_payments".intern, class_name: 'Billing::Payment', through: association_name, source: :payments
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
ActiveRecord::Base.send :include, Billing::Billable
|
data/lib/billing/engine.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
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
|
@@ -0,0 +1,16 @@
|
|
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
|
data/lib/billing/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
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
|