chargify 0.2.2 → 0.2.3
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.
- data/README.markdown +8 -0
- data/VERSION +1 -1
- data/chargify.gemspec +1 -1
- data/lib/chargify/client.rb +7 -0
- data/test/test_chargify.rb +21 -0
- metadata +2 -2
data/README.markdown
CHANGED
@@ -8,6 +8,14 @@ Ruby wrapper for the chargify.com SAAS and billing API
|
|
8
8
|
gem tumble
|
9
9
|
sudo gem install chargify
|
10
10
|
|
11
|
+
## Example Usage
|
12
|
+
|
13
|
+
### Create, cancel, then reactivate subscription
|
14
|
+
attributes = { :product_handle => 'basic' ... }
|
15
|
+
@client = Chargify::Client.new('InDhcXAAAAAg7juDD', 'xxx-test')
|
16
|
+
subscription = @client.create_subscription(attributes)
|
17
|
+
@client.cancel_subscription(subscription[:id], "Canceled due to bad customer service.")
|
18
|
+
@client.reactivate_subscription(subscription[:id]) #Made him an offer he couldn't refuse!
|
11
19
|
|
12
20
|
## Note on Patches/Pull Requests
|
13
21
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/chargify.gemspec
CHANGED
data/lib/chargify/client.rb
CHANGED
@@ -106,6 +106,13 @@ module Chargify
|
|
106
106
|
(response.subscription || response).update(:success? => deleted)
|
107
107
|
end
|
108
108
|
|
109
|
+
def reactivate_subscription(sub_id)
|
110
|
+
raw_response = self.class.put("/subscriptions/#{sub_id}/reactivate.json", :body => "")
|
111
|
+
reactivated = true if raw_response.code == 200
|
112
|
+
response = Hashie::Mash.new(raw_response) rescue Hashie::Mash.new
|
113
|
+
(response.subscription || response).update(:success? => reactivated)
|
114
|
+
end
|
115
|
+
|
109
116
|
def list_products
|
110
117
|
products = self.class.get("/products.json")
|
111
118
|
products.map{|p| Hashie::Mash.new p['product']}
|
data/test/test_chargify.rb
CHANGED
@@ -179,6 +179,27 @@ class TestChargify < Test::Unit::TestCase
|
|
179
179
|
subscription.success?.should == nil
|
180
180
|
end
|
181
181
|
|
182
|
+
should "reactivate a subscription" do
|
183
|
+
stub_put "https://OU812:x@pengwynn.chargify.com/subscriptions/123/reactivate.json", "subscription.json", 200
|
184
|
+
subscription = @client.reactivate_subscription(123)
|
185
|
+
|
186
|
+
subscription.state.should == "active"
|
187
|
+
end
|
188
|
+
|
189
|
+
should "set success? to nil when subscription is not reactivated successfully" do
|
190
|
+
stub_put "https://OU812:x@pengwynn.chargify.com/subscriptions/123/reactivate.json", "subscription_not_found.json", 500
|
191
|
+
subscription = @client.reactivate_subscription(123)
|
192
|
+
|
193
|
+
subscription.success?.should == nil
|
194
|
+
end
|
195
|
+
|
196
|
+
should "set success? to false when subscription is reactivated successfully" do
|
197
|
+
stub_put "https://OU812:x@pengwynn.chargify.com/subscriptions/123/reactivate.json", "subscription.json", 200
|
198
|
+
subscription = @client.reactivate_subscription(123)
|
199
|
+
|
200
|
+
subscription.success?.should == true
|
201
|
+
end
|
202
|
+
|
182
203
|
should "cancel subscription" do
|
183
204
|
stub_delete "https://OU812:x@pengwynn.chargify.com/subscriptions/123.json", "deleted_subscription.json", 200
|
184
205
|
subscription = @client.cancel_subscription(123)
|