CampostPaymentSDK 1.0.2
See the version list below for details.
dotnet add package CampostPaymentSDK --version 1.0.2
NuGet\Install-Package CampostPaymentSDK -Version 1.0.2
<PackageReference Include="CampostPaymentSDK" Version="1.0.2" />
<PackageVersion Include="CampostPaymentSDK" Version="1.0.2" />
<PackageReference Include="CampostPaymentSDK" />
paket add CampostPaymentSDK --version 1.0.2
#r "nuget: CampostPaymentSDK, 1.0.2"
#:package CampostPaymentSDK@1.0.2
#addin nuget:?package=CampostPaymentSDK&version=1.0.2
#tool nuget:?package=CampostPaymentSDK&version=1.0.2
SDK name
CampostPayment.SDK
SDK version
1.0.2
SDK description
Campost Payment official SDK for .NET
Note
This .NET package let you easily integrate Campost Payment API to your application or your website. Before you start using this package, it's highly recommended to check resources below depending on your use case.
Table of Contents
- 1. Requirements
- 2. Installation
- 3. Interact with API
- 4. Security helpers
- More information
- More assistance
- Contributors
1. Requirements
This package requires:
- SDK .NET v7.0 or higher
2. Installation
2.1. Install Nuget package
First of all, install Nuget package. You have two possibilities
- Install from your CMD or your Terminal
$ dotnet add package CampostPaymentSDK --version 1.0.2
- Install from your .csproj file
Add the following to your .csproj file on <ItemGroup>
<PackageReference Include="CampostPaymentSDK" Version="1.0.2" />
then enter the following command to download the package and his dependencies
$ dotnet restore
2.2. Initialize SDK object
Now you need to initialize the SDK object with your API keys.
using CampostPayment;
using SeriLog;
const CP_PUBLIC_KEY = "Add your public key here";
const CP_PRIVATE_KEY = "Add your private key here";
CampostPaymentClient client = new CampostPaymentClient(CP_PUBLIC_KEY, CP_PRIVATE_KEY, null, true);
Recommendations:
- It is better for you to save your keys outside the source code, in places like environment variables and just load them from source code
- Logger object is optional, it is used for debug purposes.
- Both Logger and CampostPaymentClient objects don't need to be instantiated every time you need them, just instantiate them once (either at application startup or at first use) then share the instances within whole app with patterns such as Singleton or Dependency Injection
CampostPaymentClient constructor parameters:
CampostPaymentClient(CP_PUBLIC_KEY, CP_PRIVATE_KEY, logger = null, debug = false);
Parameter | Type | Default | Description |
---|---|---|---|
CP_PUBLIC_KEY |
string |
Your API public key | |
CP_PRIVATE_KEY |
string |
Your API private key | |
logger |
?LoggerInterface |
null |
Logger object |
debug |
boolean |
false |
true enables debug mode |
3. Interact with API
3.1. Payment link
Dictionary<string, dynamic> data = new Dictionary<string, dynamic>{
{"amount", 100},
{"currency", "XAF"},
{"orderId", "order123"},
{"reason", "Bic pen"},
{"customer", new Dictionary<string, string> {
{"firstName", "John"},
{"lastName", "DOE"},
{"phoneNumber", "690919555"},
{"email", "john@example.com"}
}},
};
try{
Dictionary<string, string>? response = await await client.paymentLink(data)
.Result.Content.ReadAsStringAsync()
.ContinueWith(async result => JsonConvert.DeserializeObject<Dictionary<string, string>>(await result));
string? payementLink = response?["paymentLink"]; // Redirect customer to this url
string? reference = response?["reference"]; // You can store this reference to order in your database
}catch(Exception exception){
throw new LoggingFailedException(exception.Message);
}
Method description:
paymentLink(Dictionary<string, dynamic> data): Task<HttpResponseMessage>
- @param
Dictionary<string, dynamic>
data
- @return
Task<HttpResponseMessage>
- @throws
LoggingFailedException
Data description:
For full data
description check Payment link section in API Docs
3.2. Direct collection
Dictionary<string, dynamic> data = new Dictionary<string, dynamic>{
{"amount", 100},
{"currency", "XAF"},
{"orderId", "order123"},
{"operator", "CM_OM"},
{"reason", "Bic pen"},
{"customer", new Dictionary<string, string> {
{"firstName", "John"},
{"lastName", "DOE"},
{"phoneNumber", "690919555"},
{"email", "john@example.com"}
}},
};
try{
Dictionary<string, string>? response = await await client.directCollection(data)
.Result.Content.ReadAsStringAsync()
.ContinueWith(async result => JsonConvert.DeserializeObject<Dictionary<string, string>>(await result));
string? reference = response?["reference"];
string? action = response?["action"];
if (action == "OTP"){
/* Ask your user to provide OTP received by SMS
Then perform OTP request (see next section) */
}else if (action == "MOBILE_PENDING"){
string? ussdCode = response?["ussdCode"];
}else{
throw new Exception($"Unknown action {action} in direct collection response");
}
}catch(Exception exception){
throw new LoggingFailedException(exception.Message);
}
Method description:
directCollection(Dictionary<string, dynamic> data): Task<HttpResponseMessage>
- @param
Dictionary<string, dynamic>
data
- @return
Task<HttpResponseMessage>
- @throws
LoggingFailedException
Data description:
For full data
description check direct collection section in API Docs
3.3 Direct collection otp
Dictionary<string, string> data = new Dictionary<string, string>{
{"reference", "c84b4326-0266-4df9-9999-2d2d945a5122"},
{"otp", "123456"}
};
try{
Dictionary<string, string>? response = await await client.directCollectionOtp(otpRequest)
.Result.Content.ReadAsStringAsync()
.ContinueWith(async result => JsonConvert.DeserializeObject<Dictionary<string, string>>(await result));
string? action = response?["action"]; // This tells you what to do next
if (action == "MOBILE_PENDING"){
string? ussdCode = response?["ussdCode"]; // Tell user to dial this USSD code on his phone
}else{
throw new Exception($"Unknown action {action} in direct collection response");
}
}catch(Exception exception){
throw new LoggingFailedException(exception.Message)
}
Method description:
directCollectionOtp(Dictionary<string, string> data): Task<HttpResponseMessage>
- @param
Dictionary<string, string>
data
- @return
Task<HttpResponseMessage>
- @throws
LoggingFailedException
Data description
For full data
description check OTP section in API Docs
3.4. Check status
try{
Dictionary<string, dynamic>? response = await await client.status("c84b4326-0266-4df9-9999-2d2d945a5122")
.Result.Content.ReadAsStringAsync()
.ContinueWith(async result => JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(await result));
string? status = response?["status"];
}catch(Exception exception){
throw new LoggingFailedException(exception.Message);
}
Method description:
status(string reference): Task<HttpResponseMessage>
- @param
string
reference
- @return
Task<HttpResponseMessage>
- @throws
LoggingFailedException
Data description
For more information check Status section in API Docs
3.5. Operators list
try{
Dictionary<string, dynamic>? response = await await client.operatorList()
.Result.Content.ReadAsStringAsync()
.ContinueWith(async result => JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(await result));
var operators = response?["operators"];
}catch(Exception exception){
throw new LoggingFailedException(exception.Message);
}
Method description:
operatorList(): Task<HttpResponseMessage>
- @param
none
- @return
Task<HttpResponseMessage>
- @throws
LoggingFailedException
Data description
This method not contains any parameters
4. Security helpers
4.1. IP verification
try {
string hostname = Dns.GetHostName();
string remoteIp = Dns.GetHostEntry(hostname).AddressList[0].ToString();
if (client.isVerifiedIp(remoteIp) == true){
//Process callback
}
}catch(Exception exception){
throw new LoggingFailedException(exception.Message);
}
Method description:
isVerifiedIp(string ip): bool
- @param
string
ip
- @return
bool
- @throws
CampostPayment.Exceptions.UnknownIpException
More information:
For more information check Security section in API Docs
4.2. Callback request integrity
using System.IO;
using System.Text.Json;
try{
using (StreamReader reader = new StreamReader(Request.Body))
{
string requestBody = await reader.ReadToEndAsync();
Dictionary<string, dynamic> callback_data = JsonSerializer.Deserialize<Dictionary<string, dynamic>>(requestBody);
}
if (client.checkWebhookIntegrity(callback_data) == true){
//Process callback
}
}catch(Exception exception){
throw new LoggingFailedException(exception.Message);
}
Method description:
checkWebhookIntegrity(Dictionary<string, dynamic> callback_data): true
- @param
Dictionary<string, dynamic>
callback_data
- @return
true
- @throws
CampostPayment.Exceptions.KeyMismatchException
- @throws
CampostPayment.Exceptions.BadSignatureException
More information:
For more information check Security section in API Docs
More assistance
ℹ️ If you need further information or assistance, our teams are available at contact@digitalhouse-int.com.
Contributors
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Summary of changes made in this release of the package.