Class: RubyPsigate::Account

Inherits:
Object
  • Object
show all
Includes:
AccountMethods, CreditCardMethods
Defined in:
lib/ruby_psigate/account.rb

Constant Summary collapse

ACTIONS =

List of actions you can perform on an account and their associated constant codes

{
  :account => {
    :summary => "AMA00",
    :details => "AMA05",
    :register => "AMA01",
    :update => "AMA02",
    :enable => "AMA08",
    :disable => "AMA09"
  },
  :credit_card => {
    :add => "AMA11",
    :delete => "AMA14",
    :enable => "AMA18",
    :disable => "AMA19"
  },
  :charges => {
    :summary => "RBC00",
    :add => "RBC01",
    :update => "RBC02",
    :delete => "RBC04",
    :details => "RBC05",
    :enable => "RBC08",
    :disable => "RBC09",
    :immediate => "RBC99"
  }
}

Instance Attribute Summary collapse

Attributes included from CreditCardMethods

#cc

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#account_idObject Also known as: accountid

Returns the value of attribute account_id.



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

def 
  @account_id
end

#actionObject



67
68
69
# File 'lib/ruby_psigate/account.rb', line 67

def action
  ACTIONS[@action.first[0]][@action.first[1]]
end

#addressObject

Returns the value of attribute address.



54
55
56
# File 'lib/ruby_psigate/account.rb', line 54

def address
  @address
end

#commentsObject

Returns the value of attribute comments.



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

def comments
  @comments
end

#emailObject

Returns the value of attribute email.



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

def email
  @email
end

#rbchargeObject

Returns the value of attribute rbcharge.



54
55
56
# File 'lib/ruby_psigate/account.rb', line 54

def rbcharge
  @rbcharge
end

#serial_noObject

Returns the value of attribute serial_no.



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

def serial_no
  @serial_no
end

#store_idObject

Returns the value of attribute store_id.



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

def store_id
  @store_id
end

Class Method Details

.action_reverse_lookup(code) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ruby_psigate/account.rb', line 38

def self.action_reverse_lookup(code)
  result = nil
  result_first = nil
  result_second = nil
  ACTIONS.each_pair do |section, actions|
    break if result_second
    result_second = actions.select { |k,v| v == code }
    if result_second
      result_first = section
      result_second = result_second.keys[0]
    end
  end
  result = "#{result_first}_#{result_second}".downcase.to_sym
end

Instance Method Details

#conditionObject

Method used to describe the query to cross reference the account on local and Psigate’s servers



129
130
131
132
# File 'lib/ruby_psigate/account.rb', line 129

def condition
  # AccountID, RBCID, RBTrigger, Type, InvoiceNo, Status, SerialNo
  { :AccountID => "123" }
end

#process_hash(result, type) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/ruby_psigate/account.rb', line 71

def process_hash(result, type)
  result.merge!({:Action => action})
        
  if type == :account_register
    result[:Account] = Hash.new
    result[:Account].merge!(:Email => email) unless email.nil?
    result[:Account].merge!({:AccountID => nil})
    result[:Account].merge!(address.to_hash(:account)) unless address.nil?
    result[:Account].merge!({ :CardInfo => cc.to_hash(:card_info) })
  end
  
  if type == :account_update
    result.merge!({:Condition => { :AccountID =>  }})
    result[:Update] = {}
    result[:Update].merge!(address.to_hash(:billing)) unless address.nil?
    result[:Update].merge!(:Email => email) unless email.nil?
    result[:Update].merge!(:Comments => comments) unless comments.nil?
  end
  
  if type == :account_details || type == :account_enable || type == :account_disable
    result.merge!({:Condition => { :AccountID =>  }})
  end

  if type == :credit_card_add
    result[:Account] = Hash.new
    result[:Account].merge!({ :AccountID =>  })
    result[:Account].merge!({:CardInfo => cc.to_hash(:card_info)})
  end
  
  if type == :credit_card_delete || type == :credit_card_enable || type == :credit_card_disable
    result.merge!({:Condition => { :AccountID => , :SerialNo => serial_no }})
  end
  
  if type == :charges_summary
    result[:Condition] = Hash.new
    result.merge!({:Condition => { :AccountID => , :StoreID => store_id }})
    result[:Condition].merge!(rbcharge.to_hash)
  end
  
  if type == :charges_add || type == :charges_immediate
    result[:Charge] = Hash.new
    result[:Charge].merge!({:AccountID => , :SerialNo => serial_no})
    result[:Charge].merge!(rbcharge.to_hash)
  end
  
  if type == :charges_update
    result.merge!({:Condition => { :RBCID => rbcharge.rbcid }})
    result.merge!({:Update => { :RBTrigger => rbcharge.rbtrigger }})
  end
  
  if type == :charges_delete || type == :charges_details || type == :charges_enable || type == :charges_disable
    result.merge!({:Condition => { :RBCID => rbcharge.rbcid }})
  end
  
  result
end

#to_hash(type = nil) ⇒ Object



60
61
62
63
64
65
# File 'lib/ruby_psigate/account.rb', line 60

def to_hash(type=nil)
  type = self.class.action_reverse_lookup(type)
  result = {}
  result = process_hash(result, type)
  result
end