t2_airtime 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +0 -2
  3. data/app/controllers/t2_airtime/accounts_controller.rb +15 -0
  4. data/app/controllers/t2_airtime/application_controller.rb +46 -0
  5. data/app/controllers/t2_airtime/countries_controller.rb +20 -0
  6. data/app/controllers/t2_airtime/operators_controller.rb +26 -0
  7. data/app/controllers/t2_airtime/products_controller.rb +21 -0
  8. data/app/controllers/t2_airtime/transactions_controller.rb +48 -0
  9. data/config/routes.rb +5 -6
  10. data/lib/t2_airtime/api.rb +279 -277
  11. data/lib/t2_airtime/base.rb +30 -29
  12. data/lib/t2_airtime/engine.rb +10 -11
  13. data/lib/t2_airtime/errors.rb +85 -89
  14. data/lib/t2_airtime/reply.rb +57 -39
  15. data/lib/t2_airtime/request.rb +70 -65
  16. data/lib/t2_airtime/serializer.rb +294 -313
  17. data/lib/t2_airtime/url.rb +6 -6
  18. data/lib/t2_airtime/util.rb +28 -30
  19. data/lib/t2_airtime/version.rb +1 -1
  20. data/lib/t2_airtime.rb +13 -14
  21. data/spec/dummy/bin/setup +0 -1
  22. data/spec/dummy/config/application.rb +20 -9
  23. data/spec/dummy/config/environments/development.rb +2 -2
  24. data/spec/dummy/config/environments/production.rb +2 -3
  25. data/spec/dummy/config/initializers/mime_types.rb +1 -0
  26. data/spec/dummy/config/puma.rb +3 -3
  27. data/spec/dummy/config/routes.rb +1 -1
  28. data/spec/dummy/config/spring.rb +2 -2
  29. data/spec/dummy/log/development.log +6942 -0
  30. data/spec/dummy/log/production.log +8 -0
  31. data/spec/dummy/tmp/cache/361/BB0/accounts +0 -0
  32. data/spec/dummy/tmp/cache/3DD/470/countries +0 -0
  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/490/products%2F1623 +0 -0
  40. data/spec/dummy/tmp/cache/4DE/500/products%2F2901 +0 -0
  41. data/spec/dummy/tmp/cache/4DF/460/products%2F2074 +0 -0
  42. data/spec/dummy/tmp/cache/4E0/470/products%2F2075 +0 -0
  43. data/spec/dummy/tmp/cache/4E2/480/products%2F2149 +0 -0
  44. data/spec/dummy/tmp/cache/4E2/500/products%2F1573 +0 -0
  45. data/spec/dummy/tmp/cache/4E4/500/products%2F2448 +0 -0
  46. data/spec/dummy/tmp/cache/4E4/530/products%2F1827 +0 -0
  47. data/spec/dummy/tmp/cache/4E5/570/products%2F1693 +0 -0
  48. data/spec/dummy/tmp/cache/4E5/5B0/products%2F1972 +0 -0
  49. data/spec/dummy/tmp/cache/4E7/580/products%2F1767 +0 -0
  50. data/spec/dummy/tmp/cache/4EB/5E0/products%2F1789 +0 -0
  51. data/spec/dummy/tmp/cache/4EB/5F0/products%2F1879 +0 -0
  52. data/spec/dummy/tmp/cache/4EC/610/products%2F1889 +0 -0
  53. data/spec/dummy/tmp/cache/515/9E0/operators%2F701 +0 -0
  54. data/spec/dummy/tmp/cache/518/A50/operators%2F740 +0 -0
  55. data/spec/dummy/tmp/cache/519/A20/operators%2F705 +0 -0
  56. data/spec/dummy/tmp/cache/51A/A70/operators%2F661 +0 -0
  57. data/spec/dummy/tmp/cache/51C/A90/operators%2F663 +0 -0
  58. data/spec/dummy/tmp/cache/51C/AB0/operators%2F681 +0 -0
  59. data/spec/dummy/tmp/cache/51D/AA0/operators%2F664 +0 -0
  60. data/spec/dummy/tmp/cache/51D/AC0/operators%2F844 +0 -0
  61. data/spec/dummy/tmp/cache/51D/AD0/operators%2F691 +0 -0
  62. data/spec/dummy/tmp/cache/51F/AE0/operators%2F684 +0 -0
  63. data/spec/dummy/tmp/cache/521/AE0/operators%2F668 +0 -0
  64. data/spec/dummy/tmp/cache/521/AF0/operators%2F677 +0 -0
  65. data/spec/dummy/tmp/cache/522/AF0/operators%2F669 +0 -0
  66. data/spec/dummy/tmp/cache/522/B00/operators%2F678 +0 -0
  67. data/spec/dummy/tmp/cache/523/B10/operators%2F679 +0 -0
  68. data/spec/dummy/tmp/cache/523/B50/operators%2F796 +0 -0
  69. data/spec/dummy/tmp/cache/769/350/accounts%2Fcurrency +1 -0
  70. data/spec/dummy/tmp/cache/8B4/E50/countries%2Fserializer +167 -0
  71. data/spec/dummy/tmp/cache/91D/3D0/products%2F4%2Fserializer +17 -0
  72. data/spec/dummy/tmp/cache/984/980/products%2F137%2Fserializer +28 -0
  73. data/spec/dummy/tmp/cache/989/E40/products%2F439%2Fserializer +11 -0
  74. data/spec/dummy/tmp/cache/9B1/B30/products%2F2105%2Fserializer +18 -0
  75. data/spec/dummy/tmp/cache/9B4/EB0/products%2F2720%2Fserializer +19 -0
  76. data/spec/dummy/tmp/cache/9B5/F20/products%2F1524%2Fserializer +14 -0
  77. data/spec/dummy/tmp/cache/9B5/F40/products%2F1623%2Fserializer +33 -0
  78. data/spec/dummy/tmp/cache/9B5/FB0/products%2F2901%2Fserializer +9 -0
  79. data/spec/dummy/tmp/cache/9B6/FE0/products%2F2074%2Fserializer +17 -0
  80. data/spec/dummy/tmp/cache/9B7/0C0/products%2F2075%2Fserializer +17 -0
  81. data/spec/dummy/tmp/cache/9B9/270/products%2F2149%2Fserializer +8 -0
  82. data/spec/dummy/tmp/cache/9B9/2F0/products%2F1573%2Fserializer +56 -0
  83. data/spec/dummy/tmp/cache/9BB/4C0/products%2F1827%2Fserializer +35 -0
  84. data/spec/dummy/tmp/cache/9BC/5D0/products%2F1693%2Fserializer +17 -0
  85. data/spec/dummy/tmp/cache/9BC/610/products%2F1972%2Fserializer +10 -0
  86. data/spec/dummy/tmp/cache/9BE/780/products%2F1767%2Fserializer +27 -0
  87. data/spec/dummy/tmp/cache/9C2/B20/products%2F1789%2Fserializer +52 -0
  88. data/spec/dummy/tmp/cache/9C2/B30/products%2F1879%2Fserializer +28 -0
  89. data/spec/dummy/tmp/cache/9C3/C20/products%2F1889%2Fserializer +46 -0
  90. data/spec/dummy/tmp/cache/9EC/140/operators%2F701%2Fserializer +13 -0
  91. data/spec/dummy/tmp/cache/9EF/420/operators%2F740%2Fserializer +9 -0
  92. data/spec/dummy/tmp/cache/9F0/4C0/operators%2F705%2Fserializer +4 -0
  93. data/spec/dummy/tmp/cache/9F1/5E0/operators%2F661%2Fserializer +6 -0
  94. data/spec/dummy/tmp/cache/9F3/7A0/operators%2F663%2Fserializer +4 -0
  95. data/spec/dummy/tmp/cache/9F3/7C0/operators%2F681%2Fserializer +3 -0
  96. data/spec/dummy/tmp/cache/9F4/880/operators%2F664%2Fserializer +2 -0
  97. data/spec/dummy/tmp/cache/9F4/8A0/operators%2F844%2Fserializer +10 -0
  98. data/spec/dummy/tmp/cache/9F4/8B0/operators%2F691%2Fserializer +8 -0
  99. data/spec/dummy/tmp/cache/9F6/A60/operators%2F684%2Fserializer +2 -0
  100. data/spec/dummy/tmp/cache/9F8/C00/operators%2F668%2Fserializer +4 -0
  101. data/spec/dummy/tmp/cache/9F8/C10/operators%2F677%2Fserializer +5 -0
  102. data/spec/dummy/tmp/cache/9F9/CE0/operators%2F669%2Fserializer +6 -0
  103. data/spec/dummy/tmp/cache/9F9/CF0/operators%2F678%2Fserializer +14 -0
  104. data/spec/dummy/tmp/cache/9FA/DD0/operators%2F679%2Fserializer +4 -0
  105. data/spec/dummy/tmp/cache/9FA/E10/operators%2F796%2Fserializer +3 -0
  106. data/spec/dummy/tmp/caching-dev.txt +0 -0
  107. data/spec/rails_helper.rb +1 -1
  108. data/spec/spec_helper.rb +47 -49
  109. data/spec/t2_airtime_spec.rb +179 -181
  110. metadata +176 -3
  111. data/app/controllers/t2_airtime/airtime_controller.rb +0 -105
