wepay-rails 0.1.44 → 0.1.45

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +105 -50
  2. data/VERSION +1 -1
  3. data/wepay-rails.gemspec +3 -3
  4. metadata +14 -14
data/README.rdoc CHANGED
@@ -17,79 +17,134 @@ Your model:
17
17
 
18
18
  Adding wepayable to your model also adds some helpful methods to your model, like save_<your column name>
19
19
 
20
- You'll need a controller and action for wepay to call back - add the entry to your routes file:
20
+ You will have to set up a few new controllers to handle callbacks from wepay.
21
+ One is for handling the Oauth handshake. I called mine authorize_controller.rb
22
+ Another is for handling IPN (Instant Payment Notifications) - for me, it's ipn_controller.rb
23
+
24
+ I created a directory under my controllers directory called wepay so I can keep my wepay callback controllers in one place.
25
+ app
26
+ L controllers
27
+ L wepay
28
+ L application_controller.rb
29
+ L authorize_controller.rb
30
+ L ipn_controller.rb
31
+ L purchase
32
+ L checkout_controller.rb
33
+ L finalize_controller.rb
34
+
35
+ class Wepay::ApplicationController < ApplicationController
36
+ include WepayRails::Payments
37
+ end
21
38
 
22
- class Wepay::AuthorizeController < ApplicationController
23
- before_filter :authenticate_account!
39
+ class Wepay::AuthorizeController < Wepay::ApplicationController
40
+ before_filter :authenticate_account! # I use devise
41
+ def index
42
+ current_profile.save_wepay_auth_code params[:code]
43
+ initialize_wepay_access_token(params[:code])
24
44
 
25
- def index
26
- current_user.save_wepay_auth_code params[:code]
27
- initialize_wepay_access_token(params[:code])
45
+ redirect_to purchase_checkout_index_path
46
+ end
47
+ end
28
48
 
29
- redirect_to purchase_checkout_index_path
30
- end
49
+ class IpnController < Wepay::ApplicationController
50
+ def index
51
+ #Do something with the instant payment notifications back from Wepay
52
+ end
53
+ end
31
54
 
32
- private
33
- include WepayRails::Payments
55
+ Routes for these:
56
+ namespace :wepay do
57
+ resources :authorize, :only => [:index]
58
+ resources :ipn, :only => [:index]
34
59
  end
35
60
 
61
+ wepay.yml will also need these directives. See the section on wepay.yml
62
+
36
63
  When you include WepayRails::Payments, you get the controller actions you need. For instance, initialize_wepay_access_token(auth_code)
37
64
  which completes the Oauth2 handshake with Wepay and get's the access token for future comunications with Wepay.
38
65
 
39
66
  Finally, your checkout controller (or some controller that will interact with the Wepay API):
40
67
 
41
- class Purchase::CheckoutController < ApplicationController
42
- before_filter :authenticate_account!
43
-
44
- def index
45
- if current_user.has_wepay_auth_code?
46
- if wepay_access_token_exists?
47
- # Send payment off to wepay or get the user or something else
48
- render :json => wepay_gateway.wepay_user
49
- return
50
- else
51
- initialize_wepay_access_token(current_user.wepay_auth_code)
52
- end
53
- else
54
- redirect_to_wepay_for_auth
68
+ class Purchase::CheckoutController < Purchase::PurchaseController
69
+ before_filter :authenticate_account!
70
+
71
+ def index
72
+ if current_profile.wepay_auth_code.present? # Semi-permanent code used to get the Oauth Access Token
73
+ if wepay_access_token_exists? # Temporary Oauth Access token from wepay
74
+
75
+ cart = current_account.cart # EXAMPLE - get my shopping cart
76
+ tx_id = cart.init_transaction # EXAMPLE - I use a transaction table to capture attempts to checkout
77
+
78
+ checkout_params = {
79
+ :amount => cart.grand_total,
80
+ :short_description => cart.short_description,
81
+ :long_description => cart.long_description,
82
+ :callback_uri => purchase_finalize_index_url(:txID => tx_id) # Wepay redirects the user back to this url after purchase
83
+ }
84
+
85
+ init_checkout_and_send_user_to_wepay(checkout_params) # Send the customer to wepay to finish payment
86
+ else
87
+ initialize_wepay_access_token(current_profile.wepay_auth_code) # No access token - so go get one
88
+ end
89
+ else
90
+ redirect_to_wepay_for_auth # Customer doesn't have an auth code yet from Wepay - so go get one
91
+ end
55
92
  end
56
- end
93
+ end
57
94
 
58
- private
59
- include WepayRails::Payments
95
+ The controller I use for finalizing the checkout - AKA - the controller the user is sent back to after his/her trip to
96
+ wepay.
97
+ class Purchase::FinalizeController < ApplicationController
98
+ def index
99
+ Do something - the user has come back from wepay and need an acknowlegement or something.
100
+ end
101
+ end
102
+
103
+ Example Routes for these:
104
+ namespace :purchase do
105
+ resource :cart, :has_many => :purchase_items
106
+ resources :checkout, :only => [:index]
107
+ resources :finalize, :only => [:index]
60
108
  end
61
109
 
62
110
  First, we check to see if we have saved the auth code for the user, if so, we next need to see if we have an Oauth2 access token.
