acts_as_subscription 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/acts_as_subscription.gemspec +2 -2
- data/lib/acts_as_subscription/backend/chargify_client.rb +6 -4
- data/lib/acts_as_subscription/subscription.rb +14 -7
- data/spec/models/subscription_spec.rb +30 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/support/models.rb +2 -0
- data/spec/support/schema.rb +1 -0
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{acts_as_subscription}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dave Perrett"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-03-18}
|
13
13
|
s.description = %q{With ActsAsSubscription, you can hook your model into several subscription services, such as CheddarGetter.}
|
14
14
|
s.email = %q{mail@recursive-design.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -157,11 +157,13 @@ module ActsAsSubscription::Subscription::Backend
|
|
157
157
|
attributes[:credit_card_attributes] = {
|
158
158
|
:first_name => subscription.first_name,
|
159
159
|
:last_name => subscription.last_name,
|
160
|
-
:full_number => subscription.cc_number,
|
161
|
-
:expiration_month => subscription.cc_expiration_month,
|
162
|
-
:expiration_year => subscription.cc_expiration_year,
|
163
|
-
:billing_zip_code => subscription.zip_code,
|
164
160
|
}
|
161
|
+
|
162
|
+
attributes[:credit_card_attributes][:full_number] = subscription.cc_number if subscription.cc_number
|
163
|
+
attributes[:credit_card_attributes][:expiration_month] = subscription.cc_expiration_month if subscription.cc_expiration_month
|
164
|
+
attributes[:credit_card_attributes][:expiration_year] = subscription.cc_expiration_year if subscription.cc_expiration_year
|
165
|
+
attributes[:credit_card_attributes][:cvv] = subscription.cc_verification_value if subscription.cc_verification_value
|
166
|
+
attributes[:credit_card_attributes][:billing_zip_code] = subscription.zip_code if subscription.zip_code
|
165
167
|
end
|
166
168
|
|
167
169
|
return attributes
|
@@ -95,17 +95,18 @@ module ActsAsSubscription
|
|
95
95
|
|
96
96
|
validates :cc_number,
|
97
97
|
:presence => true,
|
98
|
-
:
|
98
|
+
:if => :require_cc_number?
|
99
99
|
|
100
100
|
validates_associated :credit_card,
|
101
|
-
:
|
101
|
+
:if => :require_cc_number?
|
102
102
|
|
103
103
|
before_validation :update_credit_card
|
104
104
|
|
105
105
|
before_validation :assign_customer_code,
|
106
|
-
:on
|
106
|
+
:on => :create
|
107
107
|
|
108
|
-
validate :validate_credit_card
|
108
|
+
validate :validate_credit_card,
|
109
|
+
:if => :require_cc_number?
|
109
110
|
|
110
111
|
attr_accessible :cc_expiration_month,
|
111
112
|
:cc_expiration_year,
|
@@ -158,13 +159,15 @@ module ActsAsSubscription
|
|
158
159
|
end
|
159
160
|
|
160
161
|
def backend_save
|
161
|
-
p "+++++++++++++++++++++++ saving +++++++++++++++++++++++"
|
162
162
|
if self.new_record?
|
163
163
|
result = ActsAsSubscription::Subscription::Backend.instance.create_subscription(self)
|
164
164
|
else
|
165
165
|
result = ActsAsSubscription::Subscription::Backend.instance.update_subscription(self)
|
166
166
|
end
|
167
167
|
|
168
|
+
# Decide whether payment has been recorded.
|
169
|
+
self.payment_details_recorded = (result and !self.is_free_plan?) unless self.payment_details_recorded
|
170
|
+
|
168
171
|
# No way of knowing what fields the errors are for for some backends - just add a top-level error.
|
169
172
|
unless result == true
|
170
173
|
self.errors.add :base, result
|
@@ -176,16 +179,20 @@ module ActsAsSubscription
|
|
176
179
|
|
177
180
|
# This can be overridden in the implementing model, to turn off zip-code validation.
|
178
181
|
def require_zip_code?
|
179
|
-
return self.is_free_plan? == false
|
182
|
+
return (self.is_free_plan? == false)
|
180
183
|
end
|
181
184
|
|
182
185
|
# This can be overridden in the implementing model, to turn off verification-value validation.
|
183
186
|
def require_verification_value?
|
184
|
-
return self.is_free_plan? == false
|
187
|
+
return (self.is_free_plan? == false)
|
185
188
|
end
|
186
189
|
|
187
190
|
protected
|
188
191
|
|
192
|
+
def require_cc_number?
|
193
|
+
return ((self.is_free_plan? == false) and (self.payment_details_recorded == false))
|
194
|
+
end
|
195
|
+
|
189
196
|
# Assigns a unique UUID for the customer.
|
190
197
|
def assign_customer_code
|
191
198
|
self.customer_code ||= UUIDTools::UUID.random_create.to_s
|
@@ -25,6 +25,11 @@ describe Subscription do
|
|
25
25
|
subscription.credit_card.class.should == ActiveMerchant::Billing::CreditCard
|
26
26
|
end
|
27
27
|
|
28
|
+
it 'should not have payment_details_recorded' do
|
29
|
+
subscription = Subscription.new(@free_attr)
|
30
|
+
subscription.payment_details_recorded.should == false
|
31
|
+
end
|
32
|
+
|
28
33
|
end
|
29
34
|
|
30
35
|
describe 'validation' do
|
@@ -94,6 +99,18 @@ describe Subscription do
|
|
94
99
|
subscription = Subscription.new(@free_attr)
|
95
100
|
subscription.is_free_plan?.should == true
|
96
101
|
end
|
102
|
+
|
103
|
+
it 'should not have payment_details_recorded' do
|
104
|
+
subscription = Subscription.create(@free_attr)
|
105
|
+
subscription.payment_details_recorded.should == false
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should have payment_details_recorded after update to paid plan' do
|
109
|
+
subscription = Subscription.create(@free_attr)
|
110
|
+
subscription.payment_details_recorded.should == false
|
111
|
+
subscription.update_attributes(@paid_attr)
|
112
|
+
subscription.payment_details_recorded.should == true
|
113
|
+
end
|
97
114
|
|
98
115
|
end
|
99
116
|
|
@@ -136,11 +153,18 @@ describe Subscription do
|
|
136
153
|
subscription.should_not be_valid
|
137
154
|
end
|
138
155
|
|
139
|
-
it 'should require a cc_number' do
|
156
|
+
it 'should require a cc_number if none has been recorded' do
|
140
157
|
subscription = Subscription.new(@paid_attr.merge(:cc_number => ''))
|
141
158
|
subscription.should_not be_valid
|
142
159
|
end
|
143
160
|
|
161
|
+
it 'should not require a cc_number if one has already been recorded' do
|
162
|
+
subscription = Subscription.new(@paid_attr)
|
163
|
+
subscription.cc_number = nil
|
164
|
+
subscription.payment_details_recorded = true
|
165
|
+
subscription.should be_valid
|
166
|
+
end
|
167
|
+
|
144
168
|
describe 'with valid parameters' do
|
145
169
|
|
146
170
|
it 'should validate' do
|
@@ -182,6 +206,11 @@ describe Subscription do
|
|
182
206
|
subscription.credit_card.verification_value.should == @paid_attr[:cc_verification_value]
|
183
207
|
subscription.credit_card.number.should == @paid_attr[:cc_number]
|
184
208
|
end
|
209
|
+
|
210
|
+
it 'should have payment_details_recorded' do
|
211
|
+
subscription = Subscription.create(@paid_attr)
|
212
|
+
subscription.payment_details_recorded.should == true
|
213
|
+
end
|
185
214
|
|
186
215
|
end
|
187
216
|
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/models.rb
CHANGED
data/spec/support/schema.rb
CHANGED
@@ -12,6 +12,7 @@ ActiveRecord::Schema.define :version => 0 do
|
|
12
12
|
t.integer :cc_expiration_year
|
13
13
|
t.string :cc_last_digits
|
14
14
|
t.string :cc_verification_value
|
15
|
+
t.boolean :payment_details_recorded, :null => false, :default => false
|
15
16
|
t.datetime :canceled_at
|
16
17
|
t.datetime :suspended_at
|
17
18
|
t.timestamps
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_subscription
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dave Perrett
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-03-18 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|