wepay-rails 2.5.2 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +202 -0
- data/README.rdoc +0 -134
- data/VERSION +1 -1
- data/lib/generators/wepay_rails/install/install_generator.rb +1 -1
- data/lib/generators/wepay_rails/install/templates/wepay_checkout_record.rb +0 -4
- data/lib/wepay-rails.rb +4 -2
- data/wepay-rails.gemspec +4 -2
- metadata +5 -3
data/README.md
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
# wepay-rails
|
2
|
+
|
3
|
+
Wepay-Rails allows your rails app to accept payments with [Wepay](http://www.wepay.com).
|
4
|
+
|
5
|
+
[![build status][travis]][travis-link]
|
6
|
+
[travis]: https://secure.travis-ci.org/adamthedeveloper/wepay-rails.png?branch=master
|
7
|
+
[travis-link]: http://travis-ci.org/adamthedeveloper/wepay-rails
|
8
|
+
|
9
|
+
## Features
|
10
|
+
|
11
|
+
* Added PREAPPROVAL and DELAYED CHARGE ability 09/2012
|
12
|
+
* Built in IPN that listens to push notifications from wepay and updates saved checkout records for you
|
13
|
+
* Allows you to fetch your access token easily through a web interface
|
14
|
+
* Built in API tools to allow you to make all wepay-api calls easily
|
15
|
+
* Built in ability to send your customers to wepay to make payments and handles their trip back for you OR use iFrame for checkouts (see Wiki https://github.com/adamthedeveloper/wepay-rails/wiki/Using-the-wepay-iframe)
|
16
|
+
* Saves the current state of every checkout
|
17
|
+
* Authorize many users to accept payments dynamically (see Wiki https://github.com/adamthedeveloper/wepay-rails/wiki/Authorize-Many-Users-Dynamically)
|
18
|
+
* Configurable
|
19
|
+
|
20
|
+
## Installation
|
21
|
+
|
22
|
+
To install it, add this to your Gemfile
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
gem 'wepay-rails'
|
26
|
+
```
|
27
|
+
|
28
|
+
To create your WepayCheckoutRecord model and migration:
|
29
|
+
|
30
|
+
```console
|
31
|
+
script/rails g wepay_rails:install
|
32
|
+
```
|
33
|
+
|
34
|
+
This will create 3 files for you, a migration file for a table to hold the checkout results, the model and a wepay.yml.example file. Next run:
|
35
|
+
|
36
|
+
```console
|
37
|
+
rake db:migrate
|
38
|
+
```
|
39
|
+
|
40
|
+
WepayCheckoutRecord will be updated by wepay's IPN system as changes to the checkout change - such as the status.
|
41
|
+
Wepay-rails handles those IPN notifications for you. You can write observers watching the WepayCheckoutRecord model if you need to have
|
42
|
+
something specific occur when the checkout changes. Also, since a model is created for you, you can also track changes to it's state
|
43
|
+
through state machine or paper trail or some other gem of your liking. Hook up WepayCheckoutRecord how you like.
|
44
|
+
|
45
|
+
Modify config/wepay.yml.example to your needs and copy it to config/wepay.yml.
|
46
|
+
|
47
|
+
Assuming that you have:
|
48
|
+
|
49
|
+
1. created an account on wepay
|
50
|
+
2. created a user to accept the payments
|
51
|
+
3. created your application for your account
|
52
|
+
4. set your wepay.yml file with the info it needs to talk to the wepay api minus the access_token
|
53
|
+
|
54
|
+
You can now get your access token.
|
55
|
+
|
56
|
+
To fetch your access_token, open a browser and go to:
|
57
|
+
|
58
|
+
```console
|
59
|
+
your.railsapp.com/wepay/authorize
|
60
|
+
```
|
61
|
+
|
62
|
+
Login at the prompt or register. You will be sent back to your app and you should have gotten an access_token. Copy it to your wepay.yml
|
63
|
+
file and restart your app.
|
64
|
+
|
65
|
+
## Example
|
66
|
+
|
67
|
+
I created a controller called finalize_controller and I use it for a landing page when the customer is finished paying
|
68
|
+
their order. The other controller I created is a checkout_controller - I send my customers to it when they click checkout
|
69
|
+
in the cart. Your app is surely different than mine. Do what makes sense to you.
|
70
|
+
For now, here's a small example...
|
71
|
+
|
72
|
+
```
|
73
|
+
app
|
74
|
+
|_ controllers
|
75
|
+
|_ purchase
|
76
|
+
|_ checkout_controller.rb
|
77
|
+
|_ finalize_controller.rb
|
78
|
+
```
|
79
|
+
|
80
|
+
Tell wepay-rails where to send the customer after they come back from wepay with a complete payment. Open wepay.yml:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
after_checkout_redirect_uri: "http://www.example.com/purchase/finalize"
|
84
|
+
```
|
85
|
+
|
86
|
+
Create a controller that will send the user to wepay - notice it includes WepayRails::Payments:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
class Purchase::CheckoutController < ApplicationController
|
90
|
+
include WepayRails::Payments
|
91
|
+
|
92
|
+
def index
|
93
|
+
cart = current_user.cart # EXAMPLE - get my shopping cart
|
94
|
+
|
95
|
+
checkout_params = {
|
96
|
+
:amount => cart.grand_total,
|
97
|
+
:short_description => cart.short_description,
|
98
|
+
:long_description => cart.long_description,
|
99
|
+
}
|
100
|
+
|
101
|
+
# Finally, send the user off to wepay so you can get paid! - CASH MONEY
|
102
|
+
init_checkout_and_send_user_to_wepay(checkout_params)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
107
|
+
Finally, the controller I use for finalizing the checkout - AKA - the controller the user is sent back to after his/her trip back from
|
108
|
+
wepay. A checkout_id is passed in through params so you can access the WepayCheckoutRecord, make a call to
|
109
|
+
wepay to get the checkout info - whatever you want to do (See the wiki for more info on API calls):
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
class Purchase::FinalizeController < ApplicationController
|
113
|
+
def index
|
114
|
+
# Fetch the WepayCheckoutRecord that was stored for the checkout
|
115
|
+
wcr = WepayCheckoutRecord.find_by_checkout_id(params[:checkout_id])
|
116
|
+
|
117
|
+
# Example: Set the association of the wepay checkout record to my cart - then, on to order.
|
118
|
+
cart = current_account.cart
|
119
|
+
cart.wepay_checkout_record = wcr
|
120
|
+
cart.save!
|
121
|
+
|
122
|
+
# Convert cart to an order?? Move to observer of WepayCheckoutRecord??
|
123
|
+
cart.convert_cart_to_order if wcr.state == 'authorized'
|
124
|
+
|
125
|
+
render :text => "Hooray - you bought some widgets!"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
```
|
129
|
+
|
130
|
+
## Example of WePay Oauth
|
131
|
+
|
132
|
+
For reference, please refer to WePay's [documentation on Oauth](https://www.wepay.com/developer/reference/oauth2).
|
133
|
+
|
134
|
+
### Setup
|
135
|
+
|
136
|
+
As an example, I have the User model, view, and controller.
|
137
|
+
|
138
|
+
I have the following routes for WePay in my `config/routes.rb:
|
139
|
+
|
140
|
+
```ruby
|
141
|
+
match 'wepay_connect', to: 'users#wepay_connect'
|
142
|
+
match 'wepay_auth', to: 'users#wepay_auth'
|
143
|
+
```
|
144
|
+
|
145
|
+
### Controllers
|
146
|
+
|
147
|
+
The first method that we will hit in this example is `wepay_connect` in my `Users` controller:
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
def wepay_connect
|
151
|
+
wepay_gateway = WepayRails::Payments::Gateway.new
|
152
|
+
redirect_to wepay_gateway.auth_code_url( wepay_auth_path(current_user, only_path: false) )
|
153
|
+
end
|
154
|
+
```
|
155
|
+
|
156
|
+
This will send the user to WePay's `/oauth2/authorize` uri to start the Oauth flow.
|
157
|
+
|
158
|
+
The response is an authorization code, which is used to get the user's access token.
|
159
|
+
|
160
|
+
The next method we will hit is `wepay_auth`:
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
def wepay_auth
|
164
|
+
wepay_gateway = WepayRails::Payments::Gateway.new
|
165
|
+
access_token = wepay_gateway.get_access_token(params[:code], wepay_auth_path(current_user, :only_path => false) )
|
166
|
+
if current_user.update_attributes(wepay_access_token: access_token, wepay_user_id: wepay_gateway.account_id)
|
167
|
+
flash[:success] = "Your WePay account is now connected!"
|
168
|
+
redirect_to root_path
|
169
|
+
end
|
170
|
+
end
|
171
|
+
```
|
172
|
+
|
173
|
+
### Start Oauth
|
174
|
+
|
175
|
+
I have this in the view, assuming that a user is currently signed in:
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
link_to "Connect To WePay", wepay_connect_path
|
179
|
+
```
|
180
|
+
|
181
|
+
When the user clicks on this link, he will be prompted to start the WePay Oauth flow.
|
182
|
+
|
183
|
+
## Special Thanks to additional contributers of Wepay-Rails
|
184
|
+
* lucisferre (Chris Nicola) https://github.com/lucisferre
|
185
|
+
* mindeavor (Gilbert) https://github.com/mindeavor
|
186
|
+
* ustorf (Bernd Ustorf) https://github.com/ustorf
|
187
|
+
* dragonstarwebdesign (Steve Aquino) https://github.com/dragonstarwebdesign
|
188
|
+
* jules27 (Julie Mao) https://github.com/jules27
|
189
|
+
|
190
|
+
## Contributing to wepay-rails
|
191
|
+
|
192
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
193
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
194
|
+
* Fork the project
|
195
|
+
* Start a feature/bugfix branch
|
196
|
+
* Commit and push until you are happy with your contribution
|
197
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
198
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
199
|
+
|
200
|
+
## Copyright
|
201
|
+
|
202
|
+
Copyright (c) 2011 Adam Medeiros. See LICENSE.txt for further details.
|
data/README.rdoc
CHANGED
@@ -1,134 +0,0 @@
|
|
1
|
-
= wepay-rails
|
2
|
-
|
3
|
-
Wepay-Rails allows your rails app to accept payments with Wepay (http://www.wepay.com).
|
4
|
-
|
5
|
-
{<img src="https://secure.travis-ci.org/adamthedeveloper/wepay-rails.png?branch=master" alt="Build Status" />}[http://travis-ci.org/adamthedeveloper/wepay-rails]
|
6
|
-
|
7
|
-
= Features
|
8
|
-
|
9
|
-
* Added PREAPPROVAL and DELAYED CHARGE ability 09/2012
|
10
|
-
* Built in IPN that listens to push notifications from wepay and updates saved checkout records for you
|
11
|
-
* Allows you to fetch your access token easily through a web interface
|
12
|
-
* Built in API tools to allow you to make all wepay-api calls easily
|
13
|
-
* Built in ability to send your customers to wepay to make payments and handles their trip back for you OR use iFrame for checkouts (see Wiki https://github.com/adamthedeveloper/wepay-rails/wiki/Using-the-wepay-iframe)
|
14
|
-
* Saves the current state of every checkout
|
15
|
-
* Authorize many users to accept payments dynamically (see Wiki https://github.com/adamthedeveloper/wepay-rails/wiki/Authorize-Many-Users-Dynamically)
|
16
|
-
* Configurable
|
17
|
-
|
18
|
-
= Installation
|
19
|
-
|
20
|
-
To install it, add this to your Gemfile
|
21
|
-
|
22
|
-
gem 'wepay-rails'
|
23
|
-
|
24
|
-
To create your WepayCheckoutRecord model and migration:
|
25
|
-
|
26
|
-
script/rails g wepay_rails:install
|
27
|
-
|
28
|
-
This will create 3 files for you, a migration file for a table to hold the checkout results, the model and a wepay.yml.example file. Next run:
|
29
|
-
|
30
|
-
rake db:migrate
|
31
|
-
|
32
|
-
WepayCheckoutRecord will be updated by wepay's IPN system as changes to the checkout change - such as the status.
|
33
|
-
Wepay-rails handles those IPN notifications for you. You can write observers watching the WepayCheckoutRecord model if you need to have
|
34
|
-
something specific occur when the checkout changes. Also, since a model is created for you, you can also track changes to it's state
|
35
|
-
through state machine or paper trail or some other gem of your liking. Hook up WepayCheckoutRecord how you like.
|
36
|
-
|
37
|
-
Modify config/wepay.yml.example to your needs and copy it to config/wepay.yml.
|
38
|
-
|
39
|
-
Assuming that you have:
|
40
|
-
|
41
|
-
1. created an account on wepay
|
42
|
-
2. created a user to accept the payments
|
43
|
-
3. created your application for your account
|
44
|
-
4. set your wepay.yml file with the info it needs to talk to the wepay api minus the access_token
|
45
|
-
|
46
|
-
You can now get your access token.
|
47
|
-
|
48
|
-
To fetch your access_token, open a browser and go to:
|
49
|
-
|
50
|
-
your.railsapp.com/wepay/authorize
|
51
|
-
|
52
|
-
Login at the prompt or register. You will be sent back to your app and you should have gotten an access_token. Copy it to your wepay.yml
|
53
|
-
file and restart your app.
|
54
|
-
|
55
|
-
= Example
|
56
|
-
|
57
|
-
I created a controller called finalize_controller and I use it for a landing page when the customer is finished paying
|
58
|
-
their order. The other controller I created is a checkout_controller - I send my customers to it when they click checkout
|
59
|
-
in the cart. Your app is surely different than mine. Do what makes sense to you.
|
60
|
-
For now, here's a small example...
|
61
|
-
|
62
|
-
app
|
63
|
-
|_ controllers
|
64
|
-
|_ purchase
|
65
|
-
|_ checkout_controller.rb
|
66
|
-
|_ finalize_controller.rb
|
67
|
-
|
68
|
-
Tell wepay-rails where to send the customer after they come back from wepay with a complete payment. Open wepay.yml:
|
69
|
-
|
70
|
-
after_checkout_redirect_uri: "http://www.example.com/purchase/finalize"
|
71
|
-
|
72
|
-
Create a controller that will send the user to wepay - notice it includes WepayRails::Payments:
|
73
|
-
|
74
|
-
class Purchase::CheckoutController < ApplicationController
|
75
|
-
include WepayRails::Payments
|
76
|
-
|
77
|
-
def index
|
78
|
-
cart = current_user.cart # EXAMPLE - get my shopping cart
|
79
|
-
|
80
|
-
checkout_params = {
|
81
|
-
:amount => cart.grand_total,
|
82
|
-
:short_description => cart.short_description,
|
83
|
-
:long_description => cart.long_description,
|
84
|
-
}
|
85
|
-
|
86
|
-
# Finally, send the user off to wepay so you can get paid! - CASH MONEY
|
87
|
-
init_checkout_and_send_user_to_wepay(checkout_params)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
Finally, the controller I use for finalizing the checkout - AKA - the controller the user is sent back to after his/her trip back from
|
92
|
-
wepay. A checkout_id is passed in through params so you can access the WepayCheckoutRecord, make a call to
|
93
|
-
wepay to get the checkout info - whatever you want to do (See the wiki for more info on API calls):
|
94
|
-
|
95
|
-
class Purchase::FinalizeController < ApplicationController
|
96
|
-
def index
|
97
|
-
# Fetch the WepayCheckoutRecord that was stored for the checkout
|
98
|
-
wcr = WepayCheckoutRecord.find_by_checkout_id(params[:checkout_id])
|
99
|
-
|
100
|
-
# Example: Set the association of the wepay checkout record to my cart - then, on to order.
|
101
|
-
cart = current_account.cart
|
102
|
-
cart.wepay_checkout_record = wcr
|
103
|
-
cart.save!
|
104
|
-
|
105
|
-
# Convert cart to an order?? Move to observer of WepayCheckoutRecord??
|
106
|
-
cart.convert_cart_to_order if wcr.state == 'authorized'
|
107
|
-
|
108
|
-
render :text => "Hooray - you bought some widgets!"
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
|
113
|
-
== Special Thanks to additional contributers of Wepay-Rails
|
114
|
-
* lucisferre (Chris Nicola) https://github.com/lucisferre
|
115
|
-
* mindeavor (Gilbert) https://github.com/mindeavor
|
116
|
-
* ustorf (Bernd Ustorf) https://github.com/ustorf
|
117
|
-
* dragonstarwebdesign (Steve Aquino) https://github.com/dragonstarwebdesign
|
118
|
-
|
119
|
-
|
120
|
-
== Contributing to wepay-rails
|
121
|
-
|
122
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
123
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
124
|
-
* Fork the project
|
125
|
-
* Start a feature/bugfix branch
|
126
|
-
* Commit and push until you are happy with your contribution
|
127
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
128
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
129
|
-
|
130
|
-
== Copyright
|
131
|
-
|
132
|
-
Copyright (c) 2011 Adam Medeiros. See LICENSE.txt for
|
133
|
-
further details.
|
134
|
-
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.6.0
|
@@ -21,7 +21,7 @@ module WepayRails
|
|
21
21
|
|
22
22
|
def copy_migrations
|
23
23
|
migration_template "create_wepay_checkout_records.rb", "db/migrate/create_wepay_checkout_records.rb"
|
24
|
-
copy_file "wepay_checkout_record.rb", "
|
24
|
+
copy_file "wepay_checkout_record.rb", "app/models/wepay_checkout_record.rb"
|
25
25
|
copy_file "wepay.yml", "config/wepay.yml.example"
|
26
26
|
end
|
27
27
|
end
|
data/lib/wepay-rails.rb
CHANGED
@@ -144,12 +144,14 @@ module WepayRails
|
|
144
144
|
end
|
145
145
|
|
146
146
|
# Fetch the access token from wepay for the auth code
|
147
|
-
def get_access_token(auth_code, redirect_uri)
|
147
|
+
def get_access_token(auth_code, redirect_uri, callback_uri = nil)
|
148
148
|
params = {
|
149
149
|
:client_id => @wepay_config[:client_id],
|
150
150
|
:client_secret => @wepay_config[:client_secret],
|
151
151
|
:redirect_uri => redirect_uri,
|
152
|
-
:code => auth_code
|
152
|
+
:code => auth_code,
|
153
|
+
:callback_uri => callback_uri # Optional field in which you will receive IPNs with the user_id
|
154
|
+
# when the user revokes an access_token or is deleted.
|
153
155
|
}
|
154
156
|
json = call_api("/oauth2/token", params)
|
155
157
|
raise WepayRails::Exceptions::AccessTokenError.new("A problem occurred trying to get the access token: #{json.inspect}") unless json.has_key?(:access_token)
|
data/wepay-rails.gemspec
CHANGED
@@ -5,16 +5,17 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "wepay-rails"
|
8
|
-
s.version = "2.
|
8
|
+
s.version = "2.6.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 = "2013-04-
|
12
|
+
s.date = "2013-04-18"
|
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 = [
|
16
16
|
"LICENSE.txt",
|
17
17
|
"README",
|
18
|
+
"README.md",
|
18
19
|
"README.rdoc"
|
19
20
|
]
|
20
21
|
s.files = [
|
@@ -25,6 +26,7 @@ Gem::Specification.new do |s|
|
|
25
26
|
"Gemfile.lock",
|
26
27
|
"LICENSE.txt",
|
27
28
|
"README",
|
29
|
+
"README.md",
|
28
30
|
"README.rdoc",
|
29
31
|
"Rakefile",
|
30
32
|
"VERSION",
|
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.
|
4
|
+
version: 2.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -162,6 +162,7 @@ extensions: []
|
|
162
162
|
extra_rdoc_files:
|
163
163
|
- LICENSE.txt
|
164
164
|
- README
|
165
|
+
- README.md
|
165
166
|
- README.rdoc
|
166
167
|
files:
|
167
168
|
- .DS_Store
|
@@ -171,6 +172,7 @@ files:
|
|
171
172
|
- Gemfile.lock
|
172
173
|
- LICENSE.txt
|
173
174
|
- README
|
175
|
+
- README.md
|
174
176
|
- README.rdoc
|
175
177
|
- Rakefile
|
176
178
|
- VERSION
|
@@ -214,7 +216,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
214
216
|
version: '0'
|
215
217
|
segments:
|
216
218
|
- 0
|
217
|
-
hash:
|
219
|
+
hash: 4440470659904624589
|
218
220
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
219
221
|
none: false
|
220
222
|
requirements:
|