Skip to content

Commit bf68f05

Browse files
committed
tests: add client tests
1 parent a3d6653 commit bf68f05

13 files changed

Lines changed: 602 additions & 280 deletions

.github/workflows/test.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Tests
2+
on: [push]
3+
jobs:
4+
test:
5+
name: Tests
6+
runs-on: ubuntu-latest
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
php: [ '8.2', '8.3' ]
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
16+
- name: Setup PHP
17+
uses: shivammathur/setup-php@v2
18+
with:
19+
php-version: ${{ matrix.php }}
20+
tools: composer:v2
21+
22+
- name: Setup cache
23+
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
24+
25+
- name: Cache dependencies installed with composer
26+
uses: actions/cache@v2
27+
with:
28+
path: ${{ env.COMPOSER_CACHE_DIR }}
29+
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
30+
restore-keys: |
31+
php${{ matrix.php }}-composer-latest-
32+
33+
- name: Update composer
34+
run: composer self-update
35+
36+
- name: Install dependencies with composer
37+
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
38+
39+
- name: Run tests
40+
run: make test

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This changelog references the relevant changes (bug and security fixes) done
44

55
### 2.0.0 [unreleased]
6+
- Added: `isSuccessful` to `Transaction` class
67
- Breaking Change: `pay` supports both `vpos` and `mobile` request
78
- Added: `vpos` and `mobile` method to `Client`
89
- Added: `VposResponse`, `Request`, `VposRequest`, `MobileRequest` class

README.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Flexpay PHP
22

33
![Lint](https://github.com/devscast/flexpay/actions/workflows/lint.yaml/badge.svg)
4-
![Test](https://github.com/devscast/flexpay/actions/workflows/lint.yaml/badge.svg)
4+
![Test](https://github.com/devscast/flexpay/actions/workflows/test.yaml/badge.svg)
55
[![Latest Stable Version](https://poser.pugx.org/devscast/flexpay/version)](https://packagist.org/packages/devscast/flexpay)
66
[![Total Downloads](https://poser.pugx.org/devscast/flexpay/downloads)](https://packagist.org/packages/devscast/flexpay)
77
[![License](https://poser.pugx.org/devscast/flexpay/license)](https://packagist.org/packages/devscast/flexpay)
@@ -35,30 +35,51 @@ $flexpay = new Flexpay(
3535
);
3636
```
3737

38-
### Create a Payment (Intention)
38+
### Create a Payment Request
3939

4040
```php
41-
use Devscast\Flexpay\Data\Currency;use Devscast\Flexpay\Request\MobileRequest;
41+
use Devscast\Flexpay\Data\Currency;
42+
use Devscast\Flexpay\Request\VposRequest;
43+
use Devscast\Flexpay\Request\MobileRequest;
4244

43-
$entry = new MobileRequest(
45+
$mobile = new MobileRequest(
4446
amount: 10, // 10 USD
4547
currency: Currency::USD,
46-
phone: "243999999999", // mandatory for mobile money
48+
phone: "243999999999",
4749
reference: "your_unique_transaction_reference",
4850
description: "your_transaction_description",
4951
callbackUrl: "your_website_webhook_url",
5052
);
53+
54+
$card = new VposRequest(
55+
amount: 10, // 10 USD
56+
currency: Currency::USD,
57+
reference: "your_unique_transaction_reference",
58+
description: "your_transaction_description",
59+
callbackUrl: "your_website_webhook_url",
60+
homeUrl: "your_website_home_url",
61+
)
5162
```
5263

5364
> **Note**: we highly recommend your `callbacks` urls to be unique for each transaction.
5465
55-
### Process a payment (Mobile Money)
66+
### Mobile Payment
5667
Once called, Flexpay will send a payment request to the user's mobile money account, and the user will have to confirm the payment on their phone.
5768
after that the payment will be processed and the callback url will be called with the transaction details.
5869

5970
```php
60-
$payment = $flexpay->pay($entry);
71+
$response = $flexpay->pay($mobile);
6172
```
73+
74+
### Virtual POS Payment
75+
You can set up card payment via VPOS features, which is typically used for online payments.
76+
it's a gateway that allows you to accept payments from your customers using their credit cards.
77+
78+
```php
79+
$response = $flexpay->pay($card);
80+
// redirect to $response->url to complete the payment
81+
```
82+
6283
#### **handling callback (callbackUrl, approveUrl, cancelUrl, declineUrl)**
6384
Flexpay will send a POST request to the defined callbackUrl and the response will contain the transaction details.
6485
you can use the following code to handle the callback by providing incoming data as array.
@@ -75,8 +96,3 @@ You don't trust webhook ? you can always check the transaction state by providin
7596
$state = $flexpay->check($payment->orderNumber);
7697
$state->isSuccessful(); // true or false
7798
```
78-
79-
## Features supported
80-
- [x] Mobile Payment Service
81-
- [x] Check Transaction
82-
- [ ] Card Payment (unstable)

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"Devscast\\Flexpay\\": "src/"
1515
}
1616
},
17+
"autoload-dev": {
18+
"psr-4": {
19+
"Devscast\\Flexpay\\Tests\\": "tests/"
20+
}
21+
},
1722
"authors": [
1823
{
1924
"name": "bernard-ng",

0 commit comments

Comments
 (0)