Getting Started with USSD Admin API SDK
This SDK helps you to interact with USSD Admin API API. Helpful methods include:
- Creating USSD code and attaching an item/service
- Listing all USSD codes with filters
- Topping up and getting session balance of legacy USSD codes
In order to get started, do the following activities:
Install-Package Hubtel.UssdAdmin.Sdk
The code snippet below is a command that's used in the NuGet Package Manager Console in Visual Studio. This command is written in PowerShell and it's used to install the Hubtel.UssdAdmin.Sdk
package. into the current .NET project.
Install-Package Hubtel.UssdAdmin.Sdk
Add to IServiceCollection in Program.cs or Startup.cs
services.AddHubtelUssdAdminSdk(o => { o.BaseUrl = "http://localhost:9067/"; })
is a method call toAddHubtelUssdAdminSdk
on the services object. Theservices object
is of typeIServiceCollection
, which is a framework-provided interface that is used to register services to the application's dependency injection container during the startup configuration phase.The
AddHubtelUssdAdminSdk
method is an extension method that registers the Hubtel USSD Admin SDK services into the application's dependency injection container. This allows the SDK's services to be injected into other parts of the application where they are needed.The method takes a lambda expression
o => { o.BaseUrl = "http://localhost:9067/"; }
as an argument. This lambda expression is used to configure the options for the Hubtel USSD Admin SDK. In this case, it sets theBaseUrl
property of the options to"http://localhost:9067/"
. This URL is the base URL that the SDK will use when making HTTP requests to the USSD Admin service.
services.AddHubtelUssdAdminSdk(o => { o.BaseUrl = "http://localhost:9067/"; });
Inject and consume service methods
The code snippet below is be part of a C# class in a .NET application that interacts with a USSD (Unstructured Supplementary Service Data) service provided by Hubtel.
The first two lines declare two private readonly fields:
_sessionsApi
and_ussdCodesApi
. These fields are of typesIUssdSessionsApi
andIUssdCodesApi
respectively, which are interfaces defining the operations that can be performed on USSD sessions and codes. The comment suggests that these fields should be initialized via the constructor, which is a common practice in .NET for dependency injection.The
_sessionsApi
field is used to manage USSD sessions. In the context of a USSD service, a session represents a conversation between a user and the USSD application.The
_ussdCodesApi
field is used to manage USSD codes. USSD codes are the codes that users dial to interact with the USSD service.The line
var balance = await ussdSessionsApi.GetBalance("CalBank")
is calling theGetBalance
method onussdSessionsApi
, passing in"CalBank"
as an argument. This method retrieves the balance for a specific bank (in this case, CalBank). Theawait
keyword is used to asynchronously wait for the method to complete.The line
var codes = await ussdCodesApi.ListCodes(new FilterModel())
is calling theListCodes
method onussdCodesApi
, passing in a new instance ofFilterModel
as an argument. This method retrieves a list of USSD codes, possibly filtered based on the properties of theFilterModel
. Again, theawait
keyword is used to asynchronously wait for the method to complete.
private readonly IUssdSessionsApi _sessionsApi; //use this to manage sessions
private readonly IUssdCodesApi _ussdCodesApi; //use this to manage codes
//P.S. be sure to include as constructor parameter
var balance = await ussdSessionsApi.GetBalance("CalBank");
var codes = await ussdCodesApi.ListCodes(new FilterModel());
CHAT SAMMIAT