Class: Vend::Airtime

Inherits:
Base
  • Object
show all
Defined in:
lib/airvend/airvend_objects/airtime.rb

Instance Method Summary collapse

Methods inherited from Base

#connect, #get_plans, #initialize, #mno_id, #power_id, #produce_error, #provider_id, #rename_hash, #tv_id, #underscorelize, #verify_customer

Constructor Details

This class inherits a constructor from Base

Instance Method Details

#buy(payload) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/airvend/airvend_objects/airtime.rb', line 6

def buy(payload)
  params_hash = { 'ref'=> payload[:ref], 'account'=> payload[:phone], 'networkid'=> mno_id(payload[:mno]), 'type'=> "1", 'amount'=> payload[:amount] }
  details = {}
  details.merge!({ 'details'=>params_hash })
  api_hash = @airvendObj.hash_req(details)
  response = vendAdapter(api_hash, details)
  if response.status == 200
     hash = rename_hash(JSON.parse(response.body, { symbolize_names: true }))
     rename_hash(hash[:details])
     hash
   else
     produce_error(response)
   end
end