wepay-rails 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.0
1
+ 2.2.0
@@ -0,0 +1,14 @@
1
+ class Wepay::CheckoutController < Wepay::ApplicationController
2
+ def index
3
+ record = WepayCheckoutRecord.find_by_checkout_id_and_security_token(params[:checkout_id],params[:security_token])
4
+
5
+ if record.present?
6
+ wepay_gateway = WepayRails::Payments::Gateway.new
7
+ checkout = wepay_gateway.lookup_checkout(record.checkout_id)
8
+ record.update_attributes(checkout)
9
+ redirect_to "#{wepay_gateway.configuration[:after_checkout_redirect_uri]}?checkout_id=#{params[:checkout_id]}"
10
+ else
11
+ raise StandardError.new("Wepay IPN: No record found for checkout_id #{params[:checkout_id]} and security_token #{params[:security_token]}")
12
+ end
13
+ end
14
+ end
@@ -1,7 +1,7 @@
1
1
  class Wepay::IpnController < Wepay::ApplicationController
2
2
  def create
3
3
 
4
- record = WepayCheckoutRecord.find_by_checkout_id(params[:checkout_id])
4
+ record = WepayCheckoutRecord.find_by_checkout_id_and_security_token(params[:checkout_id],params[:security_token])
5
5
 
6
6
  if record.present?
7
7
  wepay_gateway = WepayRails::Payments::Gateway.new
@@ -9,7 +9,7 @@ class Wepay::IpnController < Wepay::ApplicationController
9
9
  record.update_attributes(checkout)
10
10
  render :text => "ok"
11
11
  else
12
- raise StandardError.new("Wepay IPN: No record found for checkout_id #{params[:checkout_id]}")
12
+ raise StandardError.new("Wepay IPN: No record found for checkout_id #{params[:checkout_id]} and security_token #{params[:security_token]}")
13
13
  end
14
14
 
15
15
  end
@@ -1,3 +1,4 @@
1
+ require 'digest/sha2'
1
2
  module WepayRails
2
3
  module Api
3
4
  module CheckoutMethods
@@ -37,9 +38,10 @@ module WepayRails
37
38
  # :shipping_fee No The amount that you want to charge for shipping.
38
39
  # :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.
39
40
  def perform_checkout(parms)
41
+ security_token = Digest::SHA2.hexdigest("#{rand(4)}#{Time.now.to_i}")
40
42
  defaults = {
41
- :callback_uri => ipn_callback_uri,
42
- :redirect_uri => checkout_redirect_uri,
43
+ :callback_uri => ipn_callback_uri(security_token),
44
+ :redirect_uri => checkout_redirect_uri(security_token),
43
45
  :fee_payer => @wepay_config[:fee_payer],
44
46
  :type => @wepay_config[:checkout_type],
45
47
  :charge_tax => @wepay_config[:charge_tax] ? 1 : 0,
@@ -50,21 +52,34 @@ module WepayRails
50
52
  :account_id => @wepay_config[:account_id]
51
53
  }.merge(parms)
52
54
 
53
- self.call_api("/checkout/create", defaults)
55
+ resp = self.call_api("/checkout/create", defaults).symbolize_keys!
56
+ resp.merge({:security_token => security_token})
54
57
  end
55
58
 
56
59
  def lookup_checkout(checkout_id)
57
60
  self.call_api("/checkout", {:checkout_id => checkout_id})
58
61
  end
59
62
 
60
- def ipn_callback_uri
61
- return @wepay_config[:ipn_callback_uri] if @wepay_config[:ipn_callback_uri].present?
62
- "#{@wepay_config[:root_callback_uri]}/wepay/ipn"
63
+ def ipn_callback_uri(security_token)
64
+ uri = if @wepay_config[:ipn_callback_uri].present?
65
+ @wepay_config[:ipn_callback_uri]
66
+ else
67
+ "#{@wepay_config[:root_callback_uri]}/wepay/ipn"
68
+ end
69
+ apply_security_token(uri, security_token)
63
70
  end
64
71
 
