wepay-rails 1.0.0 → 1.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 +9 -26
- data/VERSION +1 -1
- data/app/controllers/wepay/authorize_controller.rb +3 -1
- data/config/routes.rb +1 -0
- data/lib/api/checkout_methods.rb +2 -2
- data/lib/generators/wepay_rails/install/install_generator.rb +24 -24
- data/lib/generators/wepay_rails/install/templates/wepay.yml +21 -22
- data/lib/generators/wepay_rails/install/templates/wepay_checkout_record.rb +1 -1
- data/lib/helpers/controller_helpers.rb +6 -3
- data/lib/wepay-rails.rb +2 -2
- data/wepay-rails.gemspec +2 -2
- metadata +13 -13
data/README.rdoc
CHANGED
@@ -11,7 +11,7 @@ add a column to one of your models to hold the authentication token. For example
|
|
11
11
|
|
12
12
|
Your migration:
|
13
13
|
|
14
|
-
add_column :
|
14
|
+
add_column :users, :wepay_auth_code, :string
|
15
15
|
|
16
16
|
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.
|
17
17
|
Wepay-rails handles those IPN notifications for you. You can write observers watching the WepayCheckoutRecord model if you need to have
|
@@ -30,7 +30,7 @@ Modify config/wepay.yml.example to your needs. You will need to set the model an
|
|
30
30
|
Snippet of wepay.yml showing the auth_code_location directive:
|
31
31
|
|
32
32
|
production:
|
33
|
-
auth_code_location:
|
33
|
+
auth_code_location: User.wepay_auth_code
|
34
34
|
|
35
35
|
You will have to set up a few new controllers in your rails app to handle callbacks and redirects from wepay.
|
36
36
|
I created one called finalize_controller and I use it for a landing page when the customer is finished paying
|
@@ -44,20 +44,10 @@ For now, here's what I am doing in my rails app to handle it...
|
|
44
44
|
|_ checkout_controller.rb
|
45
45
|
|_ finalize_controller.rb
|
46
46
|
|
47
|
-
The wepay-rails gem comes with an IpnController already built in for
|
48
|
-
handling requests from wepay about a specific checkout. If you wish to override it,
|
49
|
-
you can create an IpnController in your rails app.
|
50
|
-
|
51
|
-
class IpnController < Wepay::ApplicationController
|
52
|
-
def index
|
53
|
-
#Do something with the instant payment notifications back from Wepay
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
47
|
Finally, your checkout controller (or some controller that will interact with the Wepay API):
|
58
48
|
|
59
49
|
class Purchase::CheckoutController < Purchase::PurchaseController
|
60
|
-
before_filter :
|
50
|
+
before_filter :authenticate_user! # I am using devise - this line depends on your authentication scheme
|
61
51
|
|
62
52
|
# PLEASE READ
|
63
53
|
# I am saving the wepay_auth_code in my Profile model. Somewhere in my rails app, I have a method called
|
@@ -70,18 +60,17 @@ Finally, your checkout controller (or some controller that will interact with th
|
|
70
60
|
|
71
61
|
def index
|
72
62
|
|
73
|
-
cart =
|
63
|
+
cart = current_user.cart # EXAMPLE - get my shopping cart
|
74
64
|
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
|
75
65
|
|
76
66
|
checkout_params = {
|
77
67
|
:amount => cart.grand_total,
|
78
68
|
:short_description => cart.short_description,
|
79
69
|
:long_description => cart.long_description,
|
80
|
-
:redirect_uri => purchase_finalize_index_url(:txID => tx_id) # Wepay redirects the user back to this url after purchase
|
81
70
|
}
|
82
71
|
|
83
72
|
# Finally, send the user off to wepay so you can get paid! - CASH MONEY
|
84
|
-
init_checkout_and_send_user_to_wepay(checkout_params,
|
73
|
+
init_checkout_and_send_user_to_wepay(checkout_params, current_user)
|
85
74
|
end
|
86
75
|
end
|
87
76
|
|
@@ -90,11 +79,12 @@ wepay to checkout.
|
|
90
79
|
|
91
80
|
class Purchase::FinalizeController < Wepay::ApplicationController
|
92
81
|
def index
|
93
|
-
cart = Cart.find_by_transaction_id(params[:txID])
|
94
82
|
wcr = WepayCheckoutRecord.find_by_checkout_id(params[:checkout_id])
|
95
83
|
|
96
|
-
checkout
|
97
|
-
|
84
|
+
# Set the association of the wepay checkout record to my cart - then, on to order.
|
85
|
+
cart = current_account.cart
|
86
|
+
cart.wepay_checkout_record = wcr
|
87
|
+
cart.save!
|
98
88
|
|
99
89
|
# Convert cart to an order?? Move to observer of WepayCheckoutRecord??
|
100
90
|
cart.convert_cart_to_order if wcr.state == 'authorized'
|
@@ -103,13 +93,6 @@ wepay to checkout.
|
|
103
93
|
end
|
104
94
|
end
|
105
95
|
|
106
|
-
Example Routes for these:
|
107
|
-
namespace :purchase do
|
108
|
-
resource :cart, :has_many => :purchase_items
|
109
|
-
resources :checkout, :only => [:index]
|
110
|
-
resources :finalize, :only => [:index]
|
111
|
-
end
|
112
|
-
|
113
96
|
|
114
97
|
== Special Thanks to additional contributers of Wepay-Rails
|
115
98
|
* lucisferre (Chris Nicola) https://github.com/lucisferre
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
@@ -1,13 +1,15 @@
|
|
1
1
|
class Wepay::AuthorizeController < Wepay::ApplicationController
|
2
2
|
def index
|
3
3
|
ref_id = session[unique_wepay_auth_token_key]
|
4
|
+
|
4
5
|
if WepayRails::Configuration.settings[:orm] == 'mongoid'
|
5
6
|
wepayable = wepayable_class.where(wepayable_column => ref_id)[0]
|
6
7
|
else
|
7
8
|
wepayable = wepayable_class.all(:conditions => ["#{wepayable_column} = ?", ref_id])[0]
|
8
9
|
end
|
10
|
+
|
9
11
|
wepayable.update_attribute(wepayable_column.to_sym, params[:code])
|
10
|
-
redirect_to session[:after_authorize_redirect_uri] if session[:after_authorize_redirect_uri]
|
12
|
+
redirect_to session[:after_authorize_redirect_uri] and return if session[:after_authorize_redirect_uri]
|
11
13
|
redirect_to WepayRails::Configuration.settings[:after_authorize_redirect_uri]
|
12
14
|
rescue => e
|
13
15
|
raise AuthorizationError.new("WepayRails was unable to find the record to save the auth code to. : #{e.message}") unless wepayable.present?
|
data/config/routes.rb
CHANGED
data/lib/api/checkout_methods.rb
CHANGED
@@ -38,8 +38,8 @@ module WepayRails
|
|
38
38
|
# :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
39
|
def perform_checkout(parms)
|
40
40
|
defaults = {
|
41
|
-
:callback_uri => @wepay_config[:ipn_callback_uri],
|
42
|
-
:redirect_uri => @wepay_config[:checkout_redirect_uri],
|
41
|
+
:callback_uri => (@wepay_config[:ipn_callback_uri].present? ? @wepay_config[:ipn_callback_uri] : "#{@wepay_config[:root_callback_uri]}/wepay/ipn"),
|
42
|
+
:redirect_uri => (@wepay_config[:checkout_redirect_uri].present? ? @wepay_config[:checkout_redirect_uri] : "#{@wepay_config[:root_callback_uri]}/wepay/checkout"),
|
43
43
|
:fee_payer => @wepay_config[:fee_payer],
|
44
44
|
:type => @wepay_config[:checkout_type],
|
45
45
|
:charge_tax => @wepay_config[:charge_tax] ? 1 : 0,
|
@@ -1,25 +1,25 @@
|
|
1
|
-
require 'rails/generators/migration'
|
2
|
-
|
3
|
-
module WepayRails
|
4
|
-
module Generators
|
5
|
-
class InstallGenerator < ::Rails::Generators::Base
|
6
|
-
include Rails::Generators::Migration
|
7
|
-
source_root File.expand_path('../templates', __FILE__)
|
8
|
-
desc "add a migration for the Wepay Rails - WepayCheckoutRecord Model - Used to capture your transactions from Wepay"
|
9
|
-
def self.next_migration_number(path)
|
10
|
-
unless @prev_migration_nr
|
11
|
-
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
12
|
-
else
|
13
|
-
@prev_migration_nr += 1
|
14
|
-
end
|
15
|
-
@prev_migration_nr.to_s
|
16
|
-
end
|
17
|
-
|
18
|
-
def copy_migrations
|
19
|
-
migration_template "create_wepay_checkout_records.rb", "db/migrate/create_wepay_checkout_records.rb"
|
20
|
-
copy_file "wepay_checkout_record.rb", "lib/models/wepay_checkout_record.rb"
|
21
|
-
copy_file "wepay.yml", "config/wepay.yml.example"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
module WepayRails
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
desc "add a migration for the Wepay Rails - WepayCheckoutRecord Model - Used to capture your transactions from Wepay"
|
9
|
+
def self.next_migration_number(path)
|
10
|
+
unless @prev_migration_nr
|
11
|
+
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
12
|
+
else
|
13
|
+
@prev_migration_nr += 1
|
14
|
+
end
|
15
|
+
@prev_migration_nr.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
def copy_migrations
|
19
|
+
migration_template "create_wepay_checkout_records.rb", "db/migrate/create_wepay_checkout_records.rb"
|
20
|
+
copy_file "wepay_checkout_record.rb", "lib/models/wepay_checkout_record.rb"
|
21
|
+
copy_file "wepay.yml", "config/wepay.yml.example"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
25
|
end
|
@@ -1,23 +1,22 @@
|
|
1
|
-
production:
|
2
|
-
client_id: <your client id from wepay>
|
3
|
-
client_secret: <your client secret from wepay>
|
4
|
-
account_id: <your account id from wepay>
|
5
|
-
auth_code_location: MyModel.wepay_auth_code #model and column where you store the auth code for each of your customers eg. Profile.wepay_auth_code
|
6
|
-
|
7
|
-
after_authorize_redirect_uri: "http://www.example.com/purchase/checkout"
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
fee_payer: Payee
|
13
|
-
checkout_type: GOODS
|
14
|
-
charge_tax: false
|
15
|
-
app_fee: 0
|
16
|
-
auto_capture: true
|
17
|
-
require_shipping: false
|
18
|
-
shipping_fee: 0
|
19
|
-
charge_tax: false
|
20
|
-
|
21
|
-
|
22
|
-
|
1
|
+
production:
|
2
|
+
client_id: <your client id from wepay>
|
3
|
+
client_secret: <your client secret from wepay>
|
4
|
+
account_id: <your account id from wepay>
|
5
|
+
auth_code_location: MyModel.wepay_auth_code #model and column where you store the auth code for each of your customers eg. Profile.wepay_auth_code
|
6
|
+
root_callback_uri: "http://www.example.com"
|
7
|
+
after_authorize_redirect_uri: "http://www.example.com/purchase/checkout"
|
8
|
+
after_checkout_redirect_uri: "http://www.example.com/purchase/finalize"
|
9
|
+
scope: [refund_payments,collect_payments,view_balance,view_user]
|
10
|
+
wepay_api_uri: "https://api.wepay.com"
|
11
|
+
wepay_api_version: "v2"
|
12
|
+
fee_payer: Payee
|
13
|
+
checkout_type: GOODS
|
14
|
+
charge_tax: false
|
15
|
+
app_fee: 0
|
16
|
+
auto_capture: true
|
17
|
+
require_shipping: false
|
18
|
+
shipping_fee: 0
|
19
|
+
charge_tax: false
|
20
|
+
development:
|
21
|
+
|
23
22
|
test:
|
@@ -1,2 +1,2 @@
|
|
1
|
-
class WepayCheckoutRecord < ActiveRecord::Base
|
1
|
+
class WepayCheckoutRecord < ActiveRecord::Base
|
2
2
|
end
|
@@ -108,8 +108,8 @@ module WepayRails
|
|
108
108
|
# :require_shipping No A boolean value (0 or 1). If set to 1 then the payer will be asked to enter a shipping address when they pay. After payment you can retrieve this shipping address by calling /checkout
|
109
109
|
# :shipping_fee No The amount that you want to charge for shipping.
|
110
110
|
# :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.
|
111
|
-
def init_checkout_and_send_user_to_wepay(params, wepayable_object
|
112
|
-
initialize_wepay_access_token(wepayable_object)
|
111
|
+
def init_checkout_and_send_user_to_wepay(params, wepayable_object)
|
112
|
+
initialize_wepay_access_token(wepayable_object)
|
113
113
|
response = wepay_gateway.perform_checkout(params)
|
114
114
|
|
115
115
|
unless response && response.has_key?('checkout_uri')
|
@@ -118,8 +118,11 @@ module WepayRails
|
|
118
118
|
Params were: #{params}, Token was: #{wepay_access_token}")
|
119
119
|
end
|
120
120
|
|
121
|
+
wepayable_column = WepayRails::Configuration.wepayable_column
|
122
|
+
raise unless wepayable_object.send(wepayable_column.to_sym).present?
|
123
|
+
|
121
124
|
wcr_params = {
|
122
|
-
:auth_code =>
|
125
|
+
:auth_code => wepayable_object.send(wepayable_column),
|
123
126
|
:access_token => wepay_access_token,
|
124
127
|
:checkout_id => response['checkout_id']
|
125
128
|
}
|
data/lib/wepay-rails.rb
CHANGED
@@ -87,7 +87,7 @@ module WepayRails
|
|
87
87
|
params = {
|
88
88
|
:client_id => @wepay_config[:client_id],
|
89
89
|
:client_secret => @wepay_config[:client_secret],
|
90
|
-
:redirect_uri => @wepay_config[:redirect_uri],
|
90
|
+
:redirect_uri => (@wepay_config[:redirect_uri].present? ? @wepay_config[:redirect_uri] : "#{@wepay_config[:root_callback_uri]}/wepay/authorize"),
|
91
91
|
:code => auth_code
|
92
92
|
}
|
93
93
|
|
@@ -113,7 +113,7 @@ module WepayRails
|
|
113
113
|
# ex. ['manage_accounts','collect_payments','view_balance','view_user']
|
114
114
|
def auth_code_url(params = {})
|
115
115
|
params[:client_id] ||= @wepay_config[:client_id]
|
116
|
-
params[:redirect_uri] ||= @wepay_config[:redirect_uri]
|
116
|
+
params[:redirect_uri] ||= (@wepay_config[:redirect_uri].present? ? @wepay_config[:redirect_uri] : "#{@wepay_config[:root_callback_uri]}/wepay/authorize")
|
117
117
|
params[:scope] ||= WepayRails::Configuration.settings[:scope].join(',')
|
118
118
|
|
119
119
|
query = params.map do |k, v|
|
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 = "1.
|
8
|
+
s.version = "1.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-26"
|
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 = [
|
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: 1.
|
4
|
+
version: 1.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-26 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
16
|
-
requirement: &
|
16
|
+
requirement: &10731560 !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: *10731560
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: shoulda
|
27
|
-
requirement: &
|
27
|
+
requirement: &10729980 !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: *10729980
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &10728420 !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: *10728420
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &10726600 !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: *10726600
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rcov
|
60
|
-
requirement: &
|
60
|
+
requirement: &10704300 !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: *10704300
|
69
69
|
description: Rails gem that interfaces with the WePay API
|
70
70
|
email: adammede@gmail.com
|
71
71
|
executables: []
|
@@ -114,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
segments:
|
116
116
|
- 0
|
117
|
-
hash:
|
117
|
+
hash: 1601135752143681885
|
118
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
119
|
none: false
|
120
120
|
requirements:
|