wepay-rails 0.1.43 → 0.1.44
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/lib/helpers/controller_helpers.rb +52 -4
- data/lib/wepay-rails.rb +64 -1
- data/wepay-rails.gemspec +6 -6
- metadata +14 -16
data/README.rdoc
CHANGED
@@ -45,7 +45,7 @@ Finally, your checkout controller (or some controller that will interact with th
|
|
45
45
|
if current_user.has_wepay_auth_code?
|
46
46
|
if wepay_access_token_exists?
|
47
47
|
# Send payment off to wepay or get the user or something else
|
48
|
-
render :json =>
|
48
|
+
render :json => wepay_gateway.wepay_user
|
49
49
|
return
|
50
50
|
else
|
51
51
|
initialize_wepay_access_token(current_user.wepay_auth_code)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.44
|
@@ -2,11 +2,17 @@ module WepayRails
|
|
2
2
|
module Helpers
|
3
3
|
module ControllerHelpers
|
4
4
|
|
5
|
-
def redirect_to_wepay_for_auth(scope=
|
6
|
-
redirect_to
|
5
|
+
def redirect_to_wepay_for_auth(scope=wepay_gateway.scope)
|
6
|
+
redirect_to wepay_gateway.auth_code_url(scope)
|
7
7
|
end
|
8
8
|
|
9
|
+
# @deprecated Use wepay_gateway instead of gateway
|
9
10
|
def gateway
|
11
|
+
warn "[DEPRECATION] Use wepay_gateway instead of gateway"
|
12
|
+
wepay_gateway
|
13
|
+
end
|
14
|
+
|
15
|
+
def wepay_gateway
|
10
16
|
@gateway ||= WepayRails::Payments::Gateway.new(wepay_access_token)
|
11
17
|
end
|
12
18
|
|
@@ -21,10 +27,10 @@ module WepayRails
|
|
21
27
|
# Response
|
22
28
|
# {"user_id":"123456","access_token":"1337h4x0rzabcd12345","token_type":"BEARER"} Example
|
23
29
|
def initialize_wepay_access_token(auth_code)
|
24
|
-
session[unique_wepay_access_token_key] =
|
30
|
+
session[unique_wepay_access_token_key] = wepay_gateway.access_token(auth_code)
|
25
31
|
return
|
26
32
|
rescue WepayRails::Exceptions::ExpiredTokenError => e
|
27
|
-
redirect_to_wepay_for_auth(
|
33
|
+
redirect_to_wepay_for_auth(wepay_gateway.scope) and return
|
28
34
|
end
|
29
35
|
|
30
36
|
# Since we are saving the access token in the session,
|
@@ -43,6 +49,48 @@ module WepayRails
|
|
43
49
|
def wepay_access_token_exists?
|
44
50
|
@access_token_exists ||= wepay_access_token.present?
|
45
51
|
end
|
52
|
+
|
53
|
+
# Many of the settings you pass in here are already factored in from
|
54
|
+
# the wepay.yml file and only need to be overridden if you insist on doing
|
55
|
+
# so when this method is called. The following list of key values are pulled
|
56
|
+
# in for you from your wepay.yml file:
|
57
|
+
#
|
58
|
+
# Note: @config is your wepay.yml as a Hash
|
59
|
+
# :callback_uri => @config[:ipn_callback_uri],
|
60
|
+
# :redirect_uri => @config[:checkout_redirect_uri],
|
61
|
+
# :fee_payer => @config[:fee_payer],
|
62
|
+
# :type => @config[:checkout_type],
|
63
|
+
# :charge_tax => @config[:charge_tax] ? 1 : 0,
|
64
|
+
# :app_fee => @config[:app_fee],
|
65
|
+
# :auto_capture => @config[:auto_capture] ? 1 : 0,
|
66
|
+
# :require_shipping => @config[:require_shipping] ? 1 : 0,
|
67
|
+
# :shipping_fee => @config[:shipping_fee],
|
68
|
+
# :charge_tax => @config[:charge_tax],
|
69
|
+
# :account_id => wepay_user['account_id'] # wepay-rails goes and gets this for you, but you can override it if you want to.
|
70
|
+
#
|
71
|
+
#
|
72
|
+
# params hash key values possibilities are:
|
73
|
+
# Parameter: Required: Description:
|
74
|
+
# :account_id Yes The unique ID of the account you want to create a checkout for.
|
75
|
+
# :short_description Yes A short description of what is being paid for.
|
76
|
+
# :long_description No A long description of what is being paid for.
|
77
|
+
# :type Yes The the checkout type (one of the following: GOODS, SERVICE, DONATION, or PERSONAL)
|
78
|
+
# :reference_id No The unique reference id of the checkout (set by the application in /checkout/create
|
79
|
+
# :amount Yes The amount that the payer will pay.
|
80
|
+
# :app_fee No The amount that the application will receive in fees.
|
81
|
+
# :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".
|
82
|
+
# :redirect_uri No The uri the payer will be redirected to after paying.
|
83
|
+
# :callback_uri No The uri that will receive any Instant Payment Notifications sent. Needs to be a full uri (ex https://www.wepay.com )
|
84
|
+
# :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
|
85
|
+
# :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
|
86
|
+
# :shipping_fee No The amount that you want to charge for shipping.
|
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
|
+
def init_checkout_and_send_user_to_wepay(params)
|
89
|
+
create_checkout = wepay_gateway.perform_checkout(params)
|
90
|
+
response = JSON.parse(create_checkout.body)
|
91
|
+
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
|
+
redirect_to response['checkout_uri'] and return
|
93
|
+
end
|
46
94
|
end
|
47
95
|
end
|
48
96
|
end
|
data/lib/wepay-rails.rb
CHANGED
@@ -6,6 +6,7 @@ module WepayRails
|
|
6
6
|
module Exceptions
|
7
7
|
class AccessTokenError < StandardError; end
|
8
8
|
class ExpiredTokenError < StandardError; end
|
9
|
+
class InitializeCheckoutError < StandardError; end
|
9
10
|
end
|
10
11
|
|
11
12
|
module Payments
|
@@ -80,10 +81,72 @@ module WepayRails
|
|
80
81
|
{'Authorization' => "Bearer: #{@wepay_access_token}"}
|
81
82
|
end
|
82
83
|
|
84
|
+
# Make a call to wepay to get the user info. This will only make one call
|
85
|
+
# per request. Any subsequent calls to wepay_user will return the data
|
86
|
+
# retrieved from the first call.
|
83
87
|
def wepay_user
|
84
|
-
|
88
|
+
user_api = lambda {
|
89
|
+
response = self.class.get("#{@base_uri}/v2/user", {:headers => wepay_auth_header})
|
90
|
+
JSON.parse(response.body)
|
91
|
+
}
|
92
|
+
|
93
|
+
@wepay_user ||= user_api.call
|
94
|
+
end
|
95
|
+
|
96
|
+
# Many of the settings you pass in here are already factored in from
|
97
|
+
# the wepay.yml file and only need to be overridden if you insist on doing
|
98
|
+
# so when this method is called. The following list of key values are pulled
|
99
|
+
# in for you from your wepay.yml file:
|
100
|
+
#
|
101
|
+
# Note: @config is your wepay.yml as a Hash
|
102
|
+
# :callback_uri => @config[:ipn_callback_uri],
|
103
|
+
# :redirect_uri => @config[:checkout_redirect_uri],
|
104
|
+
# :fee_payer => @config[:fee_payer],
|
105
|
+
# :type => @config[:checkout_type],
|
106
|
+
# :charge_tax => @config[:charge_tax] ? 1 : 0,
|
107
|
+
# :app_fee => @config[:app_fee],
|
108
|
+
# :auto_capture => @config[:auto_capture] ? 1 : 0,
|
109
|
+
# :require_shipping => @config[:require_shipping] ? 1 : 0,
|
110
|
+
# :shipping_fee => @config[:shipping_fee],
|
111
|
+
# :charge_tax => @config[:charge_tax],
|
112
|
+
# :account_id => wepay_user['account_id'] # wepay-rails goes and gets this for you, but you can override it if you want to.
|
113
|
+
#
|
114
|
+
#
|
115
|
+
# params hash key values possibilities are:
|
116
|
+
# Parameter: Required: Description:
|
117
|
+
# :account_id Yes The unique ID of the account you want to create a checkout for.
|
118
|
+
# :short_description Yes A short description of what is being paid for.
|
119
|
+
# :long_description No A long description of what is being paid for.
|
120
|
+
# :type Yes The the checkout type (one of the following: GOODS, SERVICE, DONATION, or PERSONAL)
|
121
|
+
# :reference_id No The unique reference id of the checkout (set by the application in /checkout/create
|
122
|
+
# :amount Yes The amount that the payer will pay.
|
123
|
+
# :app_fee No The amount that the application will receive in fees.
|
124
|
+
# :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".
|
125
|
+
# :redirect_uri No The uri the payer will be redirected to after paying.
|
126
|
+
# :callback_uri No The uri that will receive any Instant Payment Notifications sent. Needs to be a full uri (ex https://www.wepay.com )
|
127
|
+
# :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
|
128
|
+
# :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
|
129
|
+
# :shipping_fee No The amount that you want to charge for shipping.
|
130
|
+
# :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.
|
131
|
+
def perform_checkout(params)
|
132
|
+
defaults = {
|
133
|
+
:callback_uri => @config[:ipn_callback_uri],
|
134
|
+
:redirect_uri => @config[:checkout_redirect_uri],
|
135
|
+
:fee_payer => @config[:fee_payer],
|
136
|
+
:type => @config[:checkout_type],
|
137
|
+
:charge_tax => @config[:charge_tax] ? 1 : 0,
|
138
|
+
:app_fee => @config[:app_fee],
|
139
|
+
:auto_capture => @config[:auto_capture] ? 1 : 0,
|
140
|
+
:require_shipping => @config[:require_shipping] ? 1 : 0,
|
141
|
+
:shipping_fee => @config[:shipping_fee],
|
142
|
+
:charge_tax => @config[:charge_tax],
|
143
|
+
:account_id => wepay_user['account_id']
|
144
|
+
}.merge(params)
|
145
|
+
|
146
|
+
response = self.class.get("#{@base_uri}/v2/checkout/create", {:headers => wepay_auth_header}.merge!(defaults))
|
85
147
|
JSON.parse(response.body)
|
86
148
|
end
|
149
|
+
|
87
150
|
end
|
88
151
|
|
89
152
|
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 = %q{wepay-rails}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.44"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [
|
12
|
-
s.date = %q{2011-
|
11
|
+
s.authors = [%q{Adam Medeiros}]
|
12
|
+
s.date = %q{2011-08-14}
|
13
13
|
s.description = %q{Rails gem that interfaces with the WePay API}
|
14
14
|
s.email = %q{adammede@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -35,9 +35,9 @@ Gem::Specification.new do |s|
|
|
35
35
|
"wepay-rails.gemspec"
|
36
36
|
]
|
37
37
|
s.homepage = %q{http://github.com/adamthedeveloper/wepay-rails}
|
38
|
-
s.licenses = [
|
39
|
-
s.require_paths = [
|
40
|
-
s.rubygems_version = %q{1.6
|
38
|
+
s.licenses = [%q{MIT}]
|
39
|
+
s.require_paths = [%q{lib}]
|
40
|
+
s.rubygems_version = %q{1.8.6}
|
41
41
|
s.summary = %q{Rails gem that interfaces with the WePay API}
|
42
42
|
|
43
43
|
if s.respond_to? :specification_version then
|
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.44
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
13
|
-
default_executable:
|
12
|
+
date: 2011-08-14 00:00:00.000000000Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: httparty
|
17
|
-
requirement: &
|
16
|
+
requirement: &12465740 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
19
|
- - ! '>='
|
@@ -22,10 +21,10 @@ dependencies:
|
|
22
21
|
version: '0'
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
24
|
+
version_requirements: *12465740
|
26
25
|
- !ruby/object:Gem::Dependency
|
27
26
|
name: shoulda
|
28
|
-
requirement: &
|
27
|
+
requirement: &12464560 !ruby/object:Gem::Requirement
|
29
28
|
none: false
|
30
29
|
requirements:
|
31
30
|
- - ! '>='
|
@@ -33,10 +32,10 @@ dependencies:
|
|
33
32
|
version: '0'
|
34
33
|
type: :development
|
35
34
|
prerelease: false
|
36
|
-
version_requirements: *
|
35
|
+
version_requirements: *12464560
|
37
36
|
- !ruby/object:Gem::Dependency
|
38
37
|
name: bundler
|
39
|
-
requirement: &
|
38
|
+
requirement: &12463340 !ruby/object:Gem::Requirement
|
40
39
|
none: false
|
41
40
|
requirements:
|
42
41
|
- - ~>
|
@@ -44,10 +43,10 @@ dependencies:
|
|
44
43
|
version: 1.0.0
|
45
44
|
type: :development
|
46
45
|
prerelease: false
|
47
|
-
version_requirements: *
|
46
|
+
version_requirements: *12463340
|
48
47
|
- !ruby/object:Gem::Dependency
|
49
48
|
name: jeweler
|
50
|
-
requirement: &
|
49
|
+
requirement: &12462100 !ruby/object:Gem::Requirement
|
51
50
|
none: false
|
52
51
|
requirements:
|
53
52
|
- - ~>
|
@@ -55,10 +54,10 @@ dependencies:
|
|
55
54
|
version: 1.6.4
|
56
55
|
type: :development
|
57
56
|
prerelease: false
|
58
|
-
version_requirements: *
|
57
|
+
version_requirements: *12462100
|
59
58
|
- !ruby/object:Gem::Dependency
|
60
59
|
name: rcov
|
61
|
-
requirement: &
|
60
|
+
requirement: &12461120 !ruby/object:Gem::Requirement
|
62
61
|
none: false
|
63
62
|
requirements:
|
64
63
|
- - ! '>='
|
@@ -66,7 +65,7 @@ dependencies:
|
|
66
65
|
version: '0'
|
67
66
|
type: :development
|
68
67
|
prerelease: false
|
69
|
-
version_requirements: *
|
68
|
+
version_requirements: *12461120
|
70
69
|
description: Rails gem that interfaces with the WePay API
|
71
70
|
email: adammede@gmail.com
|
72
71
|
executables: []
|
@@ -91,7 +90,6 @@ files:
|
|
91
90
|
- test/helper.rb
|
92
91
|
- test/test_wepay-rails.rb
|
93
92
|
- wepay-rails.gemspec
|
94
|
-
has_rdoc: true
|
95
93
|
homepage: http://github.com/adamthedeveloper/wepay-rails
|
96
94
|
licenses:
|
97
95
|
- MIT
|
@@ -107,7 +105,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
105
|
version: '0'
|
108
106
|
segments:
|
109
107
|
- 0
|
110
|
-
hash: -
|
108
|
+
hash: -744223484762769908
|
111
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
110
|
none: false
|
113
111
|
requirements:
|
@@ -116,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
114
|
version: '0'
|
117
115
|
requirements: []
|
118
116
|
rubyforge_project:
|
119
|
-
rubygems_version: 1.6
|
117
|
+
rubygems_version: 1.8.6
|
120
118
|
signing_key:
|
121
119
|
specification_version: 3
|
122
120
|
summary: Rails gem that interfaces with the WePay API
|