63
- If not, we can initialize the access token. If it is there, go ahead and make an api call - the example above gets the
64
- wepay_user.
111
+ If not, we can initialize the access token. If it is there, go ahead and make an api call - the example above initiates a checkout.
65
112
 
66
113
  Configuration is done through config/wepay.yml:
67
-
68
114
  production:
69
115
  client_id: <your wepay client id>
70
- client_secret: <your wepay client secret code>
71
- redirect_uri: "<your callback url in your rails app>"
116
+ client_secret: <your wepay client secret>
117
+ authorize_redirect_uri: "http://prod.example.com/wepay/authorize"
72
118
  scope: ['refund_payments','collect_payments','view_balance','view_user']
73
- #wepay_api_uri: "https://api.wepay.com"
74
- wepay_api_uri: "https://stage.wepay.com"
119
+ wepay_api_uri: "https://api.wepay.com"
75
120
  wepay_api_version: "v2"
76
-
121
+ ipn_callback_uri: "http://prod.example.com/wepay/ipn"
122
+ checkout_redirect_uri: "http://prod.example.com/purchase/finalize"
123
+ fee_payer: Payee
124
+ checkout_type: GOODS
125
+ charge_tax: false
126
+ app_fee: 0
127
+ auto_capture: true
128
+ require_shipping: false
129
+ shipping_fee: 0
130
+ charge_tax: false
77
131
  development:
78
- client_id: 12345
79
- client_secret: 12345asdfg
80
- redirect_uri: "http://www.example.com/wepay/authorize"
81
- scope: ['refund_payments','collect_payments','view_balance','view_user']
82
- wepay_api_uri: "https://stage.wepay.com"
83
- wepay_api_version: "v2"
84
-
85
- test:
86
- client_id: 12345
87
- client_secret: 12345asdfg
88
- redirect_uri: "http://www.example.com/wepay/authorize"
89
- scope: ['refund_payments','collect_payments','view_balance','view_user']
90
- wepay_api_uri: "https://stage.wepay.com"
91
- wepay_api_version: "v2"
92
-
132
+ client_id: <your dev client id>
133
+ client_secret: <your dev client secret>
134
+ redirect_uri: "http://dev.example.com/wepay/authorize"
135
+ scope: ['refund_payments','collect_payments','view_balance','view_user']
136
+ wepay_api_uri: "https://stage.wepay.com"
137
+ wepay_api_version: "v2"
138
+ ipn_callback_uri: "http://dev.example.com/wepay/ipn"
139
+ checkout_redirect_uri: "http://dev.example.com/purchase/finalize"
140
+ fee_payer: Payee
141
+ checkout_type: GOODS
142
+ charge_tax: false
143
+ app_fee: 0
144
+ require_shipping: false
145
+ shipping_fee: 0
146
+ charge_tax: false
147
+ auto_capture: true
93
148
 
94
149
 
95
150
  == Contributing to wepay-rails
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.44
1
+ 0.1.45
data/wepay-rails.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{wepay-rails}
8
- s.version = "0.1.44"
8
+ s.version = "0.1.45"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Adam Medeiros}]
12
- s.date = %q{2011-08-14}
12
+ s.date = %q{2011-08-19}
13
13
  s.description = %q{Rails gem that interfaces with the WePay API}
14
14
  s.email = %q{adammede@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -37,7 +37,7 @@ Gem::Specification.new do |s|
37
37
  s.homepage = %q{http://github.com/adamthedeveloper/wepay-rails}
38
38
  s.licenses = [%q{MIT}]
39
39
  s.require_paths = [%q{lib}]
40
- s.rubygems_version = %q{1.8.6}
40
+ s.rubygems_version = %q{1.8.7}
41
41
  s.summary = %q{Rails gem that interfaces with the WePay API}
42
42
 
43
43
  if s.respond_to? :specification_version then
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.44
4
+ version: 0.1.45
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-08-14 00:00:00.000000000Z
12
+ date: 2011-08-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &12465740 !ruby/object:Gem::Requirement
16
+ requirement: &17370040 !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: *12465740
24
+ version_requirements: *17370040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: shoulda
27
- requirement: &12464560 !ruby/object:Gem::Requirement
27
+ requirement: &17368900 !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: *12464560
35
+ version_requirements: *17368900
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &12463340 !ruby/object:Gem::Requirement
38
+ requirement: &17367500 !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: *12463340
46
+ version_requirements: *17367500
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &12462100 !ruby/object:Gem::Requirement
49
+ requirement: &17366520 !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: *12462100
57
+ version_requirements: *17366520
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &12461120 !ruby/object:Gem::Requirement
60
+ requirement: &17365420 !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: *12461120
68
+ version_requirements: *17365420
69
69
  description: Rails gem that interfaces with the WePay API
70
70
  email: adammede@gmail.com
71
71
  executables: []
@@ -105,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
105
  version: '0'
106
106
  segments:
107
107
  - 0
108
- hash: -744223484762769908
108
+ hash: -1961593571812299792
109
109
  required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  none: false
111
111
  requirements:
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  requirements: []
116
116
  rubyforge_project:
117
- rubygems_version: 1.8.6
117
+ rubygems_version: 1.8.7
118
118
  signing_key:
119
119
  specification_version: 3
120
120
  summary: Rails gem that interfaces with the WePay API