|
| 1 | +# Flexpay PHP |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +[](https://packagist.org/packages/devscast/flexpay) |
| 6 | +[](https://packagist.org/packages/devscast/flexpay) |
| 7 | +[](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) |
0 commit comments