Class: Megam::Billingtransactions

Inherits:
RestAdapter show all
Defined in:
lib/megam/core/billingtransactions.rb

Instance Attribute Summary

Attributes inherited from RestAdapter

#api_key, #email, #headers, #host, #master_key, #org_id, #password_hash

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RestAdapter

#megam_rest

Constructor Details

#initialize(o) ⇒ Billingtransactions

Returns a new instance of Billingtransactions.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/megam/core/billingtransactions.rb', line 3

def initialize(o)
    @id = nil
    @accounts_id = nil
    @gateway = nil
    @amountin = nil
    @amountout = nil
    @fees = nil
    @tranid = nil
    @trandate = nil
    @currency_type = nil
    @created_at = nil
    @some_msg = {}
    super(o)
end

Class Method Details

.create(params) ⇒ Object



194
195
196
197
# File 'lib/megam/core/billingtransactions.rb', line 194

def self.create(params)
    acct = from_hash(params)
    acct.create
end

.from_hash(o) ⇒ Object



174
175
176
177
178
# File 'lib/megam/core/billingtransactions.rb', line 174

def self.from_hash(o)
    bal = self.new(o)
    bal.from_hash(o)
    bal
end

.json_create(o) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/megam/core/billingtransactions.rb', line 154

def self.json_create(o)
    bal = new({})
    bal.id(o["id"]) if o.has_key?("id")
    bal.accounts_id(o["accounts_id"]) if o.has_key?("accounts_id")
    bal.gateway(o["gateway"]) if o.has_key?("gateway")
    bal.amountin(o["amountin"]) if o.has_key?("amountin")
    bal.amountout(o["amountout"]) if o.has_key?("amountout")
    bal.fees(o["fees"]) if o.has_key?("fees")
    bal.tranid(o["tranid"]) if o.has_key?("tranid")
    bal.trandate(o["trandate"]) if o.has_key?("trandate")
    bal.currency_type(o["currency_type"]) if o.has_key?("currency_type")
    bal.created_at(o["created_at"]) if o.has_key?("created_at")
    #success or error
    bal.some_msg[:code] = o["code"] if o.has_key?("code")
    bal.some_msg[:msg_type] = o["msg_type"] if o.has_key?("msg_type")
    bal.some_msg[:msg]= o["msg"] if o.has_key?("msg")
    bal.some_msg[:links] = o["links"] if o.has_key?("links")
    bal
end

.list(params) ⇒ Object



203
204
205
206
# File 'lib/megam/core/billingtransactions.rb', line 203

def self.list(params)
    bill = self.new(params)
    bill.megam_rest.get_billingtransactions
end

Instance Method Details

#accounts_id(arg = nil) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/megam/core/billingtransactions.rb', line 30

def accounts_id(arg=nil)
    if arg != nil
        @accounts_id= arg
    else
        @accounts_id
    end
end

#amountin(arg = nil) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/megam/core/billingtransactions.rb', line 46

def amountin(arg=nil)
    if arg != nil
        @amountin= arg
    else
        @amountin
    end
end

#amountout(arg = nil) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/megam/core/billingtransactions.rb', line 54

def amountout(arg=nil)
    if arg != nil
        @amountout= arg
    else
        @amountout
    end
end

#createObject



199
200
201
# File 'lib/megam/core/billingtransactions.rb', line 199

def create
    megam_rest.post_billedhistories(to_hash)
end

#created_at(arg = nil) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/megam/core/billingtransactions.rb', line 94

def created_at(arg=nil)
    if arg != nil
        @created_at = arg
    else
        @created_at
    end
end

#currency_type(arg = nil) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/megam/core/billingtransactions.rb', line 86

def currency_type(arg=nil)
    if arg != nil
        @currency_type = arg
    else
        @currency_type
    end
end

#error?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/megam/core/billingtransactions.rb', line 110

def error?
    crocked  = true if (some_msg.has_key?(:msg_type) && some_msg[:msg_type] == "error")
end

#fees(arg = nil) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/megam/core/billingtransactions.rb', line 62

def fees(arg=nil)
    if arg != nil
        @fees = arg
    else
        @fees
    end
end

#for_jsonObject



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/megam/core/billingtransactions.rb', line 137

def for_json
    result = {
        "id" => id,
        "accounts_id" => accounts_id,
        "gateway" => gateway,
        "amountin" => amountin,
        "amountout" => amountout,
        "fees" => fees,
        "tranid" => tranid,
        "trandate" => trandate,
        "currency_type" => currency_type,
        "created_at" => created_at
    }
    result
end

#from_hash(o) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/megam/core/billingtransactions.rb', line 180

def from_hash(o)
    @id            = o[:id] if o.has_key?(:id)
    @accounts_id   = o[:accounts_id] if o.has_key?(:accounts_id)
    @gateway       = o[:gateway] if o.has_key?(:gateway)
    @amountin      = o[:amountin] if o.has_key?(:amountin)
    @amountout     = o[:amountout] if o.has_key?(:amountout)
    @fees          = o[:fees] if o.has_key?(:fees)
    @tranid        = o[:tranid] if o.has_key?(:tranid)
    @trandate      = o[:trandate] if o.has_key?(:trandate)
    @currency_type = o[:currency_type] if o.has_key?(:currency_type)
    @created_at    = o[:created_at] if o.has_key?(:created_at)
    self
end

#gateway(arg = nil) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/megam/core/billingtransactions.rb', line 38

def gateway(arg=nil)
    if arg != nil
        @gateway= arg
    else
        @gateway
    end
end

#id(arg = nil) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/megam/core/billingtransactions.rb', line 22

def id(arg=nil)
    if arg != nil
        @id = arg
    else
        @id
    end
end

#selfObject



18
19
20
# File 'lib/megam/core/billingtransactions.rb', line 18

def
    self
end

#some_msg(arg = nil) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/megam/core/billingtransactions.rb', line 102

def some_msg(arg=nil)
    if arg != nil
        @some_msg = arg
    else
        @some_msg
    end
end

#to_hashObject

Transform the ruby obj -> to a Hash



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/megam/core/billingtransactions.rb', line 115

def to_hash
    index_hash = Hash.new
    index_hash["json_claz"] = self.class.name
    index_hash["id"] = id
    index_hash["accounts_id"] = accounts_id
    index_hash["gateway"] = gateway
    index_hash["amountin"] = amountin
    index_hash["amountout"] = amountout
    index_hash["fees"] = fees
    index_hash["tranid"] = tranid
    index_hash["trandate"] = trandate
    index_hash["currency_type"] = currency_type
    index_hash["created_at"] = created_at
    index_hash
end

#to_json(*a) ⇒ Object

Serialize this object as a hash: called from JsonCompat. Verify if this called from JsonCompat during testing.



133
134
135
# File 'lib/megam/core/billingtransactions.rb', line 133

def to_json(*a)
    for_json.to_json(*a)
end

#to_sObject



209
210
211
# File 'lib/megam/core/billingtransactions.rb', line 209

def to_s
    Megam::Stuff.styled_hash(to_hash)
end

#trandate(arg = nil) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/megam/core/billingtransactions.rb', line 78

def trandate(arg=nil)
    if arg != nil
        @trandate = arg
    else
        @trandate
    end
end

#tranid(arg = nil) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/megam/core/billingtransactions.rb', line 70

def tranid(arg=nil)
    if arg != nil
        @tranid = arg
    else
        @tranid
    end
end