Class: WepayClient::Client
- Inherits:
-
Object
- Object
- WepayClient::Client
- Includes:
- Singleton
- Defined in:
- lib/wepay_client/client.rb,
lib/wepay_client/account.rb,
lib/wepay_client/checkout.rb,
lib/wepay_client/preapproval.rb
Constant Summary collapse
- STAGE_API_ENDPOINT =
"https://stage.wepayapi.com/v2"
- STAGE_UI_ENDPOINT =
"https://stage.wepay.com/v2"
- PRODUCTION_API_ENDPOINT =
"https://wepayapi.com/v2"
- PRODUCTION_UI_ENDPOINT =
"https://www.wepay.com/v2"
- CLIENT_ID =
'123456'
- CLIENT_SECRET =
'123456'
- PREAPPROVAL_PERIODS =
{ :hourly => 'hourly', :daily => 'daily', :weekly => 'weekly', :biweekly => 'biweekly', :monthly => 'monthly', :quarterly=> 'quarterly', :yearly => 'yearly', :once => 'once' }
Class Method Summary collapse
Instance Method Summary collapse
- #api_endpoint ⇒ Object
-
#auth_code_url(redirect_uri, user_email = false, user_name = false, permissions = "manage_accounts,view_balance,collect_payments,refund_payments,view_user,preapprove_payments") ⇒ Object
this function returns the URL that you send the user to to authorize your API application the redirect_uri must be a full uri (ex www.wepay.com).
- #cancel_preapproval(access_token, preapproval_id) ⇒ Object
- #client_id(_client_id = nil) ⇒ Object
- #client_secret(secret = nil) ⇒ Object
-
#configure(&blk) ⇒ Object
Simple DSL to configure the client.
- #create_account(access_token, params = {}) ⇒ Object
- #create_checkout(access_token, params = {}) ⇒ Object
- #create_preapproval(access_token, params = {}) ⇒ Object
- #delete_account(access_token, account_id) ⇒ Object
- #find_account(access_token, params = {}) ⇒ Object
-
#get_access_token(auth_code, redirect_uri) ⇒ Object
this function will make a call to the /v2/oauth2/token endpoint to exchange a code for an access_token.
- #get_account(access_token, account_id) ⇒ Object
- #get_account_balance(access_token, account_id) ⇒ Object
- #get_checkout(access_token, checkout_id) ⇒ Object
- #get_preapproval(access_token, preapproval_id) ⇒ Object
- #modify_account(access_token, account_id, params = {}) ⇒ Object
- #refund(access_token, checkout_id, params = {}) ⇒ Object
- #ui_endpoint ⇒ Object
- #use_ssl(_use_ssl = nil) ⇒ Object
- #use_stage(_use_stage = nil) ⇒ Object
Class Method Details
.configure(&blk) ⇒ Object
22 23 24 |
# File 'lib/wepay_client/client.rb', line 22 def self.configure(&blk) self.instance.configure &blk end |
Instance Method Details
#api_endpoint ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/wepay_client/client.rb', line 31 def api_endpoint if @use_stage STAGE_API_ENDPOINT else PRODUCTION_API_ENDPOINT end end |
#auth_code_url(redirect_uri, user_email = false, user_name = false, permissions = "manage_accounts,view_balance,collect_payments,refund_payments,view_user,preapprove_payments") ⇒ Object
this function returns the URL that you send the user to to authorize your API application the redirect_uri must be a full uri (ex www.wepay.com)
69 70 71 72 73 |
# File 'lib/wepay_client/client.rb', line 69 def auth_code_url(redirect_uri, user_email = false, user_name = false, = "manage_accounts,view_balance,collect_payments,refund_payments,view_user,preapprove_payments") url = ui_endpoint + '/oauth2/authorize?client_id=' + client_id.to_s + '&redirect_uri=' + redirect_uri + '&scope=' + url += user_name ? '&user_name=' + CGI::escape(user_name) : '' url += user_email ? '&user_email=' + CGI::escape(user_email) : '' end |
#cancel_preapproval(access_token, preapproval_id) ⇒ Object
26 27 28 |
# File 'lib/wepay_client/preapproval.rb', line 26 def cancel_preapproval(access_token, preapproval_id) self.post("/preapproval/cancel", access_token, {:preapproval_id => preapproval_id}) end |
#client_id(_client_id = nil) ⇒ Object
62 63 64 65 |
# File 'lib/wepay_client/client.rb', line 62 def client_id(_client_id = nil) @client_id = _client_id if _client_id @client_id end |
#client_secret(secret = nil) ⇒ Object
57 58 59 60 |
# File 'lib/wepay_client/client.rb', line 57 def client_secret(secret = nil) @client_secret = secret if secret @client_secret end |
#configure(&blk) ⇒ Object
Simple DSL to configure the client.
27 28 29 |
# File 'lib/wepay_client/client.rb', line 27 def configure(&blk) instance_eval &blk end |
#create_account(access_token, params = {}) ⇒ Object
3 4 5 |
# File 'lib/wepay_client/account.rb', line 3 def create_account(access_token, params = {}) self.post("/account/create", access_token, params) end |
#create_checkout(access_token, params = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/wepay_client/checkout.rb', line 7 def create_checkout(access_token, params = {}) defaults = { :fee_payer => 'Payee', :type => 'SERVICE', :charge_tax => 0, :app_fee => 0, :auto_capture => 1, :require_shipping => 0 }.merge(params) self.post("/checkout/create", access_token, defaults.merge(params)) end |
#create_preapproval(access_token, params = {}) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/wepay_client/preapproval.rb', line 14 def create_preapproval(access_token, params = {}) defaults = { :frequency => 10 }.merge(params) self.post("/preapproval/create", access_token, defaults) end |
#delete_account(access_token, account_id) ⇒ Object
19 20 21 |
# File 'lib/wepay_client/account.rb', line 19 def delete_account(access_token, account_id) self.post("/account/delete", access_token, {:account_id => account_id}) end |
#find_account(access_token, params = {}) ⇒ Object
11 12 13 |
# File 'lib/wepay_client/account.rb', line 11 def find_account(access_token, params = {}) self.post("/account/find", access_token, params) end |
#get_access_token(auth_code, redirect_uri) ⇒ Object
this function will make a call to the /v2/oauth2/token endpoint to exchange a code for an access_token
76 77 78 79 80 |
# File 'lib/wepay_client/client.rb', line 76 def get_access_token(auth_code, redirect_uri) json = post('/oauth2/token', nil, {'client_id' => client_id, 'client_secret' => client_secret, 'redirect_uri' => redirect_uri, 'code' => auth_code }) raise WepayClient::Exceptions::AccessTokenError.new("A problem occurred trying to get the access token: #{json.inspect}") unless json.has_key?(:access_token) json end |
#get_account(access_token, account_id) ⇒ Object
7 8 9 |
# File 'lib/wepay_client/account.rb', line 7 def get_account(access_token, account_id) self.post("/account", access_token, {:account_id => account_id}) end |
#get_account_balance(access_token, account_id) ⇒ Object
23 24 25 |
# File 'lib/wepay_client/account.rb', line 23 def get_account_balance(access_token, account_id) self.post("/account/balance", access_token, {:account_id => account_id}) end |
#get_checkout(access_token, checkout_id) ⇒ Object
3 4 5 |
# File 'lib/wepay_client/checkout.rb', line 3 def get_checkout(access_token, checkout_id) self.post("/checkout", access_token, {:checkout_id => checkout_id}) end |
#get_preapproval(access_token, preapproval_id) ⇒ Object
22 23 24 |
# File 'lib/wepay_client/preapproval.rb', line 22 def get_preapproval(access_token, preapproval_id) self.post("/preapproval", access_token, {:preapproval_id => preapproval_id}) end |
#modify_account(access_token, account_id, params = {}) ⇒ Object
15 16 17 |
# File 'lib/wepay_client/account.rb', line 15 def modify_account(access_token, account_id, params={}) self.post("/account/modify", access_token, params.merge({:account_id => account_id})) end |
#refund(access_token, checkout_id, params = {}) ⇒ Object
19 20 21 |
# File 'lib/wepay_client/checkout.rb', line 19 def refund(access_token, checkout_id, params = {}) self.post("/checkout/refund", access_token, params.merge(:checkout_id => checkout_id)) end |
#ui_endpoint ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/wepay_client/client.rb', line 39 def ui_endpoint if @use_stage STAGE_UI_ENDPOINT else PRODUCTION_UI_ENDPOINT end end |
#use_ssl(_use_ssl = nil) ⇒ Object
52 53 54 55 |
# File 'lib/wepay_client/client.rb', line 52 def use_ssl(_use_ssl = nil) @use_stage = _use_ssl if _use_ssl @use_stage end |
#use_stage(_use_stage = nil) ⇒ Object
47 48 49 50 |
# File 'lib/wepay_client/client.rb', line 47 def use_stage(_use_stage = nil) @use_stage = _use_stage if _use_stage @use_stage end |