@@ -1,11 +1,10 @@
1
- module T2Airtime
2
- class Engine < ::Rails::Engine
3
- isolate_namespace T2Airtime
4
-
5
- config.generators do |g|
6
- g.api_only = true
7
- g.test_framework :rspec
8
- end
9
-
10
- end
11
- end
1
+ module T2Airtime
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace T2Airtime
4
+
5
+ config.generators do |g|
6
+ g.api_only = true
7
+ g.test_framework :rspec
8
+ end
9
+ end
10
+ end
@@ -1,89 +1,85 @@
1
- module T2Airtime
2
- # 0 Transaction successful Indicates the Top-up was successfully delivered to the recipient.
3
- # 101 Destination MSISDN out of range Numbering plan not recognized: the destination/recipient number was not identified as to belonging to any operators covered by TransferTo. Re-check recipient number and/or escalate the case to the TransferTo Support Team for further investigation.
4
- # 104 MSISDN in blacklist Here MSISDN refers to both sender and recipient phone numbers which are blacklisted due to fraudulent activities.
5
- # 105 Not enough credit on your account Transaction failed due to insufficient funds in your account's prepaid balance. Please reload balance and try again.
6
- # 200 Transaction canceled by Customer
7
- # 202 Transaction canceled by TransferTo
8
- # 203 Transaction incomplete Transaction failed due to a technical issue. Please contact TransferTo Support Team for further investigation.
9
- # 204 Destination Account is not prepaid or not valid Transaction refused by the operator because the recipient phone number is not a valid prepaid account.
10
- # 207 Transaction amount limit exceeded Here limit refers to maximum amount defined for the destination MSISDN. There are some limitations set on the operator's side, not controlled by TransferTo. When one of these limits is reached, error code 207 will be returned. Some examples:
11
- # • Indosat Indonesia operator's end, the customer must wait at least 5 mins before sending another transfer to the same recipient account.
12
- # • Indian operators' end, the customer must wait 3 mins before sending another transfer of the same amount to the same recipient account.
13
- # • Orange Africa, the recipient account is limited to a maximum rechargeable amount of 30 Euros per week and 60 Euros per month.
14
- # 213 Duplicated transaction Transaction refused because it was submitted too closely after a preceding Top-up attempt.
15
- # 214 Topup refused Transaction refused by the operator for a reason that was not specified. Common reasons for these types of failures are: Recipient number not valid for recharge. Service outage temporarily faced on the operator. Please try again at a later time and/or contact the TransferTo Support Team if the problem persists.
16
- # 215 Service to this destination operator is Transaction failed due to an outage and/or connection issue with the operator. Please try again at a later time and/or contact the TransferTo Support Team if the problem persists.
17
- # temporarily unavailable
18
- # 216 Destination number not activated Transaction refused by the operator because the recipient number has not been activated.
19
- # 217 Destination number expired Transaction refused by the operator because the recipient number is no longer an active account.
20
- # 218 Request timeout Transaction timed-out and failed because of the long processing duration. Please try again at a later time and/or contact the TransferTo Support Team if the problem persists.
21
- # 219 Key does not exist Request failed because the key provided does not exist (error returned for get_id_from_key method requests only).
22
- # 221 Fraud suspicion Transaction refused and the recipient number flagged for suspicion of fraud, due to the number of consecutive Top-up requests within a short gap of time. The recipient phone number will be locked out from receiving any Top-up for a certain period of time, after which, the restriction will be automatically released.
23
- # 222 Number barred from refill This error code is returned when the recipient has been blocked from refill directly by the recipient's operator. It prevents TransferTo system from reloading his account. Recipient must call the operator’s customer service to unblock it.
24
- # 223 ID not reserved Transaction failed because the transaction ID specified in the request was not previously reserved.
25
- # 224 Invalid length of destination MSISDN Transaction failed because the recipient number length does not match (shorter or longer) the mobile number format of the country.
26
- # 230 Recipient reached maximum topup number This error is returned when a recipient reaches the maximum number of Top-up allowable in a certain gap of time.
27
- # • 01 Day(s) => 10
28
- # • 07 Day(s) => 15
29
- # • 30 Day(s) => 40
30
- # 231 Recipient reached maximum topup amount This error is returned when a recipient reaches the maximum amount (in USD) of Top-up allowable in a certain gap of time.
31
- # • 01 Day(s) => max 100 USD
32
- # • 07 Day(s) => max 150 USD
33
- # • 30 Day(s) => max 200 USD
34
- # 232 Account reached maximum topup number This error is returned when your account has reached its maximum number of Top-up allowable in a certain gap of time.
35
- # 233 Account reached maximum topup amount This error is returned when your account has reached its maximum amount (in USD) of Top-up allowable in a certain gap of time.
36
- # 241 Account reached maximum daily topup amount This error is returned when your account has reached its maximum amount (in USD) of Top-up allowable within a day.
37
- # 242 Account reached maximum daily topup number This error is returned when your account has reached its maximum number of Top-up allowable within a day.
38
- # 243 Account reached maximum weekly topup amount This error is returned when your account has reached its maximum amount (in USD) of Top-up allowable within a week.
39
- # 244 Account reached maximum weekly topup number This error is returned when your account has reached its maximum number of Top-up allowable within a week.
40
- # 245 Account reached maximum monthly topup amount This error is returned when your account has reached its maximum amount (in USD) of Top-up allowable within a month.
41
- # 246 Account reached maximum monthly topup number This error is returned when your account has reached its maximum number of Top-up allowable within a month.
42
- # 251 Sender reached maximum daily topup amount This error is returned when the sender has reached its maximum amount (in USD) of Top-up allowable within a day.
43
- # 252 Sender reached maximum daily topup number This error is returned when the sender has reached its maximum number of Top-up allowable within a day.
44
- # 253 Sender reached maximum weekly topup amount This error is returned when the sender has reached its maximum amount (in USD) of Top-up allowable within a week.
45
- # 254 Sender reached maximum weekly topup number This error is returned when the sender has reached its maximum number of Top-up allowable within a week.
46
- # 255 Sender reached maximum monthly topup amount This error is returned when the sender has reached its maximum amount (in USD) of Top-up allowable within a month.
47
- # 256 Sender reached maximum monthly topup number This error is returned when the sender has reached its maximum number of Top-up allowable within a day month.
48
- # 301 Denomination not available Denomination not available for this destination.
49
- # 310 Denomination blocked Transaction failed because the Top-up is no longer available on the operator's offer or on the account.
50
- # 320 Requested amount out of range Transaction failed because the Top-amount request was not within the range of valid amounts.
51
- # 321 Requested currency not allowed for this account Transaction failed because the currency specified is not valid for the account.
52
- # 401 Transaction ID not found or was not made No transaction was found with the ID specified (error returned for trans_info method requests only).
53
- # by your account
54
- # 777 Insufficient balance in your master account Transaction failed because there are not enough funds in your master account.
55
- # 888 Insufficient balance in your subaccount Transaction failed because there are not enough funds in your sub-account.
56
- # 900 Not enough information to process the topup Transaction failed because some of the required fields in your Top-up request are missing/empty.
57
- # 901 Invalid action Transaction failed because the action specified in <action> field of the request is not valid.
58
- # 902 Invalid input_currency
59
- # 903 Invalid output_currency
60
- # 904 Invalid input_value
61
- # 905 Invalid start_date
62
- # 906 Invalid stop_date
63
- # 907 Invalid transaction ID Transaction ID specified in the <reserved_id> of the Top-up request is not valid.
64
- # 908 Account not configured for this service Transaction failed because the account is not configured to carry out the requested action.
65
- # 909 Invalid flag Transaction failed because the request included an invalid field/parameter.
66
- # 919 All required argument not received Transaction failed because the request is missing a mandatory field/parameter.
67
- # 921 Wrong MD5 encoding Transaction failed because the MD5 hash was not correct. Typically indicates that the password is incorrect.
68
- # 922 Originating IP not allowed Transaction failed because the request originated from an IP that is not whitelisted for the account.
69
- # 923 Key already used or invalid key value Transaction failed because the key value included in the request was not unique and greater than the previous key used.
70
- # 926 Account not active Please contact your Account Manager.
71
- # 995 Account not found Please enter and use a correct login.
72
- # 998 System not available. Please retry later. Transaction failed due to technical issues. Please contact TransferTo Support Team for further investigation.
73
- # 999 Unknown error To be escalated to the TransferTo Support Team for further investigation.
74
-
75
-
76
- class Error < StandardError
77
-
78
- attr_reader :code
79
-
80
- def initialize(code, message=nil)
81
- @code = code.to_i
82
- super(message)
83
- end
84
-
85
- end
86
-
87
- class ConfigurationError < StandardError; end
88
-
89
- end
1
+ module T2Airtime
2
+ # 0 Transaction successful Indicates the Top-up was successfully delivered to the recipient.
3
+ # 101 Destination MSISDN out of range Numbering plan not recognized: the destination/recipient number was not identified as to belonging to any operators covered by TransferTo. Re-check recipient number and/or escalate the case to the TransferTo Support Team for further investigation.
4
+ # 104 MSISDN in blacklist Here MSISDN refers to both sender and recipient phone numbers which are blacklisted due to fraudulent activities.
5
+ # 105 Not enough credit on your account Transaction failed due to insufficient funds in your account's prepaid balance. Please reload balance and try again.
6
+ # 200 Transaction canceled by Customer
7
+ # 202 Transaction canceled by TransferTo
8
+ # 203 Transaction incomplete Transaction failed due to a technical issue. Please contact TransferTo Support Team for further investigation.
9
+ # 204 Destination Account is not prepaid or not valid Transaction refused by the operator because the recipient phone number is not a valid prepaid account.
10
+ # 207 Transaction amount limit exceeded Here limit refers to maximum amount defined for the destination MSISDN. There are some limitations set on the operator's side, not controlled by TransferTo. When one of these limits is reached, error code 207 will be returned. Some examples:
11
+ # • Indosat Indonesia operator's end, the customer must wait at least 5 mins before sending another transfer to the same recipient account.
12
+ # • Indian operators' end, the customer must wait 3 mins before sending another transfer of the same amount to the same recipient account.
13
+ # • Orange Africa, the recipient account is limited to a maximum rechargeable amount of 30 Euros per week and 60 Euros per month.
14
+ # 213 Duplicated transaction Transaction refused because it was submitted too closely after a preceding Top-up attempt.
15
+ # 214 Topup refused Transaction refused by the operator for a reason that was not specified. Common reasons for these types of failures are: Recipient number not valid for recharge. Service outage temporarily faced on the operator. Please try again at a later time and/or contact the TransferTo Support Team if the problem persists.
16
+ # 215 Service to this destination operator is Transaction failed due to an outage and/or connection issue with the operator. Please try again at a later time and/or contact the TransferTo Support Team if the problem persists.
17
+ # temporarily unavailable
18
+ # 216 Destination number not activated Transaction refused by the operator because the recipient number has not been activated.
19
+ # 217 Destination number expired Transaction refused by the operator because the recipient number is no longer an active account.
20
+ # 218 Request timeout Transaction timed-out and failed because of the long processing duration. Please try again at a later time and/or contact the TransferTo Support Team if the problem persists.
21
+ # 219 Key does not exist Request failed because the key provided does not exist (error returned for get_id_from_key method requests only).
22
+ # 221 Fraud suspicion Transaction refused and the recipient number flagged for suspicion of fraud, due to the number of consecutive Top-up requests within a short gap of time. The recipient phone number will be locked out from receiving any Top-up for a certain period of time, after which, the restriction will be automatically released.
23
+ # 222 Number barred from refill This error code is returned when the recipient has been blocked from refill directly by the recipient's operator. It prevents TransferTo system from reloading his account. Recipient must call the operator’s customer service to unblock it.
24
+ # 223 ID not reserved Transaction failed because the transaction ID specified in the request was not previously reserved.
25
+ # 224 Invalid length of destination MSISDN Transaction failed because the recipient number length does not match (shorter or longer) the mobile number format of the country.
26
+ # 230 Recipient reached maximum topup number This error is returned when a recipient reaches the maximum number of Top-up allowable in a certain gap of time.
27
+ # • 01 Day(s) => 10
28
+ # • 07 Day(s) => 15
29
+ # • 30 Day(s) => 40
30
+ # 231 Recipient reached maximum topup amount This error is returned when a recipient reaches the maximum amount (in USD) of Top-up allowable in a certain gap of time.
31
+ # • 01 Day(s) => max 100 USD
32
+ # • 07 Day(s) => max 150 USD
33
+ # • 30 Day(s) => max 200 USD
34
+ # 232 Account reached maximum topup number This error is returned when your account has reached its maximum number of Top-up allowable in a certain gap of time.
35
+ # 233 Account reached maximum topup amount This error is returned when your account has reached its maximum amount (in USD) of Top-up allowable in a certain gap of time.
36
+ # 241 Account reached maximum daily topup amount This error is returned when your account has reached its maximum amount (in USD) of Top-up allowable within a day.
37
+ # 242 Account reached maximum daily topup number This error is returned when your account has reached its maximum number of Top-up allowable within a day.
38
+ # 243 Account reached maximum weekly topup amount This error is returned when your account has reached its maximum amount (in USD) of Top-up allowable within a week.
39
+ # 244 Account reached maximum weekly topup number This error is returned when your account has reached its maximum number of Top-up allowable within a week.
40
+ # 245 Account reached maximum monthly topup amount This error is returned when your account has reached its maximum amount (in USD) of Top-up allowable within a month.
41
+ # 246 Account reached maximum monthly topup number This error is returned when your account has reached its maximum number of Top-up allowable within a month.
42
+ # 251 Sender reached maximum daily topup amount This error is returned when the sender has reached its maximum amount (in USD) of Top-up allowable within a day.
43
+ # 252 Sender reached maximum daily topup number This error is returned when the sender has reached its maximum number of Top-up allowable within a day.
44
+ # 253 Sender reached maximum weekly topup amount This error is returned when the sender has reached its maximum amount (in USD) of Top-up allowable within a week.
45
+ # 254 Sender reached maximum weekly topup number This error is returned when the sender has reached its maximum number of Top-up allowable within a week.
46
+ # 255 Sender reached maximum monthly topup amount This error is returned when the sender has reached its maximum amount (in USD) of Top-up allowable within a month.
47
+ # 256 Sender reached maximum monthly topup number This error is returned when the sender has reached its maximum number of Top-up allowable within a day month.
48
+ # 301 Denomination not available Denomination not available for this destination.
49
+ # 310 Denomination blocked Transaction failed because the Top-up is no longer available on the operator's offer or on the account.
50
+ # 320 Requested amount out of range Transaction failed because the Top-amount request was not within the range of valid amounts.
51
+ # 321 Requested currency not allowed for this account Transaction failed because the currency specified is not valid for the account.
52
+ # 401 Transaction ID not found or was not made No transaction was found with the ID specified (error returned for trans_info method requests only).
53
+ # by your account
54
+ # 777 Insufficient balance in your master account Transaction failed because there are not enough funds in your master account.
55
+ # 888 Insufficient balance in your subaccount Transaction failed because there are not enough funds in your sub-account.
56
+ # 900 Not enough information to process the topup Transaction failed because some of the required fields in your Top-up request are missing/empty.
57
+ # 901 Invalid action Transaction failed because the action specified in <action> field of the request is not valid.
58
+ # 902 Invalid input_currency
59
+ # 903 Invalid output_currency
60
+ # 904 Invalid input_value
61
+ # 905 Invalid start_date
62
+ # 906 Invalid stop_date
63
+ # 907 Invalid transaction ID Transaction ID specified in the <reserved_id> of the Top-up request is not valid.
64
+ # 908 Account not configured for this service Transaction failed because the account is not configured to carry out the requested action.
65
+ # 909 Invalid flag Transaction failed because the request included an invalid field/parameter.
66
+ # 919 All required argument not received Transaction failed because the request is missing a mandatory field/parameter.
67
+ # 921 Wrong MD5 encoding Transaction failed because the MD5 hash was not correct. Typically indicates that the password is incorrect.
68
+ # 922 Originating IP not allowed Transaction failed because the request originated from an IP that is not whitelisted for the account.
69
+ # 923 Key already used or invalid key value Transaction failed because the key value included in the request was not unique and greater than the previous key used.
70
+ # 926 Account not active Please contact your Account Manager.
71
+ # 995 Account not found Please enter and use a correct login.
72
+ # 998 System not available. Please retry later. Transaction failed due to technical issues. Please contact TransferTo Support Team for further investigation.
73
+ # 999 Unknown error To be escalated to the TransferTo Support Team for further investigation.
74
+
75
+ class Error < StandardError
76
+ attr_reader :code
77
+
78
+ def initialize(code, message = nil)
79
+ @code = code.to_i
80
+ super(message)
81
+ end
82
+ end
83
+
84
+ class ConfigurationError < StandardError; end
85
+ end
@@ -1,39 +1,57 @@
1
- module T2Airtime
2
- class Reply
3
-
4
- def initialize(reply) @response = Hash(reply) end
5
-
6
- def data
7
- hash = {}
8
- @response[:body].lines.each do |line|
9
- key, value = line.strip.split "="
10
- hash[key.to_sym] = (key == "error_code") ? Integer(value) : value
11
- end; hash
12
- end
13
-
14
- def information
15
- data.reject do |key, value|
16
- [:authentication_key, :error_code, :error_txt].include?(key)
17
- end
18
- end
19
-
20
- def success?() status == 200 && error_code == 0 end
21
-
22
- def status() @response[:status] end
23
-
24
- def error_code() data[:error_code] end
25
-
26
- def error_message() data[:error_txt] end
27
-
28
- def url() "#{@response[:url]}" end
29
-
30
- def message() information[:info_txt] end
31
-
32
- def auth_key() data[:authentication_key] end
33
-
34
- def headers() @response[:response_headers] end
35
-
36
- def raw() @response[:body] end
37
-
38
- end
39
- end
1
+ module T2Airtime
2
+ class Reply
3
+ def initialize(reply)
4
+ @response = Hash(reply)
5
+ end
6
+
7
+ def data
8
+ hash = {}
9
+ @response[:body].lines.each do |line|
10
+ key, value = line.strip.split '='
11
+ hash[key.to_sym] = key == 'error_code' ? Integer(value) : value
12
+ end; hash
13
+ end
14
+
15
+ def information
16
+ data.reject do |key, _value|
17
+ %i[authentication_key error_code error_txt].include?(key)
18
+ end
19
+ end
20
+
21
+ def success?
22
+ status == 200 && error_code == 0
23
+ end
24
+
25
+ def status
26
+ @response[:status]
27
+ end
28
+
29
+ def error_code
30
+ data[:error_code]
31
+ end
32
+
33
+ def error_message
34
+ data[:error_txt]
35
+ end
36
+
37
+ def url
38
+ (@response[:url]).to_s
39
+ end
40
+
41
+ def message
42
+ information[:info_txt]
43
+ end
44
+
45
+ def auth_key
46
+ data[:authentication_key]
47
+ end
48
+
49
+ def headers
50
+ @response[:response_headers]
51
+ end
52
+
53
+ def raw
54
+ @response[:body]
55
+ end
56
+ end
57
+ end
@@ -1,65 +1,70 @@
1
- module T2Airtime
2
- class Request
3
-
4
- def initialize(user, password, url, name, params)
5
- @user = user || ""
6
- @pass = password || ""
7
- @conn = Faraday.new(url: url) do |faraday|
8
- faraday.request :url_encoded
9
- faraday.adapter :net_http
10
- end
11
- reset
12
- @name = name
13
- add_param :action, name
14
- @params.merge!(params)
15
- end
16
-
17
- def reset
18
- @params = {}
19
- authenticate
20
- end
21
-
22
- def authenticate
23
- time = Time.now.to_i.to_s
24
- add_param :key, time
25
- add_param :md5, md5_hash(@user + @pass + time)
26
- add_param :login, @user
27
- end
28
-
29
- def add_param(key, value) @params[key.to_sym] = value end
30
-
31
- def key() @params[:key] end
32
-
33
- def get?() @params[:method] == :get end
34
-
35
- def post?() @params[:method] == :post end
36
-
37
- # More than 99.5% of the transactions are currently processed within a few seconds.
38
- # However, it may happen in some rare cases that a transaction takes longer to be processed by the receiving
39
- # operator due to congested system on their end for instance.
40
- # TransferTo guarantees that transactions not processed within 600 seconds will not be charged, whatever
41
- # the final status of the transaction (successful or not). In addition, TransferTo is operating a real time system;
42
- # therefore, the status returned in the Top-up response is final and will not change.
43
- # To ensure that your system captures successfully the status of all transactions especially the longest
44
- # ones, it is advised to either set up a high timeout value of 600seconds to be on the safe side (TCP connection
45
- # could potentially be opened for a long time in this case) or to set up a mechanism to check on
46
- # the status (to do so, you can call the trans_info method to retrieve the final status of a transaction).
47
- # In case of timeout, both methods reserve_id and get_id_from_key of the API could be useful to identify
48
- # the ID of the transaction (we recommend to either send a reserve_id request and to use the ID returned
49
- # in the response in the subsequent top-up request so that you know in advance the ID of the transaction).
50
- def run(method = :get)
51
- add_param :method, method
52
- @conn.send(method, "/#{T2Airtime::ENDPOINT}", @params) do |req|
53
- req.options = { timeout: 600, open_timeout: 600 }
54
- end
55
- end
56
-
57
- private
58
-
59
- def md5_hash(str)
60
- (Digest::MD5.new << str).to_s
61
- end
62
-
63
-
64
- end
65
- end
1
+ module T2Airtime
2
+ class Request
3
+ def initialize(user, password, url, name, params)
4
+ @user = user || ''
5
+ @pass = password || ''
6
+ @conn = Faraday.new(url: url) do |faraday|
7
+ faraday.request :url_encoded
8
+ faraday.adapter :net_http
9
+ end
10
+ reset
11
+ @name = name
12
+ add_param :action, name
13
+ @params.merge!(params)
14
+ end
15
+
16
+ def reset
17
+ @params = {}
18
+ authenticate
19
+ end
20
+
21
+ def authenticate
22
+ time = Time.now.to_i.to_s
23
+ add_param :key, time
24
+ add_param :md5, md5_hash(@user + @pass + time)
25
+ add_param :login, @user
26
+ end
27
+
28
+ def add_param(key, value)
29
+ @params[key.to_sym] = value
30
+ end
31
+
32
+ def key
33
+ @params[:key]
34
+ end
35
+
36
+ def get?
37
+ @params[:method] == :get
38
+ end
39
+
40
+ def post?
41
+ @params[:method] == :post
42
+ end
43
+
44
+ # More than 99.5% of the transactions are currently processed within a few seconds.
45
+ # However, it may happen in some rare cases that a transaction takes longer to be processed by the receiving
46
+ # operator due to congested system on their end for instance.
47
+ # TransferTo guarantees that transactions not processed within 600 seconds will not be charged, whatever
48
+ # the final status of the transaction (successful or not). In addition, TransferTo is operating a real time system;
49
+ # therefore, the status returned in the Top-up response is final and will not change.
50
+ # To ensure that your system captures successfully the status of all transactions especially the longest
51
+ # ones, it is advised to either set up a high timeout value of 600seconds to be on the safe side (TCP connection
52
+ # could potentially be opened for a long time in this case) or to set up a mechanism to check on
53
+ # the status (to do so, you can call the trans_info method to retrieve the final status of a transaction).
54
+ # In case of timeout, both methods reserve_id and get_id_from_key of the API could be useful to identify
55
+ # the ID of the transaction (we recommend to either send a reserve_id request and to use the ID returned
56
+ # in the response in the subsequent top-up request so that you know in advance the ID of the transaction).
57
+ def run(method = :get)
58
+ add_param :method, method
59
+ @conn.send(method, "/#{T2Airtime::ENDPOINT}", @params) do |req|
60
+ req.options = { timeout: 600, open_timeout: 600 }
61
+ end
62
+ end
63
+
64
+ private
65
+
66
+ def md5_hash(str)
67
+ (Digest::MD5.new << str).to_s
68
+ end
69
+ end
70
+ end