t2_airtime 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/t2_airtime/topups_controller.rb +66 -0
  3. data/app/controllers/t2_airtime/transactions_controller.rb +1 -1
  4. data/config/routes.rb +3 -0
  5. data/lib/t2_airtime/api.rb +11 -27
  6. data/lib/t2_airtime/serializer.rb +148 -64
  7. data/lib/t2_airtime/version.rb +1 -1
  8. data/spec/dummy/log/development.log +5044 -0
  9. data/spec/dummy/tmp/cache/361/BB0/accounts +0 -0
  10. data/spec/dummy/tmp/cache/3DD/470/countries +0 -0
  11. data/spec/dummy/tmp/cache/4AF/760/products%2F715 +0 -0
  12. data/spec/dummy/tmp/cache/{4E5/5B0/products%2F1972 → 4B0/790/products%2F734} +0 -0
  13. data/spec/dummy/tmp/cache/4DE/490/products%2F1623 +0 -0
  14. data/spec/dummy/tmp/cache/4E6/4F0/products%2F2099 +0 -0
  15. data/spec/dummy/tmp/cache/51A/A70/operators%2F661 +0 -0
  16. data/spec/dummy/tmp/cache/51B/A80/operators%2F662 +0 -0
  17. data/spec/dummy/tmp/cache/51D/AA0/operators%2F664 +0 -0
  18. data/spec/dummy/tmp/cache/63A/8F0/msisdn%2F%2B393801524729 +0 -0
  19. data/spec/dummy/tmp/cache/6A6/C80/msisdn%2F%2B39393801524729 +0 -0
  20. data/spec/dummy/tmp/cache/769/350/accounts%2Fcurrency +1 -1
  21. data/spec/dummy/tmp/cache/78E/3C0/transactions%2F584176053 +0 -0
  22. data/spec/dummy/tmp/cache/7C4/670/products%2Fundefined +0 -0
  23. data/spec/dummy/tmp/cache/8B4/E50/countries%2Fserializer +165 -165
  24. data/spec/dummy/tmp/cache/986/BE0/products%2F715%2Fserializer +7 -0
  25. data/spec/dummy/tmp/cache/987/CE0/products%2F734%2Fserializer +12 -0
  26. data/spec/dummy/tmp/cache/9B5/F40/products%2F1623%2Fserializer +26 -32
  27. data/spec/dummy/tmp/cache/9BD/620/products%2F2099%2Fserializer +23 -0
  28. data/spec/dummy/tmp/cache/9F1/5E0/operators%2F661%2Fserializer +4 -5
  29. data/spec/dummy/tmp/cache/9F2/6C0/operators%2F662%2Fserializer +2 -0
  30. data/spec/dummy/tmp/cache/9F4/880/operators%2F664%2Fserializer +1 -1
  31. data/spec/dummy/tmp/cache/C65/D70/transactions%2F584176053%2Fserializer +0 -0
  32. metadata +29 -132
  33. data/spec/dummy/tmp/cache/446/4A0/products%2F4 +0 -0
  34. data/spec/dummy/tmp/cache/4AD/6A0/products%2F137 +0 -0
  35. data/spec/dummy/tmp/cache/4B2/750/products%2F439 +0 -0
  36. data/spec/dummy/tmp/cache/4DA/3C0/products%2F2105 +0 -0
  37. data/spec/dummy/tmp/cache/4DD/4D0/products%2F2720 +0 -0
  38. data/spec/dummy/tmp/cache/4DE/470/products%2F1524 +0 -0
  39. data/spec/dummy/tmp/cache/4DE/500/products%2F2901 +0 -0
  40. data/spec/dummy/tmp/cache/4DF/460/products%2F2074 +0 -0
  41. data/spec/dummy/tmp/cache/4E0/470/products%2F2075 +0 -0
  42. data/spec/dummy/tmp/cache/4E2/480/products%2F2149 +0 -0
  43. data/spec/dummy/tmp/cache/4E2/500/products%2F1573 +0 -0
  44. data/spec/dummy/tmp/cache/4E4/500/products%2F2448 +0 -0
  45. data/spec/dummy/tmp/cache/4E4/530/products%2F1827 +0 -0
  46. data/spec/dummy/tmp/cache/4E5/570/products%2F1693 +0 -0
  47. data/spec/dummy/tmp/cache/4E7/580/products%2F1767 +0 -0
  48. data/spec/dummy/tmp/cache/4EB/5E0/products%2F1789 +0 -0
  49. data/spec/dummy/tmp/cache/4EB/5F0/products%2F1879 +0 -0
  50. data/spec/dummy/tmp/cache/4EC/610/products%2F1889 +0 -0
  51. data/spec/dummy/tmp/cache/515/9E0/operators%2F701 +0 -0
  52. data/spec/dummy/tmp/cache/518/A50/operators%2F740 +0 -0
  53. data/spec/dummy/tmp/cache/519/A20/operators%2F705 +0 -0
  54. data/spec/dummy/tmp/cache/51C/A90/operators%2F663 +0 -0
  55. data/spec/dummy/tmp/cache/51C/AB0/operators%2F681 +0 -0
  56. data/spec/dummy/tmp/cache/51D/AC0/operators%2F844 +0 -0
  57. data/spec/dummy/tmp/cache/51D/AD0/operators%2F691 +0 -0
  58. data/spec/dummy/tmp/cache/51F/AE0/operators%2F684 +0 -0
  59. data/spec/dummy/tmp/cache/521/AE0/operators%2F668 +0 -0
  60. data/spec/dummy/tmp/cache/521/AF0/operators%2F677 +0 -0
  61. data/spec/dummy/tmp/cache/522/AF0/operators%2F669 +0 -0
  62. data/spec/dummy/tmp/cache/522/B00/operators%2F678 +0 -0
  63. data/spec/dummy/tmp/cache/523/B10/operators%2F679 +0 -0
  64. data/spec/dummy/tmp/cache/523/B50/operators%2F796 +0 -0
  65. data/spec/dummy/tmp/cache/91D/3D0/products%2F4%2Fserializer +0 -17
  66. data/spec/dummy/tmp/cache/984/980/products%2F137%2Fserializer +0 -28
  67. data/spec/dummy/tmp/cache/989/E40/products%2F439%2Fserializer +0 -11
  68. data/spec/dummy/tmp/cache/9B1/B30/products%2F2105%2Fserializer +0 -18
  69. data/spec/dummy/tmp/cache/9B4/EB0/products%2F2720%2Fserializer +0 -19
  70. data/spec/dummy/tmp/cache/9B5/F20/products%2F1524%2Fserializer +0 -14
  71. data/spec/dummy/tmp/cache/9B5/FB0/products%2F2901%2Fserializer +0 -9
  72. data/spec/dummy/tmp/cache/9B6/FE0/products%2F2074%2Fserializer +0 -17
  73. data/spec/dummy/tmp/cache/9B7/0C0/products%2F2075%2Fserializer +0 -17
  74. data/spec/dummy/tmp/cache/9B9/270/products%2F2149%2Fserializer +0 -8
  75. data/spec/dummy/tmp/cache/9B9/2F0/products%2F1573%2Fserializer +0 -56
  76. data/spec/dummy/tmp/cache/9BB/4C0/products%2F1827%2Fserializer +0 -35
  77. data/spec/dummy/tmp/cache/9BC/5D0/products%2F1693%2Fserializer +0 -17
  78. data/spec/dummy/tmp/cache/9BC/610/products%2F1972%2Fserializer +0 -10
  79. data/spec/dummy/tmp/cache/9BE/780/products%2F1767%2Fserializer +0 -27
  80. data/spec/dummy/tmp/cache/9C2/B20/products%2F1789%2Fserializer +0 -52
  81. data/spec/dummy/tmp/cache/9C2/B30/products%2F1879%2Fserializer +0 -28
  82. data/spec/dummy/tmp/cache/9C3/C20/products%2F1889%2Fserializer +0 -46
  83. data/spec/dummy/tmp/cache/9EC/140/operators%2F701%2Fserializer +0 -13
  84. data/spec/dummy/tmp/cache/9EF/420/operators%2F740%2Fserializer +0 -9
  85. data/spec/dummy/tmp/cache/9F0/4C0/operators%2F705%2Fserializer +0 -4
  86. data/spec/dummy/tmp/cache/9F3/7A0/operators%2F663%2Fserializer +0 -4
  87. data/spec/dummy/tmp/cache/9F3/7C0/operators%2F681%2Fserializer +0 -3
  88. data/spec/dummy/tmp/cache/9F4/8A0/operators%2F844%2Fserializer +0 -10
  89. data/spec/dummy/tmp/cache/9F4/8B0/operators%2F691%2Fserializer +0 -8
  90. data/spec/dummy/tmp/cache/9F6/A60/operators%2F684%2Fserializer +0 -2
  91. data/spec/dummy/tmp/cache/9F8/C00/operators%2F668%2Fserializer +0 -4
  92. data/spec/dummy/tmp/cache/9F8/C10/operators%2F677%2Fserializer +0 -5
  93. data/spec/dummy/tmp/cache/9F9/CE0/operators%2F669%2Fserializer +0 -6
  94. data/spec/dummy/tmp/cache/9F9/CF0/operators%2F678%2Fserializer +0 -14
  95. data/spec/dummy/tmp/cache/9FA/DD0/operators%2F679%2Fserializer +0 -4
  96. data/spec/dummy/tmp/cache/9FA/E10/operators%2F796%2Fserializer +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40184e3caa2b4c0f270c5a7942213d4d767c4fc5
