Class: T2Airtime::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/t2_airtime/serializer.rb

Class Method Summary collapse

Class Method Details

.serialize(data, qty = nil) ⇒ Object



145
146
147
148
# File 'lib/t2_airtime/serializer.rb', line 145

def self.serialize(data, qty=nil)
  ids = data[:transaction_list].split(",")
  ids.empty? ? {} : ids.take(qty.nil? ? ids.count : qty).each.map{ |id| show(id) }
end

.serialize_one(t) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/t2_airtime/serializer.rb', line 156

def self.serialize_one(t)
  {
    id: Integer(t[:transactionid]),
    msisdn: t[:msisdn],
    destination_msisdn: t[:destination_msisdn],
    transaction_authentication_key: t[:transaction_authentication_key],
    transaction_error_code: Integer(t[:transaction_error_code]),
    transaction_error_txt: t[:transaction_error_txt],
    country: t[:country],
    country_aid: Integer(t[:countryid]),
    alpha3: T2Airtime::Country.alpha3(t[:country]),
    operator: t[:operator],
    operator_aid: Integer(t[:operatorid]),
    operator_logo_url: T2Airtime::Util.operator_logo_url(t[:operatorid]),  
    reference_operator: t[:reference_operator],
    product_requested: t[:product_requested],
    product_requested_display: T2Airtime::Util.format_price(t[:product_requested], t[:destination_currency]),
    actual_product_sent: t[:actual_product_sent],
    actual_product_sent_display: T2Airtime::Util.format_price(t[:actual_product_sent], t[:destination_currency]),
    wholesale_price: t[:wholesale_price],
    wholesale_price_display: T2Airtime::Util.format_price(t[:wholesale_price], t[:originating_currency]),
    retail_price: t[:retail_price],
    retail_price_display: T2Airtime::Util.format_price(t[:retail_price], t[:originating_currency]),
    sms: t[:sms],
    cid1: t[:cid1],
    cid2: t[:cid2],
    cid3: t[:cid3],
    date: t[:date],
    originating_currency: t[:originating_currency],
    destination_currency: t[:destination_currency],
    pin_based: t[:pin_based],
    local_info_amount: t[:local_info_amount],
    local_info_amount_display: T2Airtime::Util.format_price(t[:local_info_amount], t[:local_info_currency]),
    local_info_currency: t[:local_info_currency],
    local_info_value: t[:local_info_value],
    local_info_value_display: T2Airtime::Util.format_price(t[:local_info_value], t[:local_info_currency]),
    error_code: t[:error_code],
    error_txt: t[:error_txt]
  }
end

.show(id) ⇒ Object



151
152
153
154
# File 'lib/t2_airtime/serializer.rb', line 151

def self.show(id)
    reply = T2Airtime::API.api.trans_info(id)
    reply.success? ? serialize_one(reply.data) : {}
end

.take(start, stop, msisdn = nil, destination = nil, code = nil, qty = 5) ⇒ Object



140
141
142
143
# File 'lib/t2_airtime/serializer.rb', line 140

def self.take(start, stop, msisdn=nil, destination=nil, code=nil, qty=5)
    reply = T2Airtime::API.api.trans_list(start, stop, msisdn, destination, code)
    reply.success? ? serialize(reply.data, qty) : []
end