# Ruby Gem for IDT Beyond [![Join the chat at https://gitter.im/IDTLabs/IDTBeyond-Ruby](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/IDTLabs/IDTBeyond-Ruby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) The official node package for interacting with the IDT Beyond API. ## Getting started with IDT Beyond To use this service, sign up for a free account at: [https://portal.idtbeyond.com](https://portal.idtbeyond.com), or read the documentation at [https://portal.idtbeyond.com/docs](https://portal.idtbeyond.com/docs). ## Requirements - bundler - ruby 2.2.1 ## Setup your environment 1. Make sure above requirements are fulfilled. (see site documentation in links above) 2. run `npm install idtbeyond --save` to add this module to your project ## Testing Running `rake spec` will run the unit tests with RSpec 3.x. ## Contributing 1. Fork it ( https://github.com/[my-github-username]/idtbeyond/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am "Add some feature"`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request ## Usage ```ruby require "idtbeyond" ``` ```ruby idtbeyond_iatu = IDTBeyond::Service::IATU.new "app-id", "app-key", "term-id" ``` ####Parameters Parameter | Required | Type | Description --------- | ------- | ----- | ----------- app-id | true | string | Application ID. app-key | true | string | Application Key. term-id | true | string | Terminal name for the environment serving the application. ## API Status This returns the status of the IDT Beyond API. **Request:** ```ruby idtbeyond_iatu.get_status ``` **Response:** ```json { "alive":true } ``` ## Get all products This endpoint retrieves a current list of products offered by our IATU API. **Request:** ```ruby idtbeyond_iatu.get_products ``` ```json [ { "country":"Guatemala", "country_code":"GT", "carrier":"Tigo", "carrier_code":"Tigo", "mask":"502-XXXX-XXXX", "denomination":700, "minDenomination":700, "maxDenomination":700, "commission":"10" }, { "country":"Argentina", "country_code":"AR", "carrier":"Movistar", "carrier_code":"Movistar", "mask":"54-XXXX-XXX-XXXX", "denomination":700, "minDenomination":700, "maxDenomination":700, "commission":"14.50" } ] ``` ## Local Value Get the local value of a particular product. ### Example: `idtbeyond_iatu.get_local_value amount, "carrier_code", "country_code", "currency_code"` **Request:** ```ruby idtbeyond_iatu.get_local_value "500", Claro, "GT", "USD" ``` **Response:** ```json { "carrier_code":"Claro", "country_code":"GT", "amount":"500", "currency_code":"USD", "local_currency":"GTQ", "local_amount":"3965", "divisor":"100" } ``` ####Parameters Parameter | Required | Type | Description --------- | ------- | ----- | ----------- country_code | true | string | 2-digit code of the country in ISO 3166 format. Ex: CO for Columbia. carrier_code | true | string | Name of the mobile carrier. Ex: Tigo currency_code | true | string | The currency code (ISO 4217) on the product you are querying. Ex: USD amount | true | integer | The amount of the product you would like to get the value of. Ex: 1000 = $10.00 (in cents). ## Balance This call allows you get the balance on a specific application. **Request:** ```ruby idtbeyond_iatu.get_balance ``` **Response:** ```json { "balance":986834, "currency_code":"USD", "currency_symbol":"$", "currency_divisor":100 } ``` ## Topup This is how you topup a phone in another country. ### Example: `idtbeyond_iatu.post_topup "amount", "carrier_code", "country_code", "mobile_number"` **Request:** ```ruby idtbeyond_iatu.post_topup "1000", "Claro", "GT", "50212345678" ``` **Response:** ```json { "success":true, "client_transaction_id":"trans_id_12345", "transaction_id":"123345678", "amount":1000, "currency_divisor":"100", "currency_symbol":"$", "wholesaler_balance":0, "wholesaler_commission":100, "local_amount":7934, "local_currency":"GTQ", "local_divisor":"100", "plan":"Sandbox", "terminal_id":"kiosk 12", "carrier_code":"Claro", "country_code":"GT", "country_name":"Guatemala", "mobile_number":1234567890, "to_service_number":"0987654321", "from_service_number":"9999999999" } ``` ####Parameters Parameter | Required | Type | Description --------- | ------- | ----- | ----------- country_code | true | string | 2-digit code of the country in ISO 3166 format. (Ex: **GT** for Guatemala). carrier_code | true | string | Name of the mobile carrier. (Ex: **Claro**). amount | true | integer | This is the amount, in cents, of the product you are purchasing. (Ex: **500** = $5.00). mobile_number | true | integer | Mobile number to topup. VALIDATE prior to submission. (Ex: **50312345678**). ##Topups Reports (all) This will return both the totals report, and the transactions during the dates requested. ### Example: `idtbeyond_iatu.get_all_topups "date_from", "date_to"` **Request:** ```ruby idtbeyond_iatu.get_all_topups "2015-01-04", "2015-01-05" ``` **Response:** ```json { "success":true, "totals":{ "purchases":"0", "transfers":"-500", "commissions":"100", "transactions_count":"1", "actual_last_transaction_date":"2015-01-05T22:44:35", "query_start_date":"2015-01-04", "query_end_date":"2015-01-05" }, "transactions":[ { "mobile_number":"50212345678", "production_pin":"0000000001", "client_transaction_id":"Transaction123456", "currency_code":"US", "currency_symbol":"$", "currency_divisor":"100", "transaction_date":"2015-01-05T22:44:34", "transaction_method":"XFER", "transaction_description":"IMTU", "transaction_amount":"-500", "retail_amount":"-500", "retail_commission":"100", "account_start_balance":"60575", "account_end_balance":"60175", "product_name":"IMTU - CLARO UNIVERSAL $5" } ] } ``` ####Parameters Parameter | Required | Type | Description --------- | ------- | ----- | ----------- date_from | true | string | YYYY-MM-DD format. Starts at 00:00:00 Eastern Time (ET). (Ex: 2015-12-01). date_to | true | string | YYYY-MM-DD format. Ends at 23:59:59 Eastern Time (ET). (Ex: 2015-12-01). ##Topups Reports (Totals) This returns a summary report of topups totals, within a given time period. ### Example: `idtbeyond_iatu.get_all_topups_totals "date_from", "date_to"` **Request:** ```ruby idtbeyond_iatu.get_all_topups_totals "2015-01-01", "2015-01-02" ``` **Response:** ```json { "success":true, "totals":{ "from_service_number":"133333333", "sales":"50000", "cost":"40000", "commissions":"10000", "transactions_count":"100", "actual_last_transaction_date":"2015-01-02T23:59:59", "query_start_date":"2015-01-01", "query_end_date":"2015-01-02", "currency_code":"US", "currency_symbol":"$", "currency_divisor":"100" } } ``` ####Parameters Parameter | Required | Type | Description --------- | ------- | ----- | ----------- date_from | true | string | YYYY-MM-DD format. Starts at 00:00:00 Eastern Time (ET). (Ex: 2015-12-01). date_to | true | string | YYYY-MM-DD format. Ends at 23:59:59 Eastern Time (ET). (Ex: 2015-12-01). ##Topups Reports (Search) Search for transaction details using your **client_transaction_id**. ### Example: `idtbeyond_iatu.client_transaction_id_search "client_transaction_id", "date_from", "date_to"` **Request:** ```ruby idtbeyond_iatu.client_transaction_id_search "my-client-trans-id", "2015-03-01", "2015-03-11" ``` **Response:** ```json { "success":true, "transaction_data":[ { "currency_code":"USD", "currency_symbol":"$", "currency_divisor":"100", "client_transaction_id":"my-client-trans-id", "transaction_date":"3/1/2015 10:57:04 AM", "description":"Success", "commission":"100", "type":"IMTU - CLARO UNIVERSAL $5", "end_balance":"56915", "amount":"-500", "terminal_id":"testTerminalId", "transaction_status":"Success", "to_service_number":"117123456" } ] } ``` ####Parameters Parameter | Required | Type | Description --------- | ------- | ----- | ----------- date_from | true | string | YYYY-MM-DD format. Starts at 00:00:00 Eastern Time (ET). (Ex: **2015-12-01**). date_to | true | string | YYYY-MM-DD format. Ends at 23:59:59 Eastern Time (ET). (Ex: **2015-12-01**). client_transaction_id | true | string | A unique id you use to track topups (Limit of 20 characters). ##Topups Reports (Quick Status) When you submit a transaction, we do some very detailed handling to complete the request. The **to_service_number** is a tracking method used to follow the status of this request, including the balance of the transaction handoff to the carrier. Use this endpoint to get a quick update on the status of the request. ### Example: `idtbeyond_iatu.to_service_number_search "to_service_number"` **Request:** ```ruby idtbeyond_iatu.to_service_number_search "2712345678" ``` **Response:** ```json { "success": true, "transaction_data": { "balance": "0", "status": "Redeemed" } } ``` ####Parameters Parameter | Required | Type | Description --------- | ------- | ----- | ----------- to_service_number | true | string | A unique IDT transaction number that gives the status of the transfer of funds from your account to the carrier. ##Topups (Reverse) Use this method to search for the status of a particular topup transaction, using the unique **clientTransactionId** you supplied in the request, and use the **toServiceNumber**. Occasionally, a carrier will not be able to successfully complete a topup request. In this case, we will attempt to automatically reverse the transaction for you, and return the money into your account. In the case when this is not possible, you may need to request a reverse on the transaction that has a status of **"status": "Not Redeemed"**. ### Example: `idtbeyond_iatu.reverse_topup "client_transaction_id", "to_service_number"` **Request:** ```ruby idtbeyond_iatu.reverse_topup "my-client-trans-id", "2712345678" ``` **Response:** ```json { "success":true, "account_id":"12345678", "client_transaction_id":"my-client-trans-id", "transaction_id":"111222333", "to_service_number":"2712345678", "remaining_amount":0, "currency_symbol":"$", "currency_divisor":"100" } ``` ####Parameters Parameter | Required | Type | Description --------- | ------- | ----- | ----------- client_transaction_id | true | string | A unique id you use to track topups (Limit of 16 characters). to_service_number | true | string | The service number of the financial transaction (moving the money between your balance and the carrier). ## Charges Reports (all) Returns a list of any credit card charges, wire-transfers, or credit adjustments on your application account. **Request:** ```ruby idtbeyond_iatu.get_all_charges "2015-03-01", "2015-03-11" ``` **Response:** ```json { "success":true, "totals":{ "purchases":"0", "transfers":"0", "commissions":"0", "transactions_count":"1", "actual_last_transaction_date":"2015-03-02T20:04:45", "query_start_date":"2015-03-01", "query_end_date":"2015-03-11" }, "transactions":[ { "mobile_number":"", "production_pin":"", "client_transaction_id":"12345678", "currency_code":"US", "currency_symbol":"$", "currency_divisor":"100", "transaction_date":"2015-03-02T20:04:44", "transaction_method":"CREDIT_LOAD", "transaction_description":"Credit Load", "transaction_amount":"100000", "retail_commission":"0", "account_start_balance":"0", "account_end_balance":"100000", "product_name":"CREDIT_LOAD" } ] } ``` ####Parameters Parameter | Required | Type | Description --------- | ------- | ----- | ----------- date_from | true | string | YYYY-MM-DD format. Starts at 00:00:00 Eastern Time (ET). (Ex: 2015-12-01). date_to | true | string | YYYY-MM-DD format. Ends at 23:59:59 Eastern Time (ET). (Ex: 2015-12-01). ##Number Validator This method validates that a phone number has a valid area code and number of digits for the selected country. **Request:** ```ruby idtbeyond_iatu.validate_number "GT", "50212345678" ``` **Response:** ```json { "country_code":"GT", "mobile_number":"50212345678", "valid":true } ``` ####Parameters Parameter | Required | Type | Description --------- | ------- | ----- | ----------- country_code | true | string | 2-digit code of the country in ISO 3166 format. (Ex: **BR** for Brazil). mobile_number | true | string | Mobile number to topup. VALIDATE prior to submission. (Ex: **5521983339000**).