class Tangocard::Account
Attributes
available_balance[R]
cc_token[R]
customer[R]
email[R]
identifier[R]
Public Class Methods
create(customer, identifier, email)
click to toggle source
Create account given customer, identifier, and email. Raises Tangocard::AccountCreateFailedException
on failure.
Example:
>> Tangocard::Account.create('bonusly', 'test', 'dev@bonus.ly') => #<Tangocard::Account:0x007f9a6fec0138 @customer="bonusly", @email="dev@bonus.ly", @identifier="test", @available_balance=0>
Arguments:
customer: (String) identifier: (String) email: (String)
# File lib/tangocard/account.rb, line 35 def self.create(customer, identifier, email) response = Tangocard::Raas.create_account({'customer' => customer, 'identifier' => identifier, 'email' => email}) if response.success? new(response.parsed_response['account']) else raise Tangocard::AccountCreateFailedException, "#{response.error_message}" end end
find(customer, identifier)
click to toggle source
Find account given customer and identifier. Raises Tangocard::AccountNotFoundException
on failure.
Example:
>> Tangocard::Account.find('bonusly', 'test') => #<Tangocard::Account:0x007f9a6fec0138 @customer="bonusly", @email="dev@bonus.ly", @identifier="test", @available_balance=1200>
Arguments:
customer: (String) identifier: (String)
# File lib/tangocard/account.rb, line 15 def self.find(customer, identifier) response = Tangocard::Raas.show_account({'customer' => customer, 'identifier' => identifier}) if response.success? new(response.parsed_response['account']) else raise Tangocard::AccountNotFoundException, "#{response.error_message}" end end
find_or_create(customer, identifier, email)
click to toggle source
Find account, or create if account not found. Raises Tangocard::AccountCreateFailedException
on failure.
Example:
>> Tangocard::Account.find_or_create('bonusly', 'test', 'dev@bonus.ly') => #<Tangocard::Account:0x007f9a6fec0138 @customer="bonusly", @email="dev@bonus.ly", @identifier="test", @available_balance=0>
Arguments:
customer: (String) identifier: (String) email: (String)
# File lib/tangocard/account.rb, line 55 def self.find_or_create(customer, identifier, email) begin find(customer, identifier) rescue Tangocard::AccountNotFoundException => e create(customer, identifier, email) end end
new(params)
click to toggle source
# File lib/tangocard/account.rb, line 63 def initialize(params) @customer = params['customer'] @email = params['email'] @identifier = params['identifier'] @available_balance = params['available_balance'].to_i end
Public Instance Methods
balance()
click to toggle source
# File lib/tangocard/account.rb, line 70 def balance @available_balance end
cc_fund(amount, client_ip, cc_token, security_code)
click to toggle source
Arguments:
amount: (Integer) client_ip: (String) cc_token: (String) security_code: (String)
def cc_fund
(amount, client_ip, cc_token
, security_code)
params = { 'amount' => amount, 'client_ip' => client_ip, 'cc_token' => cc_token, 'customer' => customer, 'account_identifier' => identifier, 'security_code' => security_code } response = Tangocard::Raas.cc_fund_account(params)
end
# File lib/tangocard/account.rb, line 137 def cc_fund(amount, client_ip, cc_token, security_code) params = { 'amount' => amount, 'client_ip' => client_ip, 'cc_token' => cc_token, 'customer' => customer, 'account_identifier' => identifier, 'security_code' => security_code } Tangocard::Raas.cc_fund_account(params) end
delete_credit_card(cc_token)
click to toggle source
Arguments:
cc_token: (String)
# File lib/tangocard/account.rb, line 158 def delete_credit_card(cc_token) params = { 'cc_token' => cc_token, 'customer' => customer, 'account_identifier' => identifier } Tangocard::Raas.delete_credit_card(params) end
register_credit_card(client_ip, credit_card)
click to toggle source
Register a credit card Raises Tango::AccountRegisterCreditCardFailedException on failure. Example:
>> account.register_credit_card('128.128.128.128', Hash (see example below)) => #<Tangocard::Response:0x007f9a6fec0138 ...>
Arguments:
client_ip: (String) credit_card: (Hash) - see
www.tangocard.com/docs/raas-api/#create-cc-registration for details
Credit Card Hash Example:
{ 'number' => '4111111111111111', 'expiration' => '2017-01', 'security_code' => '123', 'billing_address' => { 'f_name' => 'Jane', 'l_name' => 'User', 'address' => '123 Main Street', 'city' => 'Anytown', 'state' => 'NY', 'zip' => '11222', 'country' => 'USA', 'email' => 'jane@company.com' } }
# File lib/tangocard/account.rb, line 102 def register_credit_card(client_ip, credit_card) params = { 'client_ip' => client_ip, 'credit_card' => credit_card, 'customer' => customer, 'account_identifier' => identifier } response = Tangocard::Raas.register_credit_card(params) end