wepay-rails 0.1.82 → 0.1.83
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +100 -44
- data/VERSION +1 -1
- data/app/controllers/wepay/ipn_controller.rb +1 -7
- data/lib/helpers/controller_helpers.rb +0 -1
- data/lib/wepay-rails.rb +0 -9
- data/wepay-rails.gemspec +1 -1
- metadata +12 -12
data/README.rdoc
CHANGED
@@ -17,27 +17,62 @@ 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
|
20
|
+
You need to also create a new model called WepayCheckoutRecord. In future versions, I'll include a generator - but for now, here's the migration to use:
|
21
|
+
|
22
|
+
class CreateWepayCheckoutRecords < ActiveRecord::Migration
|
23
|
+
def self.up
|
24
|
+
|
25
|
+
create_table :wepay_checkout_records do |t|
|
26
|
+
t.integer :checkout_id
|
27
|
+
t.integer :account_id
|
28
|
+
t.string :auth_code
|
29
|
+
t.string :state
|
30
|
+
t.string :short_description
|
31
|
+
t.text :long_description
|
32
|
+
t.string :currency
|
33
|
+
t.decimal :amount
|
34
|
+
t.decimal :app_fee
|
35
|
+
t.string :fee_payer
|
36
|
+
t.decimal :gross
|
37
|
+
t.decimal :fee
|
38
|
+
t.string :reference_id
|
39
|
+
t.text :redirect_uri
|
40
|
+
t.text :callback_uri
|
41
|
+
t.text :checkout_uri
|
42
|
+
t.string :payer_email
|
43
|
+
t.string :payer_name
|
44
|
+
t.text :cancel_reason
|
45
|
+
t.text :refund_reason
|
46
|
+
t.boolean :auto_capture
|
47
|
+
t.boolean :require_shipping
|
48
|
+
t.text :shipping_address
|
49
|
+
t.decimal :tax
|
50
|
+
|
51
|
+
t.timestamps
|
52
|
+
end
|
53
|
+
|
54
|
+
add_index :wepay_checkout_records, :checkout_id
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.down
|
58
|
+
drop_table :wepay_checkout_records
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
You will have to set up a few new controllers to handle callbacks and redirects from wepay back to your app.
|
21
64
|
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
65
|
|
24
66
|
I created a directory under my controllers directory called wepay so I can keep my wepay callback controllers in one place.
|
25
67
|
app
|
26
68
|
|_ controllers
|
27
69
|
|_ wepay
|
28
|
-
|_ application_controller.rb
|
29
70
|
|_ authorize_controller.rb
|
30
|
-
|_ ipn_controller.rb
|
31
71
|
|_ purchase
|
32
72
|
|_ checkout_controller.rb
|
33
73
|
|_ finalize_controller.rb
|
34
74
|
|
35
|
-
class Wepay::ApplicationController < ApplicationController
|
36
|
-
include WepayRails::Payments
|
37
|
-
end
|
38
|
-
|
39
75
|
class Wepay::AuthorizeController < Wepay::ApplicationController
|
40
|
-
before_filter :authenticate_account! # I use devise
|
41
76
|
def index
|
42
77
|
current_profile.save_wepay_auth_code params[:code]
|
43
78
|
initialize_wepay_access_token(params[:code])
|
@@ -46,6 +81,10 @@ I created a directory under my controllers directory called wepay so I can keep
|
|
46
81
|
end
|
47
82
|
end
|
48
83
|
|
84
|
+
The wepay-rails gem comes with an IpnController already built in for
|
85
|
+
handling requests from wepay about a specific checkout. If you wish to override it,
|
86
|
+
you can create an IpnController in your rails app.
|
87
|
+
|
49
88
|
class IpnController < Wepay::ApplicationController
|
50
89
|
def index
|
51
90
|
#Do something with the instant payment notifications back from Wepay
|
@@ -55,7 +94,6 @@ I created a directory under my controllers directory called wepay so I can keep
|
|
55
94
|
Routes for these:
|
56
95
|
namespace :wepay do
|
57
96
|
resources :authorize, :only => [:index]
|
58
|
-
resources :ipn, :only => [:index]
|
59
97
|
end
|
60
98
|
|
61
99
|
wepay.yml will also need these directives. See the section on wepay.yml
|
@@ -73,13 +111,13 @@ Finally, your checkout controller (or some controller that will interact with th
|
|
73
111
|
if wepay_access_token_exists? # Temporary Oauth Access token from wepay
|
74
112
|
|
75
113
|
cart = current_account.cart # EXAMPLE - get my shopping cart
|
76
|
-
tx_id = cart.
|
114
|
+
tx_id = cart.transaction_id # EXAMPLE - I use a column in my cart to have a way to look up the cart upon the user's return from wepay
|
77
115
|
|
78
116
|
checkout_params = {
|
79
117
|
:amount => cart.grand_total,
|
80
118
|
:short_description => cart.short_description,
|
81
119
|
:long_description => cart.long_description,
|
82
|
-
:
|
120
|
+
:redirect_uri => purchase_finalize_index_url(:txID => tx_id) # Wepay redirects the user back to this url after purchase
|
83
121
|
}
|
84
122
|
|
85
123
|
init_checkout_and_send_user_to_wepay(checkout_params) # Send the customer to wepay to finish payment
|
@@ -112,39 +150,57 @@ If not, we can initialize the access token. If it is there, go ahead and make an
|
|
112
150
|
|
113
151
|
Configuration is done through config/wepay.yml:
|
114
152
|
production:
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
153
|
+
client_id: <your client_id from wepay>
|
154
|
+
client_secret: <your client_secret from wepay>
|
155
|
+
authorize_redirect_uri: "http://www.example.com/wepay/authorize"
|
156
|
+
scope: ['refund_payments','collect_payments','view_balance','view_user']
|
157
|
+
#wepay_api_uri: "https://api.wepay.com"
|
158
|
+
wepay_api_uri: "https://stage.wepay.com"
|
159
|
+
wepay_api_version: "v2"
|
160
|
+
ipn_callback_uri: "http://www.example.com/wepay/ipn"
|
161
|
+
checkout_redirect_uri: "http://www.example.com/purchase/finalize"
|
162
|
+
fee_payer: Payee
|
163
|
+
checkout_type: GOODS
|
164
|
+
charge_tax: false
|
165
|
+
app_fee: 0
|
166
|
+
auto_capture: true
|
167
|
+
require_shipping: false
|
168
|
+
shipping_fee: 0
|
169
|
+
charge_tax: false
|
131
170
|
development:
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
171
|
+
client_id: <your client_id from wepay>
|
172
|
+
client_secret: <your client_secret from wepay>
|
173
|
+
redirect_uri: "http://dev.example.com/wepay/authorize"
|
174
|
+
scope: ['refund_payments','collect_payments','view_balance','view_user']
|
175
|
+
wepay_api_uri: "https://stage.wepay.com"
|
176
|
+
wepay_api_version: "v2"
|
177
|
+
ipn_callback_uri: "http://dev.example.com/wepay/ipn"
|
178
|
+
checkout_redirect_uri: "http://dev.example.com/purchase/finalize"
|
179
|
+
fee_payer: Payee
|
180
|
+
checkout_type: GOODS
|
181
|
+
charge_tax: false
|
182
|
+
app_fee: 0
|
183
|
+
require_shipping: false
|
184
|
+
shipping_fee: 0
|
185
|
+
charge_tax: false
|
186
|
+
auto_capture: true
|
187
|
+
test:
|
188
|
+
client_id: <your client_id from wepay>
|
189
|
+
client_secret: <your client_secret from wepay>
|
190
|
+
redirect_uri: "http://dev.example.com/wepay/authorize"
|
191
|
+
scope: ['refund_payments','collect_payments','view_balance','view_user']
|
192
|
+
wepay_api_uri: "https://stage.wepay.com"
|
193
|
+
wepay_api_version: "v2"
|
194
|
+
ipn_callback_uri: "http://test.example.com/wepay/ipn"
|
195
|
+
checkout_redirect_uri: "http://dev.example.com/purchase/finalize"
|
196
|
+
fee_payer: Payee
|
197
|
+
checkout_type: GOODS
|
198
|
+
charge_tax: false
|
199
|
+
app_fee: 0
|
200
|
+
auto_capture: true
|
201
|
+
charge_tax: false
|
202
|
+
require_shipping: false
|
203
|
+
shipping_fee: 0
|
148
204
|
|
149
205
|
|
150
206
|
== Contributing to wepay-rails
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.83
|
@@ -1,21 +1,15 @@
|
|
1
1
|
class Wepay::IpnController < Wepay::ApplicationController
|
2
2
|
def index
|
3
3
|
|
4
|
-
log = File.open('/tmp/ipn.log','a')
|
5
|
-
|
6
4
|
record = WepayCheckoutRecord.find_by_checkout_id(params[:checkout_id])
|
7
5
|
|
8
|
-
log.puts record.inspect
|
9
|
-
|
10
6
|
if record.present?
|
11
7
|
wepay_gateway.access_token(record.auth_code)
|
12
8
|
checkout = wepay_gateway.lookup_checkout(record.checkout_id)
|
13
|
-
log.puts checkout.inspect
|
14
9
|
record.update_attributes(checkout)
|
10
|
+
render :text => 'ok'
|
15
11
|
else
|
16
12
|
raise StandardError.new("Wepay IPN: No record found for checkout_id #{params[:checkout_id]}")
|
17
13
|
end
|
18
|
-
|
19
|
-
render :text => 'ok'
|
20
14
|
end
|
21
15
|
end
|
@@ -87,7 +87,6 @@ module WepayRails
|
|
87
87
|
# :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.
|
88
88
|
def init_checkout_and_send_user_to_wepay(parms)
|
89
89
|
response = wepay_gateway.perform_checkout(parms)
|
90
|
-
File.open('/tmp/noisebytes.log','a') {|f|f.write(response.inspect)}
|
91
90
|
raise WepayRails::Exceptions::InitializeCheckoutError.new("A problem occurred while trying to checkout. Wepay didn't send us back a checkout uri") unless response && response.has_key?('checkout_uri')
|
92
91
|
redirect_to response['checkout_uri'] and return
|
93
92
|
end
|
data/lib/wepay-rails.rb
CHANGED
@@ -30,9 +30,7 @@ module WepayRails
|
|
30
30
|
@wepay_access_token = args.first
|
31
31
|
|
32
32
|
yml = Rails.root.join('config', 'wepay.yml').to_s
|
33
|
-
File.open('/tmp/wepay.log','a') {|f| f.write("Yaml for wepay is found at #{yml}")}
|
34
33
|
@config = YAML.load_file(yml)[Rails.env].symbolize_keys
|
35
|
-
File.open('/tmp/wepay.log','a') {|f| f.write("config is #{@config.inspect}")}
|
36
34
|
|
37
35
|
@scope = @config.delete(:scope)
|
38
36
|
|
@@ -97,14 +95,10 @@ module WepayRails
|
|
97
95
|
# retrieved from the first call.
|
98
96
|
def wepay_user
|
99
97
|
user_api = lambda {|headers|
|
100
|
-
File.open('/tmp/noisebytes.log','a') {|f|f.write("Base uri inside lambda is #{@base_uri}")}
|
101
|
-
File.open('/tmp/noisebytes.log','a') {|f|f.write("Headers inside lambda is #{headers}")}
|
102
98
|
response = self.class.get("#{@base_uri}/user", {:headers => headers})
|
103
99
|
JSON.parse(response.body)
|
104
100
|
}
|
105
101
|
|
106
|
-
File.open('/tmp/noisebytes.log','a'){|f|f.write("User is #{user_api.call(wepay_auth_header)}")}
|
107
|
-
|
108
102
|
@wepay_user ||= user_api.call(wepay_auth_header)
|
109
103
|
end
|
110
104
|
|
@@ -157,9 +151,6 @@ module WepayRails
|
|
157
151
|
:account_id => @config[:account_id]
|
158
152
|
}.merge(parms)
|
159
153
|
|
160
|
-
File.open('/tmp/noisebytes.log','a') {|f| f.write({:headers => wepay_auth_header}.merge!(defaults).inspect)}
|
161
|
-
|
162
|
-
|
163
154
|
response = self.class.get("#{@base_uri}/checkout/create", {:headers => wepay_auth_header}.merge!(:query => defaults))
|
164
155
|
JSON.parse(response.body)
|
165
156
|
end
|
data/wepay-rails.gemspec
CHANGED
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.
|
4
|
+
version: 0.1.83
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-09-04 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
16
|
-
requirement: &
|
16
|
+
requirement: &19031220 !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: *
|
24
|
+
version_requirements: *19031220
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: shoulda
|
27
|
-
requirement: &
|
27
|
+
requirement: &19030640 !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: *
|
35
|
+
version_requirements: *19030640
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &19030120 !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: *
|
46
|
+
version_requirements: *19030120
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &19029520 !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: *
|
57
|
+
version_requirements: *19029520
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rcov
|
60
|
-
requirement: &
|
60
|
+
requirement: &19028920 !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: *
|
68
|
+
version_requirements: *19028920
|
69
69
|
description: Rails gem that interfaces with the WePay API
|
70
70
|
email: adammede@gmail.com
|
71
71
|
executables: []
|
@@ -108,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
108
|
version: '0'
|
109
109
|
segments:
|
110
110
|
- 0
|
111
|
-
hash:
|
111
|
+
hash: -782813271623262101
|
112
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
113
|
none: false
|
114
114
|
requirements:
|