Welcome to the LibertePay SDK Docs
LibertePay .NET SDK provides a comprehensive and seamless payment integration solution for your .NET applications. This SDK simplifies interaction with LibertePay's robust payment processing services, offering a clean, intuitive API for all your payment needs.
⨠Features
- Payment Processing
- Mobile Money Collections: Easily collect payments directly from mobile money wallets.
- Bank Account Transfers: Facilitate transfers to and from bank accounts.
- Card Payments: (Coming soon) Prepare for upcoming support for card-based transactions.
- Disbursements
- Mobile Money Wallets: Disburse funds directly to mobile money accounts.
- Bank Accounts: Send payments to various bank accounts.
- Bulk Payments: Efficiently handle large-scale disbursements for both Mobile Money and Bank Accounts.
- Transaction Management
- Status Tracking: Monitor the real-time status of your transactions.
- Reversals: (Coming soon) Gain the ability to reverse transactions.
- Reconciliation: (Coming soon) Streamline your financial reconciliation processes.
- Account Services
- Name Enquiry: Verify account names for both bank accounts and mobile money numbers, reducing errors.
- Balance Checking: Programmatically check your LibertePay account balance.
- KYC Verification: (Coming soon) Integrate Know Your Customer verification directly into your application.
- Advanced Features
- Built-in Telemetry: Gain insights into SDK performance and usage.
- High Performance: Optimized for speed and efficiency.
- Thread-safe Token Management: Secure and reliable handling of authentication tokens.
- Dependency Injection Support: Seamlessly integrate with modern .NET application architectures.
- Type-safe Institution Codes: Ensure accuracy and reduce errors with strongly typed institution codes.
- Automatic Callback Handling: Simplify the processing of asynchronous payment notifications.
đģ Installation
Get started quickly by installing the LibertePay SDK via NuGet:
LibertePay.Core.Sdk
âī¸ Configuration
Basic Configuration
Add the LibertePay configuration details to your appsettings.json
file. Replace the placeholder values with your actual credentials provided during your LibertePay setup.
{
"LibertePay": {
"BaseUrl": "https://app-base-url/", /* Provided during LibertePay setup */
"Username": "your-username", /* Provided during LibertePay setup */
"Password": "your-password", /* Provided during LibertePay setup */
"HttpClientTimeoutSeconds": 30,
"CallbackUrl": "https://your-domain.com/webhook", /* Provided during LibertePay setup */
"TelemetryApiUrl": "" /* Provided during LibertePay setup */
}
}
Service Registration
Register the LibertePay services in your Program.cs
(for .NET 6+) or Startup.cs
file using the extension method:
using LibertePay.Core.DependencyInjection;
using Microsoft.Extensions.DependencyInjection; // Required for AddLibertePay
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// ... (other service registrations)
builder.Services.AddLibertePay(builder.Configuration);
// ... (rest of your Program.cs/Startup.cs)
đĄī¸ Error Handling
The SDK provides a consistent response format through the LibertePayResponse<T>
class, simplifying error detection and handling:
- IsSuccess: A boolean indicating if the operation was successful.
- StatusCode: The API's status code for the operation.
- StatusDesc: A human-readable description of the status.
- Data: The actual response data when the operation is successful.
- Message: An error message if the operation was unsuccessful.
đ Usage Guide
1. Name Enquiry Services
Bank Account Name Enquiry (Single & Bulk)
using LibertePay.Core.Clients; // For ILibertePayClient
using LibertePay.Core.Requests; // For NameEnquiryRequest, BulkNameEnquiryRequest etc.
using LibertePay.Core.Constants; // For Channels, InstitutionCodes
using Microsoft.AspNetCore.Mvc; // For IActionResult, HttpGet
using Microsoft.Extensions.Logging; // For ILogger
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq; // For .Select()
[ApiController]
[Route("api/[controller]")]
public class PaymentServiceController : ControllerBase // Renamed for clarity as an API controller
{
// ... implementation ...
}
Mobile Money Name Enquiry (Single & Bulk)
// Inside PaymentServiceController class
///
/// Verifies a single mobile money account name.
///
[HttpGet("VerifyMobileMoney")]
public async Task VerifyMobileMoneyAsync()
{
// ... implementation ...
}
2. Payment Collections
Mobile Money Collection
// Inside PaymentServiceController class
///
/// Initiates a mobile money collection (debit) from a customer's account.
///
[HttpGet("MobileMoneyCollection")]
public async Task MobileMoneyCollection(decimal amount, string description)
{
// ... implementation ...
}
3. Disbursements
Bank Disbursement
// Inside PaymentServiceController class
///
/// Handles a single bank disbursement (credit) to a recipient's bank account.
///
public async Task DisburseToBankAsync(decimal amount, string description)
{
// ... implementation ...
}
Mobile Money Disbursement
// Inside PaymentServiceController class
///
/// Handles a single mobile money disbursement (credit) to a recipient's mobile money wallet.
///
public async Task DisburseToMobileMoneyAsync(decimal amount, string description)
{
// ... implementation ...
}
4. Transaction Management
Check Transaction Status
using LibertePay.Core.Responses; // For TransactionStatusResponse
using LibertePay.Core.Requests; // For TransactionStatusRequest
using LibertePay.Core.Constants; // For ErrorCodes (if applicable)
// Inside PaymentServiceController or a dedicated TransactionService
///
/// Checks the status of a single transaction.
///
public async Task CheckTransactionStatusAsync(
string transactionId,
string transactionType)
{
// ... implementation ...
}
5. Account Services
Check Balance
// Inside PaymentServiceController or a dedicated AccountService
///
/// Retrieves the available and current balance of your LibertePay account.
///
public async Task<(decimal Available, decimal Current)> GetBalanceAsync()
{
// ... implementation ...
}
âŠī¸ Callback Implementation
1. Configure Callback URL
Ensure your callback URL is correctly configured in your appsettings.json
. This is the endpoint LibertePay will send notifications to.
{
"LibertePay": {
"CallbackUrl": "https://your-domain.com/api/callback" /* This URL must be provided during LibertePay setup */
}
}
2. Callback Types and Scenarios
- Transaction Callbacks: Mobile Money Collection, Bank Transfer, Bulk Payment
- Mandate Callbacks: Mandate Creation, Recurring Payment
3. Callback Payload Structure
Transaction Callback
{
"status": "string", // Human-readable status (e.g., "SUCCESS", "PENDING", "FAILED")
"statusCode": "string", // Numeric status code (e.g., "00" for success, "01" for pending)
"message": "string", // Additional details or error message
"transactionId": "string", // Your original transaction ID
"institutionApprovalCode": "string", // Approval code from the institution
"externalTransactionId": "string" // LibertePay's internal transaction ID
}
Mandate Callback
{
"statusCode": "string", // Numeric status code
"status": "string", // Human-readable status (e.g., "ACTIVE", "CANCELLED", "EXPIRED", "FAILED")
"message": "string", // Additional details or error message
"expiryDate": "string", // Expiry date of the mandate (if applicable)
"transactionId": "string", // Original transaction ID related to mandate creation/payment
"mandateReference": "string", // Unique reference for the mandate
"mandateId": "string", // LibertePay's ID for the mandate
"msisdnToken": null // MSISDN token (if applicable for mobile money mandates)
}
4. Create Callback Controller
using LibertePay.Core.Callbacks; // Assuming these types are defined in your SDK
using LibertePay.Core.Clients;
using LibertePay.Core.Constants; // For ErrorCodes
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
[ApiController]
[Route("api/[controller]")]
public class CallbackController : ControllerBase
{
// ... implementation ...
}
đĻ Institution Codes
The SDK provides a type-safe way to interact with various financial institutions through the InstitutionCodes
enum. This offers several benefits:
- Compile-time checking: Catch errors related to invalid institution codes before runtime.
- IntelliSense support: Easily discover available institutions directly in your IDE.
- Automatic conversion: The SDK handles the conversion from enum to the correct string format for API calls.
Available Institution Codes
Mobile Money Operators- InstitutionCodes.Mtn (300591)
- InstitutionCodes.Vodafone (300592)
- InstitutionCodes.AirtelTigo (300593)
- ... (Refer to the InstitutionCodes enum in the SDK for a complete and up-to-date list)
- InstitutionCodes.GcbBankLimited (300304)
- InstitutionCodes.EcobankGhanaLtd (300312)
- InstitutionCodes.AgriculturalDevelopmentBank (300307)
- InstitutionCodes.CalBankLimited (300313)
- InstitutionCodes.FidelityBankLimited (300323)
- InstitutionCodes.AccessBankLtd (300329)
- InstitutionCodes.ZenithBankGhanaLtd (300311)
- InstitutionCodes.GuarantyTrustBank (300322)
- InstitutionCodes.UnitedBankOfAfrica (300325)
- InstitutionCodes.StanbicBank (300318)
- InstitutionCodes.RepublicBankLimited (300310)
- InstitutionCodes.FirstBankOfNigeria (300319)
- InstitutionCodes.AbsaBankGhanaLimited (300303)
- InstitutionCodes.NationalInvestmentBank (300305)
- InstitutionCodes.Omnibisic (300324)
- InstitutionCodes.ConsolidatedBankGhana (300331)
- ... (Refer to the InstitutionCodes enum in the SDK for a complete and up-to-date list)
Using Institution Codes
// Direct enum usage for type safety and IntelliSense
var request = new NameEnquiryRequest
{
AccountNumber = "1234567890",
Institution = InstitutionCodes.Mtn // Recommended approach
};
// Getting the string value of an institution code (e.g., for logging or specific API needs)
string mtnCodeString = InstitutionCodes.Mtn.ToString(); // Returns "300591"
// Parsing a string back to an enum (useful if codes come from configuration or external sources)
// Ensure robust error handling if parsing user input
if (Enum.TryParse("300304", out InstitutionCodes parsedBankCode))
{
Console.WriteLine($"Parsed bank code: {parsedBankCode}"); // Output: GcbBankLimited
}
đ Channel Types
When specifying payment channels, use the Channels
constants for clarity and consistency:
- Channels.INTERBANK: Used for bank-to-bank transactions.
- Channels.MNO: Used for Mobile Network Operator (Mobile Money) transactions.
- Channels.CARD: Used for card payments (coming soon).
â Support
For any questions, issues, or assistance with the LibertePay SDK, please reach out to our support team:
- Email: michael.ameyaw@persol.net
- Comprehensive Documentation: https://docs.libertepay.com
- API Reference: https://api.libertepay.com
đ License
This SDK is open-sourced and licensed under the MIT License. For more details, please refer to the LICENSE file in the repository.