wepay-rails 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +26 -26
- data/VERSION +1 -1
- data/app/controllers/wepay/application_controller.rb +0 -9
- data/app/controllers/wepay/authorize_controller.rb +11 -9
- data/app/controllers/wepay/ipn_controller.rb +2 -2
- data/lib/api/account_methods.rb +6 -6
- data/lib/api/checkout_methods.rb +21 -11
- data/lib/generators/wepay_rails/install/templates/create_wepay_checkout_records.rb +0 -2
- data/lib/generators/wepay_rails/install/templates/wepay.yml +3 -3
- data/lib/helpers/controller_helpers.rb +7 -90
- data/lib/wepay-rails.rb +26 -65
- data/wepay-rails.gemspec +2 -2
- metadata +13 -13
data/README.rdoc
CHANGED
@@ -6,13 +6,6 @@ To install it, add this to your Gemfile
|
|
6
6
|
|
7
7
|
gem 'wepay-rails'
|
8
8
|
|
9
|
-
Since Wepay uses Oauth2 to authenticate, wepay-rails has been built to handle this for you. You will need to
|
10
|
-
add a column to one of your models to hold the authentication token. For example, if you have a user model:
|
11
|
-
|
12
|
-
Your migration:
|
13
|
-
|
14
|
-
add_column :users, :wepay_auth_code, :string
|
15
|
-
|
16
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.
|
17
10
|
Wepay-rails handles those IPN notifications for you. You can write observers watching the WepayCheckoutRecord model if you need to have
|
18
11
|
something specific occur when the checkout changes.
|
@@ -25,12 +18,23 @@ This will create 3 files for you, a migration file for a table to hold the check
|
|
25
18
|
|
26
19
|
rake db:migrate
|
27
20
|
|
28
|
-
Modify config/wepay.yml.example to your needs
|
21
|
+
Modify config/wepay.yml.example to your needs and copy it to config/wepay.yml.
|
22
|
+
|
23
|
+
Assuming that you have:
|
24
|
+
|
25
|
+
1. created an account on wepay
|
26
|
+
2. created a user to accept the payments
|
27
|
+
3. created your application for your account
|
28
|
+
4. set your wepay.yml file with the info it needs to talk to the wepay api minus the access_token
|
29
|
+
|
30
|
+
You can now get your access token.
|
29
31
|
|
30
|
-
|
32
|
+
To fetch your access_token, open a browser and go to:
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
+
your.railsapp.com/wepay/authorize
|
35
|
+
|
36
|
+
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
|
+
file and restart your app.
|
34
38
|
|
35
39
|
You will have to set up a few new controllers in your rails app to handle callbacks and redirects from wepay.
|
36
40
|
I created one called finalize_controller and I use it for a landing page when the customer is finished paying
|
@@ -44,24 +48,20 @@ For now, here's what I am doing in my rails app to handle it...
|
|
44
48
|
|_ checkout_controller.rb
|
45
49
|
|_ finalize_controller.rb
|
46
50
|
|
47
|
-
|
51
|
+
You will need to set the location of these files in your wepay.yml file. The directives are:
|
48
52
|
|
49
|
-
|
50
|
-
|
53
|
+
after_authorize_redirect_uri: "http://www.example.com/purchase/checkout"
|
54
|
+
after_checkout_redirect_uri: "http://www.example.com/purchase/finalize"
|
51
55
|
|
52
|
-
|
53
|
-
# I am saving the wepay_auth_code in my Profile model. Somewhere in my rails app, I have a method called
|
54
|
-
# current_profile which I use to return the Profile object of my user. I pass that object through the
|
55
|
-
# init_checkout_and_send_user_to_wepay method along with my checkout parameters.
|
56
|
+
Finally, your checkout controller (or some controller that will interact with the Wepay API) - notice it includes WepayRails::Payments:
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
# either here - or in wepay.yml. Using it here overrides wepay.yml.
|
58
|
+
class Purchase::CheckoutController < ApplicationController
|
59
|
+
include WepayRails::Payments
|
60
60
|
|
61
|
-
|
61
|
+
before_filter :authenticate_user! # I am using devise - this line depends on your authentication scheme
|
62
62
|
|
63
|
+
def index
|
63
64
|
cart = current_user.cart # EXAMPLE - get my shopping cart
|
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
|
65
65
|
|
66
66
|
checkout_params = {
|
67
67
|
:amount => cart.grand_total,
|
@@ -70,14 +70,14 @@ Finally, your checkout controller (or some controller that will interact with th
|
|
70
70
|
}
|
71
71
|
|
72
72
|
# Finally, send the user off to wepay so you can get paid! - CASH MONEY
|
73
|
-
init_checkout_and_send_user_to_wepay(checkout_params
|
73
|
+
init_checkout_and_send_user_to_wepay(checkout_params)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
The controller I use for finalizing the checkout - AKA - the controller the user is sent back to after his/her trip to
|
78
78
|
wepay to checkout.
|
79
79
|
|
80
|
-
class Purchase::FinalizeController <
|
80
|
+
class Purchase::FinalizeController < ApplicationController
|
81
81
|
def index
|
82
82
|
wcr = WepayCheckoutRecord.find_by_checkout_id(params[:checkout_id])
|
83
83
|
|
@@ -89,7 +89,7 @@ wepay to checkout.
|
|
89
89
|
# Convert cart to an order?? Move to observer of WepayCheckoutRecord??
|
90
90
|
cart.convert_cart_to_order if wcr.state == 'authorized'
|
91
91
|
|
92
|
-
render :text =>
|
92
|
+
render :text => "Hooray - you bought some widgets!"
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.0
|
@@ -1,17 +1,19 @@
|
|
1
|
+
require 'digest/sha2'
|
1
2
|
class Wepay::AuthorizeController < Wepay::ApplicationController
|
3
|
+
|
2
4
|
def index
|
3
|
-
|
5
|
+
wepay_gateway = WepayRails::Payments::Gateway.new
|
4
6
|
|
5
|
-
if
|
6
|
-
|
7
|
+
if params[:code].present?
|
8
|
+
access_token = wepay_gateway.get_access_token(params[:code], redirect_uri)
|
9
|
+
render :text => "Copy this access token, #{access_token} to the access_token directive in your wepay.yml"
|
7
10
|
else
|
8
|
-
|
11
|
+
redirect_to wepay_gateway.auth_code_url redirect_uri
|
9
12
|
end
|
13
|
+
end
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
rescue => e
|
15
|
-
raise AuthorizationError.new("WepayRails was unable to find the record to save the auth code to. : #{e.message}") unless wepayable.present?
|
15
|
+
private
|
16
|
+
def redirect_uri
|
17
|
+
"#{WepayRails::Configuration.settings[:root_callback_uri]}/wepay/authorize"
|
16
18
|
end
|
17
19
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
class Wepay::IpnController < Wepay::ApplicationController
|
2
|
-
def
|
2
|
+
def create
|
3
3
|
|
4
4
|
record = WepayCheckoutRecord.find_by_checkout_id(params[:checkout_id])
|
5
5
|
|
6
6
|
if record.present?
|
7
|
-
wepay_gateway
|
7
|
+
wepay_gateway = WepayRails::Payments::Gateway.new
|
8
8
|
checkout = wepay_gateway.lookup_checkout(record.checkout_id)
|
9
9
|
record.update_attributes(checkout)
|
10
10
|
render :text => "ok"
|
data/lib/api/account_methods.rb
CHANGED
@@ -2,27 +2,27 @@ module WepayRails
|
|
2
2
|
module Api
|
3
3
|
module AccountMethods
|
4
4
|
def create_account(params)
|
5
|
-
self.
|
5
|
+
self.call_api("/account/create", params)
|
6
6
|
end
|
7
7
|
|
8
8
|
def get_account(account_id)
|
9
|
-
self.
|
9
|
+
self.call_api("/account", {:account_id => account_id})
|
10
10
|
end
|
11
11
|
|
12
12
|
def find_account(args)
|
13
|
-
self.
|
13
|
+
self.call_api("/account/find", args)
|
14
14
|
end
|
15
15
|
|
16
16
|
def modify_account(args)
|
17
|
-
self.
|
17
|
+
self.call_api("/account/modify", args)
|
18
18
|
end
|
19
19
|
|
20
20
|
def delete_account(account_id)
|
21
|
-
self.
|
21
|
+
self.call_api("/account/delete", {:account_id => account_id})
|
22
22
|
end
|
23
23
|
|
24
24
|
def get_account_balance(account_id)
|
25
|
-
self.
|
25
|
+
self.call_api("/account/balance", {:account_id => account_id})
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
data/lib/api/checkout_methods.rb
CHANGED
@@ -38,23 +38,33 @@ 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
|
42
|
-
:redirect_uri
|
43
|
-
:fee_payer
|
44
|
-
:type
|
45
|
-
:charge_tax
|
46
|
-
:app_fee
|
47
|
-
:auto_capture
|
41
|
+
:callback_uri => ipn_callback_uri,
|
42
|
+
:redirect_uri => checkout_redirect_uri,
|
43
|
+
:fee_payer => @wepay_config[:fee_payer],
|
44
|
+
:type => @wepay_config[:checkout_type],
|
45
|
+
:charge_tax => @wepay_config[:charge_tax] ? 1 : 0,
|
46
|
+
:app_fee => @wepay_config[:app_fee],
|
47
|
+
:auto_capture => @wepay_config[:auto_capture] ? 1 : 0,
|
48
48
|
:require_shipping => @wepay_config[:require_shipping] ? 1 : 0,
|
49
|
-
:shipping_fee
|
50
|
-
:account_id
|
49
|
+
:shipping_fee => @wepay_config[:shipping_fee],
|
50
|
+
:account_id => @wepay_config[:account_id]
|
51
51
|
}.merge(parms)
|
52
52
|
|
53
|
-
self.
|
53
|
+
self.call_api("/checkout/create", defaults)
|
54
54
|
end
|
55
55
|
|
56
56
|
def lookup_checkout(checkout_id)
|
57
|
-
self.
|
57
|
+
self.call_api("/checkout", {:checkout_id => checkout_id})
|
58
|
+
end
|
59
|
+
|
60
|
+
def ipn_callback_uri
|
61
|
+
return @wepay_config[:ipn_callback_uri] if @wepay_config[:ipn_callback_uri].present?
|
62
|
+
"#{@wepay_config[:root_callback_uri]}/wepay/ipn"
|
63
|
+
end
|
64
|
+
|
65
|
+
def checkout_redirect_uri
|
66
|
+
return @wepay_config[:checkout_redirect_uri] if @wepay_config[:checkout_redirect_uri].present?
|
67
|
+
"#{@wepay_config[:root_callback_uri]}/wepay/checkout"
|
58
68
|
end
|
59
69
|
end
|
60
70
|
end
|
@@ -4,8 +4,6 @@ class CreateWepayCheckoutRecords < ActiveRecord::Migration
|
|
4
4
|
create_table :wepay_checkout_records do |t|
|
5
5
|
t.integer :checkout_id
|
6
6
|
t.integer :account_id
|
7
|
-
t.string :auth_code
|
8
|
-
t.string :access_token
|
9
7
|
t.string :state
|
10
8
|
t.string :short_description
|
11
9
|
t.text :long_description
|
@@ -2,13 +2,13 @@ production:
|
|
2
2
|
client_id: <your client id from wepay>
|
3
3
|
client_secret: <your client secret from wepay>
|
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
7
|
after_authorize_redirect_uri: "http://www.example.com/purchase/checkout"
|
8
8
|
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."
|
9
10
|
scope: [refund_payments,collect_payments,view_balance,view_user]
|
10
|
-
wepay_api_uri: "https://api.wepay.com"
|
11
|
-
wepay_api_version: "v2"
|
11
|
+
wepay_api_uri: "https://api.wepay.com/v2"
|
12
12
|
fee_payer: Payee
|
13
13
|
checkout_type: GOODS
|
14
14
|
charge_tax: false
|
@@ -2,77 +2,6 @@ module WepayRails
|
|
2
2
|
module Helpers
|
3
3
|
module ControllerHelpers
|
4
4
|
|
5
|
-
def redirect_to_wepay_for_auth(wepayable_object, params = {})
|
6
|
-
# Initially set a reference ID to the column created for the wepayable
|
7
|
-
# so that when the redirect back from wepay happens, we can reference
|
8
|
-
# the original wepayable, and then save the new auth code into the reference ID's
|
9
|
-
# place
|
10
|
-
ref_id = Digest::SHA1.hexdigest("#{Time.now.to_i+rand(4)}")
|
11
|
-
session[unique_wepay_auth_token_key] = ref_id
|
12
|
-
wepayable_object.update_attribute(WepayRails::Configuration.wepayable_column.to_sym, ref_id)
|
13
|
-
|
14
|
-
redirect_to wepay_gateway.auth_code_url(params)
|
15
|
-
end
|
16
|
-
|
17
|
-
# @deprecated Use wepay_gateway instead of gateway
|
18
|
-
def gateway
|
19
|
-
warn "[DEPRECATION] Use wepay_gateway instead of gateway"
|
20
|
-
wepay_gateway
|
21
|
-
end
|
22
|
-
|
23
|
-
def wepay_gateway
|
24
|
-
@gateway ||= WepayRails::Payments::Gateway.new(wepay_access_token)
|
25
|
-
end
|
26
|
-
|
27
|
-
# From https://stage.wepay.com/developer/tutorial/authorization
|
28
|
-
# Request
|
29
|
-
# https://stage.wepay.com/v2/oauth2/token
|
30
|
-
# ?client_id=[your client id]
|
31
|
-
# &redirect_uri=[your redirect uri ex. 'http://exampleapp.com/wepay']
|
32
|
-
# &client_secret=[your client secret]
|
33
|
-
# &code=[the code you got in step one]
|
34
|
-
#
|
35
|
-
# Response
|
36
|
-
# {"user_id":"123456","access_token":"1337h4x0rzabcd12345","token_type":"BEARER"} Example
|
37
|
-
def initialize_wepay_access_token(wepayable_object)
|
38
|
-
return if wepay_access_token_exists?
|
39
|
-
begin
|
40
|
-
# check to see if they have an auth code
|
41
|
-
# If not, send them to wepay to get one
|
42
|
-
wepayable_column = WepayRails::Configuration.wepayable_column
|
43
|
-
raise unless wepayable_object.send(wepayable_column.to_sym).present?
|
44
|
-
|
45
|
-
# It's possible that we raise an exception here - probably the auth code
|
46
|
-
# was too old and they need an updated one. Send them to wepay to
|
47
|
-
# get a new one if a raise happens while we run the following line of code.
|
48
|
-
session[unique_wepay_access_token_key] = wepay_gateway.access_token(wepayable_object)
|
49
|
-
rescue
|
50
|
-
redirect_to_wepay_for_auth(wepayable_object)
|
51
|
-
end
|
52
|
-
return
|
53
|
-
end
|
54
|
-
|
55
|
-
# Since we are saving the access token in the session,
|
56
|
-
# ensure key uniqueness. Might be a good idea to have this
|
57
|
-
# be a setting in the wepay.yml file.
|
58
|
-
def unique_wepay_access_token_key
|
59
|
-
:IODDR8856UUFG6788
|
60
|
-
end
|
61
|
-
|
62
|
-
def unique_wepay_auth_token_key
|
63
|
-
:J8876GFUU6588RDDO
|
64
|
-
end
|
65
|
-
|
66
|
-
# Access token is the OAUTH access token that is used for future
|
67
|
-
# comunique
|
68
|
-
def wepay_access_token
|
69
|
-
session[unique_wepay_access_token_key]
|
70
|
-
end
|
71
|
-
|
72
|
-
def wepay_access_token_exists?
|
73
|
-
wepay_access_token.present?
|
74
|
-
end
|
75
|
-
|
76
5
|
# Many of the settings you pass in here are already factored in from
|
77
6
|
# the wepay.yml file and only need to be overridden if you insist on doing
|
78
7
|
# so when this method is called. The following list of key values are pulled
|
@@ -108,28 +37,16 @@ module WepayRails
|
|
108
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
|
109
38
|
# :shipping_fee No The amount that you want to charge for shipping.
|
110
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.
|
111
|
-
def init_checkout_and_send_user_to_wepay(params,
|
112
|
-
|
113
|
-
response
|
114
|
-
|
115
|
-
|
116
|
-
raise WepayRails::Exceptions::InitializeCheckoutError.new("A problem occurred while trying to checkout.
|
117
|
-
Wepay didn't send us back a checkout uri. Response was: #{response.inspect},
|
118
|
-
Params were: #{params}, Token was: #{wepay_access_token}")
|
119
|
-
end
|
120
|
-
|
121
|
-
wepayable_column = WepayRails::Configuration.wepayable_column
|
122
|
-
raise unless wepayable_object.send(wepayable_column.to_sym).present?
|
123
|
-
|
124
|
-
wcr_params = {
|
125
|
-
:auth_code => wepayable_object.send(wepayable_column),
|
126
|
-
:access_token => wepay_access_token,
|
40
|
+
def init_checkout_and_send_user_to_wepay(params, access_token=nil)
|
41
|
+
wepay_gateway = WepayRails::Payments::Gateway.new(access_token)
|
42
|
+
response = wepay_gateway.perform_checkout(params)
|
43
|
+
params.merge!({
|
44
|
+
:access_token => wepay_gateway.access_token,
|
127
45
|
:checkout_id => response['checkout_id']
|
128
|
-
}
|
129
|
-
|
130
|
-
params.merge!(wcr_params)
|
46
|
+
})
|
131
47
|
|
132
48
|
WepayCheckoutRecord.create(params)
|
49
|
+
|
133
50
|
redirect_to response['checkout_uri'] and return
|
134
51
|
end
|
135
52
|
end
|
data/lib/wepay-rails.rb
CHANGED
@@ -4,23 +4,12 @@ require 'api/account_methods'
|
|
4
4
|
require 'api/checkout_methods'
|
5
5
|
module WepayRails
|
6
6
|
class Configuration
|
7
|
-
@@wepayable_class = nil
|
8
|
-
@@wepayable_column = nil
|
9
7
|
@@settings = nil
|
10
8
|
|
11
|
-
def self.init_conf(
|
12
|
-
@@wepayable_class, @@wepayable_column = klass, column
|
9
|
+
def self.init_conf(settings)
|
13
10
|
@@settings = settings
|
14
11
|
end
|
15
12
|
|
16
|
-
def self.wepayable_class
|
17
|
-
@@wepayable_class
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.wepayable_column
|
21
|
-
@@wepayable_column
|
22
|
-
end
|
23
|
-
|
24
13
|
def self.settings
|
25
14
|
@@settings
|
26
15
|
end
|
@@ -31,8 +20,7 @@ module WepayRails
|
|
31
20
|
initializer "WepayRails.initialize_wepay_rails" do |app|
|
32
21
|
yml = Rails.root.join('config', 'wepay.yml').to_s
|
33
22
|
settings = YAML.load_file(yml)[Rails.env].symbolize_keys
|
34
|
-
|
35
|
-
Configuration.init_conf(eval(klass), column, settings)
|
23
|
+
Configuration.init_conf(settings)
|
36
24
|
end
|
37
25
|
end
|
38
26
|
|
@@ -49,72 +37,52 @@ module WepayRails
|
|
49
37
|
|
50
38
|
base_uri @base_uri
|
51
39
|
|
52
|
-
attr_accessor :
|
40
|
+
attr_accessor :access_token
|
53
41
|
|
54
42
|
# Pass in the wepay access token that we got after the oauth handshake
|
55
43
|
# and use it for ongoing comunique with Wepay.
|
56
44
|
# This also relies heavily on there being a wepay.yml file in your
|
57
45
|
# rails config directory - it must look like this:
|
58
|
-
#
|
59
|
-
#
|
60
46
|
def initialize(*args)
|
61
|
-
@wepay_access_token = args.first
|
62
|
-
|
63
47
|
@wepay_config = WepayRails::Configuration.settings
|
64
|
-
|
65
|
-
|
66
|
-
# Default if there isn't a setting for version and/or api uri
|
67
|
-
version = @wepay_config[:wepay_api_version].present? ? @wepay_config[:wepay_api_version] : "v2"
|
68
|
-
api_uri = @wepay_config[:wepay_api_uri].present? ? @wepay_config[:wepay_api_uri] : "https://wepayapi.com"
|
69
|
-
|
70
|
-
@base_uri = "#{api_uri}/#{version}"
|
48
|
+
@access_token = args.first || @wepay_config[:access_token]
|
49
|
+
@base_uri = @wepay_config[:wepay_api_uri] || "https://www.wepay.com/v2"
|
71
50
|
end
|
72
51
|
|
73
|
-
|
74
|
-
|
75
|
-
auth_code = if wepayable_object.is_a?(String)
|
76
|
-
wepayable_object
|
77
|
-
elsif wepayable_object.respond_to?(w_column)
|
78
|
-
wepayable_object.send(w_column)
|
79
|
-
end
|
80
|
-
|
81
|
-
unless auth_code.present?
|
82
|
-
raise WepayRails::Exceptions::AccessTokenError.new("The argument, #{wepayable_object.inspect}, passed into the
|
83
|
-
access_token method cannot be used to get an access token. It is neither a string,
|
84
|
-
nor an object containing the auth_code column you specified in wepay.yml.")
|
85
|
-
end
|
52
|
+
# Fetch the access token from wepay for the auth code
|
53
|
+
def get_access_token(auth_code, redirect_uri)
|
86
54
|
|
87
55
|
params = {
|
88
|
-
:client_id
|
56
|
+
:client_id => @wepay_config[:client_id],
|
89
57
|
:client_secret => @wepay_config[:client_secret],
|
90
|
-
:redirect_uri
|
91
|
-
:code
|
58
|
+
:redirect_uri => redirect_uri,
|
59
|
+
:code => auth_code
|
92
60
|
}
|
93
61
|
|
94
|
-
response = self.
|
62
|
+
response = self.class.post("#{@base_uri}/oauth2/token", {:body => params})
|
63
|
+
json = JSON.parse(response.body)
|
95
64
|
|
96
|
-
if
|
97
|
-
if
|
98
|
-
if ['invalid code parameter','the code has expired'].include?(
|
99
|
-
raise WepayRails::Exceptions::ExpiredTokenError.new("Token either expired or invalid: #{
|
65
|
+
if json.has_key?("error")
|
66
|
+
if json.has_key?("error_description")
|
67
|
+
if ['invalid code parameter','the code has expired','this access_token has been revoked'].include?(json['error_description'])
|
68
|
+
raise WepayRails::Exceptions::ExpiredTokenError.new("Token either expired, revoked or invalid: #{json["error_description"]}")
|
100
69
|
end
|
101
|
-
raise WepayRails::Exceptions::AccessTokenError.new(
|
70
|
+
raise WepayRails::Exceptions::AccessTokenError.new(json["error_description"])
|
102
71
|
end
|
103
72
|
end
|
104
73
|
|
105
|
-
raise WepayRails::Exceptions::AccessTokenError.new("A problem occurred trying to get the access token: #{
|
74
|
+
raise WepayRails::Exceptions::AccessTokenError.new("A problem occurred trying to get the access token: #{json.inspect}") unless json.has_key?("access_token")
|
106
75
|
|
107
|
-
@
|
108
|
-
@wepay_access_token = response["access_token"]
|
76
|
+
@access_token = json["access_token"]
|
109
77
|
end
|
110
78
|
|
111
79
|
# Get the auth code url that will be used to fetch the auth code for the customer
|
112
80
|
# arguments are the redirect_uri and an array of permissions that your application needs
|
113
81
|
# ex. ['manage_accounts','collect_payments','view_balance','view_user']
|
114
|
-
def auth_code_url(params = {})
|
82
|
+
def auth_code_url(redirect_uri, params = {})
|
115
83
|
params[:client_id] ||= @wepay_config[:client_id]
|
116
|
-
params[:
|
117
|
-
params[:
|
84
|
+
params[:scope] ||= @wepay_config[:scope].join(',')
|
85
|
+
params[:redirect_uri] = redirect_uri
|
118
86
|
|
119
87
|
query = params.map do |k, v|
|
120
88
|
"#{k.to_s}=#{v}"
|
@@ -124,21 +92,14 @@ module WepayRails
|
|
124
92
|
end
|
125
93
|
|
126
94
|
def wepay_auth_header
|
127
|
-
unless @
|
95
|
+
unless @access_token
|
128
96
|
raise WepayRails::Exceptions::AccessTokenError.new("No access token available")
|
129
97
|
end
|
130
|
-
{'Authorization' => "Bearer: #{@
|
131
|
-
end
|
132
|
-
|
133
|
-
# Make a call to wepay to get the user info. This will only make one call
|
134
|
-
# per request. Any subsequent calls to wepay_user will return the data
|
135
|
-
# retrieved from the first call.
|
136
|
-
def wepay_user
|
137
|
-
@wepay_user ||= self.call("/user")
|
98
|
+
{'Authorization' => "Bearer: #{@access_token}"}
|
138
99
|
end
|
139
100
|
|
140
|
-
def
|
141
|
-
response = self.class.post("#{@base_uri}#{api_path}", {:headers => wepay_auth_header}.merge!(params))
|
101
|
+
def call_api(api_path, params={})
|
102
|
+
response = self.class.post("#{@base_uri}#{api_path}", {:headers => wepay_auth_header}.merge!({:body => params}))
|
142
103
|
JSON.parse(response.body)
|
143
104
|
end
|
144
105
|
|
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 = "
|
8
|
+
s.version = "2.0.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-27"
|
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:
|
4
|
+
version: 2.0.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-27 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
16
|
-
requirement: &
|
16
|
+
requirement: &9095360 !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: *9095360
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: shoulda
|
27
|
-
requirement: &
|
27
|
+
requirement: &9093080 !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: *9093080
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &9091480 !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: *9091480
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &9090080 !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: *9090080
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rcov
|
60
|
-
requirement: &
|
60
|
+
requirement: &9088680 !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: *9088680
|
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: -431317544786585156
|
118
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
119
|
none: false
|
120
120
|
requirements:
|