4
- data.tar.gz: 1a93efdccc04226c874954fa3f95010cb4e40bae
3
+ metadata.gz: 326cdd5b38f8d1c9749d76ba60268f5d5d7c98d1
4
+ data.tar.gz: '07913bae3db4c8571829ac372aac6a4112472023'
5
5
  SHA512:
6
- metadata.gz: d07b06bf1606067eb0385cace5dbc01d826c7516ea25a63c4f87463a54c57cbc2cd6434afef9882569ff1852968ee376c2e3b108f00103085bdd02742cf840be
7
- data.tar.gz: b38610435a2bcb450b3fa805f77d47ec7927c802a97fadf9419ccf065320fe2a721828006143f8262965818de36f968ea9b40aad75b28a41bc66c05202a93679
6
+ metadata.gz: 28c3c4f9055cbd006ff05b2bd629e874d93162859e25ab7180a463a61aa68028aad04e7d9bcad5da4038f8544bae6b06ebec7e2d6951006b5b617a601161853e
7
+ data.tar.gz: f64ba5dd35a5e8d7ba427526ccc732c5c6049fe9a979bdee67b4e0311b02983eb0bbaef0f6c5caa5cbca09840b79b414dab0b9cef154dc23e8285c18447cf3b6
@@ -0,0 +1,66 @@
1
+ module T2Airtime
2
+ # Help with topup
3
+ class TopupsController < ApplicationController
4
+ def msisdn_info
5
+ @msisdn_info = T2Airtime::Msisdn.info permitted_params[:destination_number]
6
+ if @msisdn_info.success?
7
+ render_data T2Airtime::Msisdn.serialize @msisdn_info.data,
8
+ @msisdn_info.headers[:date]
9
+ else
10
+ render_error T2Airtime::Error.new @msisdn_info.error_code,
11
+ @msisdn_info.error_message
12
+ end
13
+ end
14
+
15
+ def reserve_id
16
+ @reserve_id = T2Airtime::API.api.reserve_id
17
+ if @reserve_id.success?
18
+ render_data @reserve_id.data
19
+ else
20
+ render_error T2Airtime::Error.new @reserve_id.error_code,
21
+ @reserve_id.error_message
22
+ end
23
+ end
24
+
25
+ def topup
26
+ @topup = T2Airtime::API.api.topup permitted_params[:msisdn],
27
+ permitted_params[:destination_number],
28
+ permitted_params[:product],
29
+ permitted_params[:method],
30
+ permitted_params[:reserved_id],
31
+ permitted_params[:send_sms],
32
+ permitted_params[:sms],
33
+ permitted_params[:sender_text],
34
+ permitted_params[:cid1],
35
+ permitted_params[:cid2],
36
+ permitted_params[:cid3]
37
+
38
+ if @topup.success?
39
+ render_data T2Airtime::Topup.serialize @topup.data
40
+ else
41
+ render_error T2Airtime::Error.new @topup.error_code,
42
+ @topup.error_message
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+
49
+ def permitted_params
50
+ params.permit(
51
+ :msisdn,
52
+ :destination_number,
53
+ :product,
54
+ :method,
55
+ :reserved_id,
56
+ :send_sms,
57
+ :sms,
58
+ :sender_text,
59
+ :cid1,
60
+ :cid2,
61
+ :cid3
62
+ )
63
+ end
64
+ end
65
+ end
66
+
@@ -16,7 +16,7 @@ module T2Airtime
16
16
  end
