chargify_api_ares 0.2.3 → 0.2.4
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/VERSION +1 -1
- data/chargify_api_ares.gemspec +2 -2
- data/lib/chargify_api_ares.rb +5 -0
- data/samples/subscriptions.rb +5 -0
- data/spec/product_spec.rb +1 -0
- data/spec/subscription_spec.rb +21 -12
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.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.2.
|
8
|
+
s.version = "0.2.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"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-03-05}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = %q{mklett@grasshopper.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/chargify_api_ares.rb
CHANGED
@@ -81,6 +81,11 @@ module Chargify
|
|
81
81
|
end
|
82
82
|
|
83
83
|
class Subscription < Base
|
84
|
+
def self.find_by_customer_reference(reference)
|
85
|
+
customer = Customer.find_by_reference(reference)
|
86
|
+
find(:first, :params => {:customer_id => customer.id})
|
87
|
+
end
|
88
|
+
|
84
89
|
# Strip off nested attributes of associations before saving, or type-mismatch errors will occur
|
85
90
|
def save
|
86
91
|
self.attributes.delete('customer')
|
data/samples/subscriptions.rb
CHANGED
@@ -31,6 +31,11 @@ subscription = Chargify::Subscription.create(
|
|
31
31
|
# => #<Chargify::Subscription:0x1020ed4b0 @prefix_options={}, @attributes={"cancellation_message"=>nil, "activated_at"=>Tue Nov 17 16:00:17 UTC 2009, "expires_at"=>nil, "updated_at"=>Tue Nov 17 16:00:17 UTC 2009, "credit_card"=>#<Chargify::Subscription::CreditCard:0x102046b10 @prefix_options={}, @attributes={"card_type"=>"bogus", "expiration_year"=>2020, "masked_card_number"=>"XXXX-XXXX-XXXX-1", "first_name"=>"Michael", "expiration_month"=>1, "last_name"=>"Klett"}>, "product"=>#<Chargify::Product:0x10204a2d8 @prefix_options={}, @attributes={"price_in_cents"=>0, "name"=>"Chargify API Ares Test", "handle"=>"chargify-api-ares-test", "product_family"=>#<Chargify::Product::ProductFamily:0x1020490b8 @prefix_options={}, @attributes={"name"=>"Chargify API ARes Test", "handle"=>"chargify-api-ares-test", "id"=>79, "accounting_code"=>nil}>, "id"=>153, "accounting_code"=>nil, "interval_unit"=>"month", "interval"=>1}>, "credit_card_attributes"=>#<Chargify::Subscription::CreditCardAttributes:0x1020ecab0 @prefix_options={}, @attributes={"expiration_year"=>2020, "full_number"=>"1", "first_name"=>"Michael", "expiration_month"=>1, "last_name"=>"Klett"}>, "trial_ended_at"=>nil, "id"=>331, "current_period_ends_at"=>Thu Dec 17 16:00:17 UTC 2009, "product_handle"=>"chargify-api-ares-test", "trial_started_at"=>nil, "customer"=>#<Chargify::Customer:0x10204b688 @prefix_options={}, @attributes={"reference"=>"moklett", "updated_at"=>Tue Nov 17 15:51:02 UTC 2009, "id"=>331, "first_name"=>"Michael", "organization"=>"Chargify", "last_name"=>"Klett", "email"=>"moklett@example.com", "created_at"=>Tue Nov 17 15:51:02 UTC 2009}>, "balance_in_cents"=>0, "current_period_started_at"=>Tue Nov 17 16:00:17 UTC 2009, "state"=>"active", "created_at"=>Tue Nov 17 16:00:17 UTC 2009, "customer_reference"=>"moklett"}>
|
32
32
|
|
33
33
|
|
34
|
+
# Lookup up existing Subscription using the Customer's reference
|
35
|
+
Subscription.find_by_customer_reference('moklett')
|
36
|
+
# => #<Chargify::Subscription:0x1020ed4b0 @prefix_options={}, @attributes={"cancellation_message"=>nil, "activated_at"=>Tue Nov 17 16:00:17 UTC 2009, "expires_at"=>nil, "updated_at"=>Tue Nov 17 16:00:17 UTC 2009, "credit_card"=>#<Chargify::Subscription::CreditCard:0x102046b10 @prefix_options={}, @attributes={"card_type"=>"bogus", "expiration_year"=>2020, "masked_card_number"=>"XXXX-XXXX-XXXX-1", "first_name"=>"Michael", "expiration_month"=>1, "last_name"=>"Klett"}>, "product"=>#<Chargify::Product:0x10204a2d8 @prefix_options={}, @attributes={"price_in_cents"=>0, "name"=>"Chargify API Ares Test", "handle"=>"chargify-api-ares-test", "product_family"=>#<Chargify::Product::ProductFamily:0x1020490b8 @prefix_options={}, @attributes={"name"=>"Chargify API ARes Test", "handle"=>"chargify-api-ares-test", "id"=>79, "accounting_code"=>nil}>, "id"=>153, "accounting_code"=>nil, "interval_unit"=>"month", "interval"=>1}>, "trial_ended_at"=>nil, "id"=>331, "current_period_ends_at"=>Thu Dec 17 16:00:17 UTC 2009, "product_handle"=>"chargify-api-ares-test", "trial_started_at"=>nil, "customer"=>#<Chargify::Customer:0x10204b688 @prefix_options={}, @attributes={"reference"=>"moklett", "updated_at"=>Tue Nov 17 15:51:02 UTC 2009, "id"=>331, "first_name"=>"Michael", "organization"=>"Chargify", "last_name"=>"Klett", "email"=>"moklett@example.com", "created_at"=>Tue Nov 17 15:51:02 UTC 2009}>, "balance_in_cents"=>0, "current_period_started_at"=>Tue Nov 17 16:00:17 UTC 2009, "state"=>"active", "created_at"=>Tue Nov 17 16:00:17 UTC 2009, "customer_reference"=>"moklett"}>
|
37
|
+
|
38
|
+
|
34
39
|
# Update credit card information
|
35
40
|
subscription.credit_card_attributes = {:full_number => "2", :expiration_year => "2015"}
|
36
41
|
subscription.save
|
data/spec/product_spec.rb
CHANGED
@@ -6,6 +6,7 @@ describe Chargify::Product do
|
|
6
6
|
before do
|
7
7
|
@handle = 'handle1'
|
8
8
|
@existing_product = Factory(:product, :handle => @handle, :id => Factory.next(:product_id))
|
9
|
+
puts @existing_product.attributes.to_xml
|
9
10
|
FakeWeb.register_uri(:get, "#{test_domain}/products/lookup.xml?handle=#{@existing_product.handle}", :body => @existing_product.attributes.to_xml)
|
10
11
|
end
|
11
12
|
|
data/spec/subscription_spec.rb
CHANGED
@@ -32,18 +32,27 @@ describe Chargify::Subscription do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
35
|
+
it 'creates a one-time charge' do
|
36
|
+
id = Factory.next(:subscription_id)
|
37
|
+
subscription = Factory(:subscription, :id => id)
|
38
|
+
expected_response = {:charge => {:amount_in_cents => 1000, :memo => "one-time charge", :success => true}}.to_xml
|
39
|
+
FakeWeb.register_uri(:post, "#{test_domain}/subscriptions/#{id}/charges.xml?charge%5Bamount%5D=10.00&charge%5Bmemo%5D=one-time+charge", :status => 201, :body => expected_response)
|
40
|
+
|
41
|
+
response = subscription.charge(:amount => "10.00", "memo" => "one-time charge")
|
42
|
+
|
43
|
+
response.body.should == expected_response
|
44
|
+
response.should be_a(Net::HTTPCreated)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'finds by customer reference' do
|
48
|
+
customer = Factory(:customer, :reference => 'roger', :id => 10)
|
49
|
+
subscription = Factory(:subscription, :id => 11, :customer_id => customer.id, :product => Factory(:product))
|
50
|
+
|
51
|
+
expected_response = [subscription.attributes].to_xml(:root => 'subscriptions')
|
52
|
+
FakeWeb.register_uri(:get, "#{test_domain}/subscriptions.xml?customer_id=#{customer.id}", :status => 200, :body => expected_response)
|
53
|
+
|
54
|
+
Chargify::Customer.stub!(:find_by_reference).with('roger').and_return(customer)
|
55
|
+
Chargify::Subscription.find_by_customer_reference('roger').should eql(subscription)
|
47
56
|
end
|
48
57
|
|
49
58
|
it 'cancels the subscription' do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 4
|
9
|
+
version: 0.2.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Klett
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-03-05 00:00:00 -05:00
|
20
20
|
default_executable:
|
21
21
|
dependencies: []
|
22
22
|
|