WeBirr 1.0.3
dotnet add package WeBirr --version 1.0.3
NuGet\Install-Package WeBirr -Version 1.0.3
<PackageReference Include="WeBirr" Version="1.0.3" />
paket add WeBirr --version 1.0.3
#r "nuget: WeBirr, 1.0.3"
// Install WeBirr as a Cake Addin #addin nuget:?package=WeBirr&version=1.0.3 // Install WeBirr as a Cake Tool #tool nuget:?package=WeBirr&version=1.0.3
Official .NET Client Library for WeBirr Payment Gateway APIs
This Client Library provides convenient access to WeBirr Payment Gateway APIs from .NET/Xamarin Apps.
Install
run the following command to install webirr client library
With .NET CLI
$ dotnet add package WeBirr
With Package Manager
PM> Install-Package WeBirr
Usage
The library needs to be configured with a merchant Id & API key. You can get it by contacting webirr.com
You can use this library for production or test environments. you will need to set isTestEnv=true for test, and false for production apps when creating objects of class WeBirrClient
Example
using System;
using System.Threading.Tasks;
namespace WeBirr.Example
{
class Program
{
const string apikey = "YOUR_API_KEY";
const string merchantId = "YOUR_MERCHANT_ID";
//static readonly string apikey = Environment.GetEnvironmentVariable("wb_apikey_1") ?? "";
//static readonly string merchantId = Environment.GetEnvironmentVariable("wb_merchid_1") ?? "";
static async Task Main(string[] args)
{
await CreateAndUpdateBillAsync();
await GetPaymentStatusAsync();
await DeleteBillAsync();
}
/// Creating a new Bill / Updating an existing Bill on WeBirr Servers
public static async Task CreateAndUpdateBillAsync()
{
var api = new WeBirrClient(apikey: apikey, isTestEnv: true);
var bill = new Bill
{
amount = "270.90",
customerCode = "cc01", // it can be email address or phone number if you dont have customer code
customerName = "Elias Haileselassie",
time = "2021-07-22 22:14", // your bill time, always in this format
description = "hotel booking",
billReference = "dotnet/2021/132", // your unique reference number
merchantID = merchantId,
// customerPhone = "0968817878" // to use sms notification merchant needs to be activated at WeBirr
};
//bill.extras["newfield"] = "new value"; // extras is reserved for future use
//bill.extras["newcommand"] = "new value";
Console.WriteLine("Creating Bill...");
var res = await api.CreateBillAsync(bill);
if (res.error == null)
{
// success
var paymentCode = res.res ?? ""; // returns paymentcode such as 429 723 975
Console.WriteLine($"Payment Code = {paymentCode}"); // we may want to save payment code in local db.
}
else
{
// fail
Console.WriteLine($"error: {res.error}");
Console.WriteLine($"errorCode: {res.errorCode}"); // can be used to handle specific busines error such as ERROR_INVLAID_INPUT_DUP_REF
}
// update existing bill if it is not paid
bill.amount = "278.00";
bill.customerName = "Elias dotnet";
//bill.billReference = "WE CAN NOT CHANGE THIS";
Console.WriteLine("Updating Bill...");
res = await api.UpdateBillAsync(bill);
if (res.error == null)
{
// success
Console.WriteLine("bill is updated successfully"); //res.res will be 'OK' no need to check here!
}
else
{
// fail
Console.WriteLine($"error: {res.error}");
Console.WriteLine($"errorCode: {res.errorCode}"); // can be used to handle specific busines error such as ERROR_INVLAID_INPUT
}
}
/// Deleting an existing Bill from WeBirr Servers (if it is not paid)
public static async Task DeleteBillAsync()
{
var api = new WeBirrClient(apikey: apikey, isTestEnv: true);
var paymentCode = "PAYMENT_CODE_YOU_SAVED_AFTER_CREATING_A_NEW_BILL"; // suchas as '141 263 782';
Console.WriteLine("Deleting Bill...");
var res = await api.DeleteBillAsync(paymentCode);
if (res.error == null)
{
// success
Console.WriteLine("bill is deleted successfully"); //res.res will be 'OK' no need to check here!
}
else
{
// fail
Console.WriteLine($"error: {res.error}");
Console.WriteLine($"errorCode: {res.errorCode}"); // can be used to handle specific busines error such as ERROR_INVLAID_INPUT
}
}
/// Getting Payment status of an existing Bill from WeBirr Servers
public static async Task GetPaymentStatusAsync()
{
var api = new WeBirrClient(apikey: apikey, isTestEnv: true);
var paymentCode = "PAYMENT_CODE_YOU_SAVED_AFTER_CREATING_A_NEW_BILL"; // suchas as '141 263 782';
Console.WriteLine("Getting Payment Status...");
var r = await api.GetPaymentStatusAsync(paymentCode);
if (r.error == null)
{
// success
if (r.res?.IsPaid ?? false)
{
Console.WriteLine("bill is paid");
Console.WriteLine("bill payment detail");
Console.WriteLine($"Bank: {r.res?.data?.bankID}");
Console.WriteLine($"Bank Reference Number: {r.res?.data?.paymentReference}");
Console.WriteLine($"Amount Paid: {r.res?.data?.amount}");
}
else
Console.WriteLine("bill is pending payment");
}
else
{
// fail
Console.WriteLine($"error: {r.error}");
Console.WriteLine($"errorCode: {r.errorCode}"); // can be used to handle specific busines error such as ERROR_INVLAID_INPUT
}
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.AspNet.WebApi.Client (>= 5.2.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release