Skip to content

Getting Started with Hubtel VISA SDK

This SDK helps you to interact with VISA API. Helpful methods include:

  • Check if a card is a valid VISA card
  • Push funds to a VISA account
  • Pull funds from a VISA account
  • Check the status of a push funds transaction
  • Check the status of a pull funds transaction

In order to get started with Hubtel.VisaDirect.Sdk, do the following activities:

Install-Package Hubtel.VisaDirect.Sdk

The provided code snippet is a command that is used to install Hubtel.VisaDirect.Sdk in a .NET project.

C#
    Install-Package Hubtel.VisaDirect.Sdk

Add to appsettings.json

The "HubtelVisaDirectConfig" block contains four properties:

  • "BaseUrl": This property specifies the base URL for the Visa API. In this case, it's set to the sandbox environment of the Visa API, which is a testing environment where developers can test their code without affecting live data.

  • "UserId": This property is a placeholder for the user ID required to authenticate with the Visa API. The actual user ID should be provided here.

  • "Password": This property is a placeholder for the password required to authenticate with the Visa API. The actual password should be provided here.

  • "CertificatePassword": This property is a placeholder for the password of the certificate used in the SSL/TLS handshake when establishing a secure connection to the Visa API. The actual certificate password should be provided here.

c#
"HubtelVisaDirectConfig" : {
    "BaseUrl": "https://sandbox.api.visa.com",
    "UserId": "<user_id>",
    "Password": "<password>",
    "CertificatePassword": "<certificate_password>"
}

Add to IServiceCollection in Program.cs or Startup.cs

services.AddHubtelVisaDirectSdk(option => {...})

  • This line is adding the Hubtel Visa Direct SDK to the application's services. This is a method provided by the Hubtel.VisaDirect.Sdk package that sets up any necessary services for the SDK to function, such as HTTP clients or other dependencies.

The argument to AddHubtelVisaDirectSdk is a lambda expression that configures the SDK. It uses the Configuration object to retrieve the settings from the HubtelVisaDirectConfig section of the application's configuration (usually found in appsettings.json).

  • option.BaseUrl = Configuration["HubtelVisaDirectConfig:BaseUrl"]: Sets the base URL for the Visa API.

  • option.UserId = Configuration["HubtelVisaDirectConfig:UserId"]: Sets the user ID for authentication with the Visa API.

  • option.Password = Configuration["HubtelVisaDirectConfig:Password"]: Sets the password for authentication with the Visa API.

  • option.CertificatePassword = Configuration["HubtelVisaDirectConfig:CertificatePassword"]:Sets the password for the certificate used in the SSL/TLS handshake when establishing a secure connection to the Visa API.

c#
services.AddHubtelVisaDirectSdk(option =>
{
    option.BaseUrl = Configuration["HubtelVisaDirectConfig:BaseUrl"];
    option.UserId = Configuration["HubtelVisaDirectConfig:UserId"];
    option.Password = Configuration["HubtelVisaDirectConfig:Password"];
    option.CertificatePassword = Configuration["HubtelVisaDirectConfig:CertificatePassword"];
});

Inject and consume service methods

c#
private readonly IVisaDirectApi _visaDirectApi;   

//P.S. be sure to include as constructor parameters

// Check if a card is a valid VISA card
var result = _visaDirectApi.IsValidVisaCard("<valid_card_number>");

// Push funds to a VISA account
var result = await _visaDirectApi.PushFunds(new PushFundsRequest {
    Amount = "124.05",
    SenderAddress = "901 Metro Center Blvd",
    LocalTransactionDateTime = DateTime.UtcNow.ToString("s"),
    PointOfServiceData = new PointOfServiceData
    {
        MotoECIIndicator = 0,
        PanEntryMode = 90,
        PosConditionCode = 00
    },
    RecipientPrimaryAccountNumber = "<valid_account_number>",
    CardAcceptor = new CardAcceptor
    {
        Address = new CardAcceptorAddress
        {
            Country = "USA",
            County = "San Mateo",
            State = "CA",
            ZipCode = "94404"
        },
        IdCode = "CA-IDCode-77765",   
        Name = "Visa Inc. USA-Foster City",   
        TerminalId = "TID-9999"
    },
    TransactionIdentifier = "381228649430015",
    AcquirerCountryCode = "840",
    AcquiringBin = "408999",
    RetrievalReferenceNumber = "412770451018",
    SenderCity = "Foster City",
    SenderStateCode = "CA",
    SystemsTraceAuditNumber = "451018",
    SenderName = "Mohammed Qasim", 
    BusinessApplicationId = "AA",
    MerchantCategoryCode = "6012",
    TransactionCurrencyCode = "USD", 
    RecipientName = "rohan",
    SenderCountryCode = "124",
    SenderAccountNumber = "<valid_account_number>",
    SourceOfFundsCode = "05",
    SenderReference = "233245564356345",
});

// Pull funds from a VISA account
var result = _visaDirectApi.PullFunds(new PullFundsRequest {
    Surcharge = "11.99",
    Amount = "124.02",
    LocalTransactionDateTime = DateTime.UtcNow.ToString("s"),
    CpsAuthorizationCharacteristicsIndicator = "Y",
    RiskAssessmentData = new RiskAssessmentData
    {
        TraExemptionIndicator = "true",
        TrustedMerchantExemptionIndicator = "true",
        ScpExemptionIndicator = "true",
        DelegatedAuthenticationIndicator = "true",
        LowValueExemptionIndicator = "true"
    },
    CardAcceptor = new CardAcceptor
    {
        Address = new CardAcceptorAddress
        {
            Country = "USA",
            County = "081",
            State = "CA",
            ZipCode = "94404"
        },
        IdCode = "ABCD1234ABCD123",   
        Name = "Visa Inc. USA-Foster City",   
        TerminalId = "ABCD1234"
    },
    AcquirerCountryCode = "840",
    AcquiringBin = "408999",
    SenderCurrencyCode = "USD",
    RetrievalReferenceNumber = "330000550000",
    AddressVerificationData = new AddressVerificationData
    {
        Street = "XYZ St",
        PostalCode = "12345"
    },
    Cavv = "0700100038238906000013405823891061668252",
    SystemsTraceAuditNumber = "451001",
    BusinessApplicationId = "AA",
    SenderPrimaryAccountNumber = "<valid_account_number>",
    SettlementServiceIndicator = 9,
    VisaMerchantIdentifier = "73625198",
    ForeignExchangeFeeTransaction = "11.99",
    SenderCardExpiryDate = "2023-10",
    NationalReimbursementFee = "11.22",
});

// Check status of push funds transaction status
var result = _visaDirectApi.GetPushFundsTransactionStatus("330000550000");

// Check status of pull funds transaction status
var result = _visaDirectApi.GetPushFundsTransactionStatus("330000550000");