Class: Tangocard::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/tangocard/account.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Account

Returns a new instance of Account.


63
64
65
66
67
68
# 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

Instance Attribute Details

#available_balanceObject (readonly)

Returns the value of attribute available_balance.


2
3
4
# File 'lib/tangocard/account.rb', line 2

def available_balance
  @available_balance
end

#cc_tokenObject (readonly)

Returns the value of attribute cc_token.


2
3
4
# File 'lib/tangocard/account.rb', line 2

def cc_token
  @cc_token
end

#customerObject (readonly)

Returns the value of attribute customer.


2
3
4
# File 'lib/tangocard/account.rb', line 2

def customer
  @customer
end

#emailObject (readonly)

Returns the value of attribute email.


2
3
4
# File 'lib/tangocard/account.rb', line 2

def email
  @email
end

#identifierObject (readonly)

Returns the value of attribute identifier.


2
3
4
# File 'lib/tangocard/account.rb', line 2

def identifier
  @identifier
end

Class Method Details

.create(customer, identifier, email) ⇒ Object

Create account given customer, identifier, and email. Raises Tangocard::AccountCreateFailedException on failure.

Example:

>> Tangocard::Account.create('bonusly', 'test', '[email protected]')
 => #<Tangocard::Account:0x007f9a6fec0138 @customer="bonusly", @email="[email protected]", @identifier="test", @available_balance=0>

Arguments:

customer: (String)
identifier: (String)
email: (String)

35
36
37
38
39
40
41
42
# File 'lib/tangocard/account.rb', line 35

def self.create(customer, identifier, email)
  response = Tangocard::Raas.({'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) ⇒ Object

Find account given customer and identifier. Raises Tangocard::AccountNotFoundException on failure.

Example:

>> Tangocard::Account.find('bonusly', 'test')
 => #<Tangocard::Account:0x007f9a6fec0138 @customer="bonusly", @email="[email protected]", @identifier="test", @available_balance=1200>

Arguments:

customer: (String)
identifier: (String)

15
16
17
18
19
20
21
22
# File 'lib/tangocard/account.rb', line 15

def self.find(customer, identifier)
  response = Tangocard::Raas.({'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) ⇒ Object

Find account, or create if account not found. Raises Tangocard::AccountCreateFailedException on failure.

Example:

>> Tangocard::Account.find_or_create('bonusly', 'test', '[email protected]')
 => #<Tangocard::Account:0x007f9a6fec0138 @customer="bonusly", @email="[email protected]", @identifier="test", @available_balance=0>

Arguments:

customer: (String)
identifier: (String)
email: (String)

55
56
57
58
59
60
61
# 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

Instance Method Details

#balanceObject


70
71
72
# File 'lib/tangocard/account.rb', line 70

def balance
  @available_balance
end

#cc_fund(amount, client_ip, cc_token, security_code) ⇒ Object

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.(params)

end


137
138
139
140
141
142
143
144
145
146
147
148
# 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.(params)
end

#delete_credit_card(cc_token) ⇒ Object

Arguments:

cc_token: (String)

158
159
160
161
162
163
164
165
166
# 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) ⇒ Object

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' => '[email protected]'
    }
}

102
103
104
105
106
107
108
109
110
111
# 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