Skip to content

Commit

Permalink
async naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
elias-haileselassie committed Aug 6, 2021
1 parent c8c42d7 commit d319300
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 40 deletions.
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ namespace WeBirr.Example
static async Task Main(string[] args)
{
await CreateAndUpdateBill();
await GeytPaymentStatus();
await DeleteBill();
await CreateAndUpdateBillAsync();
await GetPaymentStatusAsync();
await DeleteBillAsync();
}

/// Creating a new Bill / Updating an existing Bill on WeBirr Servers
public static async Task CreateAndUpdateBill()
public static async Task CreateAndUpdateBillAsync()
{
var api = new WeBirrClient(apikey: apikey, isTestEnv: true);

Expand All @@ -65,7 +65,7 @@ namespace WeBirr.Example

Console.WriteLine("Creating Bill...");

var res = await api.CreateBill(bill);
var res = await api.CreateBillAsync(bill);

if (res.error == null)
{
Expand All @@ -88,12 +88,12 @@ namespace WeBirr.Example

Console.WriteLine("Updating Bill...");
res = await api.UpdateBill(bill);
res = await api.UpdateBillAsync(bill);

if (res.error == null)
{
// success
Console.WriteLine("bill is updated succesfully"); //res.res will be 'OK' no need to check here!
Console.WriteLine("bill is updated successfully"); //res.res will be 'OK' no need to check here!
}
else
{
Expand All @@ -105,19 +105,19 @@ namespace WeBirr.Example
}

/// Deleting an existing Bill from WeBirr Servers (if it is not paid)
public static async Task DeleteBill()
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.DeleteBill(paymentCode);
var res = await api.DeleteBillAsync(paymentCode);

if (res.error == null)
{
// success
Console.WriteLine("bill is deleted succesfully"); //res.res will be 'OK' no need to check here!
Console.WriteLine("bill is deleted successfully"); //res.res will be 'OK' no need to check here!
}
else
{
Expand All @@ -129,14 +129,14 @@ namespace WeBirr.Example
}

/// Getting Payment status of an existing Bill from WeBirr Servers
public static async Task GeytPaymentStatus()
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.GetPaymentStatus(paymentCode);
var r = await api.GetPaymentStatusAsync(paymentCode);

if (r.error == null)
{
Expand Down Expand Up @@ -164,7 +164,6 @@ namespace WeBirr.Example
}
}


```


24 changes: 12 additions & 12 deletions WeBirr.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ class Program

static async Task Main(string[] args)
{
await CreateAndUpdateBill();
await GeytPaymentStatus();
await DeleteBill();
await CreateAndUpdateBillAsync();
await GetPaymentStatusAsync();
await DeleteBillAsync();
}

/// Creating a new Bill / Updating an existing Bill on WeBirr Servers
public static async Task CreateAndUpdateBill()
public static async Task CreateAndUpdateBillAsync()
{
var api = new WeBirrClient(apikey: apikey, isTestEnv: true);

Expand All @@ -36,7 +36,7 @@ public static async Task CreateAndUpdateBill()

Console.WriteLine("Creating Bill...");

var res = await api.CreateBill(bill);
var res = await api.CreateBillAsync(bill);

if (res.error == null)
{
Expand All @@ -59,12 +59,12 @@ public static async Task CreateAndUpdateBill()


Console.WriteLine("Updating Bill...");
res = await api.UpdateBill(bill);
res = await api.UpdateBillAsync(bill);

if (res.error == null)
{
// success
Console.WriteLine("bill is updated succesfully"); //res.res will be 'OK' no need to check here!
Console.WriteLine("bill is updated successfully"); //res.res will be 'OK' no need to check here!
}
else
{
Expand All @@ -76,19 +76,19 @@ public static async Task CreateAndUpdateBill()
}

/// Deleting an existing Bill from WeBirr Servers (if it is not paid)
public static async Task DeleteBill()
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.DeleteBill(paymentCode);
var res = await api.DeleteBillAsync(paymentCode);

if (res.error == null)
{
// success
Console.WriteLine("bill is deleted succesfully"); //res.res will be 'OK' no need to check here!
Console.WriteLine("bill is deleted successfully"); //res.res will be 'OK' no need to check here!
}
else
{
Expand All @@ -100,14 +100,14 @@ public static async Task DeleteBill()
}

/// Getting Payment status of an existing Bill from WeBirr Servers
public static async Task GeytPaymentStatus()
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.GetPaymentStatus(paymentCode);
var r = await api.GetPaymentStatusAsync(paymentCode);

if (r.error == null)
{
Expand Down
20 changes: 10 additions & 10 deletions WeBirr.Test/WeBirrClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public async Task CreateBill_should_get_error_from_WebService_on_invalid_api_key
var bill = sampleBill();
var api = new WeBirrClient("x", true);

var res = await api.CreateBill(bill);
Assert.IsTrue(res.error.Length > 0);
var res = await api.CreateBillAsync(bill);
Assert.IsTrue(res.errorCode.Length > 0);

}

Expand All @@ -23,8 +23,8 @@ public async Task CreateBill_should_get_error_from_WebService_on_invalid_api_key
var bill = sampleBill();
var api = new WeBirrClient("x", false);

var res = await api.CreateBill(bill);
Assert.IsTrue(res.error.Length > 0);
var res = await api.CreateBillAsync(bill);
Assert.IsTrue(res.errorCode.Length > 0);

}

Expand All @@ -34,27 +34,27 @@ public async Task UpdateBill_should_get_error_from_WebService_on_invalid_api_key
var bill = sampleBill();
var api = new WeBirrClient("x", true);

var res = await api.UpdateBill(bill);
Assert.IsTrue(res.error.Length > 0);
var res = await api.UpdateBillAsync(bill);
Assert.IsTrue(res.errorCode.Length > 0);

}

[Test]
public async Task DeleteBill_should_get_error_from_WebService_on_invalid_api_key()
{
var api = new WeBirrClient("x", true);
var res = await api.DeleteBill("xxxx");
var res = await api.DeleteBillAsync("xxxx");

Assert.IsTrue(res.error.Length > 0); // should contain error
Assert.IsTrue(res.error.Length > 0); // should contain error, erroCode is not implemented for deleteBill
}

[Test]
public async Task GetPaymentStatus_should_get_error_from_WebService_on_invalid_api_key()
{
var api = new WeBirrClient("x", true);
var res = await api.GetPaymentStatus("xxxx");
var res = await api.GetPaymentStatusAsync("xxxx");

Assert.IsTrue(res.error.Length > 0); // should contain error
Assert.IsTrue(res.errorCode.Length > 0); // should contain error
}

Bill sampleBill() => new Bill
Expand Down
2 changes: 1 addition & 1 deletion WeBirr/WeBirr.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>WeBirr</RootNamespace>
<PackageId>WeBirr</PackageId>
<Version>1.0.1</Version>
<Version>1.0.2</Version>
<Authors>WeBirr</Authors>
<Product>WeBirr</Product>
<Description>Official .NET Client Library for WeBirr Payment Gateway APIs</Description>
Expand Down
8 changes: 4 additions & 4 deletions WeBirr/WeBirrClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public WeBirrClient(string apikey, bool isTestEnv)
/// </summary>
/// <param name="bill">Bill object to be created</param>
/// <returns></returns>
public async Task<ApiResponse<String>> CreateBill(Bill bill)
public async Task<ApiResponse<String>> CreateBillAsync(Bill bill)
{
var client = new HttpClient();

Expand All @@ -51,7 +51,7 @@ public async Task<ApiResponse<String>> CreateBill(Bill bill)
/// The billReference has to be the same as the original bill created.
/// Check if(ApiResponse.error == null) to see if there are errors.
/// ApiResponse.res will have the value of "OK" on success.
public async Task<ApiResponse<String>> UpdateBill(Bill bill)
public async Task<ApiResponse<String>> UpdateBillAsync(Bill bill)
{
var client = new HttpClient();

Expand All @@ -73,7 +73,7 @@ public async Task<ApiResponse<String>> UpdateBill(Bill bill)
/// [paymentCode] is the number that WeBirr Payment Gateway returns on createBill.
/// Check if(ApiResponse.error == null) to see if there are errors.
/// ApiResponse.res will have the value of "OK" on success.
public async Task<ApiResponse<String>> DeleteBill(String paymentCode)
public async Task<ApiResponse<String>> DeleteBillAsync(String paymentCode)
{
var client = new HttpClient();

Expand All @@ -94,7 +94,7 @@ public async Task<ApiResponse<String>> DeleteBill(String paymentCode)
/// ApiResponse.res will have `Payment` object on success (will be null otherwise!)
/// ApiResponse.res?.isPaid ?? false -> will return true if the bill is paid (payment completed)
/// ApiResponse.res?.data ?? null -> will have `PaymentDetail` object
public async Task<ApiResponse<Payment>> GetPaymentStatus(String paymentCode)
public async Task<ApiResponse<Payment>> GetPaymentStatusAsync(String paymentCode)
{
var client = new HttpClient();

Expand Down

0 comments on commit d319300

Please sign in to comment.