wepay-rails 2.2.9 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,105 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+
3
+ class TestWepayRailsAccountMethods < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ create_wepay_config_file(false, true)
7
+ initialize_wepay_config
8
+ end
9
+
10
+ def teardown
11
+ delete_wepay_config_file
12
+ end
13
+
14
+ test "should raise error from WePay when using invalid access token" do
15
+ stub_request(:post, "https://stage.wepayapi.com/v2/account/create").
16
+ with(:body => "name=Example%20Account&description=This%20is%20just%20an%20example%20WePay%20account.",
17
+ :headers => wepay_gateway.wepay_auth_header.merge('Authorization' => "Bearer: notAnAccessToken")).
18
+ to_return({:status => 401, :body => {:error_description => 'a valid access_token is required'}.to_json})
19
+ assert_raise WepayRails::Exceptions::ExpiredTokenError do
20
+ wepay_gateway = WepayRails::Payments::Gateway.new("notAnAccessToken")
21
+ wepay_gateway.create_account({
22
+ :name => "Example Account",
23
+ :description => "This is just an example WePay account."
24
+ })
25
+ end
26
+ end
27
+
28
+ test "should create new WePay account" do
29
+ stub_request(:post, "https://stage.wepayapi.com/v2/account/create").
30
+ with(:body => "name=Example%20Account&description=This%20is%20just%20an%20example%20WePay%20account.", :headers => wepay_gateway.wepay_auth_header).
31
+ to_return({:status => 200, :body => sample_account_response})
32
+ @response = wepay_gateway.create_account({
33
+ :name => "Example Account",
34
+ :description => "This is just an example WePay account."
35
+ })
36
+
37
+ assert_not_nil @response[:account_id]
38
+ assert_not_nil @response[:account_uri]
39
+ end
40
+
41
+ test "should get WePay account" do
42
+ stub_request(:post, "https://stage.wepayapi.com/v2/account").
43
+ with(:body => "account_id=12345", :headers => wepay_gateway.wepay_auth_header).
44
+ to_return(:status => 200, :body => sample_account_response)
45
+ @response = wepay_gateway.get_account(12345)
46
+
47
+ assert_not_nil @response[:name]
48
+ assert_equal "Example Account", @response[:name]
49
+ assert_equal "This is just an example WePay account.", @response[:description]
50
+ end
51
+
52
+ test "should find WePay account by reference id or name" do
53
+ stub_request(:post, "https://stage.wepayapi.com/v2/account/find").
54
+ with(:body => "reference_id=wepayrailstestaccount123", :headers => wepay_gateway.wepay_auth_header).
55
+ to_return({:status => 200, :body => sample_find_response, :headers => {}})
56
+ @response = wepay_gateway.find_account(:reference_id => "wepayrailstestaccount123")
57
+
58
+ assert @response.kind_of?(Array), "<Array> expected but was <#{@response.class}>"
59
+ assert_equal 1, @response.length
60
+ assert_equal "Custom Reference ID", @response.first[:name]
61
+ end
62
+
63
+ test "should find all WePay accounts for current authorized user" do
64
+ stub_request(:post, "https://stage.wepayapi.com/v2/account/find").
65
+ with(:headers => wepay_gateway.wepay_auth_header).
66
+ to_return({:status => 200, :body => sample_find_response, :headers => {}})
67
+ @response = wepay_gateway.find_account
68
+ assert @response.kind_of?(Array), "<Array> expected but was <#{@response.class}>"
69
+ assert_equal "Custom Reference ID", @response.last[:name]
70
+ end
71
+
72
+ test "should modify WePay account" do
73
+ options = { :name => "This is a new Name!",
74
+ :description => "This is a new description!" }
75
+ stub_request(:post, "https://stage.wepayapi.com/v2/account/modify").
76
+ with(:headers => wepay_gateway.wepay_auth_header).
77
+ to_return({:status => 200, :body => sample_account_response(options), :headers => {}})
78
+ @response = wepay_gateway.modify_account(12345, options)
79
+
80
+ assert_not_nil @response[:account_id]
81
+ assert_equal "This is a new Name!", @response[:name]
82
+ assert_equal "This is a new description!", @response[:description]
83
+ end
84
+
85
+ test "should get current balance of WePay account" do
86
+ stub_request(:post, "https://stage.wepayapi.com/v2/account/balance").
87
+ with(:headers => wepay_gateway.wepay_auth_header).
88
+ to_return({:status => 200, :body => sample_balance_response, :headers => {}})
89
+ @response = wepay_gateway.get_account_balance(12345)
90
+
91
+ assert_equal "500", @response[:pending_balance]
92
+ assert_equal "500", @response[:available_balance]
93
+ assert_equal "USD", @response[:currency]
94
+ end
95
+
96
+ test "should delete WePay account" do
97
+ stub_request(:post, "https://stage.wepayapi.com/v2/account/delete").
98
+ with(:body => "account_id=12345", :headers => wepay_gateway.wepay_auth_header).
99
+ to_return(:status => 200, :body => sample_account_response, :headers => {})
100
+ @response = wepay_gateway.delete_account(12345)
101
+
102
+ assert_not_nil @response[:account_id]
103
+ assert_equal "12345", @response[:account_id]
104
+ end
105
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+
3
+ class TestWepayRailsAuthorize < ActiveSupport::TestCase
4
+ def setup
5
+ create_wepay_config_file(false, true)
6
+ initialize_wepay_config
7
+ end
8
+
9
+ def teardown
10
+ delete_wepay_config_file
11
+ end
12
+
13
+ test "WePay gateway should have correct authorize url" do
14
+ @gateway = WepayRails::Payments::Gateway.new
15
+ @url = @gateway.auth_code_url("http://www.example.com")
16
+ assert @url.match("https://stage.wepay.com/v2/oauth2/authorize"), "<https://stage.wepayapi.com/v2/oauth2/authorize> expected but was #{@url}"
17
+ end
18
+
19
+ test "should raise errors when authorizing an invalid auth code" do
20
+ @gateway = WepayRails::Payments::Gateway.new("notAnAccessToken")
21
+ stub_request(:post, "https://stage.wepayapi.com/v2/oauth2/token").
22
+ with(:body => "client_id=168738&client_secret=8d701ad2ac&redirect_uri=http%3A%2F%2Fwww.example.com&code=authCode",
23
+ :headers => {'Authorization'=>'Bearer: notAnAccessToken', 'User-Agent'=>'WepayRails'}).
24
+ to_return(:status => 200, :body => {:error_description => 'invalid code parameter'}.to_json, :headers => {})
25
+ assert_raise WepayRails::Exceptions::AccessTokenError do
26
+ @gateway.get_access_token("authCode", "http://www.example.com")
27
+ end
28
+ end
29
+
30
+ # ToDo: Add test for successful authorization
31
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+
3
+ class TestWepayRailsCheckoutMethods < ActiveSupport::TestCase
4
+ include WepayRails::Helpers::ControllerHelpers
5
+
6
+ def setup
7
+ create_wepay_config_file(false, true)
8
+ initialize_wepay_config
9
+ @checkout_params = {
10
+ :amount => 100,
11
+ :short_description => "This is a checkout test!",
12
+ :account_id => "12345"
13
+ }
14
+ end
15
+
16
+ def teardown
17
+ delete_wepay_config_file
18
+ end
19
+
20
+ test "should create a new WePay checkout object" do
21
+ security_token = Digest::SHA2.hexdigest("1#{Time.now.to_i}")
22
+ stub_request(:post, "https://stage.wepayapi.com/v2/checkout/create").
23
+ with(:body => "callback_uri=http%3A%2F%2Fwww.example.com%2Fwepay%2Fipn%3Fsecurity_token%3D#{security_token}&redirect_uri=http%3A%2F%2Fwww.example.com%2Fwepay%2Fcheckout%3Fsecurity_token%3D#{security_token}&fee_payer=Payee&type=GOODS&charge_tax=0&app_fee=0&auto_capture=1&require_shipping=0&shipping_fee=0&account_id=12345&amount=100&short_description=This%20is%20a%20checkout%20test!",
24
+ :headers => wepay_gateway.wepay_auth_header).
25
+ to_return(:status => 200, :body => sample_checkout_response, :headers => {})
26
+
27
+ @response = wepay_gateway.perform_checkout(@checkout_params)
28
+ assert_equal "6789", @response[:checkout_id]
29
+ assert_equal "http://stage.wepay.com/api/checkout/6789", @response[:checkout_uri]
30
+ assert_not_nil @response[:security_token]
31
+ end
32
+ end
33
+
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+
3
+ class TestWepayRailsInitialize < ActiveSupport::TestCase
4
+ def teardown
5
+ delete_wepay_config_file
6
+ end
7
+
8
+ test "should initialize WepayRails with settings from wepay.yml" do
9
+ create_wepay_config_file
10
+ initialize_wepay_config
11
+ @gateway = WepayRails::Payments::Gateway.new
12
+
13
+ assert_not_nil @gateway.configuration
14
+ assert_equal "http://www.example.com", @gateway.configuration[:root_callback_uri]
15
+ end
16
+
17
+ test "should initialize WepayRails with embedded Ruby in wepay.yml.erb" do
18
+ create_wepay_config_file(true)
19
+ initialize_wepay_config
20
+ @gateway = WepayRails::Payments::Gateway.new
21
+
22
+ assert_not_nil @gateway.configuration
23
+ assert_equal "http://www.example.com", @gateway.configuration[:root_callback_uri]
24
+ assert_equal 'abc' * 3, @gateway.access_token
25
+ end
26
+
27
+ test "should initialize WepayRails with an existing access_token" do
28
+ @gateway = WepayRails::Payments::Gateway.new("myAccessToken")
29
+ assert_equal "myAccessToken", @gateway.access_token
30
+ end
31
+
32
+ test "should raise error when WePay times out" do
33
+ # In this test we simply pass 1 (ie 1 millisecond)) as our third (optional) value for timeout,
34
+ # basically forcing the request to timeout
35
+ assert_raise WepayRails::Exceptions::WepayApiError do
36
+ wepay_gateway.call_api("account/find", {}, 1)
37
+ end
38
+ end
39
+ end
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{wepay-rails}
8
- s.version = "2.2.9"
7
+ s.name = "wepay-rails"
8
+ s.version = "2.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Adam Medeiros"]
12
- s.date = %q{2012-05-28}
13
- s.description = %q{Rails gem that interfaces with the WePay API}
14
- s.email = %q{adammede@gmail.com}
12
+ s.date = "2012-09-16"
13
+ s.description = "Rails gem that interfaces with the WePay API"
14
+ s.email = "adammede@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README",
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  ]
20
20
  s.files = [
21
21
  ".document",
22
+ ".travis.yml",
22
23
  "Gemfile",
23
24
  "Gemfile.lock",
24
25
  "LICENSE.txt",
@@ -30,7 +31,7 @@ Gem::Specification.new do |s|
30
31
  "app/controllers/wepay/authorize_controller.rb",
31
32
  "app/controllers/wepay/checkout_controller.rb",
32
33
  "app/controllers/wepay/ipn_controller.rb",
33
- "config/routes.rb",
34
+ "build",
34
35
  "lib/api/account_methods.rb",
35
36
  "lib/api/checkout_methods.rb",
36
37
  "lib/generators/wepay_rails/install/install_generator.rb",
@@ -40,37 +41,49 @@ Gem::Specification.new do |s|
40
41
  "lib/helpers/controller_helpers.rb",
41
42
  "lib/wepay-rails.rb",
42
43
  "test/helper.rb",
43
- "test/test_wepay-rails.rb",
44
+ "test/test_wepay_rails_account_methods.rb",
45
+ "test/test_wepay_rails_authorize.rb",
46
+ "test/test_wepay_rails_checkout_methods.rb",
47
+ "test/test_wepay_rails_initialize.rb",
44
48
  "wepay-rails.gemspec"
45
49
  ]
