Skip to content

Commit 6013eb5

Browse files
unit tests added
1 parent ec4f410 commit 6013eb5

8 files changed

+188
-11
lines changed

Diff for: CHANGELOG.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
## 0.1.0
22

3-
- test publication
3+
- Test publication
44

55
## 1.0.0
66

77
- Initial version
88

99
## 1.0.1
1010

11-
- Examples added
11+
- Examples added
12+
13+
## 1.0.2
14+
15+
- Unit tests added

Diff for: README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,10 @@ import 'package:webirr/webirr.dart';
9999
void main() async {
100100
101101
const apikey = 'YOUR_API_KEY';
102-
const merchantId = 'YOUR_MERCHANT_ID';
103102
104103
var api = new WeBirrClient(apikey: apikey, isTestEnv: true);
105104
106-
var paymentCode = 'PAYMENT_CODE_YOU_SAVED_AFTER_CREATING_A_NEW_BILL' // suchas as '141 263 782';
105+
var paymentCode = 'PAYMENT_CODE_YOU_SAVED_AFTER_CREATING_A_NEW_BILL'; // suchas as '141 263 782';
107106
108107
print('Getting Payment Status...');
109108
var r = await api.getPaymentStatus(paymentCode);
@@ -137,14 +136,13 @@ import 'package:webirr/webirr.dart';
137136
void main() async {
138137
139138
const apikey = 'YOUR_API_KEY';
140-
const merchantId = 'YOUR_MERCHANT_ID';
141139
142140
var api = new WeBirrClient(apikey: apikey, isTestEnv: true);
143141
144-
var paymentCode = 'PAYMENT_CODE_YOU_SAVED_AFTER_CREATING_A_NEW_BILL' // suchas as '141 263 782';
142+
var paymentCode = 'PAYMENT_CODE_YOU_SAVED_AFTER_CREATING_A_NEW_BILL'; // suchas as '141 263 782';
145143
146144
print('Deleting Bill...');
147-
res = await api.deleteBill(paymentCode);
145+
var res = await api.deleteBill(paymentCode);
148146
149147
if (res.error == null) {
150148
// success

Diff for: example/lib/create_update_bill_example.dart

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import 'package:webirr/webirr.dart';
2+
3+
void main() async {
4+
const apikey = 'YOUR_API_KEY';
5+
const merchantId = 'YOUR_MERCHANT_ID';
6+
7+
var api = new WeBirrClient(apikey: apikey, isTestEnv: true);
8+
9+
var bill = new Bill(
10+
amount: '270.90',
11+
customerCode:
12+
'cc01', // it can be email address or phone number if you dont have customer code
13+
customerName: 'Elias Haileselassie',
14+
time: '2021-07-22 22:14', // your bill time, always in this format
15+
description: 'hotel booking',
16+
billReference: 'drt/2021/125', // your unique reference number
17+
merchantID: merchantId,
18+
);
19+
20+
print('Creating Bill...');
21+
var res = await api.createBill(bill);
22+
23+
var paymentCode = '';
24+
25+
if (res.error == null) {
26+
// success
27+
paymentCode = res.res ?? ''; // returns paymentcode such as 429 723 975
28+
print(
29+
'Payment Code = $paymentCode'); // we may want to save payment code in local db.
30+
31+
} else {
32+
// fail
33+
print('error: ${res.error}');
34+
print(
35+
'errorCode: ${res.errorCode}'); // can be used to handle specific busines error such as ERROR_INVLAID_INPUT_DUP_REF
36+
}
37+
38+
// update existing bill if it is not paid
39+
bill.amount = "278.00";
40+
bill.customerName = 'Elias dart3';
41+
//bill.billReference = "WE CAN NOT CHANGE THIS";
42+
43+
print('Updating Bill...');
44+
res = await api.updateBill(bill);
45+
46+
if (res.error == null) {
47+
// success
48+
print(
49+
'bill is updated succesfully'); //res.res will be 'OK' no need to check here!
50+
} else {
51+
// fail
52+
print('error: ${res.error}');
53+
print(
54+
'errorCode: ${res.errorCode}'); // can be used to handle specific busines error such as ERROR_INVLAID_INPUT
55+
}
56+
}

Diff for: example/lib/delete_bill_example.dart

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import 'package:webirr/webirr.dart';
2+
3+
void main() async {
4+
const apikey = 'YOUR_API_KEY';
5+
6+
var api = new WeBirrClient(apikey: apikey, isTestEnv: true);
7+
8+
var paymentCode =
9+
'PAYMENT_CODE_YOU_SAVED_AFTER_CREATING_A_NEW_BILL'; // suchas as '141 263 782';
10+
11+
print('Deleting Bill...');
12+
var res = await api.deleteBill(paymentCode);
13+
14+
if (res.error == null) {
15+
// success
16+
print(
17+
'bill is deleted succesfully'); //res.res will be 'OK' no need to check here!
18+
} else {
19+
// fail
20+
print('error: ${res.error}');
21+
print(
22+
'errorCode: ${res.errorCode}'); // can be used to handle specific bussines error such as ERROR_INVLAID_INPUT
23+
}
24+
}

Diff for: example/lib/get_payment_status_example.dart

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'package:webirr/webirr.dart';
2+
3+
void main() async {
4+
const apikey = 'YOUR_API_KEY';
5+
6+
var api = new WeBirrClient(apikey: apikey, isTestEnv: true);
7+
8+
var paymentCode =
9+
'PAYMENT_CODE_YOU_SAVED_AFTER_CREATING_A_NEW_BILL'; // suchas as '141 263 782';
10+
11+
print('Getting Payment Status...');
12+
var r = await api.getPaymentStatus(paymentCode);
13+
14+
if (r.error == null) {
15+
// success
16+
if (r.res?.isPaid ?? false) {
17+
print('bill is paid');
18+
print('bill payment detail');
19+
print('Bank: ${r.res?.data?.bankID}');
20+
print('Bank Reference Number: ${r.res?.data?.paymentReference}');
21+
print('Amount Paid: ${r.res?.data?.amount}');
22+
} else
23+
print('bill is pending payment');
24+
} else {
25+
// fail
26+
print('error: ${r.error}');
27+
print(
28+
'errorCode: ${r.errorCode}'); // can be used to handle specific busines error such as ERROR_INVLAID_INPUT
29+
}
30+
}

Diff for: lib/src/payment.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class Payment {
33
/// 0 = not paid, 1 = payment in progress, 2. paid !
44
late int status;
55
PaymentDetail? data;
6-
6+
77
Payment.fromJson(Map<String, dynamic> json) {
88
status = json['status'];
99
data =

Diff for: pubspec.yaml

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
name: webirr
2-
version: 1.0.1
2+
version: 1.0.2
33
description: >-
4-
Official Dart Client Library for WeBirr APIs
4+
Official Dart Client Library for WeBirr Payment Gateway APIs.
5+
It provides convenient access to WeBirr Payment Gateway APIs from Dart/Flutter Apps.
56
homepage: https://github.com/webirr/webirr-api-dart-client
67
environment:
78
sdk: '>=2.12.0 <3.0.0'
89
dependencies:
9-
http: ^0.13.3
10+
http: ^0.13.3
11+
dev_dependencies:
12+
test: ^1.17.10

Diff for: test/webirr_test.dart

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import 'package:test/test.dart';
2+
import 'package:webirr/webirr.dart';
3+
4+
void main() {
5+
test(
6+
'createBill should get error from WebService on invalid api key - TestEnv',
7+
() async {
8+
var bill = sampleBill();
9+
10+
var api = new WeBirrClient(apikey: 'x', isTestEnv: true);
11+
var res = await api.createBill(bill);
12+
13+
expect((res.error?.length ?? 0) > 0, true); // should contain error
14+
});
15+
16+
test(
17+
'createBill should get error from WebService on invalid api key - ProdEnv',
18+
() async {
19+
var bill = sampleBill();
20+
21+
var api = new WeBirrClient(apikey: 'x', isTestEnv: false);
22+
var res = await api.createBill(bill);
23+
24+
expect((res.error?.length ?? 0) > 0, true); // should contain error
25+
});
26+
27+
test('updateBill should get error from WebService on invalid api key',
28+
() async {
29+
var bill = sampleBill();
30+
31+
var api = new WeBirrClient(apikey: 'x', isTestEnv: true);
32+
var res = await api.updateBill(bill);
33+
34+
expect((res.error?.length ?? 0) > 0, true); // should contain error
35+
});
36+
37+
test('deleteBill should get error from WebService on invalid api key',
38+
() async {
39+
var api = new WeBirrClient(apikey: 'x', isTestEnv: true);
40+
var res = await api.deleteBill('xxxx');
41+
42+
expect((res.error?.length ?? 0) > 0, true); // should contain error
43+
});
44+
45+
test('getPaymentStatus should get error from WebService on invalid api key',
46+
() async {
47+
var api = new WeBirrClient(apikey: 'x', isTestEnv: true);
48+
var res = await api.getPaymentStatus('xxxx');
49+
50+
expect((res.error?.length ?? 0) > 0, true); // should contain error
51+
});
52+
}
53+
54+
Bill sampleBill() => Bill(
55+
amount: '270.90',
56+
customerCode: 'cc01',
57+
customerName: 'Elias Haileselassie',
58+
time: '2021-07-22 22:14',
59+
description: 'hotel booking',
60+
billReference: 'drt/2021/125',
61+
merchantID: 'x',
62+
);

0 commit comments

Comments
 (0)