17
17
 
18
18
  def show
19
- @transaction = T2Airtime::API.api.transaction_info(params[:id])
19
+ @transaction = T2Airtime::Transaction.get(params[:id])
20
20
  if @transaction.success?
21
21
  render_data T2Airtime::Transaction.serialize_one @transaction.data,
22
22
  @transaction.headers[:date]
data/config/routes.rb CHANGED
@@ -4,4 +4,7 @@ T2Airtime::Engine.routes.draw do
4
4
  resources :operators, only: %i[index show]
5
5
  resources :products, only: [:index]
6
6
  resources :transactions, only: %i[index show]
7
+ get "msisdn_info", to: "topups#msisdn_info"
8
+ get "reserve_id", to: "topups#reserve_id"
9
+ post "topup", to: "topups#topup"
7
10
  end
@@ -75,7 +75,9 @@ module T2Airtime
75
75
  # “sms” of the topup method.
76
76
 
77
77
  def topup(msisdn, destination_msisdn, product, method = 'topup',
78
- reserved_id = nil, send_sms = true, sms = nil, sender_text = nil, operator_id = nil,
78
+ reserved_id = nil, send_sms = true, sms = nil, sender_text = nil,
79
+ cid1 = '', cid2 = '', cid3 = '',
80
+ operator_id = nil,
79
81
  return_service_fee = 1, delivered_amount_info = 1, return_timestamp = 1, return_version = 1,
80
82
  return_promo = 0)
