wepay-rails 2.2.9 → 2.5.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/.travis.yml +4 -0
- data/Gemfile +17 -14
- data/Gemfile.lock +116 -24
- data/README.rdoc +4 -2
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/app/controllers/wepay/checkout_controller.rb +5 -1
- data/app/controllers/wepay/ipn_controller.rb +4 -0
- data/build +1 -0
- data/lib/api/account_methods.rb +4 -4
- data/lib/api/checkout_methods.rb +98 -88
- data/lib/generators/wepay_rails/install/install_generator.rb +4 -0
- data/lib/generators/wepay_rails/install/templates/wepay.yml +10 -8
- data/lib/helpers/controller_helpers.rb +2 -0
- data/lib/wepay-rails.rb +158 -124
- data/test/helper.rb +102 -18
- data/test/test_wepay_rails_account_methods.rb +105 -0
- data/test/test_wepay_rails_authorize.rb +31 -0
- data/test/test_wepay_rails_checkout_methods.rb +33 -0
- data/test/test_wepay_rails_initialize.rb +39 -0
- data/wepay-rails.gemspec +29 -16
- metadata +96 -21
- data/config/routes.rb +0 -7
- data/test/test_wepay-rails.rb +0 -7
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -1,14 +1,17 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
5
|
-
gem 'httparty'
|
6
|
-
|
7
|
-
# Add dependencies to develop your gem here.
|
8
|
-
# Include everything needed to run rake, tests, features, etc.
|
9
|
-
group :development do
|
10
|
-
gem "
|
11
|
-
gem
|
12
|
-
gem
|
13
|
-
gem "
|
14
|
-
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem 'httparty'
|
6
|
+
|
7
|
+
# Add dependencies to develop your gem here.
|
8
|
+
# Include everything needed to run rake, tests, features, etc.
|
9
|
+
group :development do
|
10
|
+
gem "rails", "3.1.0"
|
11
|
+
gem 'turn', '0.8.2', :require => false
|
12
|
+
gem 'thor'
|
13
|
+
gem "bundler"
|
14
|
+
gem "jeweler", "~> 1.6.4"
|
15
|
+
gem "rcov", ">= 0"
|
16
|
+
gem "webmock"
|
17
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,24 +1,116 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actionmailer (3.1.0)
|
5
|
+
actionpack (= 3.1.0)
|
6
|
+
mail (~> 2.3.0)
|
7
|
+
actionpack (3.1.0)
|
8
|
+
activemodel (= 3.1.0)
|
9
|
+
activesupport (= 3.1.0)
|
10
|
+
builder (~> 3.0.0)
|
11
|
+
erubis (~> 2.7.0)
|
12
|
+
i18n (~> 0.6)
|
13
|
+
rack (~> 1.3.2)
|
14
|
+
rack-cache (~> 1.0.3)
|
15
|
+
rack-mount (~> 0.8.2)
|
16
|
+
rack-test (~> 0.6.1)
|
17
|
+
sprockets (~> 2.0.0)
|
18
|
+
activemodel (3.1.0)
|
19
|
+
activesupport (= 3.1.0)
|
20
|
+
bcrypt-ruby (~> 3.0.0)
|
21
|
+
builder (~> 3.0.0)
|
22
|
+
i18n (~> 0.6)
|
23
|
+
activerecord (3.1.0)
|
24
|
+
activemodel (= 3.1.0)
|
25
|
+
activesupport (= 3.1.0)
|
26
|
+
arel (~> 2.2.1)
|
27
|
+
tzinfo (~> 0.3.29)
|
28
|
+
activeresource (3.1.0)
|
29
|
+
activemodel (= 3.1.0)
|
30
|
+
activesupport (= 3.1.0)
|
31
|
+
activesupport (3.1.0)
|
32
|
+
multi_json (~> 1.0)
|
33
|
+
addressable (2.3.2)
|
34
|
+
ansi (1.4.2)
|
35
|
+
arel (2.2.3)
|
36
|
+
bcrypt-ruby (3.0.1)
|
37
|
+
bcrypt-ruby (3.0.1-x86-mingw32)
|
38
|
+
builder (3.0.0)
|
39
|
+
crack (0.3.1)
|
40
|
+
erubis (2.7.0)
|
41
|
+
git (1.2.5)
|
42
|
+
hike (1.2.1)
|
43
|
+
httparty (0.9.0)
|
44
|
+
multi_json (~> 1.0)
|
45
|
+
multi_xml
|
46
|
+
i18n (0.6.0)
|
47
|
+
jeweler (1.6.4)
|
48
|
+
bundler (~> 1.0)
|
49
|
+
git (>= 1.2.5)
|
50
|
+
rake
|
51
|
+
json (1.7.3)
|
52
|
+
mail (2.3.3)
|
53
|
+
i18n (>= 0.4.0)
|
54
|
+
mime-types (~> 1.16)
|
55
|
+
treetop (~> 1.4.8)
|
56
|
+
mime-types (1.18)
|
57
|
+
multi_json (1.3.5)
|
58
|
+
multi_xml (0.5.1)
|
59
|
+
polyglot (0.3.3)
|
60
|
+
rack (1.3.6)
|
61
|
+
rack-cache (1.0.3)
|
62
|
+
rack (>= 0.4)
|
63
|
+
rack-mount (0.8.3)
|
64
|
+
rack (>= 1.0.0)
|
65
|
+
rack-ssl (1.3.2)
|
66
|
+
rack
|
67
|
+
rack-test (0.6.1)
|
68
|
+
rack (>= 1.0)
|
69
|
+
rails (3.1.0)
|
70
|
+
actionmailer (= 3.1.0)
|
71
|
+
actionpack (= 3.1.0)
|
72
|
+
activerecord (= 3.1.0)
|
73
|
+
activeresource (= 3.1.0)
|
74
|
+
activesupport (= 3.1.0)
|
75
|
+
bundler (~> 1.0)
|
76
|
+
railties (= 3.1.0)
|
77
|
+
railties (3.1.0)
|
78
|
+
actionpack (= 3.1.0)
|
79
|
+
activesupport (= 3.1.0)
|
80
|
+
rack-ssl (~> 1.3.2)
|
81
|
+
rake (>= 0.8.7)
|
82
|
+
rdoc (~> 3.4)
|
83
|
+
thor (~> 0.14.6)
|
84
|
+
rake (0.9.2)
|
85
|
+
rcov (0.9.9)
|
86
|
+
rdoc (3.12)
|
87
|
+
json (~> 1.4)
|
88
|
+
sprockets (2.0.4)
|
89
|
+
hike (~> 1.2)
|
90
|
+
rack (~> 1.0)
|
91
|
+
tilt (~> 1.1, != 1.3.0)
|
92
|
+
thor (0.14.6)
|
93
|
+
tilt (1.3.3)
|
94
|
+
treetop (1.4.10)
|
95
|
+
polyglot
|
96
|
+
polyglot (>= 0.3.1)
|
97
|
+
turn (0.8.2)
|
98
|
+
ansi (>= 1.2.2)
|
99
|
+
tzinfo (0.3.33)
|
100
|
+
webmock (1.8.9)
|
101
|
+
addressable (>= 2.2.7)
|
102
|
+
crack (>= 0.1.7)
|
103
|
+
|
104
|
+
PLATFORMS
|
105
|
+
ruby
|
106
|
+
x86-mingw32
|
107
|
+
|
108
|
+
DEPENDENCIES
|
109
|
+
bundler
|
110
|
+
httparty
|
111
|
+
jeweler (~> 1.6.4)
|
112
|
+
rails (= 3.1.0)
|
113
|
+
rcov
|
114
|
+
thor
|
115
|
+
turn (= 0.8.2)
|
116
|
+
webmock
|
data/README.rdoc
CHANGED
@@ -2,14 +2,16 @@
|
|
2
2
|
|
3
3
|
Wepay-Rails allows your rails app to accept payments with Wepay (http://www.wepay.com).
|
4
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
|
+
|
5
7
|
= Features
|
6
8
|
|
7
9
|
* Built in IPN that listens to push notifications from wepay and updates saved checkout records for you
|
8
10
|
* Allows you to fetch your access token easily through a web interface
|
9
11
|
* 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
|
12
|
+
* 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)
|
11
13
|
* Saves the current state of every checkout
|
12
|
-
* Authorize many users to accept payments dynamically (see Wiki)
|
14
|
+
* Authorize many users to accept payments dynamically (see Wiki https://github.com/adamthedeveloper/wepay-rails/wiki/Authorize-Many-Users-Dynamically)
|
13
15
|
* Configurable
|
14
16
|
|
15
17
|
= Installation
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.0
|
@@ -3,8 +3,12 @@ class Wepay::CheckoutController < Wepay::ApplicationController
|
|
3
3
|
record = WepayCheckoutRecord.find_by_checkout_id_and_security_token(params[:checkout_id],params[:security_token])
|
4
4
|
|
5
5
|
if record.present?
|
6
|
-
wepay_gateway = WepayRails::Payments::Gateway.new
|
6
|
+
wepay_gateway = WepayRails::Payments::Gateway.new( record.access_token )
|
7
7
|
checkout = wepay_gateway.lookup_checkout(record.checkout_id)
|
8
|
+
|
9
|
+
# remove unnecessary attributes
|
10
|
+
checkout.delete_if {|k,v| !record.attributes.include? k.to_s}
|
11
|
+
|
8
12
|
record.update_attributes(checkout)
|
9
13
|
redirect_to "#{wepay_gateway.configuration[:after_checkout_redirect_uri]}?checkout_id=#{params[:checkout_id]}"
|
10
14
|
else
|
@@ -6,6 +6,10 @@ class Wepay::IpnController < Wepay::ApplicationController
|
|
6
6
|
if record.present?
|
7
7
|
wepay_gateway = WepayRails::Payments::Gateway.new
|
8
8
|
checkout = wepay_gateway.lookup_checkout(record.checkout_id)
|
9
|
+
|
10
|
+
# remove unnecessary attributes
|
11
|
+
checkout.delete_if {|k,v| !record.attributes.include? k.to_s}
|
12
|
+
|
9
13
|
record.update_attributes(checkout)
|
10
14
|
render :text => "ok"
|
11
15
|
else
|
data/build
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Thu Jun 7 08:31:25 PDT 2012
|
data/lib/api/account_methods.rb
CHANGED
@@ -9,12 +9,12 @@ module WepayRails
|
|
9
9
|
self.call_api("/account", {:account_id => account_id})
|
10
10
|
end
|
11
11
|
|
12
|
-
def find_account(
|
13
|
-
self.call_api("/account/find",
|
12
|
+
def find_account(params={})
|
13
|
+
self.call_api("/account/find", params)
|
14
14
|
end
|
15
15
|
|
16
|
-
def modify_account(
|
17
|
-
self.call_api("/account/modify",
|
16
|
+
def modify_account(account_id, params={})
|
17
|
+
self.call_api("/account/modify", params.merge({:account_id => account_id}))
|
18
18
|
end
|
19
19
|
|
20
20
|
def delete_account(account_id)
|
data/lib/api/checkout_methods.rb
CHANGED
@@ -1,88 +1,98 @@
|
|
1
|
-
require 'digest/sha2'
|
2
|
-
module WepayRails
|
3
|
-
module Api
|
4
|
-
module CheckoutMethods
|
5
|
-
# Many of the settings you pass in here are already factored in from
|
6
|
-
# the wepay.yml file and only need to be overridden if you insist on doing
|
7
|
-
# so when this method is called. The following list of key values are pulled
|
8
|
-
# in for you from your wepay.yml file:
|
9
|
-
#
|
10
|
-
# Note: @wepay_config is your wepay.yml as a Hash
|
11
|
-
# :callback_uri => @wepay_config[:ipn_callback_uri],
|
12
|
-
# :redirect_uri => @wepay_config[:checkout_redirect_uri],
|
13
|
-
# :fee_payer => @wepay_config[:fee_payer],
|
14
|
-
# :type => @wepay_config[:checkout_type],
|
15
|
-
# :charge_tax => @wepay_config[:charge_tax] ? 1 : 0,
|
16
|
-
# :app_fee => @wepay_config[:app_fee],
|
17
|
-
# :auto_capture => @wepay_config[:auto_capture] ? 1 : 0,
|
18
|
-
# :require_shipping => @wepay_config[:require_shipping] ? 1 : 0,
|
19
|
-
# :shipping_fee => @wepay_config[:shipping_fee],
|
20
|
-
# :charge_tax => @wepay_config[:charge_tax],
|
21
|
-
# :account_id => wepay_user['account_id'] # wepay-rails goes and gets this for you, but you can override it if you want to.
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# params hash key values possibilities are:
|
25
|
-
# Parameter: Required: Description:
|
26
|
-
# :account_id Yes The unique ID of the account you want to create a checkout for.
|
27
|
-
# :short_description Yes A short description of what is being paid for.
|
28
|
-
# :long_description No A long description of what is being paid for.
|
29
|
-
# :type Yes The the checkout type (one of the following: GOODS, SERVICE, DONATION, or PERSONAL)
|
30
|
-
# :reference_id No The unique reference id of the checkout (set by the application in /checkout/create
|
31
|
-
# :amount Yes The amount that the payer will pay.
|
32
|
-
# :app_fee No The amount that the application will receive in fees.
|
33
|
-
# :fee_payer No Who will pay the fees (WePay's fees and any app fees). Set to "Payer" to charge fees to the person paying (Payer will pay amount + fees, payee will receive amount). Set to "Payee" to charge fees to the person receiving money (Payer will pay amount, Payee will receive amount - fees). Defaults to "Payer".
|
34
|
-
# :redirect_uri No The uri the payer will be redirected to after paying.
|
35
|
-
# :callback_uri No The uri that will receive any Instant Payment Notifications sent. Needs to be a full uri (ex https://www.wepay.com )
|
36
|
-
# :auto_capture No A boolean value (0 or 1). Default is 1. If set to 0 then the payment will not automatically be released to the account and will be held by WePay in payment state 'reserved'. To release funds to the account you must call /checkout/capture
|
37
|
-
# :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
|
38
|
-
# :shipping_fee No The amount that you want to charge for shipping.
|
39
|
-
# :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.
|
40
|
-
def perform_checkout(
|
41
|
-
security_token = Digest::SHA2.hexdigest("#{rand(4)}#{Time.now.to_i}")
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
1
|
+
require 'digest/sha2'
|
2
|
+
module WepayRails
|
3
|
+
module Api
|
4
|
+
module CheckoutMethods
|
5
|
+
# Many of the settings you pass in here are already factored in from
|
6
|
+
# the wepay.yml file and only need to be overridden if you insist on doing
|
7
|
+
# so when this method is called. The following list of key values are pulled
|
8
|
+
# in for you from your wepay.yml file:
|
9
|
+
#
|
10
|
+
# Note: @wepay_config is your wepay.yml as a Hash
|
11
|
+
# :callback_uri => @wepay_config[:ipn_callback_uri],
|
12
|
+
# :redirect_uri => @wepay_config[:checkout_redirect_uri],
|
13
|
+
# :fee_payer => @wepay_config[:fee_payer],
|
14
|
+
# :type => @wepay_config[:checkout_type],
|
15
|
+
# :charge_tax => @wepay_config[:charge_tax] ? 1 : 0,
|
16
|
+
# :app_fee => @wepay_config[:app_fee],
|
17
|
+
# :auto_capture => @wepay_config[:auto_capture] ? 1 : 0,
|
18
|
+
# :require_shipping => @wepay_config[:require_shipping] ? 1 : 0,
|
19
|
+
# :shipping_fee => @wepay_config[:shipping_fee],
|
20
|
+
# :charge_tax => @wepay_config[:charge_tax],
|
21
|
+
# :account_id => wepay_user['account_id'] # wepay-rails goes and gets this for you, but you can override it if you want to.
|
22
|
+
#
|
23
|
+
#
|
24
|
+
# params hash key values possibilities are:
|
25
|
+
# Parameter: Required: Description:
|
26
|
+
# :account_id Yes The unique ID of the account you want to create a checkout for.
|
27
|
+
# :short_description Yes A short description of what is being paid for.
|
28
|
+
# :long_description No A long description of what is being paid for.
|
29
|
+
# :type Yes The the checkout type (one of the following: GOODS, SERVICE, DONATION, or PERSONAL)
|
30
|
+
# :reference_id No The unique reference id of the checkout (set by the application in /checkout/create
|
31
|
+
# :amount Yes The amount that the payer will pay.
|
32
|
+
# :app_fee No The amount that the application will receive in fees.
|
33
|
+
# :fee_payer No Who will pay the fees (WePay's fees and any app fees). Set to "Payer" to charge fees to the person paying (Payer will pay amount + fees, payee will receive amount). Set to "Payee" to charge fees to the person receiving money (Payer will pay amount, Payee will receive amount - fees). Defaults to "Payer".
|
34
|
+
# :redirect_uri No The uri the payer will be redirected to after paying.
|
35
|
+
# :callback_uri No The uri that will receive any Instant Payment Notifications sent. Needs to be a full uri (ex https://www.wepay.com )
|
36
|
+
# :auto_capture No A boolean value (0 or 1). Default is 1. If set to 0 then the payment will not automatically be released to the account and will be held by WePay in payment state 'reserved'. To release funds to the account you must call /checkout/capture
|
37
|
+
# :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
|
38
|
+
# :shipping_fee No The amount that you want to charge for shipping.
|
39
|
+
# :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.
|
40
|
+
def perform_checkout(params)
|
41
|
+
security_token = Digest::SHA2.hexdigest("#{Rails.env.production? ? rand(4) : 1}#{Time.now.to_i}") # Make less random during tests
|
42
|
+
|
43
|
+
# add the security token to any urls that were passed in from the app
|
44
|
+
if params[:callback_uri]
|
45
|
+
params[:callback_uri] = apply_security_token( params[:callback_uri], security_token )
|
46
|
+
end
|
47
|
+
|
48
|
+
if params[:redirect_uri]
|
49
|
+
params[:redirect_uri] = apply_security_token( params[:redirect_uri], security_token )
|
50
|
+
end
|
51
|
+
|
52
|
+
defaults = {
|
53
|
+
:callback_uri => ipn_callback_uri(security_token),
|
54
|
+
:redirect_uri => checkout_redirect_uri(security_token),
|
55
|
+
:fee_payer => @wepay_config[:fee_payer],
|
56
|
+
:type => @wepay_config[:checkout_type],
|
57
|
+
:charge_tax => @wepay_config[:charge_tax] ? 1 : 0,
|
58
|
+
:app_fee => @wepay_config[:app_fee],
|
59
|
+
:auto_capture => @wepay_config[:auto_capture] ? 1 : 0,
|
60
|
+
:require_shipping => @wepay_config[:require_shipping] ? 1 : 0,
|
61
|
+
:shipping_fee => @wepay_config[:shipping_fee],
|
62
|
+
:account_id => @wepay_config[:account_id]
|
63
|
+
}.merge(params)
|
64
|
+
|
65
|
+
resp = self.call_api("/checkout/create", defaults)
|
66
|
+
resp.merge({:security_token => security_token})
|
67
|
+
end
|
68
|
+
|
69
|
+
def lookup_checkout(checkout_id)
|
70
|
+
co = self.call_api("/checkout", {:checkout_id => checkout_id})
|
71
|
+
co.delete(:type)
|
72
|
+
co
|
73
|
+
end
|
74
|
+
|
75
|
+
def ipn_callback_uri(security_token)
|
76
|
+
uri = if @wepay_config[:ipn_callback_uri].present?
|
77
|
+
@wepay_config[:ipn_callback_uri]
|
78
|
+
else
|
79
|
+
"#{@wepay_config[:root_callback_uri]}/wepay/ipn"
|
80
|
+
end
|
81
|
+
apply_security_token(uri, security_token)
|
82
|
+
end
|
83
|
+
|
84
|
+
def checkout_redirect_uri(security_token)
|
85
|
+
uri = if @wepay_config[:ipn_callback_uri].present?
|
86
|
+
@wepay_config[:checkout_redirect_uri]
|
87
|
+
else
|
88
|
+
"#{@wepay_config[:root_callback_uri]}/wepay/checkout"
|
89
|
+
end
|
90
|
+
apply_security_token(uri, security_token)
|
91
|
+
end
|
92
|
+
|
93
|
+
def apply_security_token(uri, security_token)
|
94
|
+
uri += (uri =~ /\?/ ? '&' : '?') + "security_token=#{security_token}"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|