chargify_api_ares 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
@@ -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.3"
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-02-26}
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 = [
@@ -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')
@@ -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
@@ -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
 
@@ -32,18 +32,27 @@ describe Chargify::Subscription do
32
32
  end
33
33
  end
34
34
 
35
- describe 'one-time charges' do
36
- it 'creates a one-time charge' do
37
- id = Factory.next(:subscription_id)
38
- subscription = Factory(:subscription, :id => id)
39
- expected_response = {:charge => {:amount_in_cents => 1000, :memo => "one-time charge", :success => true}}.to_xml
40
- 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)
41
-
42
- response = subscription.charge(:amount => "10.00", "memo" => "one-time charge")
43
-
44
- response.body.should == expected_response
45
- response.should be_a(Net::HTTPCreated)
46
- end
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
- - 3
9
- version: 0.2.3
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-02-26 00:00:00 -07:00
19
+ date: 2010-03-05 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies: []
22
22