81
83
 
@@ -86,7 +88,7 @@ module T2Airtime
86
88
  }
87
89
  self.oid = operator_id
88
90
 
89
- @params.merge(cid1: '', cid2: '', cid3: '',
91
+ @params.merge(cid1: cid1, cid2: cid2, cid3: cid3,
90
92
  reserved_id: reserved_id,
91
93
  sender_sms: (sender_text ? 'yes' : 'no'),
92
94
  send_sms: (send_sms ? 'yes' : 'no'),
@@ -99,26 +101,6 @@ module T2Airtime
99
101
  return_promo: return_promo)
100
102
 
101
103
  run_action method
102
- # {
103
- # requesting_msisdn: response[:msisdn],
104
- # destination_msisdn: response[:destination_msisdn],
105
- # product_sent: response[:actual_product_sent].to_i,
106
- # local_amount: response[:local_info_amount],
107
- # local_value: response[:local_info_value],
108
- # local_currency_code: response[:local_info_currency],
109
- # transaction_status: response[:error_txt],
110
- # operation_result: response[:error_code],
111
- # operation_info: response[:info_txt],
112
- # transaction_api_id: response[:transactionid].to_i,
113
- # country_api_id: response[:countryid].to_i,
114
- # operator_api_id: response[:operatorid].to_i,
115
- # product_api_id: response[:product_requested].to_i,
116
- # originator_currency_code: response[:originating_currency],
117
- # destination_currency_code: response[:destination_currency],
118
- # wholesale_price: response[:wholesale_price],
119
- # retail_price: response[:retail_price],
120
- # service_fee: response[:service_fee]
121
- # }
122
104
  end
123
105
 
124
106
  # This method is used to retrieve various information of a specific MSISDN
@@ -194,11 +176,13 @@ module T2Airtime
194
176
  # ---------
195
177
  # Defines the end date of the search (included). Format must be YYYY-MM-DD.
196
178
  def transaction_list(start = (Time.now - 24.hours), stop = Time.now, msisdn = nil, destination = nil, code = nil)
197
- @params[:code] = code unless code
198
- @params[:msisdn] = msisdn unless msisdn
199
- @params[:stop_date] = to_yyyymmdd(stop)
200
- @params[:start_date] = to_yyyymmdd(start)
201
- @params[:destination_msisdn] = destination unless destination
179
+ @params = {
180
+ stop_date: to_yyyymmdd(stop),
181
+ start_date: to_yyyymmdd(start)
182
+ }
183
+ code && !code.empty? && @params[:code] = code
184
+ msisdn && !msisdn.empty? && @params[:msisdn] = msisdn
185
+ destination && !destination.empty? && @params[:destination_msisdn] = destination
202
186
  run_action :trans_list
203
187
  end
204
188
 
@@ -1,4 +1,69 @@
1
1
  module T2Airtime
2
+
3
+ class Topup
4
+
5
+ def self.serialize(data, ts = Time.zone.now.to_s)
6
+ {
7
+ type: 'topup',
8
+ balance: data[:balance],
9
+ balanceDisplay: "#{Money.new(Integer(data[:balance]) * 100, Account.currency).format}",
10
+ msisdn: data[:destination_msisdn],
11
+ destinationMsisdn: data[:destination_msisdn],
12
+ transactionId: data[:transactionid],
13
+ transactionAuthenticationKey: data[:authentication_key],
14
+ transactionErrorCode: Integer(data[:error_code]),
15
+ transactionErrorTxt: data[:error_txt],
16
+ referenceOperator: data[:reference_operator],
17
+ actualProductSent: data[:actual_product_sent],
18
+ sms: data[:sms],
19
+ smsSent: data[:sms_sent],
20
+ cid1: data[:cid1],
21
+ cid2: data[:cid2],
22
+ cid3: data[:cid3],
23
+ currency: data[:originating_currency],
24
+ localCurrency: data[:destination_currency],
25
+ countryId: Integer(data[:countryid]),
26
+ countryName: data[:country],
27
+ operatorId: Integer(data[:operatorid]),
28
+ operatorName: data[:operator],
29
+ operatorLogo: T2Airtime::Util.operator_logo_url(data[:operatorid]),
30
+ productName: "#{Money.new(Integer(data[:product_requested]) * 100, data[:destination_currency]).format}",
31
+ productLocalCurrency: data[:destination_currency],
32
+ productLocalCurrencySymbol: Money::Currency.new(data[:destination_currency]).symbol,
33
+ productCurrency: Account.currency,
34
+ productCurrencySymbol: Money::Currency.new(Account.currency).symbol,
35
+ productLocalPrice: Float(data[:product_requested]),
36
+ productRetailPrice: Float(data[:retail_price]),
37
+ productWholesalePrice: Float(data[:wholesale_price]),
38
+ executedAt: T2Airtime::Util.format_time(ts)
39
+ }
40
+ end
41
+
42
+ end
43
+
44
+
45
+ class Msisdn
46
+
47
+ def self.info(msisdn)
48
+ Rails.cache.fetch("msisdn/#{msisdn}", expires_in: 24.hours) do # cache the result for 1 day
49
+ T2Airtime::API.api.msisdn_info(msisdn)
50
+ end
51
+ end
52
+
53
+ def self.serialize(data, ts = Time.zone.now.to_s)
54
+ {
55
+ type: 'msisdn',
56
+ msisdn: data[:destination_msisdn],
57
+ country: data[:country],
58
+ countryId: data[:countryid],
59
+ operator: data[:operator],
60
+ operatorId: data[:operatorid],
61
+ fetchedAt: T2Airtime::Util.format_time(ts)
62
+ }
63
+ end
64
+
65
+ end
66
+
2
67
  class Account
3
68
  def self.get
4
69
  Rails.cache.fetch('accounts', expires_in: 1.hour) do
@@ -7,8 +72,9 @@ module T2Airtime
7
72
  end
8
73
 
9
74
  def self.currency
10
- Rails.cache.fetch('accounts/currency', expires_in: 24.hours) do
11
- serialize(get.data)["attributes"]["currency"]
75
+ account = serialize(get.data)
76
+ Rails.cache.fetch('accounts/currency', expires_in: 24.hours) do # cache the result for 1 day
77
+ account[:attributes][:currency]
12
78
  end
13
79
  end
14
80
 
@@ -56,6 +122,7 @@ module T2Airtime
56
122
  attributes: {
57
123
  name: names[n],
58
124
  alpha3: alpha3(names[n]),
125
+ callingCode: calling_code(alpha3(names[n])),
59
126
  fetchedAt: T2Airtime::Util.format_time(ts)
60
127
  }
61
128
  }
