This quick start will guide you through integrating Reloadly’s Utility Payments API using a Ruby application. Prerequisites needed for this guide are:
- The reader should have a decent understanding of Ruby
- A Reloadly account. If you don’t already have one, follow the registration procedure.
- Next, you need to have funds in your test wallet. When you sign up, a certain amount of funds are automatically added to your test wallet. You can fund your live wallet by following the steps in the Wallet section.
- Sign in to retrieve your client_id and client_secret keys for test mode. You can get both keys by toggling from live to test mode on the sidebar and navigating to Developers > API settings
Get an access token
Reloadly issues access tokens (also called bearer tokens) that are used to authorize API requests. Using the right parameters, make a request to Reloadly’s authorization URL to obtain the appropriate access token.
You can get a test access token by making a request in your Ruby application like this
require 'json'
require 'uri'
require 'net/http'
require 'openssl'
url = URI('https://auth.reloadly.com/oauth/token')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request['Content-Type'] = 'application/json'
request.body = {
client_id: 'qwcLzXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
client_secret: '7kscVxQZ32-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
grant_type: 'client_credentials',
audience: 'https://utilities-sandbox.reloadly.com'
}.to_json
response = http.request(request)
puts response.read_body
While production access tokens are valid for 60 days, test access tokens are only valid for 24 hours.
If your request is successful, you should get the following response.
{
"access_token": "eyJraWQiOiI1N2JjZjNhNy01YmYwLTQ1M2QtODQ0Mi03ODhlMTA4OWI3MDIiLCJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI2NzkzIiwiaXNzIjoiaHR0cHM6Ly9yZWxvYWRseS1zYW5kYm94LmF1dGgwLmNvbS8iLCJodHRwczovL3JlbG9hZGx5LmNvbS9zYW5kYm94Ijp0cnVlLCJodHRwczovL3JlbG9hZGx5LmNvbS9wcmVwYWlkVXNlcklkIjoiNjc5MyIsImd0eSI6ImNsaWVudC1jcmVkZW50aWFscyIsImF1ZCI6Imh0dHBzOi8vdG9wdXBzLWhzMjU2LXNhbmRib3gucmVsb2FkbHkuY29tIiwibmJmIjoxNjU0MDgzNjY3LCJhenAiOiI2NzkzIiwic2NvcGUiOiJzZW5kLXRvcHVwcyByZWFkLW9wZXJhdG9ycyByZWFkLXByb21vdGlvbnMgcmVhZC10b3B1cHMtaGlzdG9yeSByZWFkLXByZXBhaWQtYmFsYW5jZSByZWFkLXByZXBhaWQtY29tbWlzc2lvbnMiLCJleHAiOjE2NTQxNzAwNjcsImh0dHBzOi8vcmVsb2FkbHkuY29tL2p0aSI6IjYwMTY4ODNiLWYxYTgtNGJhMy1hNmM3LWIwNjBkNDRmN2EyMCIsImlhdCI6MTY1NDA4MzY2NywianRpIjoiZGUwNzRlM2QtM2JkYi00N2ExLTkzNDktZTk1YmZiNjZlNGVmIn0.ZXUzCYbCCTzpDMr5hP7YvgWYqniy9kBY0Y5vWS8wRrA",
"scope": "developer",
"expires_in": 86400,
"token_type": "Bearer"
}
Pay a utility bill
Now that you have an access token, you can pay a utility bill with the Utility Payments API. You can find details of the bill you want to pay by Getting all billers available on Reloadly’s platform.
In the example below, we will show how making a bill payment works by paying for an electricity bill for a Nigerian electricity payment provider.
require 'json'
require 'uri'
require 'net/http'
require 'openssl'
url = URI('https://utilities-sandbox.reloadly.com/pay')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request['Content-Type'] = 'application/json'
request['Authorization'] = 'Bearer <YOUR_TOKEN_HERE>'
request.body = {
subscriberAccountNumber: 4223568280,
amount: 1000,
billerId: 5,
useLocalAmount: false,
referenceId: 'april-electricity-bill'
}.to_json
response = http.request(request)
puts response.read_body
If your request is successful, you should receive a response from Reloadly
{
"id": 69,
"status": "PROCESSING",
"referenceId": null,
"code": "PAYMENT_PROCESSING_IN_PROGRESS",
"message": "The payment is being processed, status will be updated when biller processes the payment.",
"submittedAt": "2022-06-10 16:46:32",
"finalStatusAvailabilityAt": "2022-06-11 16:46:31"
}
If you made it to this point, you have successfully made your first utility payment in a Ruby application.