-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3fc19d3
Showing
26 changed files
with
3,833 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Lint | ||
on: [push, pull_request] | ||
jobs: | ||
lint: | ||
name: PHP Lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.2 | ||
|
||
- name: Cache Composer dependencies | ||
uses: actions/cache@v2 | ||
with: | ||
path: /tmp/composer-cache | ||
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} | ||
|
||
- uses: actions/checkout@master | ||
- name: lint | ||
run: make lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Test | ||
on: [push, pull_request] | ||
jobs: | ||
lint: | ||
name: PHP Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.2 | ||
|
||
- name: Cache Composer dependencies | ||
uses: actions/cache@v2 | ||
with: | ||
path: /tmp/composer-cache | ||
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} | ||
|
||
- uses: actions/checkout@master | ||
- name: test | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/vendor/ | ||
.idea | ||
.phpunit.result.cache | ||
.phpunit.cache | ||
.vscode | ||
index.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) [2023] [Devscast] | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
.DEFAULT_GOAL := help | ||
|
||
# ----------------------------------- | ||
# Variables | ||
# ----------------------------------- | ||
is_docker := $(shell docker info > /dev/null 2>&1 && echo 1) | ||
user := $(shell id -u) | ||
group := $(shell id -g) | ||
|
||
#ifeq ($(is_docker), 1) | ||
# php := USER_ID=$(user) GROUP_ID=$(group) docker-compose run --rm --no-deps php | ||
# composer := $(php) composer | ||
#else | ||
# php := php | ||
# composer := composer | ||
#endif | ||
|
||
php := php | ||
composer := composer | ||
|
||
# ----------------------------------- | ||
# Recipes | ||
# ----------------------------------- | ||
.PHONY: help | ||
help: ## affiche cet aide | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
|
||
.PHONY: lint | ||
lint: vendor/autoload.php ## affiche les erreurs de formatage de code | ||
$(php) vendor/bin/ecs | ||
$(php) vendor/bin/phpstan | ||
|
||
.PHONY: test | ||
test: vendor/autoload.php ## lance les tests | ||
$(php) vendor/bin/phpunit | ||
|
||
.PHONY: lint-fix | ||
lint-fix: vendor/autoload.php ## corrige les erreurs de formatage de code | ||
$(php) vendor/bin/ecs --fix | ||
|
||
vendor/autoload.php: composer.lock # installe les dépendances PHP | ||
$(composer) update | ||
$(composer) dump-autoload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Flexpay PHP | ||
|
||
![Lint](https://github.com/devscast/flexpay/actions/workflows/lint.yaml/badge.svg) | ||
![Test](https://github.com/devscast/flexpay/actions/workflows/test.yaml/badge.svg) | ||
[![Latest Stable Version](https://poser.pugx.org/devscast/flexpay/version)](https://packagist.org/packages/devscast/flexpay) | ||
[![Total Downloads](https://poser.pugx.org/devscast/flexpay/downloads)](https://packagist.org/packages/devscast/flexpay) | ||
[![License](https://poser.pugx.org/devscast/flexpay/license)](https://packagist.org/packages/devscast/flexpay) | ||
|
||
For privacy reasons, Flexpay original documentation cannot be shared without written permission, for more information about credentials | ||
and implementation details, please reach them at flexpay.cd | ||
|
||
## Installation | ||
You can use the PHP client by installing the Composer package and adding it to your application’s dependencies: | ||
|
||
```bash | ||
composer require devscast/flexpay | ||
``` | ||
## Usage | ||
|
||
### Authentication | ||
* **Step 1**. Contact Flexpay to get a Merchant Account | ||
You will receive a Merchant Form to complete in order to provide your business details and preferred Cash out Wallet or Banking Details. | ||
* **Step 2**. Once the paperwork is completed, you will be issued with Live and Sandbox Accounts (Merchant Code and Authorization token) | ||
|
||
Then use these credentials to authenticate your client | ||
|
||
```php | ||
use Devscast\Flexpay\Client as Flexpay; | ||
use Devscast\Flexpay\Credential; | ||
use Devscast\Flexpay\Environment; | ||
|
||
$flexpay = new Flexpay( | ||
new Credential('token', 'merchant_code'), | ||
Environment::SANDBOX // use Environment::LIVE for production | ||
); | ||
``` | ||
|
||
### Create a Payment (Intention) | ||
```php | ||
use Devscast\Flexpay\PaymentEntry; | ||
use Devscast\Flexpay\Data\Currency; | ||
|
||
$entry = new PaymentEntry( | ||
amount: 10, // 10 USD | ||
currency: Currency::USD, | ||
phone: "243999999999", // mandatory for mobile money | ||
reference: "your_unique_transaction_reference", | ||
description: "your_transaction_description", | ||
callbackUrl: "your_website_webhook_url", | ||
); | ||
``` | ||
|
||
> **Note**: we highly recommend your `callbacks` urls to be unique for each transaction. | ||
### Process a payment (Mobile Money) | ||
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. | ||
after that the payment will be processed and the callback url will be called with the transaction details. | ||
|
||
```php | ||
$payment = $flexpay->pay($entry); | ||
``` | ||
#### **handling callback (callbackUrl, approveUrl, cancelUrl, declineUrl)** | ||
Flexpay will send a POST request to the defined callbackUrl and the response will contain the transaction details. | ||
you can use the following code to handle the callback by providing incoming data as array. | ||
|
||
```php | ||
$state = $flexpay->handleCallback($_POST); | ||
$state->isSuccessful(); // true or false | ||
```` | ||
|
||
### Check Transaction state | ||
You don't trust webhook ? you can always check the transaction state by providing the order number. | ||
|
||
```php | ||
$state = $flexpay->check($payment->orderNumber); | ||
$state->isSuccessful(); // true or false | ||
``` | ||
|
||
## Features supported | ||
- [x] Mobile Payment Service | ||
- [x] Check Transaction | ||
- [ ] Card Payment (unstable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "devscast/flexpay", | ||
"description": "FlexPay API PHP Client", | ||
"keywords": [ | ||
"flexpay", | ||
"mobile money", | ||
"payment gateway", | ||
"api" | ||
], | ||
"type": "library", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"Devscast\\Flexpay\\": "src/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "bernard-ng", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"minimum-stability": "stable", | ||
"require": { | ||
"php": ">=8.2", | ||
"symfony/http-client": "^7.0", | ||
"webmozart/assert": "^1.11", | ||
"symfony/serializer": "^7.0", | ||
"symfony/property-access": "^7.0" | ||
}, | ||
"require-dev": { | ||
"phpstan/phpstan": "^1.10", | ||
"phpunit/phpunit": "^11.1", | ||
"symplify/easy-coding-standard": "^12.1", | ||
"symfony/var-dumper": "^7.0" | ||
} | ||
} |
Oops, something went wrong.