subscription_fu 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,3 @@
1
1
  .bundle
2
- Gemfile.lock
3
2
  pkg/*
4
3
  log
@@ -0,0 +1,138 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ subscription_fu (0.4.0)
5
+ paypal-express (~> 0.4.1)
6
+ rails (>= 3.0.3)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ actionmailer (3.1.1)
12
+ actionpack (= 3.1.1)
13
+ mail (~> 2.3.0)
14
+ actionpack (3.1.1)
15
+ activemodel (= 3.1.1)
16
+ activesupport (= 3.1.1)
17
+ builder (~> 3.0.0)
18
+ erubis (~> 2.7.0)
19
+ i18n (~> 0.6)
20
+ rack (~> 1.3.2)
21
+ rack-cache (~> 1.1)
22
+ rack-mount (~> 0.8.2)
23
+ rack-test (~> 0.6.1)
24
+ sprockets (~> 2.0.2)
25
+ activemodel (3.1.1)
26
+ activesupport (= 3.1.1)
27
+ builder (~> 3.0.0)
28
+ i18n (~> 0.6)
29
+ activerecord (3.1.1)
30
+ activemodel (= 3.1.1)
31
+ activesupport (= 3.1.1)
32
+ arel (~> 2.2.1)
33
+ tzinfo (~> 0.3.29)
34
+ activeresource (3.1.1)
35
+ activemodel (= 3.1.1)
36
+ activesupport (= 3.1.1)
37
+ activesupport (3.1.1)
38
+ multi_json (~> 1.0)
39
+ addressable (2.2.6)
40
+ arel (2.2.1)
41
+ attr_required (0.0.3)
42
+ builder (3.0.0)
43
+ crack (0.3.1)
44
+ diff-lcs (1.1.3)
45
+ erubis (2.7.0)
46
+ factory_girl (2.2.0)
47
+ activesupport
48
+ haml (3.1.3)
49
+ hike (1.2.1)
50
+ i18n (0.6.0)
51
+ json (1.6.1)
52
+ mail (2.3.0)
53
+ i18n (>= 0.4.0)
54
+ mime-types (~> 1.16)
55
+ treetop (~> 1.4.8)
56
+ mime-types (1.17.2)
57
+ multi_json (1.0.3)
58
+ paypal-express (0.4.1)
59
+ activesupport (>= 2.3)
60
+ attr_required (>= 0.0.3)
61
+ i18n
62
+ restclient_with_cert
63
+ polyglot (0.3.3)
64
+ rack (1.3.5)
65
+ rack-cache (1.1)
66
+ rack (>= 0.4)
67
+ rack-mount (0.8.3)
68
+ rack (>= 1.0.0)
69
+ rack-ssl (1.3.2)
70
+ rack
71
+ rack-test (0.6.1)
72
+ rack (>= 1.0)
73
+ rails (3.1.1)
74
+ actionmailer (= 3.1.1)
75
+ actionpack (= 3.1.1)
76
+ activerecord (= 3.1.1)
77
+ activeresource (= 3.1.1)
78
+ activesupport (= 3.1.1)
79
+ bundler (~> 1.0)
80
+ railties (= 3.1.1)
81
+ railties (3.1.1)
82
+ actionpack (= 3.1.1)
83
+ activesupport (= 3.1.1)
84
+ rack-ssl (~> 1.3.2)
85
+ rake (>= 0.8.7)
86
+ rdoc (~> 3.4)
87
+ thor (~> 0.14.6)
88
+ rake (0.9.2.2)
89
+ rdoc (3.11)
90
+ json (~> 1.4)
91
+ rest-client (1.6.7)
92
+ mime-types (>= 1.16)
93
+ restclient_with_cert (0.0.8)
94
+ rest-client (>= 1.6)
95
+ rspec (2.7.0)
96
+ rspec-core (~> 2.7.0)
97
+ rspec-expectations (~> 2.7.0)
98
+ rspec-mocks (~> 2.7.0)
99
+ rspec-core (2.7.1)
100
+ rspec-expectations (2.7.0)
101
+ diff-lcs (~> 1.1.2)
102
+ rspec-mocks (2.7.0)
103
+ rspec-rails (2.7.0)
104
+ actionpack (~> 3.0)
105
+ activesupport (~> 3.0)
106
+ railties (~> 3.0)
107
+ rspec (~> 2.7.0)
108
+ shoulda-matchers (1.0.0)
109
+ sprockets (2.0.3)
110
+ hike (~> 1.2)
111
+ rack (~> 1.0)
112
+ tilt (~> 1.1, != 1.3.0)
113
+ sqlite3 (1.3.4)
114
+ thor (0.14.6)
115
+ tilt (1.3.3)
116
+ time_travel (0.1.0)
117
+ treetop (1.4.10)
118
+ polyglot
119
+ polyglot (>= 0.3.1)
120
+ tzinfo (0.3.31)
121
+ webmock (1.7.7)
122
+ addressable (~> 2.2, > 2.2.5)
123
+ crack (>= 0.1.7)
124
+
125
+ PLATFORMS
126
+ ruby
127
+
128
+ DEPENDENCIES
129
+ factory_girl
130
+ haml
131
+ rails
132
+ rspec (>= 2.5.0)
133
+ rspec-rails
134
+ shoulda-matchers
135
+ sqlite3
136
+ subscription_fu!
137
+ time_travel (= 0.1.0)
138
+ webmock
@@ -53,13 +53,24 @@ class SubscriptionFu::Transaction < ActiveRecord::Base
53
53
  send("complete_#{action}_#{gateway}", opts)
54
54
  update_attributes!(:status => "complete")
55
55
  rescue Exception => err
56
+ data = {
57
+ :subscription => subscription.inspect,
58
+ :transaction => self.inspect }
59
+ if err.instance_of?(Paypal::Exception::APIError)
60
+ data[:paypal_response] = err.response.inspect
61
+ data[:paypal_error_message] = err.message
62
+ elsif err.instance_of?(Paypal::Exception::HttpError)
63
+ data[:http_error_code] = err.code
64
+ data[:http_error_message] = err.message
65
+ end
66
+
56
67
  if defined? ::ExceptionNotifier
57
- data = {:api_response => err.respond_to?(:response) ? err.response : nil, :subscription => subscription.inspect, :transaction => self.inspect}
58
68
  ::ExceptionNotifier::Notifier.background_exception_notification(err, :data => data).deliver
59
69
  elsif defined? ::HoptoadNotifier
60
- data = {:subscription => subscription.inspect, :transaction => self.inspect}
61
70
  ::HoptoadNotifier.notify(err, :parameters => data)
62
71
  else
72
+ logger.info("could not complete #{action} on #{gateway}")
73
+ logger.info("details: #{data.inspect}")
63
74
  logger.warn(err)
64
75
  logger.debug(err.backtrace.join("\n"))
65
76
  end
@@ -109,9 +120,11 @@ class SubscriptionFu::Transaction < ActiveRecord::Base
109
120
  :amount => sub_plan.price,
110
121
  :tax_amount => sub_plan.price_tax,
111
122
  :currency_code => sub_plan.currency } )
112
- response = SubscriptionFu::Paypal.express_request.subscribe!(identifier, profile)
113
- subscription.update_attributes!(:paypal_profile_id => response.recurring.identifier, :activated_at => Time.now)
114
- complete_activation
123
+ begin
124
+ response = SubscriptionFu::Paypal.express_request.subscribe!(identifier, profile)
125
+ subscription.update_attributes!(:paypal_profile_id => response.recurring.identifier, :activated_at => Time.now)
126
+ complete_activation
127
+ end
115
128
  end
116
129
 
117
130
  def complete_activation_nogw(opts)
@@ -1,3 +1,3 @@
1
1
  module SubscriptionFu
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -20,26 +20,6 @@ describe SubscriptionFu::Transaction do
20
20
  lambda { @trans.start_checkout("url1", "url2") }.should raise_error RuntimeError
21
21
  end
22
22
  end
23
- def complete_should_transition_to_activated
24
- context "complete" do
25
- before { @res = @trans.complete }
26
- it("should return true") { @res.should == true }
27
- it "should transition" do
28
- @trans.status.should == "complete"
29
- @trans.subscription.should be_activated
30
- end
31
- end
32
- end
33
- def complete_should_transition_to_canceled
34
- context "complete" do
35
- before { @res = @trans.complete }
36
- it("should return true") { @res.should == true }
37
- it "should transition" do
38
- @trans.status.should == "complete"
39
- @trans.subscription.should be_canceled
40
- end
41
- end
42
- end
43
23
  end
44
24
 
45
25
  it { should belong_to :subscription }
@@ -62,6 +42,22 @@ describe SubscriptionFu::Transaction do
62
42
  %w( initiated complete failed aborted ).each {|v| it { should allow_value(v).for(:status) } }
63
43
  it { should_not allow_value("unknown").for(:status) }
64
44
 
45
+
46
+ shared_examples "successful checkout" do
47
+ before { @res = @trans.complete }
48
+ it("should return true") { @res.should == true }
49
+ it "should transition" do
50
+ @trans.status.should == "complete"
51
+ @trans.subscription.should be_activated
52
+ end
53
+ end
54
+
55
+ shared_examples "failed checkout" do
56
+ before { @res = @trans.complete }
57
+ it("should return false") { @res.should == false }
58
+ it("should fail") { @trans.status.should == "failed" }
59
+ end
60
+
65
61
  context "initiated activation nogw transaction" do
66
62
  before do
67
63
  @sub = Factory(:subscription, :plan_key => 'free')
@@ -70,13 +66,9 @@ describe SubscriptionFu::Transaction do
70
66
  should_have_nogw_initiated_status
71
67
 
72
68
  context "checkout" do
73
- before do
74
- @redirect_target = @trans.start_checkout("url1", "url2")
75
- end
76
- it "should redirect to confirmation URL" do
77
- @redirect_target.should == "url1"
78
- end
79
- complete_should_transition_to_activated
69
+ before { @redirect_target = @trans.start_checkout("url1", "url2") }
70
+ it("should redirect to confirmation URL") { @redirect_target.should == "url1" }
71
+ it_should_behave_like "successful checkout"
80
72
  end
81
73
  end
82
74
 
@@ -87,7 +79,14 @@ describe SubscriptionFu::Transaction do
87
79
  end
88
80
  should_have_nogw_initiated_status
89
81
  should_not_support_start_checkout
90
- complete_should_transition_to_canceled
82
+ context "complete" do
83
+ before { @res = @trans.complete }
84
+ it("should return true") { @res.should == true }
85
+ it "should transition" do
86
+ @trans.status.should == "complete"
87
+ @trans.subscription.should be_canceled
88
+ end
89
+ end
91
90
  end
92
91
 
93
92
  context "complete nogw transaction" do
@@ -106,19 +105,27 @@ describe SubscriptionFu::Transaction do
106
105
  context "checkout" do
107
106
  before do
108
107
  mock_paypal_express_checkout("bgds65sd")
109
- mock_paypal_create_profile("bgds65sd")
110
108
  @redirect_target = @trans.start_checkout("url1", "url2")
111
109
  end
112
110
  it "should redirect to paypal" do
113
111
  @redirect_target.should == "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=bgds65sd"
114
112
  @trans.identifier.should == "bgds65sd"
115
113
  end
116
- complete_should_transition_to_activated
114
+ context "ok" do
115
+ before { mock_paypal_create_profile("bgds65sd") }
116
+ it_should_behave_like "successful checkout"
117
+ end
118
+ context "error (paypal)" do
119
+ before { mock_paypal_create_profile_with_error("bgds65sd") }
120
+ it_should_behave_like "failed checkout"
121
+ end
122
+ context "error (http)" do
123
+ before { stub_request(:post, "https://api-3t.paypal.com/nvp").to_return(:status => 500, :body => "Internal Server Error") }
124
+ it_should_behave_like "failed checkout"
125
+ end
117
126
  end
118
- context "complete without checkout" do
119
- before { @res = @trans.complete }
120
- it("should return false") { @res.should == false }
121
- it("should fail") { @trans.status.should == "failed" }
127
+ context "without checkout" do
128
+ it_should_behave_like "failed checkout"
122
129
  end
123
130
  end
124
131
 
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.rubyforge_project = "subscriptionfu"
17
17
 
18
18
  s.add_dependency 'rails', '>= 3.0.3'
19
- s.add_dependency 'paypal-express', '~> 0.3.0'
19
+ s.add_dependency 'paypal-express', '~> 0.4.1'
20
20
 
21
21
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
22
  end
metadata CHANGED
@@ -1,52 +1,50 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: subscription_fu
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
4
5
  prerelease:
5
- version: 0.3.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Paul McMahon
9
9
  - Michael Reinsch
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2011-07-05 00:00:00 +09:00
15
- default_executable:
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
13
+ date: 2011-11-07 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
18
16
  name: rails
19
- prerelease: false
20
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &21534640 !ruby/object:Gem::Requirement
21
18
  none: false
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
25
22
  version: 3.0.3
26
23
  type: :runtime
27
- version_requirements: *id001
28
- - !ruby/object:Gem::Dependency
29
- name: paypal-express
30
24
  prerelease: false
31
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *21534640
26
+ - !ruby/object:Gem::Dependency
27
+ name: paypal-express
28
+ requirement: &21533440 !ruby/object:Gem::Requirement
32
29
  none: false
33
- requirements:
30
+ requirements:
34
31
  - - ~>
35
- - !ruby/object:Gem::Version
36
- version: 0.3.0
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.1
37
34
  type: :runtime
38
- version_requirements: *id002
39
- description: SubscriptionFu helps with building services which have paid subscriptions. It includes the models to store subscription status, and provides integration with PayPal for paid subscriptions.
35
+ prerelease: false
36
+ version_requirements: *21533440
37
+ description: SubscriptionFu helps with building services which have paid subscriptions.
38
+ It includes the models to store subscription status, and provides integration with
39
+ PayPal for paid subscriptions.
40
40
  email: info@mobalean.com
41
41
  executables: []
42
-
43
42
  extensions: []
44
-
45
43
  extra_rdoc_files: []
46
-
47
- files:
44
+ files:
48
45
  - .gitignore
49
46
  - Gemfile
47
+ - Gemfile.lock
50
48
  - LICENSE
51
49
  - README.md
52
50
  - Rakefile
@@ -107,33 +105,28 @@ files:
107
105
  - spec/spec_helper.rb
108
106
  - spec/support/paypal_test_helper.rb
109
107
  - subscription_fu.gemspec
110
- has_rdoc: true
111
108
  homepage: http://www.mobalean.com
112
109
  licenses: []
113
-
114
110
  post_install_message:
115
111
  rdoc_options: []
116
-
117
- require_paths:
112
+ require_paths:
118
113
  - lib
119
- required_ruby_version: !ruby/object:Gem::Requirement
114
+ required_ruby_version: !ruby/object:Gem::Requirement
120
115
  none: false
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: "0"
125
- required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
121
  none: false
127
- requirements:
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- version: "0"
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
131
126
  requirements: []
132
-
133
127
  rubyforge_project: subscriptionfu
134
- rubygems_version: 1.6.2
128
+ rubygems_version: 1.8.10
135
129
  signing_key:
136
130
  specification_version: 3
137
131
  summary: Rails support for handling free/paid subscriptions
138
132
  test_files: []
139
-