Skip to content

Commit e0d740d

Browse files
initial
1 parent c4ba203 commit e0d740d

File tree

9 files changed

+501
-80
lines changed

9 files changed

+501
-80
lines changed

Diff for: README.md

+202-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,203 @@
1-
# webirr-api-php-client
21
Official PHP Client Library for WeBirr Payment Gateway APIs
2+
3+
This Client Library provides convenient access to WeBirr Payment Gateway APIs from PHP Applications.
4+
5+
## Install
6+
7+
```bash
8+
$ composer require webirr/webirr
9+
```
10+
11+
## Usage
12+
13+
The library needs to be configured with a *merchant Id* & *API key*. You can get it by contacting [webirr.com](https://webirr.com)
14+
15+
> 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
16+
17+
## Example
18+
19+
### Creating a new Bill / Updating an existing Bill on WeBirr Servers
20+
21+
```php
22+
<?php
23+
24+
require 'vendor/autoload.php';
25+
26+
use WeBirr\Bill;
27+
use WeBirr\WeBirrClient;
28+
29+
// Create & Update Bill
30+
function main()
31+
{
32+
$apiKey = 'YOUR_API_KEY';
33+
$merchantId = 'YOUR_MERCHANT_ID';
34+
35+
//$apiKey = getenv('wb_apikey_1');
36+
//$merchantId = getenv('wb_merchid_1');
37+
38+
$api = new WeBirrClient($apiKey, true);
39+
40+
$bill = new Bill();
41+
42+
$bill->amount = '270.90';
43+
$bill->customerCode = 'cc01'; // it can be email address or phone number if you dont have customer code
44+
$bill->customerName = 'Elias Haileselassie';
45+
$bill->time = '2021-07-22 22:14'; // your bill time, always in this format
46+
$bill->description = 'hotel booking';
47+
$bill->billReference = 'php/2021/127'; // your unique reference number
48+
$bill->merchantID = $merchantId;
49+
50+
echo "\nCreating Bill...";
51+
52+
$res = $api->createBill($bill);
53+
54+
if (!$res->error) {
55+
// success
56+
$paymentCode = $res->res; // returns paymentcode such as 429 723 975
57+
echo "\nPayment Code = $paymentCode"; // we may want to save payment code in local db.
58+
59+
} else {
60+
// fail
61+
echo "\nerror: $res->error";
62+
echo "\nerrorCode: $res->errorCode"; // can be used to handle specific busines error such as ERROR_INVLAID_INPUT_DUP_REF
63+
}
64+
65+
//var_dump($res);
66+
67+
// Update existing bill if it is not paid
68+
$bill->amount = "278.00";
69+
$bill->customerName = 'Elias php';
70+
//$bill->billReference = "WE CAN NOT CHANGE THIS";
71+
72+
echo "\nUpdating Bill...";
73+
74+
$res = $api->updateBill($bill);
75+
76+
if (!$res->error) {
77+
// success
78+
echo "\nbill is updated succesfully"; //res.res will be 'OK' no need to check here!
79+
} else {
80+
// fail
81+
echo "\nerror: $res->error";
82+
echo "\nerrorCode: $res->errorCode"; // can be used to handle specific busines error such as ERROR_INVLAID_INPUT
83+
}
84+
}
85+
86+
main();
87+
88+
```
89+
90+
### Getting Payment status of an existing Bill from WeBirr Servers
91+
92+
```php
93+
<?php
94+
95+
require 'vendor/autoload.php';
96+
97+
use WeBirr\Bill;
98+
use WeBirr\WeBirrClient;
99+
100+
// Get Payment Status of Bill
101+
function main()
102+
{
103+
$apiKey = 'YOUR_API_KEY';
104+
$merchantId = 'YOUR_MERCHANT_ID';
105+
106+
//$apiKey = getenv('wb_apikey_1');
107+
//$merchantId = getenv('wb_merchid_1');
108+
109+
$api = new WeBirrClient($apiKey, true);
110+
111+
$paymentCode = 'PAYMENT_CODE_YOU_SAVED_AFTER_CREATING_A_NEW_BILL'; // suchas as '141 263 782';
112+
113+
echo "\nGetting Payment Status...";
114+
115+
$res = $api->getPaymentStatus($paymentCode);
116+
117+
if (!$res->error) {
118+
// success
119+
if ($res->res->status == 2) {
120+
$data = $res->res->data;
121+
echo "\nbill is paid";
122+
echo "\nbill payment detail";
123+
echo "\nBank: $data->bankID";
124+
echo "\nBank Reference Number: $data->paymentReference";
125+
echo "\nAmount Paid: $data->amount";
126+
} else
127+
echo "\nbill is pending payment";
128+
} else {
129+
// fail
130+
echo "\nerror: $res->error";
131+
echo "\nerrorCode: $res->errorCode"; // can be used to handle specific busines error such as ERROR_INVLAID_INPUT
132+
}
133+
134+
//var_dump($res);
135+
}
136+
137+
main();
138+
139+
```
140+
141+
*Sample object returned from getPaymentStatus()*
142+
143+
```javascript
144+
{
145+
error: null,
146+
res: {
147+
status: 2,
148+
data: {
149+
id: 111112347,
150+
paymentReference: '8G3303GHJN',
151+
confirmed: true,
152+
confirmedTime: '2021-07-03 10:25:35',
153+
bankID: 'cbe_birr',
154+
time: '2021-07-03 10:25:33',
155+
amount: '4.60',
156+
wbcCode: '624 549 955'
157+
}
158+
},
159+
errorCode: null
160+
}
161+
162+
```
163+
164+
### Deleting an existing Bill from WeBirr Servers (if it is not paid)
165+
166+
```php
167+
<?php
168+
169+
require 'vendor/autoload.php';
170+
171+
use WeBirr\WeBirrClient;
172+
173+
// Delete an existing Bill
174+
function main()
175+
{
176+
$apiKey = 'YOUR_API_KEY';
177+
$merchantId = 'YOUR_MERCHANT_ID';
178+
179+
//$apiKey = getenv('wb_apikey_1');
180+
//$merchantId = getenv('wb_merchid_1');
181+
182+
$api = new WeBirrClient($apiKey, true);
183+
184+
$paymentCode = 'PAYMENT_CODE_YOU_SAVED_AFTER_CREATING_A_NEW_BILL'; // suchas as '141 263 782';
185+
186+
echo "\nDeleting Bill...";
187+
188+
$res = $api->deleteBill($paymentCode);
189+
190+
if (!$res->error) {
191+
// success
192+
echo "\nbill is deleted succesfully"; //res.res will be 'OK' no need to check here!
193+
} else {
194+
// fail
195+
echo "\nerror: $res->error";
196+
echo "\nerrorCode: $res->errorCode"; // can be used to handle specific bussines error such as ERROR_INVLAID_INPUT
197+
}
198+
//var_dump($res);
199+
}
200+
201+
main();
202+
203+
```

Diff for: composer.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
}
1515
],
1616
"require": {
17-
"php": "^7.2.5||^8.0",
18-
"guzzlehttp/guzzle": "^7.3",
19-
"guzzlehttp/psr7": "^1.8||^2.0"
17+
"php": "^5.6||^7.0||^8.0",
18+
"guzzlehttp/guzzle": "~5.3.3||~6.0||~7.3",
19+
"guzzlehttp/psr7": "^1.8"
2020
},
2121
"require-dev": {
2222
"phpunit/phpunit": "^9.5"
@@ -25,5 +25,11 @@
2525
"psr-4": {
2626
"WeBirr\\": "src/"
2727
}
28+
},
29+
"autoload-dev": {
30+
"psr-4": {
31+
"WeBirr\\": "src/",
32+
"WeBirr\\Tests\\": "tests/"
33+
}
2834
}
2935
}