65
- def checkout_redirect_uri
66
- return @wepay_config[:checkout_redirect_uri] if @wepay_config[:checkout_redirect_uri].present?
67
- "#{@wepay_config[:root_callback_uri]}/wepay/checkout"
72
+ def checkout_redirect_uri(security_token)
73
+ uri = if @wepay_config[:ipn_callback_uri].present?
74
+ @wepay_config[:checkout_redirect_uri]
75
+ else
76
+ "#{@wepay_config[:root_callback_uri]}/wepay/checkout"
77
+ end
78
+ apply_security_token(uri, security_token)
79
+ end
80
+
81
+ def apply_security_token(uri, security_token)
82
+ uri += (uri =~ /\?/ ? '&' : '?') + "security_token=#{security_token}"
68
83
  end
69
84
  end
70
85
  end
@@ -25,6 +25,7 @@ class CreateWepayCheckoutRecords < ActiveRecord::Migration
25
25
  t.boolean :require_shipping
26
26
  t.text :shipping_address
27
27
  t.decimal :tax
28
+ t.string :security_token
28
29
 
29
30
  t.timestamps
30
31
  end
@@ -41,18 +41,19 @@ module WepayRails
41
41
  wepay_gateway = WepayRails::Payments::Gateway.new(access_token)
42
42
  response = wepay_gateway.perform_checkout(params)
43
43
 
44
- if response['checkout_uri'].blank?
44
+ if response[:checkout_uri].blank?
45
45
  raise WepayRails::Exceptions::WepayCheckoutError.new("An error occurred: #{response.inspect}")
46
46
  end
47
47
 
48
48
  params.merge!({
49
- :access_token => wepay_gateway.access_token,
50
- :checkout_id => response['checkout_id']
49
+ :access_token => wepay_gateway.access_token,
50
+ :checkout_id => response[:checkout_id],
51
+ :security_token => response[:security_token]
51
52
  })
52
53
 
53
54
  WepayCheckoutRecord.create(params)
54
55
 
55
- redirect_to response['checkout_uri'] and return
56
+ redirect_to response[:checkout_uri] and return
56
57
  end
57
58
  end
58
59
  end
data/wepay-rails.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "wepay-rails"
8
- s.version = "2.1.0"
8
+ s.version = "2.2.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 = "2011-11-28"
12
+ s.date = "2011-11-29"
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 = [
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  "VERSION",
29
29
  "app/controllers/wepay/application_controller.rb",
30
30
  "app/controllers/wepay/authorize_controller.rb",
31
+ "app/controllers/wepay/checkout_controller.rb",
31
32
  "app/controllers/wepay/ipn_controller.rb",
32
33
  "config/routes.rb",
33
34
  "lib/api/account_methods.rb",
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.1.0
4
+ version: 2.2.0
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-11-28 00:00:00.000000000Z
12
+ date: 2011-11-29 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &24514020 !ruby/object:Gem::Requirement
16
+ requirement: &12133880 !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: *24514020
24
+ version_requirements: *12133880
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: shoulda
27
- requirement: &24512520 !ruby/object:Gem::Requirement
27
+ requirement: &12132460 !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: *24512520
35
+ version_requirements: *12132460
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &24510740 !ruby/object:Gem::Requirement
38
+ requirement: &12130820 !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: *24510740
46
+ version_requirements: *12130820
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &24486880 !ruby/object:Gem::Requirement
49
+ requirement: &12108320 !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: *24486880
57
+ version_requirements: *12108320
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &24484080 !ruby/object:Gem::Requirement
60
+ requirement: &12106040 !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: *24484080
68
+ version_requirements: *12106040
69
69
  description: Rails gem that interfaces with the WePay API
70
70
  email: adammede@gmail.com
71
71
  executables: []
@@ -85,6 +85,7 @@ files:
85
85
  - VERSION
86
86
  - app/controllers/wepay/application_controller.rb
87
87
  - app/controllers/wepay/authorize_controller.rb
88
+ - app/controllers/wepay/checkout_controller.rb
88
89
  - app/controllers/wepay/ipn_controller.rb
89
90
  - config/routes.rb
90
91
  - lib/api/account_methods.rb
@@ -113,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
114
  version: '0'
114
115
  segments:
115
116
  - 0
116
- hash: 2056025376124091245
117
+ hash: -341794943592480612
117
118
  required_rubygems_version: !ruby/object:Gem::Requirement
118
119
  none: false
119
120
  requirements: