Class: InternetBS::AccountTransactions

Inherits:
Base
  • Object
show all
Defined in:
lib/internetbs/account_transactions.rb

Instance Method Summary collapse

Methods inherited from Base

#inspect

Instance Method Details

#fetchObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/internetbs/account_transactions.rb', line 8

def fetch
  @errors.clear
  
  params = {}
  params.merge!({'transaction_id' => @transaction_id}) if @transaction_id
  params.merge!({'client_transaction_id' => @client_transaction_id}) if @client_transaction_id
  
  response = Client.get('/account/transactioninfo/get', params)
  code = response.code rescue ""
  
  case code
  when '200'
    hash = JSON.parse(response.body)

    @status = hash["status"]
    @transaction_id = hash["transactid"]

    # Receiving: "FAILURE", "Permission Denied %1%"
    # This endpoint may require activation by InternetBS themselves?
    # Documentation exists in PDF only. May be an artifact, but would
    # expect to receive an error stating the endpoint doesn't exist.
    debugger
    puts hash
    
    if @status == 'SUCCESS'
      @currency = hash['currency']
    
      hash['product'].each do |product|
        @list << AccountTransaction.new(
          :currency => @currency ,
          :name     => product['name'], 
          :price    => product['price']
        )
      end
    else
      set_errors(response)
      return false
    end
    
    return true
  else
    set_errors(response)
    return false
  end
end