Diff for: examples/example.php

-33
This file was deleted.

Diff for: examples/example1.php

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
require 'vendor/autoload.php';
4+
5+
use WeBirr\Bill;
6+
use WeBirr\WeBirrClient;
7+
8+
// Create & Update Bill
9+
function main()
10+
{
11+
$apiKey = 'YOUR_API_KEY';
12+
$merchantId = 'YOUR_MERCHANT_ID';
13+
14+
//$apiKey = getenv('wb_apikey_1');
15+
//$merchantId = getenv('wb_merchid_1');
16+
17+
$api = new WeBirrClient($apiKey, true);
18+
19+
$bill = new Bill();
20+
21+
$bill->amount = '270.90';
22+
$bill->customerCode = 'cc01'; // it can be email address or phone number if you dont have customer code
23+
$bill->customerName = 'Elias Haileselassie';
24+
$bill->time = '2021-07-22 22:14'; // your bill time, always in this format
25+
$bill->description = 'hotel booking';
26+
$bill->billReference = 'php/2021/127'; // your unique reference number
27+
$bill->merchantID = $merchantId;
28+
29+
echo "\nCreating Bill...";
30+
31+
$res = $api->createBill($bill);
32+
33+
if (!$res->error) {
34+
// success
35+
$paymentCode = $res->res; // returns paymentcode such as 429 723 975
36+
echo "\nPayment Code = $paymentCode"; // we may want to save payment code in local db.
37+
38+
} else {
39+
// fail
40+
echo "\nerror: $res->error";
41+
echo "\nerrorCode: $res->errorCode"; // can be used to handle specific busines error such as ERROR_INVLAID_INPUT_DUP_REF
42+
}
43+
44+
//var_dump($res);
45+
46+
// Update existing bill if it is not paid
47+
$bill->amount = "278.00";
48+
$bill->customerName = 'Elias php';
49+
//$bill->billReference = "WE CAN NOT CHANGE THIS";
50+
51+
echo "\nUpdating Bill...";
52+
53+
$res = $api->updateBill($bill);
54+
55+
if (!$res->error) {
56+
// success
57+
echo "\nbill is updated succesfully"; //res.res will be 'OK' no need to check here!
58+
} else {
59+
// fail
60+
echo "\nerror: $res->error";
61+
echo "\nerrorCode: $res->errorCode"; // can be used to handle specific busines error such as ERROR_INVLAID_INPUT
62+
}
63+
}
64+
65+
main();

