wepay-rails 0.1.115 → 0.1.116

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.115
1
+ 0.1.116
@@ -7,6 +7,7 @@ class Wepay::AuthorizeController < Wepay::ApplicationController
7
7
  wepayable = wepayable_class.all(:conditions => ["#{wepayable_column} = ?", ref_id])[0]
8
8
  end
9
9
  wepayable.update_attribute(wepayable_column.to_sym, params[:code])
10
+ redirect_to session[:after_authorize_redirect_uri] if session[:after_authorize_redirect_uri]
10
11
  redirect_to WepayRails::Configuration.settings[:after_authorize_redirect_uri]
11
12
  rescue => e
12
13
  raise AuthorizationError.new("WepayRails was unable to find the record to save the auth code to. : #{e.message}") unless wepayable.present?
@@ -2,7 +2,7 @@ module WepayRails
2
2
  module Helpers
3
3
  module ControllerHelpers
4
4
 
5
- def redirect_to_wepay_for_auth(wepayable_object)
5
+ def redirect_to_wepay_for_auth(wepayable_object, params = {})
6
6
  # Initially set a reference ID to the column created for the wepayable
7
7
  # so that when the redirect back from wepay happens, we can reference
8
8
  # the original wepayable, and then save the new auth code into the reference ID's
@@ -11,7 +11,7 @@ module WepayRails
11
11
  session[unique_wepay_auth_token_key] = ref_id
12
12
  wepayable_object.update_attribute(WepayRails::Configuration.wepayable_column.to_sym, ref_id)
13
13
 
14
- redirect_to wepay_gateway.auth_code_url(wepayable_object)
14
+ redirect_to wepay_gateway.auth_code_url(params)
15
15
  end
16
16
 
17
17
  # @deprecated Use wepay_gateway instead of gateway
@@ -37,8 +37,6 @@ module WepayRails
37
37
  def initialize_wepay_access_token(wepayable_object)
38
38
  session[unique_wepay_access_token_key] = wepay_gateway.access_token(wepayable_object)
39
39
  return
40
- rescue WepayRails::Exceptions::ExpiredTokenError => e
41
- redirect_to_wepay_for_auth(wepayable_object) and return
42
40
  end
43
41
 
44
42
  # Since we are saving the access token in the session,
@@ -59,7 +57,7 @@ module WepayRails
59
57
  end
60
58
 
61
59
  def wepay_access_token_exists?
62
- @access_token_exists ||= wepay_access_token.present?
60
+ wepay_access_token.present?
63
61
  end
64
62
 
65
63
  # Many of the settings you pass in here are already factored in from
@@ -97,11 +95,12 @@ module WepayRails
97
95
  # :require_shipping No A boolean value (0 or 1). If set to 1 then the payer will be asked to enter a shipping address when they pay. After payment you can retrieve this shipping address by calling /checkout
98
96
  # :shipping_fee No The amount that you want to charge for shipping.
99
97
  # :charge_tax No A boolean value (0 or 1). If set to 1 and the account has a relevant tax entry (see /account/set_tax), then tax will be charged.
100
- def init_checkout_and_send_user_to_wepay(parms)
101
- response = wepay_gateway.perform_checkout(parms)
102
- raise WepayRails::Exceptions::InitializeCheckoutError.new("A problem occurred while trying to checkout. Wepay didn't send us back a checkout uri. Response was: #{response.inspect}") unless response && response.has_key?('checkout_uri')
98
+ def init_checkout_and_send_user_to_wepay(params)
99
+ response = wepay_gateway.perform_checkout(params)
100
+ checkout = WepayCheckoutRecord.create(params.merge({ checkout_id: response['checkout_id'] }))
101
+ raise WepayRails::Exceptions::InitializeCheckoutError.new("A problem occurred while trying to checkout. Wepay didn't send us back a checkout uri. Response was: #{response.inspect}, Params were: #{params}, Token was: #{wepay_access_token}") unless response && response.has_key?('checkout_uri')
103
102
  redirect_to response['checkout_uri'] and return
