Download the PHP package fintreen/laravel-client without Composer
On this page you can find all versions of the php package fintreen/laravel-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fintreen/laravel-client
More information about fintreen/laravel-client
Files in fintreen/laravel-client
Package laravel-client
Short Description A Laravel client for interacting with Fintreen.com API.
License MIT
Informations about the package laravel-client
Laravel client for fintreen.com.
Fintreen.com laravel client for crypto-payment gateway API
Fintreen.com laravel client
Explore the docs on apiary »
Report Bug
·
Request Feature
.
>>> PHP Client <<<
Tested on php 8.0, 8.1, 8.2. Should be also good with php 8.3. Tested on laravel 9, 10.
Use composer2 for package installation.
Installation:
1. Add next env variables to your .env file
2. Install the client
3. Publish config
4. Migrate
Laravel BackPack + Settings integration
If you are using Laravel BackPack and Settings add-on
you can use FINTREEN_USE_BAKCPACK=true
at your .env. It will add fintreen_token
and fintreen_email
setting
from the FINTREEN_TOKEN
and FINTREEN_EMAIL
to database, and default client initialization (without params) will use them.
But if no setting were found (db records are empty) even if you are using FINTREEN_USE_BAKCPACK flag, it will fallback to configuration values from .env.
Otherwise you can use own params on initClient
method.
Usage:
0. General usage
You can use all methods from php-client
with getClient()
method. Example:
1. Client initialization
As far as this is just a laravel wrapper, you can initialize the client with no params. This will load config from config/fintreen.php file which should be published (installation point 3) which takes env variables.
Bit still you can init client with own params.
2. Calculation
You can use existing route to calculate with {{route('fintreen.calculate')}}
which goes to /fintreen/calculate
by default.
The POST params you need to set are currency
(CryptoCode) and amount
(Fiat in EUR).
Exaple of using this with jQuery
But for sure its better to use custom route. Take a look on calculateAction
in ./vendor/fintreen/laravel-client/src/app/Http/Controllers/FintreenController.php
Note that in custom variant you can set parameters for initClient and use comma-separated crypto codes calculate method.
3. Create transaction
Example with validation in real project:
4. Transaction list and check
4.1 Transactions list
List transactions are just like with php client.
The params to filter can be found here https://fintreen.docs.apiary.io/#/reference/order-flow/transactions-list/get-transactions-list/200?mc=reference%2Forder-flow%2Ftransactions-list%2Fget-transactions-list%2F200
4.2 Transaction check
To check if transactions are paid you can use console command fintreen:transactions:check
It run the check
mehod on FintreenModel
.
Also you can call this method from instance with callback.
!! Note, that callback fires only if transaction is successful.
5. How to handle transaction paid event (deposit balance in your app if transaction is successful)
This is most dangerous one. Please be careful and avoid double checking and depositing balances.
The check
method on FintreenModel
can get callback. In case that transaction is paid it will:
1) update status in table
2) then dispatch event FintreenTransactionIsSuccess
3) if callback is set it will fire the callback.
There are 2 ways - use custom check with callable as described above and events subscribtion.
Callback method:
!! Note, that callback fires only if transaction is successful.
Event method:
When transaction is successful FintreenTransactionIsSuccess
event is triggered.
To create it read https://laravel.com/docs/10.x/events#registering-events-and-listeners
Example of listiner
Dont forget to register it at your App\Providers\EventServiceProvider
!! Note, that event dispatches only if transaction is successful.
6. Using webhook
6.1 Using exsting webhook
You can set existing webhook to retrive data when transaction is checked.
By default it uses /fintreen/webhook
but you still need to set it on your settings in https://fintreen.com/account/tokens at Update webhook section AND ignore CSFR in this POST request the middleware.
To do that please edit your VerifyCsrfToken at App\Http\Middleware\VerifyCsrfToken
If you are using existing webhook, by default it will run check
method on FintreenModel
to handle transaction there. This method will mark transaction as successful and dispatch FintreenTransactionIsSuccess
event.
6.2 Using custom webhook
Example how to retrieve data by custom webhook.
1) create route 2) check its working with POST request without Csrf 3) set it in your account settings https://fintreen.com/account/tokens at Update webhook section 4) get the data
In your routes/web.php
6.3 Webhook format
Format is json:
To retrieve webhook data to check transaction you can use:
7. Good practices and Exception handling
It would be good to use own logging channel for this library.
Add to config/logging.php
new channel
There are two types of exception for now
FintreenClientException
- when client is not properly initialized
FintreenApiException
- when request fails