Class: Lightrail::Account

Inherits:
LightrailObject show all
Defined in:
lib/lightrail_client/account.rb

Class Method Summary collapse

Methods inherited from LightrailObject

#initialize

Constructor Details

This class inherits a constructor from Lightrail::LightrailObject

Class Method Details

.charge(charge_params) ⇒ Object



40
41
42
43
# File 'lib/lightrail_client/account.rb', line 40

def self.charge(charge_params)
   = self.replace_contact_id_or_shopper_id_with_card_id(charge_params)
  Lightrail::Card.charge()
end

.create(account_params) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/lightrail_client/account.rb', line 3

def self.create()
  validated_params = Lightrail::Validator.()

  # Make sure contact exists first
  contact_id = Lightrail::Validator.get_contact_id()
  shopper_id = Lightrail::Validator.get_shopper_id()

  if contact_id
    contact = Lightrail::Contact.retrieve_by_contact_id(contact_id)
    if shopper_id && (contact['userSuppliedId'] != shopper_id)
      raise Lightrail::LightrailArgumentError.new("Account creation error: you've specified both a contactId and a shopperId for this account, but the contact with that contactId has a different shopperId.")
    end

  elsif shopper_id
    contact = Lightrail::Contact.retrieve_or_create_by_shopper_id(shopper_id)
  end

  # If the contact already has an account in that currency, return it
   = Lightrail::Account.retrieve({contact_id: contact['contactId'], currency: [:currency]})
  return ['cardId'] if 

  params_with_contact_id = validated_params.clone
  params_with_contact_id[:contactId] = contact['contactId']
  response = Lightrail::Connection.send :make_post_request_and_parse_response, "cards", params_with_contact_id
  response['card']
end

.fund(fund_params) ⇒ Object



50
51
52
53
# File 'lib/lightrail_client/account.rb', line 50

def self.fund(fund_params)
   = self.replace_contact_id_or_shopper_id_with_card_id(fund_params)
  Lightrail::Card.fund()
end

.get_account_details(account_details_params) ⇒ Object



55
56
57
58
# File 'lib/lightrail_client/account.rb', line 55

def self.()
   = self.replace_contact_id_or_shopper_id_with_card_id()
  Lightrail::Card.get_details([:card_id])
end

.get_maximum_account_value(max_account_value_params) ⇒ Object



60
61
62
63
# File 'lib/lightrail_client/account.rb', line 60

def self.()
   = self.replace_contact_id_or_shopper_id_with_card_id()
  Lightrail::Card.get_maximum_value([:card_id])
end

.retrieve(account_retrieval_params) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/lightrail_client/account.rb', line 30

def self.retrieve()
  new_params = .clone
  currency = new_params[:currency] || new_params['currency']
  Lightrail::Validator.validate_currency!(currency)
  Lightrail::Validator.set_contactId_from_contact_or_shopper_id!(new_params, new_params)
  contact_id = new_params[:contactId]
  response = Lightrail::Connection.send :make_get_request_and_parse_response, "cards?cardType=ACCOUNT_CARD&contactId=#{CGI::escape(contact_id)}&currency=#{CGI::escape(currency)}"
  response['cards'][0]
end

.simulate_charge(charge_params) ⇒ Object



45
46
47
48
# File 'lib/lightrail_client/account.rb', line 45

def self.simulate_charge(charge_params)
   = self.replace_contact_id_or_shopper_id_with_card_id(charge_params)
  Lightrail::Card.simulate_charge()
end