Skip to content

Commit 3fc19d3

Browse files
committed
Initial Commit
0 parents  commit 3fc19d3

26 files changed

Lines changed: 3833 additions & 0 deletions

.github/workflows/lint.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Lint
2+
on: [push, pull_request]
3+
jobs:
4+
lint:
5+
name: PHP Lint
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Setup PHP
9+
uses: shivammathur/setup-php@v2
10+
with:
11+
php-version: 8.2
12+
13+
- name: Cache Composer dependencies
14+
uses: actions/cache@v2
15+
with:
16+
path: /tmp/composer-cache
17+
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
18+
19+
- uses: actions/checkout@master
20+
- name: lint
21+
run: make lint

.github/workflows/test.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Test
2+
on: [push, pull_request]
3+
jobs:
4+
lint:
5+
name: PHP Test
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Setup PHP
9+
uses: shivammathur/setup-php@v2
10+
with:
11+
php-version: 8.2
12+
13+
- name: Cache Composer dependencies
14+
uses: actions/cache@v2
15+
with:
16+
path: /tmp/composer-cache
17+
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
18+
19+
- uses: actions/checkout@master
20+
- name: test
21+
run: make test

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/vendor/
2+
.idea
3+
.phpunit.result.cache
4+
.phpunit.cache
5+
.vscode
6+
index.php

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) [2023] [Devscast]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
.DEFAULT_GOAL := help
2+
3+
# -----------------------------------
4+
# Variables
5+
# -----------------------------------
6+
is_docker := $(shell docker info > /dev/null 2>&1 && echo 1)
7+
user := $(shell id -u)
8+
group := $(shell id -g)
9+
10+
#ifeq ($(is_docker), 1)
11+
# php := USER_ID=$(user) GROUP_ID=$(group) docker-compose run --rm --no-deps php
12+
# composer := $(php) composer
13+
#else
14+
# php := php
15+
# composer := composer
16+
#endif
17+
18+
php := php
19+
composer := composer
20+
21+
# -----------------------------------
22+
# Recipes
23+
# -----------------------------------
24+
.PHONY: help
25+
help: ## affiche cet aide
26+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
27+
28+
.PHONY: lint
29+
lint: vendor/autoload.php ## affiche les erreurs de formatage de code
30+
$(php) vendor/bin/ecs
31+
$(php) vendor/bin/phpstan
32+
33+
.PHONY: test
34+
test: vendor/autoload.php ## lance les tests
35+
$(php) vendor/bin/phpunit
36+
37+
.PHONY: lint-fix
38+
lint-fix: vendor/autoload.php ## corrige les erreurs de formatage de code
39+
$(php) vendor/bin/ecs --fix
40+
41+
vendor/autoload.php: composer.lock # installe les dépendances PHP
42+
$(composer) update
43+
$(composer) dump-autoload

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Flexpay PHP
2+
3+
![Lint](https://github.com/devscast/flexpay/actions/workflows/lint.yaml/badge.svg)
4+
![Test](https://github.com/devscast/flexpay/actions/workflows/test.yaml/badge.svg)
5+
[![Latest Stable Version](https://poser.pugx.org/devscast/flexpay/version)](https://packagist.org/packages/devscast/flexpay)
6+
[![Total Downloads](https://poser.pugx.org/devscast/flexpay/downloads)](https://packagist.org/packages/devscast/flexpay)
7+
[![License](https://poser.pugx.org/devscast/flexpay/license)](https://packagist.org/packages/devscast/flexpay)
8+
9+
For privacy reasons, Flexpay original documentation cannot be shared without written permission, for more information about credentials
10+
and implementation details, please reach them at flexpay.cd
11+
12+
## Installation
13+
You can use the PHP client by installing the Composer package and adding it to your application’s dependencies:
14+
15+
```bash
16+
composer require devscast/flexpay
17+
```
18+
## Usage
19+
20+
### Authentication
21+
* **Step 1**. Contact Flexpay to get a Merchant Account
22+
You will receive a Merchant Form to complete in order to provide your business details and preferred Cash out Wallet or Banking Details.
23+
* **Step 2**. Once the paperwork is completed, you will be issued with Live and Sandbox Accounts (Merchant Code and Authorization token)
24+
25+
Then use these credentials to authenticate your client
26+
27+
```php
28+
use Devscast\Flexpay\Client as Flexpay;
29+
use Devscast\Flexpay\Credential;
30+
use Devscast\Flexpay\Environment;
31+
32+
$flexpay = new Flexpay(
33+
new Credential('token', 'merchant_code'),
34+
Environment::SANDBOX // use Environment::LIVE for production
35+
);
36+
```
37+
38+
### Create a Payment (Intention)
39+
```php
40+
use Devscast\Flexpay\PaymentEntry;
41+
use Devscast\Flexpay\Data\Currency;
42+
43+
$entry = new PaymentEntry(
44+
amount: 10, // 10 USD
45+
currency: Currency::USD,
46+
phone: "243999999999", // mandatory for mobile money
47+
reference: "your_unique_transaction_reference",
48+
description: "your_transaction_description",
49+
callbackUrl: "your_website_webhook_url",
50+
);
51+
```
52+
53+
> **Note**: we highly recommend your `callbacks` urls to be unique for each transaction.
54+
55+
### Process a payment (Mobile Money)
56+
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.
57+
after that the payment will be processed and the callback url will be called with the transaction details.
58+
59+
```php
60+
$payment = $flexpay->pay($entry);
61+
```
62+
#### **handling callback (callbackUrl, approveUrl, cancelUrl, declineUrl)**
63+
Flexpay will send a POST request to the defined callbackUrl and the response will contain the transaction details.
64+
you can use the following code to handle the callback by providing incoming data as array.
65+
66+
```php
67+
$state = $flexpay->handleCallback($_POST);
68+
$state->isSuccessful(); // true or false
69+
````
70+
71+
### Check Transaction state
72+
You don't trust webhook ? you can always check the transaction state by providing the order number.
73+
74+
```php
75+
$state = $flexpay->check($payment->orderNumber);
76+
$state->isSuccessful(); // true or false
77+
```
78+
79+
## Features supported
80+
- [x] Mobile Payment Service
81+
- [x] Check Transaction
82+
- [ ] Card Payment (unstable)

composer.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "devscast/flexpay",
3+
"description": "FlexPay API PHP Client",
4+
"keywords": [
5+
"flexpay",
6+
"mobile money",
7+
"payment gateway",
8+
"api"
9+
],
10+
"type": "library",
11+
"license": "MIT",
12+
"autoload": {
13+
"psr-4": {
14+
"Devscast\\Flexpay\\": "src/"
15+
}
16+
},
17+
"authors": [
18+
{
19+
"name": "bernard-ng",
20+
"email": "bernard@devscast.tech"
21+
}
22+
],
23+
"minimum-stability": "stable",
24+
"require": {
25+
"php": ">=8.2",
26+
"symfony/http-client": "^7.0",
27+
"webmozart/assert": "^1.11",
28+
"symfony/serializer": "^7.0",
29+
"symfony/property-access": "^7.0"
30+
},
31+
"require-dev": {
32+
"phpstan/phpstan": "^1.10",
33+
"phpunit/phpunit": "^11.1",
34+
"symplify/easy-coding-standard": "^12.1",
35+
"symfony/var-dumper": "^7.0"
36+
}
37+
}

0 commit comments

Comments
 (0)