104
103
  end
105
104
  end
106
105
  end
107
- end
106
+ end
@@ -71,13 +71,13 @@ module WepayRails
71
71
 
72
72
  def access_token(wepayable_object)
73
73
  auth_code = wepayable_object.send(WepayRails::Configuration.wepayable_column.to_s)
74
- query = {
74
+ params = {
75
75
  :client_id => @wepay_config[:client_id],
76
76
  :client_secret => @wepay_config[:client_secret],
77
77
  :redirect_uri => @wepay_config[:redirect_uri],
78
78
  :code => auth_code
79
79
  }
80
- response = self.class.post("#{@base_uri}/oauth2/token", :body => query)
80
+ response = self.class.post("#{@base_uri}/oauth2/token", :body => params)
81
81
  json = JSON.parse(response.body)
82
82
 
83
83
  if json.has_key?("error")
@@ -97,14 +97,12 @@ module WepayRails
97
97
  # Get the auth code url that will be used to fetch the auth code for the customer
98
98
  # arguments are the redirect_uri and an array of permissions that your application needs
99
99
  # ex. ['manage_accounts','collect_payments','view_balance','view_user']
100
- def auth_code_url(wepayable_object)
101
- parms = {
102
- :client_id => @wepay_config[:client_id],
103
- :redirect_uri => @wepay_config[:redirect_uri],
104
- :scope => WepayRails::Configuration.settings[:scope].join(',')
105
- }
100
+ def auth_code_url(params = {})
101
+ params[:client_id] ||= @wepay_config[:client_id]
102
+ params[:redirect_uri] ||= @wepay_config[:redirect_uri]
103
+ params[:scope] ||= WepayRails::Configuration.settings[:scope].join(',')
106
104
 
107
- query = parms.map do |k, v|
105
+ query = params.map do |k, v|
108
106
  "#{k.to_s}=#{v}"
109
107
  end.join('&')
110
108
 
@@ -112,6 +110,9 @@ module WepayRails
112
110
  end
113
111
 
114
112
  def wepay_auth_header
113
+ unless @wepay_access_token
114
+ raise WepayRails::Exceptions::AccessTokenError.new("No access token available")
115
+ end
115
116
  {'Authorization' => "Bearer: #{@wepay_access_token}"}
116
117
  end
117
118
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "wepay-rails"
8
- s.version = "0.1.115"
8
+ s.version = "0.1.116"
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 = "2011-10-14"
12
+ s.date = "2011-11-15"
13
13
  s.description = "Rails gem that interfaces with the WePay API"
14
14
  s.email = "adammede@gmail.com"
15
15
  s.extra_rdoc_files = [
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: 0.1.115
4
+ version: 0.1.116
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-14 00:00:00.000000000Z
12
+ date: 2011-11-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &13232840 !ruby/object:Gem::Requirement
16
+ requirement: &15515820 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *13232840
24
+ version_requirements: *15515820
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: shoulda
27
- requirement: &13231320 !ruby/object:Gem::Requirement
27
+ requirement: &15514680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *13231320
35
+ version_requirements: *15514680
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &13226500 !ruby/object:Gem::Requirement
38
+ requirement: &15513480 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *13226500
46
+ version_requirements: *15513480
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &13225100 !ruby/object:Gem::Requirement
49
+ requirement: &15512360 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *13225100
57
+ version_requirements: *15512360
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &13223720 !ruby/object:Gem::Requirement
60
+ requirement: &15507620 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *13223720
68
+ version_requirements: *15507620
69
69
  description: Rails gem that interfaces with the WePay API
70
70
  email: adammede@gmail.com
71
71
  executables: []
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  segments:
111
111
  - 0
112
- hash: 3713795422808856888
112
+ hash: 3634481726847388061
113
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  none: false
115
115
  requirements: