wepay-rails 2.0.0 → 2.1.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/README.rdoc +28 -16
- data/VERSION +1 -1
- data/app/controllers/wepay/authorize_controller.rb +7 -3
- data/lib/generators/wepay_rails/install/templates/wepay.yml +0 -2
- data/lib/helpers/controller_helpers.rb +5 -0
- data/lib/wepay-rails.rb +5 -2
- data/wepay-rails.gemspec +2 -3
- metadata +13 -14
- data/lib/helpers/model_helpers.rb +0 -6
data/README.rdoc
CHANGED
@@ -2,14 +2,21 @@
|
|
2
2
|
|
3
3
|
Wepay-Rails allows your rails app to accept payments with Wepay (http://www.wepay.com).
|
4
4
|
|
5
|
+
= Features
|
6
|
+
|
7
|
+
* Built in IPN that listens to push notifications from wepay and updates saved checkout records for you
|
8
|
+
* Allows you to fetch your access token easily through a web interface
|
9
|
+
* Built in API tools to allow you to make all wepay-api calls easily
|
10
|
+
* Built in ability to send your customers to wepay to make payments and handles their trip back for you
|
11
|
+
* Saves the current state of every checkout
|
12
|
+
* Configurable
|
13
|
+
|
14
|
+
= Installation
|
15
|
+
|
5
16
|
To install it, add this to your Gemfile
|
6
17
|
|
7
18
|
gem 'wepay-rails'
|
8
19
|
|
9
|
-
You need to also create a new model called WepayCheckoutRecord. It will be updated by wepay's IPN system as changes to the checkout change - such as the status.
|
10
|
-
Wepay-rails handles those IPN notifications for you. You can write observers watching the WepayCheckoutRecord model if you need to have
|
11
|
-
something specific occur when the checkout changes.
|
12
|
-
|
13
20
|
To create your WepayCheckoutRecord model and migration:
|
14
21
|
|
15
22
|
script/rails g wepay_rails:install
|
@@ -18,6 +25,11 @@ This will create 3 files for you, a migration file for a table to hold the check
|
|
18
25
|
|
19
26
|
rake db:migrate
|
20
27
|
|
28
|
+
WepayCheckoutRecord will be updated by wepay's IPN system as changes to the checkout change - such as the status.
|
29
|
+
Wepay-rails handles those IPN notifications for you. You can write observers watching the WepayCheckoutRecord model if you need to have
|
30
|
+
something specific occur when the checkout changes. Also, since a model is created for you, you can also track changes to it's state
|
31
|
+
through state machine or paper trail or some other gem of your liking. Hook up WepayCheckoutRecord how you like.
|
32
|
+
|
21
33
|
Modify config/wepay.yml.example to your needs and copy it to config/wepay.yml.
|
22
34
|
|
23
35
|
Assuming that you have:
|
@@ -36,11 +48,12 @@ To fetch your access_token, open a browser and go to:
|
|
36
48
|
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
|
37
49
|
file and restart your app.
|
38
50
|
|
39
|
-
|
40
|
-
|
51
|
+
= Example
|
52
|
+
|
53
|
+
I created a controller called finalize_controller and I use it for a landing page when the customer is finished paying
|
41
54
|
their order. The other controller I created is a checkout_controller - I send my customers to it when they click checkout
|
42
|
-
in the cart. Your app is surely
|
43
|
-
For now, here's
|
55
|
+
in the cart. Your app is surely different than mine. Do what makes sense to you.
|
56
|
+
For now, here's a small example...
|
44
57
|
|
45
58
|
app
|
46
59
|
|_ controllers
|
@@ -48,18 +61,15 @@ For now, here's what I am doing in my rails app to handle it...
|
|
48
61
|
|_ checkout_controller.rb
|
49
62
|
|_ finalize_controller.rb
|
50
63
|
|
51
|
-
|
64
|
+
Tell wepay-rails where to send the customer after they come back from wepay with a complete payment. Open wepay.yml:
|
52
65
|
|
53
|
-
after_authorize_redirect_uri: "http://www.example.com/purchase/checkout"
|
54
66
|
after_checkout_redirect_uri: "http://www.example.com/purchase/finalize"
|
55
67
|
|
56
|
-
|
68
|
+
Create a controller that will send the user to wepay - notice it includes WepayRails::Payments:
|
57
69
|
|
58
70
|
class Purchase::CheckoutController < ApplicationController
|
59
71
|
include WepayRails::Payments
|
60
72
|
|
61
|
-
before_filter :authenticate_user! # I am using devise - this line depends on your authentication scheme
|
62
|
-
|
63
73
|
def index
|
64
74
|
cart = current_user.cart # EXAMPLE - get my shopping cart
|
65
75
|
|
@@ -74,14 +84,16 @@ Finally, your checkout controller (or some controller that will interact with th
|
|
74
84
|
end
|
75
85
|
end
|
76
86
|
|
77
|
-
|
78
|
-
wepay to
|
87
|
+
Finally, the controller I use for finalizing the checkout - AKA - the controller the user is sent back to after his/her trip back from
|
88
|
+
wepay. A checkout_id is passed in through params so you can access the WepayCheckoutRecord, make a call to
|
89
|
+
wepay to get the checkout info - whatever you want to do (See the wiki for more info on API calls):
|
79
90
|
|
80
91
|
class Purchase::FinalizeController < ApplicationController
|
81
92
|
def index
|
93
|
+
# Fetch the WepayCheckoutRecord that was stored for the checkout
|
82
94
|
wcr = WepayCheckoutRecord.find_by_checkout_id(params[:checkout_id])
|
83
95
|
|
84
|
-
# Set the association of the wepay checkout record to my cart - then, on to order.
|
96
|
+
# Example: Set the association of the wepay checkout record to my cart - then, on to order.
|
85
97
|
cart = current_account.cart
|
86
98
|
cart.wepay_checkout_record = wcr
|
87
99
|
cart.save!
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.1.0
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'digest/sha2'
|
2
1
|
class Wepay::AuthorizeController < Wepay::ApplicationController
|
3
2
|
|
4
3
|
def index
|
@@ -8,7 +7,12 @@ class Wepay::AuthorizeController < Wepay::ApplicationController
|
|
8
7
|
access_token = wepay_gateway.get_access_token(params[:code], redirect_uri)
|
9
8
|
render :text => "Copy this access token, #{access_token} to the access_token directive in your wepay.yml"
|
10
9
|
else
|
11
|
-
|
10
|
+
# For security purposes, stop people from hitting this page and resetting the access_token.
|
11
|
+
if wepay_gateway.configuration[:access_token].present?
|
12
|
+
render :text => "You have already specified an access token in wepay.yml. If you wish to change it, please delete the current one and try again."
|
13
|
+
else
|
14
|
+
redirect_to wepay_gateway.auth_code_url redirect_uri
|
15
|
+
end
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
@@ -16,4 +20,4 @@ class Wepay::AuthorizeController < Wepay::ApplicationController
|
|
16
20
|
def redirect_uri
|
17
21
|
"#{WepayRails::Configuration.settings[:root_callback_uri]}/wepay/authorize"
|
18
22
|
end
|
19
|
-
end
|
23
|
+
end
|
@@ -4,9 +4,7 @@ production:
|
|
4
4
|
account_id: <your account id from wepay>
|
5
5
|
access_token: <your access token that you recieved when you went to http://your.domain.com/wepay/authorize>
|
6
6
|
root_callback_uri: "http://www.example.com"
|
7
|
-
after_authorize_redirect_uri: "http://www.example.com/purchase/checkout"
|
8
7
|
after_checkout_redirect_uri: "http://www.example.com/purchase/finalize"
|
9
|
-
registration_confirmation_uri: "http://www.example.com/purchase/cart?msg=Please confirm your wepay account."
|
10
8
|
scope: [refund_payments,collect_payments,view_balance,view_user]
|
11
9
|
wepay_api_uri: "https://api.wepay.com/v2"
|
12
10
|
fee_payer: Payee
|
@@ -40,6 +40,11 @@ module WepayRails
|
|
40
40
|
def init_checkout_and_send_user_to_wepay(params, access_token=nil)
|
41
41
|
wepay_gateway = WepayRails::Payments::Gateway.new(access_token)
|
42
42
|
response = wepay_gateway.perform_checkout(params)
|
43
|
+
|
44
|
+
if response['checkout_uri'].blank?
|
45
|
+
raise WepayRails::Exceptions::WepayCheckoutError.new("An error occurred: #{response.inspect}")
|
46
|
+
end
|
47
|
+
|
43
48
|
params.merge!({
|
44
49
|
:access_token => wepay_gateway.access_token,
|
45
50
|
:checkout_id => response['checkout_id']
|
data/lib/wepay-rails.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
require 'helpers/controller_helpers'
|
3
|
-
require 'api/account_methods'
|
4
3
|
require 'api/checkout_methods'
|
5
4
|
module WepayRails
|
6
5
|
class Configuration
|
@@ -29,6 +28,7 @@ module WepayRails
|
|
29
28
|
class ExpiredTokenError < StandardError; end
|
30
29
|
class InitializeCheckoutError < StandardError; end
|
31
30
|
class AuthorizationError < StandardError; end
|
31
|
+
class WepayCheckoutError < StandardError; end
|
32
32
|
end
|
33
33
|
|
34
34
|
module Payments
|
@@ -98,13 +98,16 @@ module WepayRails
|
|
98
98
|
{'Authorization' => "Bearer: #{@access_token}"}
|
99
99
|
end
|
100
100
|
|
101
|
+
def configuration
|
102
|
+
@wepay_config
|
103
|
+
end
|
104
|
+
|
101
105
|
def call_api(api_path, params={})
|
102
106
|
response = self.class.post("#{@base_uri}#{api_path}", {:headers => wepay_auth_header}.merge!({:body => params}))
|
103
107
|
JSON.parse(response.body)
|
104
108
|
end
|
105
109
|
|
106
110
|
include WepayRails::Api::CheckoutMethods
|
107
|
-
include WepayRails::Api::AccountMethods
|
108
111
|
end
|
109
112
|
|
110
113
|
include WepayRails::Exceptions
|
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.
|
8
|
+
s.version = "2.1.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-
|
12
|
+
s.date = "2011-11-28"
|
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 = [
|
@@ -37,7 +37,6 @@ Gem::Specification.new do |s|
|
|
37
37
|
"lib/generators/wepay_rails/install/templates/wepay.yml",
|
38
38
|
"lib/generators/wepay_rails/install/templates/wepay_checkout_record.rb",
|
39
39
|
"lib/helpers/controller_helpers.rb",
|
40
|
-
"lib/helpers/model_helpers.rb",
|
41
40
|
"lib/wepay-rails.rb",
|
42
41
|
"test/helper.rb",
|
43
42
|
"test/test_wepay-rails.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.
|
4
|
+
version: 2.1.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-
|
12
|
+
date: 2011-11-28 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
16
|
-
requirement: &
|
16
|
+
requirement: &24514020 !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: *24514020
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: shoulda
|
27
|
-
requirement: &
|
27
|
+
requirement: &24512520 !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: *24512520
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &24510740 !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: *24510740
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &24486880 !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: *24486880
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rcov
|
60
|
-
requirement: &
|
60
|
+
requirement: &24484080 !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: *24484080
|
69
69
|
description: Rails gem that interfaces with the WePay API
|
70
70
|
email: adammede@gmail.com
|
71
71
|
executables: []
|
@@ -94,7 +94,6 @@ files:
|
|
94
94
|
- lib/generators/wepay_rails/install/templates/wepay.yml
|
95
95
|
- lib/generators/wepay_rails/install/templates/wepay_checkout_record.rb
|
96
96
|
- lib/helpers/controller_helpers.rb
|
97
|
-
- lib/helpers/model_helpers.rb
|
98
97
|
- lib/wepay-rails.rb
|
99
98
|
- test/helper.rb
|
100
99
|
- test/test_wepay-rails.rb
|
@@ -114,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
113
|
version: '0'
|
115
114
|
segments:
|
116
115
|
- 0
|
117
|
-
hash:
|
116
|
+
hash: 2056025376124091245
|
118
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
118
|
none: false
|
120
119
|
requirements:
|