subscription_fu 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ class SubscriptionFu::Plan
7
7
  attr_accessor :key
8
8
  attr_accessor :price
9
9
 
10
- def initialize(key, price, data)
10
+ def initialize(key, price, data = {})
11
11
  self.key = key
12
12
  self.price = price
13
13
  data.each {|k,v| self.send("#{k}=", v) }
@@ -104,7 +104,7 @@ class SubscriptionFu::Transaction < ActiveRecord::Base
104
104
  :period => :Month,
105
105
  :frequency => 1,
106
106
  :amount => sub_plan.price,
107
- :tax => sub_plan.price_tax,
107
+ :tax_amount => sub_plan.price_tax,
108
108
  :currency_code => sub_plan.currency } )
109
109
  response = SubscriptionFu::Paypal.express_request.subscribe!(identifier, profile)
110
110
  subscription.update_attributes!(:paypal_profile_id => response.recurring.identifier, :activated_at => Time.now)
@@ -1,3 +1,3 @@
1
1
  module SubscriptionFu
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe SubscriptionFu::Plan do
4
+ it "should calculate tax" do
5
+ plan = described_class.new("basic", 1000)
6
+ plan.price_with_tax.should == 1050
7
+ plan.price_tax.should == 50
8
+ end
9
+ end
@@ -103,14 +103,14 @@ describe SubscriptionFu::Subscription do
103
103
  instance_variable_get("@#{sub_instance}").subject.pending_transaction("token123").should == @trans
104
104
  end
105
105
  context "complete" do
106
- before { mock_paypal_create_profile("token123", "6bvsaksd9j") }
106
+ before { mock_paypal_create_profile("token123", :new_profile_id => "6bvsaksd9j") }
107
107
  before { mock_paypal_delete_profile("fgsga564aa") } unless first_sub
108
108
  before { @trans.complete }
109
109
  should_activate_subscription(sub_instance)
110
110
  should_cancel_previous_subscription(sub_instance) unless first_sub
111
111
  end
112
112
  context "complete with error in cancel" do
113
- before { mock_paypal_create_profile("token123", "6bvsaksd9j") }
113
+ before { mock_paypal_create_profile("token123", :new_profile_id => "6bvsaksd9j") }
114
114
  before { mock_paypal_delete_profile_with_error("fgsga564aa") }
115
115
  before { @trans.complete }
116
116
  should_activate_subscription(sub_instance)
@@ -132,4 +132,12 @@ describe SubscriptionFu::Transaction do
132
132
  should_not_support_start_checkout
133
133
  end
134
134
 
135
+ it "should calculate tax correctly" do
136
+ trans = Factory(:transaction, :gateway => "paypal", :status => "initiated", :action => "activation", :identifier => "foo")
137
+ trans.sub_plan.price_tax.should == 250
138
+ mock_paypal_create_profile("foo", "AMT" => "5000.00", "TAXAMT" => "250.00")
139
+ trans.complete
140
+ trans.status.should == "complete"
141
+ end
142
+
135
143
  end
@@ -41,10 +41,12 @@ module PaypalTestHelper
41
41
  with{|request| PaypalRequestMatcher.new("GetRecurringPaymentsProfileDetails", "PROFILEID" => profile) =~ request }
42
42
  end
43
43
 
44
- def mock_paypal_create_profile(token, new_profile_id = "49vnq320dsj", status = "ActiveProfile")
44
+ def mock_paypal_create_profile(token, args = {})
45
+ new_profile_id = args.delete(:new_profile_id) || "49vnq320dsj"
46
+ status = args.delete(:status) || "ActiveProfile"
45
47
  stub_request(:post, "https://api-3t.paypal.com/nvp").
46
48
  to_return(:status => 200, :body => paypal_profile_res(new_profile_id, status), :headers => {}).
47
- with{|request| PaypalRequestMatcher.new("CreateRecurringPaymentsProfile", "TOKEN" => token) =~ request }
49
+ with{|request| PaypalRequestMatcher.new("CreateRecurringPaymentsProfile", {"TOKEN" => token}.merge(args)) =~ request }
48
50
  end
49
51
 
50
52
  def mock_paypal_create_profile_with_error(token)
metadata CHANGED
@@ -1,8 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subscription_fu
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.2.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 1
9
+ version: 0.2.1
6
10
  platform: ruby
7
11
  authors:
8
12
  - Paul McMahon
@@ -11,7 +15,7 @@ autorequire:
11
15
  bindir: bin
12
16
  cert_chain: []
13
17
 
14
- date: 2011-05-29 00:00:00 +09:00
18
+ date: 2011-06-07 00:00:00 +09:00
15
19
  default_executable:
16
20
  dependencies:
17
21
  - !ruby/object:Gem::Dependency
@@ -22,6 +26,10 @@ dependencies:
22
26
  requirements:
23
27
  - - ">="
24
28
  - !ruby/object:Gem::Version
29
+ segments:
30
+ - 3
31
+ - 0
32
+ - 3
25
33
  version: 3.0.3
26
34
  type: :runtime
27
35
  version_requirements: *id001
@@ -33,6 +41,10 @@ dependencies:
33
41
  requirements:
34
42
  - - ~>
35
43
  - !ruby/object:Gem::Version
44
+ segments:
45
+ - 0
46
+ - 3
47
+ - 0
36
48
  version: 0.3.0
37
49
  type: :runtime
38
50
  version_requirements: *id002
@@ -97,6 +109,7 @@ files:
97
109
  - spec/factories/subject.rb
98
110
  - spec/factories/subscription.rb
99
111
  - spec/factories/transaction.rb
112
+ - spec/models/subscription_plan_spec.rb
100
113
  - spec/models/subscription_spec.rb
101
114
  - spec/models/subscription_transaction_spec.rb
102
115
  - spec/spec_helper.rb
@@ -116,17 +129,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
129
  requirements:
117
130
  - - ">="
118
131
  - !ruby/object:Gem::Version
132
+ segments:
133
+ - 0
119
134
  version: "0"
120
135
  required_rubygems_version: !ruby/object:Gem::Requirement
121
136
  none: false
122
137
  requirements:
123
138
  - - ">="
124
139
  - !ruby/object:Gem::Version
140
+ segments:
141
+ - 0
125
142
  version: "0"
126
143
  requirements: []
127
144
 
128
145
  rubyforge_project: subscriptionfu
129
- rubygems_version: 1.5.2
146
+ rubygems_version: 1.3.7
130
147
  signing_key:
131
148
  specification_version: 3
132
149
  summary: Rails support for handling free/paid subscriptions