billingly 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -119,7 +119,7 @@ module Billingly
119
119
 
120
120
  subscriptions.build.tap do |new|
121
121
  [:payable_upfront, :description, :periodicity,
122
- :amount, :grace_period].each do |k|
122
+ :amount, :grace_period, :signup_price].each do |k|
123
123
  new[k] = plan[k]
124
124
  end
125
125
  new.plan = plan if plan.is_a?(Billingly::Plan)
@@ -138,6 +138,7 @@ module Billingly
138
138
  code = Billingly::SpecialPlanCode.find_by_code(code_string)
139
139
  return if code.nil?
140
140
  return if code.redeemed?
141
+ credit_payment(code.bonus_amount) if code.bonus_amount
141
142
  subscribe_to_plan(code.plan)
142
143
  code.update_attributes(customer: self, redeemed_on: Time.now)
143
144
  end
@@ -95,6 +95,16 @@ module Billingly
95
95
  not is_trial_expiring_on.nil?
96
96
  end
97
97
 
98
+ # Some subscriptions have a setup fee, or an initial discount.
99
+ # For billingly, this is considered a signup_price. If set, then the first invoice
100
+ # to be generated for this subscription will be for the amount specified in signup_price
101
+ # instead of {#amount}
102
+ #
103
+ # A signup_price can also be specified on a {Billingly::Plan Plan} and will be copied
104
+ # over to the subscription when subscribing to it.
105
+ # @property signup_price
106
+ # @return [BigDecimal]
107
+
98
108
  # Invoices will be generated before their due_date, as soon as possible,
99
109
  # but not sooner than GENERATE_AHEAD days.
100
110
  GENERATE_AHEAD = 3.days
@@ -108,6 +118,8 @@ module Billingly
108
118
  # The invoice generation process should run frequently, at least on a daily basis.
109
119
  # It will create invoices some time before they are due, to give customers a chance
110
120
  # to pay and settle them.
121
+ # If there is any {#signup_price} then the first invoice will be for that amount
122
+ # instead of the regular amount.
111
123
  # This method is idempotent, if an upcoming invoice for a subscription already exists,
112
124
  # it does not create yet another one.
113
125
  def generate_next_invoice
@@ -118,7 +130,9 @@ module Billingly
118
130
  due_on = (payable_upfront ? from : to) + grace_period
119
131
  return if GENERATE_AHEAD.from_now < from
120
132
 
121
- invoice = invoices.create!(customer: customer, amount: amount,
133
+ payable_amount = (invoices.empty? && signup_price) ? signup_price : amount
134
+
135
+ invoice = invoices.create!(customer: customer, amount: payable_amount,
122
136
  due_on: due_on, period_start: from, period_end: to)
123
137
  invoice.charge
124
138
  return invoice
@@ -11,7 +11,7 @@ class Billingly::SpecialPlanCode < ActiveRecord::Base
11
11
  validates :plan, presence: true
12
12
  validates :code, presence: true
13
13
 
14
- attr_accessible :plan, :code, :customer, :redeemed_on
14
+ attr_accessible :plan, :code, :customer, :redeemed_on, :bonus_amount
15
15
 
16
16
  # !@attribute [r] redeemed?
17
17
  # @return [Boolean] Whether this code has been redeemed or not
@@ -36,9 +36,9 @@ class Billingly::SpecialPlanCode < ActiveRecord::Base
36
36
  # with pre-existing codes.
37
37
  # @param plan [Plan] The plan to generate the codes for.
38
38
  # @param how_many [Integer] How many new codes to issue.
39
- def self.generate_for_plan(plan, how_many)
39
+ def self.generate_for_plan(plan, how_many, bonus_amount = nil)
40
40
  generate_ean_13_codes(how_many).collect do |code|
41
- self.create!(code: code, plan: plan)
41
+ self.create!(code: code, plan: plan, bonus_amount: bonus_amount)
42
42
  end
43
43
  end
44
44
 
@@ -1,3 +1,3 @@
1
1
  module Billingly
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
@@ -51,6 +51,7 @@ class CreateBillinglyTables < ActiveRecord::Migration
51
51
  t.datetime 'notified_trial_will_expire_on'
52
52
  t.datetime 'notified_trial_expired_on'
53
53
  t.references :plan
54
+ t.decimal :signup_price, precision: 11, scale: 2
54
55
  t.timestamps
55
56
  end
56
57
 
@@ -61,12 +62,14 @@ class CreateBillinglyTables < ActiveRecord::Migration
61
62
  t.decimal 'amount', precision: 11, scale: 2, default: 0.0, null: false # 9.99
62
63
  t.boolean 'payable_upfront', null: false
63
64
  t.string 'grace_period', null: false
65
+ t.integer 'signup_price'
64
66
  t.boolean 'hidden_on'
65
67
  t.timestamps
66
68
  end
67
69
 
68
70
  create_table :billingly_special_plan_codes do |t|
69
71
  t.references :plan, null: false
72
+ t.decimal :bonus_amount, precision: 11, scale: 2
70
73
  t.string :code
71
74
  t.references :customer
72
75
  t.datetime :redeemed_on
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: billingly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-01 00:00:00.000000000 Z
12
+ date: 2012-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70254701290620 !ruby/object:Gem::Requirement
16
+ requirement: &70111324776440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70254701290620
24
+ version_requirements: *70111324776440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: validates_email_format_of
27
- requirement: &70254701289380 !ruby/object:Gem::Requirement
27
+ requirement: &70111324775900 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70254701289380
35
+ version_requirements: *70111324775900
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: has_duration
38
- requirement: &70254701288520 !ruby/object:Gem::Requirement
38
+ requirement: &70111324775360 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70254701288520
46
+ version_requirements: *70111324775360
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: ean13
49
- requirement: &70254701287420 !ruby/object:Gem::Requirement
49
+ requirement: &70111324774840 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70254701287420
57
+ version_requirements: *70111324774840
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: timecop
60
- requirement: &70254701286240 !ruby/object:Gem::Requirement
60
+ requirement: &70111324774320 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70254701286240
68
+ version_requirements: *70111324774320
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
- requirement: &70254701285400 !ruby/object:Gem::Requirement
71
+ requirement: &70111324773780 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70254701285400
79
+ version_requirements: *70111324773780
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec-rails
82
- requirement: &70254701284720 !ruby/object:Gem::Requirement
82
+ requirement: &70111324773280 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70254701284720
90
+ version_requirements: *70111324773280
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: factory_girl_rails
93
- requirement: &70254701284160 !ruby/object:Gem::Requirement
93
+ requirement: &70111324772780 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70254701284160
101
+ version_requirements: *70111324772780
102
102
  description: Rails Engine for SaaS subscription management. Manage subscriptions,
103
103
  plan changes, free trials and more!!!
104
104
  email: