Class: T2Airtime::API
Instance Method Summary collapse
-
#check_wallet ⇒ Object
Returns the balance in your TransferTo account.
-
#country_list ⇒ Object
Convenience method to get the country list.
-
#get_id_from_key(key) ⇒ Object
This method is used to retrieve the ID of a transaction previously performed based on the key used in the request at that time.
-
#msisdn_info(destination_msisdn, operator_id = nil, delivered_amount_info = 1, return_service_fee = 1, return_promo = 1) ⇒ Object
This method is used to retrieve various information of a specific MSISDN (operator, country…) as well as the list of all products configured for your specific account and the destination operator of the MSISDN.
-
#operator_list(country_aid) ⇒ Object
Convenience method to get the operators list for a given country.
-
#ping ⇒ Object
Test the connection to the Airtime API.
-
#price_list(info_type, content = nil) ⇒ Object
These methods are used to retrieve coverage and pricelist offered to you.
-
#product_list(operator_aid) ⇒ Object
Convenience method to get the product list for a given operator.
-
#reserve_id ⇒ Object
This method is used to reserve an ID in the system.
-
#topup(msisdn, destination_msisdn, product, method = 'topup', reserved_id = nil, send_sms = true, sms = nil, sender_text = nil, operator_id = nil, return_service_fee = 1, delivered_amount_info = 1, return_timestamp = 1, return_version = 1, return_promo = 0) ⇒ Object
By default, an SMS notification is sent to the recipient after every successful Top-up.
-
#trans_info(id) ⇒ Object
Retrieve available information on a specific transaction.
-
#trans_list(start = (Time.now-24.hours), stop = Time.now, msisdn = nil, destination = nil, code = nil) ⇒ Object
This method is used to retrieve the list of transactions performed within the date range by the MSISDN if set.
Methods inherited from Base
Constructor Details
This class inherits a constructor from T2Airtime::Base
Instance Method Details
#check_wallet ⇒ Object
Returns the balance in your TransferTo account. This method shall not be used more than 24 times per day.
11 12 13 |
# File 'lib/t2_airtime/api.rb', line 11 def check_wallet run_action :check_wallet end |
#country_list ⇒ Object
Convenience method to get the country list
245 |
# File 'lib/t2_airtime/api.rb', line 245 def country_list() price_list('countries') end |
#get_id_from_key(key) ⇒ Object
This method is used to retrieve the ID of a transaction previously performed based on the key used in the request at that time.
219 220 221 222 |
# File 'lib/t2_airtime/api.rb', line 219 def get_id_from_key(key) @params = { from_key: key } run_action :get_id_from_key end |
#msisdn_info(destination_msisdn, operator_id = nil, delivered_amount_info = 1, return_service_fee = 1, return_promo = 1) ⇒ Object
This method is used to retrieve various information of a specific MSISDN (operator, country…) as well as the list of all products configured for your specific account and the destination operator of the MSISDN. Returns relevant information on a MSISDN (operator, country…) as well as the list of products configured for your account and the destination operator linked to that MSISDN. Allows to check if a MSISDN is subjected to a promotion
destination_msisdn Destination MSISDN (usually recipient phone number). This is the destination phone number that will be credited with the amount transferred. Format is similar to “msisdn” and restricted to international phone number only.
delivered_amount_info Setting this to “1” will return the fields local_info_amount_list,local_info_currency and local_info_value_list in the API response. Blank or “no” if you do not want this returned. return_service_fee Setting this to “1” will return the field service_fee_list in the API response. Blank or “0” if you do not want it returned. operatorid Operator ID of the receiving operator that must be used when treating the request. If set, the platform will be forced to use this operator ID and will not identify the operator of the destination MSISDN based on the numbering plan. It is very useful in case of countries with number portability if you are able to know the destination operator.
return_promo Setting this to “1” will return the current promotion related to the transaction’s operator.
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/t2_airtime/api.rb', line 149 def msisdn_info(destination_msisdn, operator_id=nil, delivered_amount_info=1, return_service_fee=1, return_promo=1) @params = { destination_msisdn: destination_msisdn, delivered_amount_info: delivered_amount_info, return_service_fee: return_service_fee, return_promo: return_promo } self.oid = operator_id run_action :msisdn_info end |
#operator_list(country_aid) ⇒ Object
Convenience method to get the operators list for a given country
249 |
# File 'lib/t2_airtime/api.rb', line 249 def operator_list(country_aid) price_list('country', country_aid) end |
#ping ⇒ Object
Test the connection to the Airtime API. Can be used for keep-alive.
5 6 7 |
# File 'lib/t2_airtime/api.rb', line 5 def ping run_action :ping end |
#price_list(info_type, content = nil) ⇒ Object
These methods are used to retrieve coverage and pricelist offered to you. parameters
info_type
i) “countries”: Returns a list of all countries offered to you
ii) “country” : Returns a list of operators in the country
iii) “operator” : Returns a list of wholesale and retail price for the operator
content
i) Not used if info_type = “countries”
ii) countryid of the requested country if info_type = “country”
iii) operatorid of the requested operator if info_type = “operator”
238 239 240 241 242 |
# File 'lib/t2_airtime/api.rb', line 238 def price_list(info_type, content=nil) @params[:info_type] = info_type content && @params[:content] = content run_action :pricelist end |
#product_list(operator_aid) ⇒ Object
Convenience method to get the product list for a given operator
253 |
# File 'lib/t2_airtime/api.rb', line 253 def product_list(operator_aid) price_list('operator', operator_aid) end |
#reserve_id ⇒ Object
This method is used to reserve an ID in the system. This ID can then be used in the “topup” or “simulation” requests. This way, your system knows the ID of the transaction before sending the request to TransferTo (else it will only be displayed in the response).
166 167 168 |
# File 'lib/t2_airtime/api.rb', line 166 def reserve_id run_action :reserve_id end |
#topup(msisdn, destination_msisdn, product, method = 'topup', reserved_id = nil, send_sms = true, sms = nil, sender_text = nil, operator_id = nil, return_service_fee = 1, delivered_amount_info = 1, return_timestamp = 1, return_version = 1, return_promo = 0) ⇒ Object
By default, an SMS notification is sent to the recipient after every successful Top-up. The default originating address for the SMS is “8888”. The following is the default SMS which is translated into local languages for most of recipient countries: Congratulations! You've received AMOUNT_CURRENCY from SENDER. Thank you for using TransferTo. FREE_TEXT. • AMOUNT CURRENCY is the amount that has been sent with the currency. • SENDER can be a name or a phone number. • FREE_TEXT is the content of the field named “sms” of the topup method.
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 |
# File 'lib/t2_airtime/api.rb', line 78 def topup(msisdn, destination_msisdn, product, method='topup', reserved_id=nil, send_sms=true, sms=nil, sender_text=nil, operator_id=nil, return_service_fee=1, delivered_amount_info=1, =1, return_version=1, return_promo=0) @params = { msisdn: msisdn, destination_msisdn: destination_msisdn, product: product } self.oid = operator_id @params.merge({ cid1: "", cid2: "", cid3: "", reserved_id: reserved_id, sender_sms: (sender_text ? "yes" : "no"), send_sms: (send_sms ? "yes" : "no"), sms: sms, sender_text: sender_text, delivered_amount_info: delivered_amount_info, return_service_fee: return_service_fee, return_timestamp: , return_version: return_version, return_promo: return_promo }) run_action method #{ # requesting_msisdn: response[:msisdn], # destination_msisdn: response[:destination_msisdn], # product_sent: response[:actual_product_sent].to_i, # local_amount: response[:local_info_amount], # local_value: response[:local_info_value], # local_currency_code: response[:local_info_currency], # transaction_status: response[:error_txt], # operation_result: response[:error_code], # operation_info: response[:info_txt], # transaction_api_id: response[:transactionid].to_i, # country_api_id: response[:countryid].to_i, # operator_api_id: response[:operatorid].to_i, # product_api_id: response[:product_requested].to_i, # originator_currency_code: response[:originating_currency], # destination_currency_code: response[:destination_currency], # wholesale_price: response[:wholesale_price], # retail_price: response[:retail_price], # service_fee: response[:service_fee] #} end |
#trans_info(id) ⇒ Object
Retrieve available information on a specific transaction. Please note that values of “input_value” and “debit_amount_validated” are rounded to 2 digits after the comma but are the same as the values returned in the fields “input_value” and “validated_input_value” of the “topup” method response.
212 213 214 215 |
# File 'lib/t2_airtime/api.rb', line 212 def trans_info(id) @params = { transactionid: id } run_action :trans_info end |
#trans_list(start = (Time.now-24.hours), stop = Time.now, msisdn = nil, destination = nil, code = nil) ⇒ Object
This method is used to retrieve the list of transactions performed within the date range by the MSISDN if set. Note that both dates are included during the search.
parameters
msisdn
The format must be international with or without the ‘+’ or ‘00’: “6012345678” or “+6012345678” or “006012345678” (Malaysia)
destination_msisdn
The format must be international with or without the ‘+’ or ‘00’: “6012345678” or “+6012345678” or “006012345678” (Malaysia)
code
The error_code of the transactions to search for. E.g “0” to search for only all successful transactions. If left empty, all transactions will be returned(Failed and successful).
start_date
Defines the start date of the search. Format must be YYYY-MM-DD.
stop_date
Defines the end date of the search (included). Format must be YYYY-MM-DD.
199 200 201 202 203 204 205 206 |
# File 'lib/t2_airtime/api.rb', line 199 def trans_list(start=(Time.now-24.hours), stop=Time.now, msisdn=nil, destination=nil, code=nil) @params[:code] = code unless code @params[:msisdn] = msisdn unless msisdn @params[:stop_date] = to_yyyymmdd(stop) @params[:start_date] = to_yyyymmdd(start) @params[:destination_msisdn] = destination unless destination run_action :trans_list end |