Diff for: examples/example2.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
require 'vendor/autoload.php';
4+
5+
use WeBirr\Bill;
6+
use WeBirr\WeBirrClient;
7+
8+
// Get Payment Status of Bill
9+
function main()
10+
{
11+
$apiKey = 'YOUR_API_KEY';
12+
$merchantId = 'YOUR_MERCHANT_ID';
13+
14+
//$apiKey = getenv('wb_apikey_1');
15+
//$merchantId = getenv('wb_merchid_1');
16+
17+
$api = new WeBirrClient($apiKey, true);
18+
19+
$paymentCode = 'PAYMENT_CODE_YOU_SAVED_AFTER_CREATING_A_NEW_BILL'; // suchas as '141 263 782';
20+
21+
echo "\nGetting Payment Status...";
22+
23+
$res = $api->getPaymentStatus($paymentCode);
24+
25+
if (!$res->error) {
26+
// success
27+
if ($res->res->status == 2) {
28+
$data = $res->res->data;
29+
echo "\nbill is paid";
30+
echo "\nbill payment detail";
31+
echo "\nBank: $data->bankID";
32+
echo "\nBank Reference Number: $data->paymentReference";
33+
echo "\nAmount Paid: $data->amount";
34+
} else
35+
echo "\nbill is pending payment";
36+
} else {
37+
// fail
38+
echo "\nerror: $res->error";
39+
echo "\nerrorCode: $res->errorCode"; // can be used to handle specific busines error such as ERROR_INVLAID_INPUT
40+
}
41+
42+
//var_dump($res);
43+
}
44+
45+
main();

0 commit comments

Comments
 (0)