46
- s.homepage = %q{http://github.com/adamthedeveloper/wepay-rails}
50
+ s.homepage = "http://github.com/adamthedeveloper/wepay-rails"
47
51
  s.licenses = ["MIT"]
48
52
  s.require_paths = ["lib"]
49
- s.rubygems_version = %q{1.6.2}
50
- s.summary = %q{Rails gem that interfaces with the WePay API}
53
+ s.rubygems_version = "1.8.24"
54
+ s.summary = "Rails gem that interfaces with the WePay API"
51
55
 
52
56
  if s.respond_to? :specification_version then
53
57
  s.specification_version = 3
54
58
 
55
59
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
60
  s.add_runtime_dependency(%q<httparty>, [">= 0"])
57
- s.add_development_dependency(%q<shoulda>, [">= 0"])
58
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
61
+ s.add_development_dependency(%q<rails>, ["= 3.1.0"])
62
+ s.add_development_dependency(%q<turn>, ["= 0.8.2"])
63
+ s.add_development_dependency(%q<thor>, [">= 0"])
64
+ s.add_development_dependency(%q<bundler>, [">= 0"])
59
65
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
60
66
  s.add_development_dependency(%q<rcov>, [">= 0"])
67
+ s.add_development_dependency(%q<webmock>, [">= 0"])
61
68
  else
62
69
  s.add_dependency(%q<httparty>, [">= 0"])
63
- s.add_dependency(%q<shoulda>, [">= 0"])
64
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
70
+ s.add_dependency(%q<rails>, ["= 3.1.0"])
71
+ s.add_dependency(%q<turn>, ["= 0.8.2"])
72
+ s.add_dependency(%q<thor>, [">= 0"])
73
+ s.add_dependency(%q<bundler>, [">= 0"])
65
74
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
66
75
  s.add_dependency(%q<rcov>, [">= 0"])
76
+ s.add_dependency(%q<webmock>, [">= 0"])
67
77
  end
68
78
  else
69
79
  s.add_dependency(%q<httparty>, [">= 0"])
70
- s.add_dependency(%q<shoulda>, [">= 0"])
71
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
80
+ s.add_dependency(%q<rails>, ["= 3.1.0"])
81
+ s.add_dependency(%q<turn>, ["= 0.8.2"])
82
+ s.add_dependency(%q<thor>, [">= 0"])
83
+ s.add_dependency(%q<bundler>, [">= 0"])
72
84
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
73
85
  s.add_dependency(%q<rcov>, [">= 0"])
86
+ s.add_dependency(%q<webmock>, [">= 0"])
74
87
  end
75
88
  end
76
89
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wepay-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.9
4
+ version: 2.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-28 00:00:00.000000000 -07:00
13
- default_executable:
12
+ date: 2012-09-16 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: httparty
17
- requirement: &2161037600 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,10 +21,47 @@ dependencies:
22
21
  version: '0'
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *2161037600
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - '='
36
+ - !ruby/object:Gem::Version
37
+ version: 3.1.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.1.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: turn
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.8.2
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.2
26
62
  - !ruby/object:Gem::Dependency
27
- name: shoulda
28
- requirement: &2161036220 !ruby/object:Gem::Requirement
63
+ name: thor
64
+ requirement: !ruby/object:Gem::Requirement
29
65
  none: false
30
66
  requirements:
31
67
  - - ! '>='
@@ -33,21 +69,31 @@ dependencies:
33
69
  version: '0'
34
70
  type: :development
35
71
  prerelease: false
36
- version_requirements: *2161036220
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
37
78
  - !ruby/object:Gem::Dependency
38
79
  name: bundler
39
- requirement: &2161034580 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
40
81
  none: false
41
82
  requirements:
42
- - - ~>
83
+ - - ! '>='
43
84
  - !ruby/object:Gem::Version
44
- version: 1.0.0
85
+ version: '0'
45
86
  type: :development
46
87
  prerelease: false
47
- version_requirements: *2161034580
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
48
94
  - !ruby/object:Gem::Dependency
49
95
  name: jeweler
50
- requirement: &2161032980 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
51
97
  none: false
52
98
  requirements:
53
99
  - - ~>
@@ -55,10 +101,15 @@ dependencies:
55
101
  version: 1.6.4
56
102
  type: :development
57
103
  prerelease: false
58
- version_requirements: *2161032980
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.6.4
59
110
  - !ruby/object:Gem::Dependency
60
111
  name: rcov
61
- requirement: &2161032060 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
62
113
  none: false
63
114
  requirements:
64
115
  - - ! '>='
@@ -66,7 +117,28 @@ dependencies:
66
117
  version: '0'
67
118
  type: :development
68
119
  prerelease: false
69
- version_requirements: *2161032060
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: webmock
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
70
142
  description: Rails gem that interfaces with the WePay API
71
143
  email: adammede@gmail.com
72
144
  executables: []
@@ -77,6 +149,7 @@ extra_rdoc_files:
77
149
  - README.rdoc
78
150
  files:
79
151
  - .document
152
+ - .travis.yml
80
153
  - Gemfile
81
154
  - Gemfile.lock
82
155
  - LICENSE.txt
@@ -88,7 +161,7 @@ files:
88
161
  - app/controllers/wepay/authorize_controller.rb
89
162
  - app/controllers/wepay/checkout_controller.rb
90
163
  - app/controllers/wepay/ipn_controller.rb
91
- - config/routes.rb
164
+ - build
92
165
  - lib/api/account_methods.rb
93
166
  - lib/api/checkout_methods.rb
94
167
  - lib/generators/wepay_rails/install/install_generator.rb
@@ -98,9 +171,11 @@ files:
98
171
  - lib/helpers/controller_helpers.rb
99
172
  - lib/wepay-rails.rb
100
173
  - test/helper.rb
101
- - test/test_wepay-rails.rb
174
+ - test/test_wepay_rails_account_methods.rb
175
+ - test/test_wepay_rails_authorize.rb
176
+ - test/test_wepay_rails_checkout_methods.rb
177
+ - test/test_wepay_rails_initialize.rb
102
178
  - wepay-rails.gemspec
103
- has_rdoc: true
104
179
  homepage: http://github.com/adamthedeveloper/wepay-rails
105
180
  licenses:
106
181
  - MIT
@@ -116,7 +191,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
191
  version: '0'
117
192
  segments:
118
193
  - 0
119
- hash: -4350296257976175224
194
+ hash: 1100875515219871170
120
195
  required_rubygems_version: !ruby/object:Gem::Requirement
121
196
  none: false
122
197
  requirements:
@@ -125,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
200
  version: '0'
126
201
  requirements: []
127
202
  rubyforge_project:
128
- rubygems_version: 1.6.2
203
+ rubygems_version: 1.8.24
129
204
  signing_key:
130
205
  specification_version: 3
131
206
  summary: Rails gem that interfaces with the WePay API