chargify_api_ares 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -2
- data/VERSION +1 -1
- data/chargify_api_ares.gemspec +9 -2
- data/config/remote.example.yml +7 -0
- data/lib/chargify_api_ares.rb +64 -12
- data/samples/transactions.rb +17 -0
- data/spec/remote/remote_spec.rb +446 -0
- data/spec/remote/spec_helper.rb +37 -0
- data/spec/spec.opts +2 -0
- data/spec/subscription_spec.rb +0 -1
- metadata +16 -4
data/.gitignore
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
-
config
|
2
|
-
pkg
|
1
|
+
config/remote.yml
|
2
|
+
pkg
|
3
|
+
.rvmrc
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.4
|
data/chargify_api_ares.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{chargify_api_ares}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Klett", "The Lab Rats @ Phase Two Labs", "Brian Rose", "Nathan Verni"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-08-03}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = %q{mklett@grasshopper.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -23,17 +23,22 @@ Gem::Specification.new do |s|
|
|
23
23
|
"Rakefile",
|
24
24
|
"VERSION",
|
25
25
|
"chargify_api_ares.gemspec",
|
26
|
+
"config/remote.example.yml",
|
26
27
|
"lib/chargify_api_ares.rb",
|
27
28
|
"samples/customers.rb",
|
28
29
|
"samples/metered_components.rb",
|
29
30
|
"samples/products.rb",
|
30
31
|
"samples/subscriptions.rb",
|
32
|
+
"samples/transactions.rb",
|
31
33
|
"spec/base_spec.rb",
|
32
34
|
"spec/components_spec.rb",
|
33
35
|
"spec/customer_spec.rb",
|
34
36
|
"spec/factories.rb",
|
35
37
|
"spec/mocks/fake_resource.rb",
|
36
38
|
"spec/product_spec.rb",
|
39
|
+
"spec/remote/remote_spec.rb",
|
40
|
+
"spec/remote/spec_helper.rb",
|
41
|
+
"spec/spec.opts",
|
37
42
|
"spec/spec_helper.rb",
|
38
43
|
"spec/subscription_spec.rb",
|
39
44
|
"spec/subscriptions_component_spec.rb"
|
@@ -50,6 +55,8 @@ Gem::Specification.new do |s|
|
|
50
55
|
"spec/factories.rb",
|
51
56
|
"spec/mocks/fake_resource.rb",
|
52
57
|
"spec/product_spec.rb",
|
58
|
+
"spec/remote/remote_spec.rb",
|
59
|
+
"spec/remote/spec_helper.rb",
|
53
60
|
"spec/spec_helper.rb",
|
54
61
|
"spec/subscription_spec.rb",
|
55
62
|
"spec/subscriptions_component_spec.rb"
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Copy this file to config/remote.yml and make adjustments as necessary.
|
2
|
+
#
|
3
|
+
# Note: Remote tests will only work when configured to run on a test site that uses the Bogus gateway.
|
4
|
+
# Warning: all data in the site specified by 'subdomain' will be cleared and replaced with test data.
|
5
|
+
run_tests: true
|
6
|
+
subdomain: yoursubdomain
|
7
|
+
api_key: xxx
|
data/lib/chargify_api_ares.rb
CHANGED
@@ -50,29 +50,25 @@ end
|
|
50
50
|
module Chargify
|
51
51
|
|
52
52
|
class << self
|
53
|
-
attr_accessor :subdomain, :api_key, :site, :format
|
53
|
+
attr_accessor :subdomain, :api_key, :site, :format, :timeout
|
54
54
|
|
55
55
|
def configure
|
56
56
|
yield self
|
57
57
|
|
58
58
|
Base.user = api_key
|
59
59
|
Base.password = 'X'
|
60
|
+
Base.timeout = timeout unless (timeout.blank?)
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
Base.site = site
|
66
|
-
Subscription::Component.site = site + "/subscriptions/:subscription_id"
|
67
|
-
end
|
62
|
+
self.site ||= "https://#{subdomain}.chargify.com"
|
63
|
+
|
64
|
+
Base.site = site
|
65
|
+
Subscription::Component.site = site + "/subscriptions/:subscription_id"
|
68
66
|
end
|
69
67
|
end
|
70
68
|
|
71
69
|
class Base < ActiveResource::Base
|
72
|
-
|
73
|
-
|
74
|
-
name.split(/::/).last.underscore
|
75
|
-
end
|
70
|
+
def self.element_name
|
71
|
+
name.split(/::/).last.underscore
|
76
72
|
end
|
77
73
|
|
78
74
|
def to_xml(options = {})
|
@@ -81,10 +77,26 @@ module Chargify
|
|
81
77
|
end
|
82
78
|
end
|
83
79
|
|
80
|
+
class Site < Base
|
81
|
+
def self.clear_data!
|
82
|
+
post(:clear_data)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
84
86
|
class Customer < Base
|
85
87
|
def self.find_by_reference(reference)
|
86
88
|
Customer.new get(:lookup, :reference => reference)
|
87
89
|
end
|
90
|
+
|
91
|
+
def subscriptions(params = {})
|
92
|
+
params.merge!({:customer_id => self.id})
|
93
|
+
Subscription.find(:all, :params => params)
|
94
|
+
end
|
95
|
+
|
96
|
+
def payment_profiles(params = {})
|
97
|
+
params.merge!({:customer_id => self.id})
|
98
|
+
PaymentProfile.find(:all, :params => params)
|
99
|
+
end
|
88
100
|
end
|
89
101
|
|
90
102
|
class Subscription < Base
|
@@ -114,6 +126,10 @@ module Chargify
|
|
114
126
|
Component.find(:all, :params => params)
|
115
127
|
end
|
116
128
|
|
129
|
+
def payment_profile
|
130
|
+
credit_card
|
131
|
+
end
|
132
|
+
|
117
133
|
# Perform a one-time charge on an existing subscription.
|
118
134
|
# For more information, please see the one-time charge API docs available
|
119
135
|
# at: http://support.chargify.com/faqs/api/api-charges
|
@@ -121,6 +137,18 @@ module Chargify
|
|
121
137
|
post :charges, :charge => attrs
|
122
138
|
end
|
123
139
|
|
140
|
+
def credit(attrs = {})
|
141
|
+
post :credits, :credit => attrs
|
142
|
+
end
|
143
|
+
|
144
|
+
def reactivate(params = {})
|
145
|
+
put :reactivate, params
|
146
|
+
end
|
147
|
+
|
148
|
+
def reset_balance
|
149
|
+
put :reset_balance
|
150
|
+
end
|
151
|
+
|
124
152
|
def transactions()
|
125
153
|
Transaction.find(:all, :params =>{:subscription_id => self.id})
|
126
154
|
end
|
@@ -137,9 +165,30 @@ module Chargify
|
|
137
165
|
def self.find_by_handle(handle)
|
138
166
|
Product.new get(:lookup, :handle => handle)
|
139
167
|
end
|
168
|
+
|
169
|
+
protected
|
170
|
+
|
171
|
+
# Products are created in the scope of a ProductFamily, i.e. /product_families/nnn/products
|
172
|
+
#
|
173
|
+
# This alters the collection path such that it uses the product_family_id that is set on the
|
174
|
+
# attributes.
|
175
|
+
def create
|
176
|
+
pfid = begin
|
177
|
+
self.product_family_id
|
178
|
+
rescue NoMethodError
|
179
|
+
0
|
180
|
+
end
|
181
|
+
connection.post("/product_families/#{pfid}/products.#{self.class.format.extension}", encode, self.class.headers).tap do |response|
|
182
|
+
self.id = id_from_response(response)
|
183
|
+
load_attributes_from_response(response)
|
184
|
+
end
|
185
|
+
end
|
140
186
|
end
|
141
187
|
|
142
188
|
class ProductFamily < Base
|
189
|
+
def self.find_by_handle(handle, attributes = {})
|
190
|
+
ProductFamily.find(:one, :from => :lookup, :handle => handle)
|
191
|
+
end
|
143
192
|
end
|
144
193
|
|
145
194
|
class Usage < Base
|
@@ -157,4 +206,7 @@ module Chargify
|
|
157
206
|
class Transaction < Base
|
158
207
|
end
|
159
208
|
|
209
|
+
class PaymentProfile < Base
|
210
|
+
end
|
211
|
+
|
160
212
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
$: << File.expand_path(File.dirname(__FILE__) + '/../lib')
|
2
|
+
|
3
|
+
require 'chargify_api_ares'
|
4
|
+
|
5
|
+
# You could load your credentials from a file...
|
6
|
+
chargify_config = YAML::load_file(File.join(File.dirname(__FILE__), '..', 'config', 'chargify.yml'))
|
7
|
+
|
8
|
+
Chargify.configure do |c|
|
9
|
+
c.subdomain = chargify_config['subdomain']
|
10
|
+
c.api_key = chargify_config['api_key']
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
# Retrieve a list of all your customers
|
15
|
+
subscription = Chargify::Subscription.find(:all).first
|
16
|
+
|
17
|
+
transactions = subscription.transactions
|
@@ -0,0 +1,446 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
if run_remote_tests?
|
4
|
+
describe "Remote" do
|
5
|
+
before(:all) do
|
6
|
+
clear_site_data
|
7
|
+
setup_plans
|
8
|
+
setup_customer
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "creating a new subscription to a product with a trial" do
|
12
|
+
context "when providing valid attributes for the customer and the payment profile" do
|
13
|
+
before(:each) do
|
14
|
+
@subscription = create_once(:subscription) do
|
15
|
+
Chargify::Subscription.create(
|
16
|
+
:product_handle => @@basic_plan.handle,
|
17
|
+
:customer_attributes => valid_customer_attributes,
|
18
|
+
:payment_profile_attributes => good_payment_profile_attributes
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "successfully creates the subscription" do
|
24
|
+
@subscription.should be_a(Chargify::Subscription)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "sets the current_period_started_at attribute to now" do
|
28
|
+
@subscription.current_period_started_at.utc.should be_close(now.utc, approximately)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "sets the current_period_ends_at attribute to 1 month from now" do
|
32
|
+
@subscription.current_period_ends_at.utc.should be_close(one_month_from_now.utc, approximately)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "is in the trialing state" do
|
36
|
+
@subscription.state.should == 'trialing'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "creating a new subscription to a product without a trial" do
|
42
|
+
context "when providing an existing customer reference and valid payment profile attributes" do
|
43
|
+
before(:each) do
|
44
|
+
@subscription = create_once(:subscription) do
|
45
|
+
Chargify::Subscription.create(
|
46
|
+
:product_handle => @@pro_plan.handle,
|
47
|
+
:customer_reference => @@johnadoe.reference,
|
48
|
+
:payment_profile_attributes => good_payment_profile_attributes
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "successfully creates the subscription" do
|
54
|
+
@subscription.should be_a(Chargify::Subscription)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "sets the current_period_started_at attribute to now" do
|
58
|
+
@subscription.current_period_started_at.utc.should be_close(now.utc, approximately)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "sets the current_period_ends_at attribute to 1 month from now" do
|
62
|
+
@subscription.current_period_ends_at.utc.should be_close(one_month_from_now.utc, approximately)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "is in the active state" do
|
66
|
+
@subscription.state.should == 'active'
|
67
|
+
end
|
68
|
+
|
69
|
+
it "belongs to the existing customer" do
|
70
|
+
@subscription.customer.should == @@johnadoe
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "when providing an existing customer reference and an existing payment profile" do
|
75
|
+
before(:each) do
|
76
|
+
@subscription = create_once(:subscription) do
|
77
|
+
Chargify::Subscription.create(
|
78
|
+
:product_handle => @@pro_plan.handle,
|
79
|
+
:customer_reference => @@johnadoe.reference,
|
80
|
+
:payment_profile_id => @@johnadoes_credit_card.id.to_s
|
81
|
+
)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it "successfully creates the subscription" do
|
86
|
+
@subscription.should be_a(Chargify::Subscription)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "is in the active state" do
|
90
|
+
@subscription.state.should == 'active'
|
91
|
+
end
|
92
|
+
|
93
|
+
it "belongs to the existing customer" do
|
94
|
+
@subscription.customer.should == @@johnadoe
|
95
|
+
end
|
96
|
+
|
97
|
+
it "uses the provided credit card" do
|
98
|
+
expected_card = Chargify::PaymentProfile.find(@@johnadoes_credit_card.id)
|
99
|
+
@subscription.payment_profile.id.should == @@johnadoes_credit_card.id
|
100
|
+
@subscription.payment_profile.attributes.should == expected_card.attributes
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "when providing valid attributes for the customer and attributes for a credit card that cannot be stored" do
|
105
|
+
before(:each) do
|
106
|
+
@customer_attributes = valid_customer_attributes.dup
|
107
|
+
@subscription = create_once(:subscription) do
|
108
|
+
Chargify::Subscription.create(
|
109
|
+
:product_handle => @@basic_plan.handle,
|
110
|
+
:customer_attributes => @customer_attributes,
|
111
|
+
:payment_profile_attributes => unstorable_payment_profile_attributes
|
112
|
+
)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
it "does not create the subscription" do
|
117
|
+
@subscription.should_not be_valid
|
118
|
+
end
|
119
|
+
|
120
|
+
it "does not create the customer" do
|
121
|
+
lambda {
|
122
|
+
Chargify::Customer.find_by_reference(@customer_attributes[:reference])
|
123
|
+
}.should raise_error(ActiveResource::ResourceNotFound)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "importing a subscription to a product with a trial and a next billing date 10 days from now" do
|
130
|
+
context "when giving valid attributes for the customer and the payment profile" do
|
131
|
+
before(:each) do
|
132
|
+
@subscription = create_once(:subscription) do
|
133
|
+
Chargify::Subscription.create(
|
134
|
+
:product_handle => @@basic_plan.handle,
|
135
|
+
:customer_attributes => valid_customer_attributes,
|
136
|
+
:payment_profile_attributes => pretokenized_card_attributes,
|
137
|
+
:next_billing_at => ten_days_from_now.utc
|
138
|
+
)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
it "successfully creates the subscription" do
|
143
|
+
@subscription.should be_a(Chargify::Subscription)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "sets the current_period_started_at attribute to now" do
|
147
|
+
@subscription.current_period_started_at.utc.should be_close(now.utc, approximately)
|
148
|
+
end
|
149
|
+
|
150
|
+
it "sets the current_period_ends_at attribute to 1 month from now" do
|
151
|
+
@subscription.current_period_ends_at.utc.should be_close(ten_days_from_now.utc, approximately)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "is in the active state" do
|
155
|
+
@subscription.state.should == 'active'
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "creating failed subscriptions" do
|
161
|
+
context "due to providing payment profile attribtues for a card that will be declined" do
|
162
|
+
before(:each) do
|
163
|
+
@customer_attributes = valid_customer_attributes.dup
|
164
|
+
@subscription = create_once(:subscription) do
|
165
|
+
Chargify::Subscription.create(
|
166
|
+
:product_handle => @@pro_plan.handle,
|
167
|
+
:customer_attributes => @customer_attributes,
|
168
|
+
:payment_profile_attributes => declined_payment_profile_attributes
|
169
|
+
)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
it "does not create the subscription" do
|
174
|
+
@subscription.should_not be_valid
|
175
|
+
end
|
176
|
+
|
177
|
+
it "does not create the customer" do
|
178
|
+
lambda {
|
179
|
+
Chargify::Customer.find_by_reference(@customer_attributes[:reference])
|
180
|
+
}.should raise_error(ActiveResource::ResourceNotFound)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe "cancelling a subscription" do
|
186
|
+
before(:each) do
|
187
|
+
@subscription = create_once(:subscription) do
|
188
|
+
Chargify::Subscription.create(
|
189
|
+
:product_handle => @@pro_plan.handle,
|
190
|
+
:customer_reference => @@johnadoe.reference,
|
191
|
+
:payment_profile_attributes => good_payment_profile_attributes
|
192
|
+
)
|
193
|
+
end
|
194
|
+
@subscription.cancel
|
195
|
+
end
|
196
|
+
|
197
|
+
it "is in the canceled state" do
|
198
|
+
Chargify::Subscription.find(@subscription.id).state.should == 'canceled'
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "reactivating a subscriptions" do
|
203
|
+
before(:each) do
|
204
|
+
@subscription = create_once(:subscription) do
|
205
|
+
Chargify::Subscription.create(
|
206
|
+
:product_handle => @@pro_plan.handle,
|
207
|
+
:customer_reference => @@johnadoe.reference,
|
208
|
+
:payment_profile_attributes => good_payment_profile_attributes
|
209
|
+
)
|
210
|
+
end
|
211
|
+
@subscription.cancel
|
212
|
+
@subscription.reload.state.should == 'canceled'
|
213
|
+
@subscription.reactivate
|
214
|
+
end
|
215
|
+
|
216
|
+
it "puts it in the active state" do
|
217
|
+
@subscription.reload.state.should == 'active'
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
describe "adding a one time charge" do
|
222
|
+
before(:each) do
|
223
|
+
@subscription = create_once(:subscription) do
|
224
|
+
Chargify::Subscription.create(
|
225
|
+
:product_handle => @@pro_plan.handle,
|
226
|
+
:customer_reference => @@johnadoe.reference,
|
227
|
+
:payment_profile_attributes => good_payment_profile_attributes
|
228
|
+
)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
it "creates a charge and payment" do
|
232
|
+
lambda{
|
233
|
+
@subscription.charge(:amount => 7, :memo => 'One Time Charge')
|
234
|
+
}.should change{@subscription.reload.transactions.size}.by(2)
|
235
|
+
@subscription.transactions.first.amount_in_cents.should == 700
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
describe "adding a credit" do
|
240
|
+
before(:each) do
|
241
|
+
@subscription = create_once(:subscription) do
|
242
|
+
Chargify::Subscription.create(
|
243
|
+
:product_handle => @@pro_plan.handle,
|
244
|
+
:customer_reference => @@johnadoe.reference,
|
245
|
+
:payment_profile_attributes => good_payment_profile_attributes
|
246
|
+
)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
it "creates a credit" do
|
251
|
+
lambda{
|
252
|
+
@subscription.credit(:amount => 7, :memo => 'credit')
|
253
|
+
}.should change{@subscription.reload.transactions.size}.by(1)
|
254
|
+
@subscription.transactions.first.amount_in_cents.should == 700
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
def already_cleared_site_data?
|
259
|
+
@@already_cleared_site_data ||= nil
|
260
|
+
@@already_cleared_site_data == true
|
261
|
+
end
|
262
|
+
|
263
|
+
def cleared_site_data!
|
264
|
+
@@already_cleared_site_data = true
|
265
|
+
end
|
266
|
+
|
267
|
+
def clear_site_data
|
268
|
+
return if already_cleared_site_data?
|
269
|
+
begin
|
270
|
+
Chargify::Site.clear_data!
|
271
|
+
cleared_site_data!
|
272
|
+
rescue ActiveResource::ForbiddenAccess
|
273
|
+
raise StandardError.new("Remote specs may only be run against a site in test mode")
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
# Create Basic and Pro products in the Acme Projects family
|
278
|
+
def setup_plans
|
279
|
+
begin
|
280
|
+
@@acme_projects ||= Chargify::ProductFamily.find_by_handle('acme-projects')
|
281
|
+
rescue ActiveResource::ResourceNotFound
|
282
|
+
@@acme_projects = Chargify::ProductFamily.new(
|
283
|
+
:name => "Acme Projects"
|
284
|
+
)
|
285
|
+
result = @@acme_projects.save
|
286
|
+
result.should be_true
|
287
|
+
end
|
288
|
+
|
289
|
+
begin
|
290
|
+
@@basic_plan ||= Chargify::Product.find_by_handle('basic')
|
291
|
+
rescue ActiveResource::ResourceNotFound
|
292
|
+
@@basic_plan = Chargify::Product.new(
|
293
|
+
:product_family_id => @@acme_projects.id,
|
294
|
+
:name => "Basic Plan",
|
295
|
+
:handle => "basic",
|
296
|
+
:price_in_cents => 1000,
|
297
|
+
:interval => 1,
|
298
|
+
:interval_unit => 'month',
|
299
|
+
:trial_interval => 1,
|
300
|
+
:trial_interval_unit => 'month',
|
301
|
+
:trial_price_in_cents => 0
|
302
|
+
)
|
303
|
+
result = @@basic_plan.save
|
304
|
+
result.should be_true
|
305
|
+
end
|
306
|
+
|
307
|
+
begin
|
308
|
+
@@pro_plan ||= Chargify::Product.find_by_handle('pro')
|
309
|
+
rescue ActiveResource::ResourceNotFound
|
310
|
+
@@pro_plan = Chargify::Product.new(
|
311
|
+
:product_family_id => @@acme_projects.id,
|
312
|
+
:name => "Pro Plan",
|
313
|
+
:handle => "pro",
|
314
|
+
:price_in_cents => 5000,
|
315
|
+
:interval => 1,
|
316
|
+
:interval_unit => 'month'
|
317
|
+
)
|
318
|
+
result = @@pro_plan.save
|
319
|
+
result.should be_true
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
def setup_customer
|
324
|
+
# Create a customer
|
325
|
+
begin
|
326
|
+
@@johnadoe ||= Chargify::Customer.find_by_reference('a')
|
327
|
+
rescue ActiveResource::ResourceNotFound
|
328
|
+
@@johnadoe = Chargify::Customer.new(valid_customer_attributes)
|
329
|
+
result = @@johnadoe.save
|
330
|
+
result.should be_true
|
331
|
+
|
332
|
+
@@johnadoes_credit_card = Chargify::PaymentProfile.new(
|
333
|
+
good_payment_profile_attributes.merge(:customer_id => @@johnadoe.id)
|
334
|
+
)
|
335
|
+
result = @@johnadoes_credit_card.save
|
336
|
+
result.should be_true
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
def now
|
341
|
+
Time.now
|
342
|
+
end
|
343
|
+
|
344
|
+
def one_month_from_now
|
345
|
+
Time.now + 1.month
|
346
|
+
end
|
347
|
+
|
348
|
+
def ten_days_from_now
|
349
|
+
10.days.from_now
|
350
|
+
end
|
351
|
+
|
352
|
+
# Gives a reasonable range for time comparisons
|
353
|
+
def approximately
|
354
|
+
@approximately ||= 5.minutes
|
355
|
+
end
|
356
|
+
|
357
|
+
def valid_customer_attributes
|
358
|
+
initial = next_customer_initial
|
359
|
+
{
|
360
|
+
:first_name => "John #{initial.upcase}",
|
361
|
+
:last_name => "Doe",
|
362
|
+
:email => "john.#{initial}.doe@example.com",
|
363
|
+
:reference => initial
|
364
|
+
}
|
365
|
+
end
|
366
|
+
|
367
|
+
def good_payment_profile_attributes
|
368
|
+
{
|
369
|
+
:full_number => '1',
|
370
|
+
:expiration_month => '12',
|
371
|
+
:expiration_year => Time.now.year + 1
|
372
|
+
}
|
373
|
+
end
|
374
|
+
|
375
|
+
def declined_payment_profile_attributes
|
376
|
+
{
|
377
|
+
:full_number => '2',
|
378
|
+
:expiration_month => '12',
|
379
|
+
:expiration_year => Time.now.year + 1
|
380
|
+
}
|
381
|
+
end
|
382
|
+
|
383
|
+
def unstorable_payment_profile_attributes
|
384
|
+
{
|
385
|
+
:full_number => '3',
|
386
|
+
:expiration_month => '12',
|
387
|
+
:expiration_year => Time.now.year + 1
|
388
|
+
}
|
389
|
+
end
|
390
|
+
|
391
|
+
def expired_payment_profile_attributes
|
392
|
+
{
|
393
|
+
:full_number => '1',
|
394
|
+
:expiration_month => '12',
|
395
|
+
:expiration_year => Time.now.year - 1
|
396
|
+
}
|
397
|
+
end
|
398
|
+
|
399
|
+
def pretokenized_card_attributes
|
400
|
+
{
|
401
|
+
:vault_token => '1',
|
402
|
+
:current_vault => 'bogus',
|
403
|
+
:expiration_month => '12',
|
404
|
+
:expiration_year => Time.now.year + 1,
|
405
|
+
:last_four => '1234',
|
406
|
+
:card_type => 'visa'
|
407
|
+
}
|
408
|
+
end
|
409
|
+
|
410
|
+
# Don't create more than 26 customers until we add more initials :)
|
411
|
+
def next_customer_initial
|
412
|
+
@@customer_initial_index ||= 0
|
413
|
+
initial = customer_initials[@@customer_initial_index]
|
414
|
+
@@customer_initial_index += 1
|
415
|
+
initial
|
416
|
+
end
|
417
|
+
|
418
|
+
# An array of intials
|
419
|
+
def customer_initials
|
420
|
+
@customer_initials ||= ('a'..'z').to_a
|
421
|
+
end
|
422
|
+
|
423
|
+
# Allows us to create remote resources once per spec hierarchy
|
424
|
+
def create_once(type, &block)
|
425
|
+
hierarchy = example_group_hierarchy.collect(&:object_id).to_s
|
426
|
+
|
427
|
+
unless resource(type, hierarchy)
|
428
|
+
register_resource(type, hierarchy, block.call)
|
429
|
+
end
|
430
|
+
resource(type, hierarchy)
|
431
|
+
end
|
432
|
+
|
433
|
+
def resource(type, hierarchy)
|
434
|
+
@@resources ||= {}
|
435
|
+
@@resources[type] ||= {}
|
436
|
+
@@resources[type][hierarchy]
|
437
|
+
end
|
438
|
+
|
439
|
+
def register_resource(type, hierarchy, resource)
|
440
|
+
@@resources ||= {}
|
441
|
+
@@resources[type] ||= {}
|
442
|
+
@@resources[type][hierarchy] = resource
|
443
|
+
end
|
444
|
+
|
445
|
+
end
|
446
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
5
|
+
|
6
|
+
require 'chargify_api_ares'
|
7
|
+
|
8
|
+
Spec::Runner.configure do |config|
|
9
|
+
config.before(:all) do
|
10
|
+
Chargify.configure do |c|
|
11
|
+
c.subdomain = remote_configuration['subdomain']
|
12
|
+
c.api_key = remote_configuration['api_key']
|
13
|
+
if remote_configuration['site']
|
14
|
+
c.site = remote_configuration['site']
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def run_remote_tests?
|
21
|
+
remote_configuration['run_tests'] === true
|
22
|
+
end
|
23
|
+
|
24
|
+
def remote_configuration
|
25
|
+
@remote_configuration ||= load_remote_configuration_file
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def load_remote_configuration_file
|
31
|
+
configuration_file = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'remote.yml'))
|
32
|
+
if File.exist?(configuration_file)
|
33
|
+
YAML.load_file(configuration_file)
|
34
|
+
else
|
35
|
+
{}
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/subscription_spec.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chargify_api_ares
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
9
|
+
- 4
|
10
|
+
version: 0.3.4
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Michael Klett
|
@@ -17,7 +18,7 @@ autorequire:
|
|
17
18
|
bindir: bin
|
18
19
|
cert_chain: []
|
19
20
|
|
20
|
-
date: 2010-
|
21
|
+
date: 2010-08-03 00:00:00 -04:00
|
21
22
|
default_executable:
|
22
23
|
dependencies: []
|
23
24
|
|
@@ -37,17 +38,22 @@ files:
|
|
37
38
|
- Rakefile
|
38
39
|
- VERSION
|
39
40
|
- chargify_api_ares.gemspec
|
41
|
+
- config/remote.example.yml
|
40
42
|
- lib/chargify_api_ares.rb
|
41
43
|
- samples/customers.rb
|
42
44
|
- samples/metered_components.rb
|
43
45
|
- samples/products.rb
|
44
46
|
- samples/subscriptions.rb
|
47
|
+
- samples/transactions.rb
|
45
48
|
- spec/base_spec.rb
|
46
49
|
- spec/components_spec.rb
|
47
50
|
- spec/customer_spec.rb
|
48
51
|
- spec/factories.rb
|
49
52
|
- spec/mocks/fake_resource.rb
|
50
53
|
- spec/product_spec.rb
|
54
|
+
- spec/remote/remote_spec.rb
|
55
|
+
- spec/remote/spec_helper.rb
|
56
|
+
- spec/spec.opts
|
51
57
|
- spec/spec_helper.rb
|
52
58
|
- spec/subscription_spec.rb
|
53
59
|
- spec/subscriptions_component_spec.rb
|
@@ -61,23 +67,27 @@ rdoc_options:
|
|
61
67
|
require_paths:
|
62
68
|
- lib
|
63
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
64
71
|
requirements:
|
65
72
|
- - ">="
|
66
73
|
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
67
75
|
segments:
|
68
76
|
- 0
|
69
77
|
version: "0"
|
70
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
71
80
|
requirements:
|
72
81
|
- - ">="
|
73
82
|
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
74
84
|
segments:
|
75
85
|
- 0
|
76
86
|
version: "0"
|
77
87
|
requirements: []
|
78
88
|
|
79
89
|
rubyforge_project:
|
80
|
-
rubygems_version: 1.3.
|
90
|
+
rubygems_version: 1.3.7
|
81
91
|
signing_key:
|
82
92
|
specification_version: 3
|
83
93
|
summary: A Chargify API wrapper for Ruby using ActiveResource
|
@@ -88,6 +98,8 @@ test_files:
|
|
88
98
|
- spec/factories.rb
|
89
99
|
- spec/mocks/fake_resource.rb
|
90
100
|
- spec/product_spec.rb
|
101
|
+
- spec/remote/remote_spec.rb
|
102
|
+
- spec/remote/spec_helper.rb
|
91
103
|
- spec/spec_helper.rb
|
92
104
|
- spec/subscription_spec.rb
|
93
105
|
- spec/subscriptions_component_spec.rb
|