@@ -92,6 +159,17 @@ module T2Airtime
92
159
  name: name
93
160
  )
94
161
  end
162
+
163
+ def self.calling_code(alpha3)
164
+ country_code = case alpha3
165
+ when 'PCN'
166
+ '64'
167
+ when 'ATF'
168
+ '262'
169
+ end
170
+ country_code || ISO3166::Country.find_country_by_alpha3(alpha3).try(:country_code)
171
+ end
172
+
95
173
  end
96
174
 
97
175
  class Operator
@@ -153,9 +231,7 @@ module T2Airtime
153
231
  def self.take(operator_qty = 1, qty = 5)
154
232
  operators = T2Airtime::Operator.take(operator_qty).shuffle
155
233
  unless operators.empty?
156
- operators.flat_map do |operator| (
157
-
158
-
234
+ operators.flat_map do |operator| (
159
235
  products = all(operator['id'])
160
236
  products.success? ? serialize(products.data, products.headers[:date], qty) : []
161
237
  )
@@ -222,73 +298,81 @@ module T2Airtime
222
298
  ids.take(qty.nil? ? ids.count : qty).each.map { |id| show(id) }
223
299
  end
224
300
 
301
+ def self.get(id)
302
+ Rails.cache.fetch("transactions/#{id}", expires_in: 365.days) do # once we've got it, no need to refetch
303
+ T2Airtime::API.api.transaction_info(id)
304
+ end
305
+ end
306
+
225
307
  def self.show(id)
226
- reply = T2Airtime::API.api.transaction_info(id)
227
- reply.success? ? serialize_one(reply.data, reply.headers[:date]) : {}
308
+ transaction = get(id)
309
+ transaction.success? ? serialize_one(transaction.data, transaction.headers[:date]) : {}
228
310
  end
229
311
 
230
312
  def self.serialize_one(data, ts = Time.zone.now.to_s)
231
- {
232
- type: 'transactions',
233
- id: Integer(data[:transactionid]),
234
- attributes: {
235
- msisdn: data[:msisdn],
236
- destinationMsisdn: data[:destination_msisdn],
237
- transactionAuthenticationKey: data[:transaction_authentication_key],
238
- transactionErrorCode: Integer(data[:transaction_error_code]),
239
- transactionErrorTxt: data[:transaction_error_txt],
240
- referenceOperator: data[:reference_operator],
241
- actualProductSent: data[:actual_product_sent],
242
- sms: data[:sms],
243
- cid1: data[:cid1],
244
- cid2: data[:cid2],
245
- cid3: data[:cid3],
246
- date: data[:date],
247
- currency: data[:originating_currency],
248
- localCurrency: data[:destination_currency],
249
- pinBased: data[:pin_based],
250
- localInfoAmount: data[:local_info_amount],
251
- localInfoCurrency: data[:local_info_currency],
252
- localInfoValue: data[:local_info_value],
253
- errorCode: data[:error_code],
254
- errorTxt: data[:error_txt],
255
- countryId: Integer(data[:countryid]),
256
- countryName: data[:country],
257
- countryAlpha3: T2Airtime::Country.alpha3(data[:country]),
258
- operatorId: Integer(data[:operatorid]),
259
- operatorName: data[:operator],
260
- operatorLogo: T2Airtime::Util.operator_logo_url(data[:operatorid]),
261
- productName: "#{Money.new(Integer(data[:product_requested]) * 100, data[:destination_currency]).format}",
262
- productLocalCurrency: data[:destination_currency],
263
- productLocalCurrencySymbol: Money::Currency.new(data[:destination_currency]).symbol,
264
- productCurrency: Account.currency,
265
- productCurrencySymbol: Money::Currency.new(Account.currency).symbol,
266
- productLocalPrice: Float(data[:product_requested]),
267
- productRetailPrice: Float(data[:retail_price]),
268
- productWholesalePrice: Float(data[:wholesale_price]),
269
- fetchedAt: T2Airtime::Util.format_time(ts)
270
- },
271
- relationships: {
272
- country: {
273
- data: {
274
- type: 'countries',
275
- id: Integer(data[:countryid])
276
- }
277
- },
278
- operator: {
279
- data: {
280
- type: 'operators',
281
- id: Integer(data[:operatorid])
282
- }
313
+ Rails.cache.fetch("transactions/#{data[:transactionid]}/serializer", expires_in: 365.hour) do
314
+ {
315
+ type: 'transactions',
316
+ id: Integer(data[:transactionid]),
317
+ attributes: {
318
+ msisdn: data[:msisdn],
319
+ destinationMsisdn: data[:destination_msisdn],
320
+ transactionAuthenticationKey: data[:transaction_authentication_key],
321
+ transactionErrorCode: Integer(data[:transaction_error_code]),
322
+ transactionErrorTxt: data[:transaction_error_txt],
323
+ referenceOperator: data[:reference_operator],
324
+ actualProductSent: data[:actual_product_sent],
325
+ sms: data[:sms],
326
+ cid1: data[:cid1],
327
+ cid2: data[:cid2],
328
+ cid3: data[:cid3],
329
+ date: data[:date],
330
+ currency: data[:originating_currency],
331
+ localCurrency: data[:destination_currency],
332
+ pinBased: data[:pin_based],
333
+ localInfoAmount: data[:local_info_amount],
334
+ localInfoCurrency: data[:local_info_currency],
335
+ localInfoValue: data[:local_info_value],
336
+ errorCode: data[:error_code],
337
+ errorTxt: data[:error_txt],
338
+ countryId: Integer(data[:countryid]),
339
+ countryName: data[:country],
340
+ countryAlpha3: T2Airtime::Country.alpha3(data[:country]),
341
+ operatorId: Integer(data[:operatorid]),
342
+ operatorName: data[:operator],
343
+ operatorLogo: T2Airtime::Util.operator_logo_url(data[:operatorid]),
344
+ productName: "#{Money.new(Integer(data[:product_requested]) * 100, data[:destination_currency]).format}",
345
+ productLocalCurrency: data[:destination_currency],
346
+ productLocalCurrencySymbol: Money::Currency.new(data[:destination_currency]).symbol,
347
+ productCurrency: Account.currency,
348
+ productCurrencySymbol: Money::Currency.new(Account.currency).symbol,
349
+ productLocalPrice: Float(data[:product_requested]),
350
+ productRetailPrice: Float(data[:retail_price]),
351
+ productWholesalePrice: Float(data[:wholesale_price]),
352
+ fetchedAt: T2Airtime::Util.format_time(ts)
283
353
  },
284
- product: {
285
- data: {
286
- type: 'products',
287
- id: Integer(data[:product_requested])
354
+ relationships: {
355
+ country: {
356
+ data: {
357
+ type: 'countries',
358
+ id: Integer(data[:countryid])
359
+ }
360
+ },
361
+ operator: {
362
+ data: {
363
+ type: 'operators',
364
+ id: Integer(data[:operatorid])
365
+ }
366
+ },
367
+ product: {
368
+ data: {
369
+ type: 'products',
370
+ id: Integer(data[:product_requested])
371
+ }
288
372
  }
289
373
  }
290
374
  }
291
- }
375
+ end
292
376
  end
293
377
  end
294
378
  end
@@ -1,3 +1,3 @@
1
1
  module T2Airtime
2
- VERSION = '0.3.1'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end