Skip to content

Getting Started with CyberSource SDK

This SDK helps you to interact with CyberSource APIs.

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

Install-Package Hubtel.CyberSource.Sdk

The command Install-Package Hubtel.CyberSource.Sdk is a PowerShell command used in the NuGet Package Manager Console in Visual Studio. This command installs the Hubtel.CyberSource.Sdk package into the current project.

To run this command, you would open the Package Manager Console in Visual Studio (View -> Other Windows -> Package Manager Console) and then enter the command.

C#
    Install-Package Hubtel.CyberSource.Sdk

Add to appsettings.json

The CyberSourceConfig object contains several properties that are used to configure the CyberSource integration:

  • MerchantId: This is the identifier for the merchant account in the CyberSource system. You would replace <merchant_id> with your actual merchant ID.

  • Password: This is the password associated with the merchant account. You would replace <password> with your actual password.

  • Username: This is the username associated with the merchant account. You would replace <username> with your actual username.

  • Url: This is the URL of the CyberSource API endpoint. You would replace <url> with the actual URL.

  • Timeout: This is the timeout value (in seconds) for requests to the CyberSource API. In this case, it's set to 45 seconds.

These values are typically sensitive and should not be hard-coded into your application's source code. Instead, they should be stored securely and retrieved from the configuration at runtime.

json
 "CyberSourceConfig": {
    "MerchantId": "<merchant_id>",
    "Password": "<password>",
    "Username": "<username>",
    "Url": "<url>",
    "Timeout": 45
  },

Add to IServiceCollection in Program.cs or Startup.cs

c#

services.AddHubtelCyberSourceSdk(c =>
{
    c.Url = hostContext.Configuration["CyberSourceConfig:Url"];
    c.Username = hostContext.Configuration["CyberSourceConfig:Username"];
    c.Password = hostContext.Configuration["CyberSourceConfig:Password"];
    c.MerchantId = hostContext.Configuration["CyberSourceConfig:MerchantId"];
    c.Timeout = int.Parse(hostContext.Configuration["CyberSourceConfig:Timeout"]);
});

Inject and consume service methods

private readonly ICyberSourceApi _api;

  • This line declares a private, read-only field named _api of type ICyberSourceApi. This is an interface that defines methods for interacting with the CyberSource API. The readonly keyword indicates that the value of _api is set at the time of object creation and cannot be changed afterwards.

var resp = await _api.ProcessCardNotPresent(new CardNotPresentRequest {...});

  • This line is calling the ProcessCardNotPresent method on the _api instance, which presumably sends a payment request to the CyberSource API for a transaction where the card is not physically present (e.g., an online transaction).

  • The ProcessCardNotPresent method is asynchronous, as indicated by the await keyword, which means it returns a Task that represents the ongoing operation. The result of the operation (once it completes) is stored in the resp variable.

  • The ProcessCardNotPresent method takes a CardNotPresentRequest object as an argument, which is being created inline with the new keyword. This object is initialized with several properties:

  1. HubtelReference: This is a reference ID for the transaction, taken from the debitRequest object.

  2. Amount: This is the amount of the transaction, taken from the debitRequest object. BusinessName: This is the name of the business conducting the transaction, taken from the debitRequest object.

  3. Currency: This is the currency of the transaction, taken from the debitRequest object.

  4. City: This is the city where the transaction is taking place. In this case, it's hard-coded as "Accra".

  5. Token: This is presumably a payment token, taken from the debitRequest object.

c#
    private readonly ICyberSourceApi _api;

    var resp = await _api.ProcessCardNotPresent(new CardNotPresentRequest
    {
        HubtelReference = debitRequest.HubtelReference,
        Amount = debitRequest.Amount,
        BusinessName = debitRequest.BusinessName,
        Currency = debitRequest.Currency,
        City = "Accra",
        Token = debitRequest.Token
    });

Available Methods

Each method in the ICyberSourceApi interface represents a different operation that can be performed with the CyberSource API. All methods are asynchronous, as indicated by the return type of Task<T>, where T is the type of the response object.

Here's a brief overview of each method:

  • ProcessCardNotPresent(CardNotPresentRequest model): This method is used to process a payment where the card is not physically present.

  • ProcessCardAuthorization(CardAuthorizationRequest model): This method is used to authorize a payment card transaction.

  • ProcessCardAuthorizationReversal(CardAuthorizationReversalRequest model): This method is used to reverse a previously authorized payment card transaction.

  • Process3DSCheck(Card3DSCheckRequest model): This method is used to perform a 3D Secure check on a payment card transaction.

  • ProcessCardCreateToken(CardCreateTokenRequest model): This method is used to create a token for a payment card.

  • ProcessCardSale(CardSaleRequest model): This method is used to process a payment card sale transaction.

  • ProcessCardCaptureVoid(CardCaptureVoidRequest model): This method is used to void a previously captured payment card transaction.

  • ProcessCard3DSValidate(Card3DSValidateRequest model): This method is used to validate a 3D Secure payment card transaction.

  • Each method takes a request model as an argument, which contains the necessary data for the operation, and returns a Task that represents the ongoing operation. The result of the operation (once it completes) is a response model that contains the result of the operation.

c#
    public interface ICyberSourceApi
    {
        Task<CardNotPresentResponse> ProcessCardNotPresent(CardNotPresentRequest model);
        Task<CardAuthorizationResponse> ProcessCardAuthorization(CardAuthorizationRequest model);
        Task<CardAuthorizationReversalResponse> ProcessCardAuthorizationReversal(CardAuthorizationReversalRequest model);
        Task<Card3DSCheckResponse> Process3DSCheck(Card3DSCheckRequest model);
        Task<CardCreateTokenResponse> ProcessCardCreateToken(CardCreateTokenRequest model);
        Task<CardSaleResponse> ProcessCardSale(CardSaleRequest model);
        Task<CardCaptureVoidResponse> ProcessCardCaptureVoid(CardCaptureVoidRequest model);
        Task<Card3DSValidateResponse> ProcessCard3DSValidate(Card3DSValidateRequest model);
    }

Was this page helpful?

Happy React is loading...