Refactor ilink transaction controller, more secure

This commit is contained in:
Djery-Tom 2022-04-20 09:08:32 +01:00
parent 61b2c481c9
commit 0bc3eaf856
10 changed files with 854 additions and 658 deletions

View File

@ -3,6 +3,7 @@
namespace App\Exceptions;
use App\Traits\ApiResponser;
use ErrorException;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ServerException;
use Illuminate\Auth\Access\AuthorizationException;
@ -102,7 +103,7 @@ class Handler extends ExceptionHandler
return $this->errorResponse($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
if ($exception instanceof \ErrorException) {
if ($exception instanceof ErrorException) {
return $this->errorResponse($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}

File diff suppressed because it is too large Load Diff

View File

@ -164,6 +164,11 @@ class ConfigWallet extends Model
return $this->hasMany(PaliersConfigWallet::class, 'idConfig');
}
public function paliers_commissions_wallets()
{
return $this->hasMany(PaliersCommissionWallet::class, 'idConfig');
}
public function paliers_config_nano_credits()
{
return $this->hasMany(PaliersConfigNanoCredit::class, 'idConfig');

View File

@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class PaliersCommissionWallet extends Model
{
protected $table = 'paliers_commissions_wallet';
protected $guarded = ['id'];
}

View File

@ -217,8 +217,8 @@ class WalletIlinkTransaction extends Model
public function cash_cash_rules()
{
return [
'final_country' => 'required|integer|min:0|not_in:0',
'network_destinataire' => 'required|integer|min:0|not_in:0',
'final_country' => 'required|integer|exists:countries,id',
'network_destinataire' => 'required|integer|exists:networks,id',
'nom_emetteur' => 'required',
'prenom_emetteur' => 'required',
'type_document_emetteur' => 'required',
@ -240,23 +240,23 @@ class WalletIlinkTransaction extends Model
/// User Operation rules
public function send_wallet_wallet_rules(){
return [
'final_country' =>'required|integer|min:0|not_in:0',
'type_document_destinataire'=>'required',
'final_country' => 'required|integer|exists:countries,id',
'type_document_destinataire' => 'required',
// 'id_document_destinataire'=>'required',
'id_destinataire' =>'required_without:phone_destinataire',
'network_destinataire'=>'required|integer|min:0|not_in:0',
'id_destinataire' => 'required_without:phone_destinataire',
'network_destinataire' => 'required|integer|exists:networks,id',
];
}
public function send_wallet_cash_rules(){
return [
'final_country' =>'required|integer|min:0|not_in:0',
'nom_destinataire'=>'required',
'prenom_destinataire'=>'required',
'type_document_destinataire'=>'required',
'final_country' => 'required|integer|exists:countries,id',
'nom_destinataire' => 'required',
'prenom_destinataire' => 'required',
'type_document_destinataire' => 'required',
// 'id_document_destinataire'=>'required',
'id_destinataire' =>'required_without:phone_destinataire',
'network_destinataire'=>'required|integer|min:0|not_in:0',
'id_destinataire' => 'required_without:phone_destinataire',
'network_destinataire' => 'required|integer|exists:networks,id',
];
}
}

View File

@ -34,6 +34,9 @@ trait ApiResponser
public function errorResponse($message, $code = Response::HTTP_BAD_REQUEST)
{
if ($code == 0) {
$code = Response::HTTP_BAD_REQUEST;
}
return response()->json($this->formatResponse($code, null, $message), $code);
}

View File

@ -29,6 +29,7 @@ use Brick\Money\ExchangeRateProvider\PDOProvider;
use Brick\Money\ExchangeRateProvider\PDOProviderConfiguration;
use Brick\Money\Money;
use Carbon\Carbon;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\DB;
@ -531,16 +532,20 @@ trait Helper
}
// Verifier l'identification d'un utilisateur à partir de son id
/**
* @throws Exception
*/
public function checkUserIdentification($id_user)
{
$identification = Identification::where('id_user', $id_user)->first();
if (isset($identification)) {
if ($identification->status == 0)
return $this->errorResponse(trans('errors.validation_user_identification_required'));
throw new Exception(trans('errors.validation_user_identification_required'), 422);
else
return $identification;
} else {
return $this->errorResponse(trans('errors.user_identification_required'));
throw new Exception(trans('errors.user_identification_required'), 422);
}
}
@ -568,4 +573,14 @@ trait Helper
return $pdf;
}
/**
* @throws Exception
*/
public function validatePassword($password, $encrypted_password, $salt)
{
if (!$this->checkPassword($password, $encrypted_password, $salt)) {
throw new Exception(trans('messages.incorrect_user_password'), 422);
}
}
}

View File

@ -109,7 +109,7 @@ $app->register(Illuminate\Mail\MailServiceProvider::class);
$app->register(\SwaggerLume\ServiceProvider::class);
$app->register(Maatwebsite\Excel\ExcelServiceProvider::class);
$app->register(\Barryvdh\DomPDF\ServiceProvider::class);
$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);
/*
|--------------------------------------------------------------------------
| Load The Application Routes

View File

@ -6,17 +6,18 @@
"type": "project",
"require": {
"php": "^7.3|^8.0",
"ext-json": "*",
"barryvdh/laravel-dompdf": "^0.9.0",
"brick/money": "^0.5.2",
"darkaonline/swagger-lume": "^8.0",
"flipbox/lumen-generator": "^9.1",
"guzzlehttp/guzzle": "^7.0.1",
"illuminate/mail": "^8.62",
"laravel/legacy-factories": "^1.1",
"laravel/lumen-framework": "^8.0",
"maatwebsite/excel": "^3.1",
"simplesoftwareio/simple-qrcode": "^4.2",
"twilio/sdk": "^6.28",
"ext-json": "*"
"twilio/sdk": "^6.28"
},
"require-dev": {
"fzaninotto/faker": "^1.9.1",

310
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "634654b92540c00e468be0b92031e6cd",
"content-hash": "04c333a4ed5959dbda293a3fdc8f6944",
"packages": [
{
"name": "bacon/bacon-qr-code",
@ -242,6 +242,73 @@
],
"time": "2021-04-03T20:56:48+00:00"
},
{
"name": "classpreloader/classpreloader",
"version": "4.2.0",
"source": {
"type": "git",
"url": "https://github.com/ClassPreloader/ClassPreloader.git",
"reference": "af9284543aedb45ed58359374918141c0ac7ae34"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/ClassPreloader/ClassPreloader/zipball/af9284543aedb45ed58359374918141c0ac7ae34",
"reference": "af9284543aedb45ed58359374918141c0ac7ae34",
"shasum": ""
},
"require": {
"ext-tokenizer": "*",
"nikic/php-parser": "^4.10.3",
"php": "^7.0.8 || ^8.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.4.1",
"graham-campbell/analyzer": "^2.4.3 || ^3.0.4",
"phpunit/phpunit": "^6.5.14 || ^7.5.20 || ^8.5.19"
},
"type": "library",
"autoload": {
"psr-4": {
"ClassPreloader\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com"
},
{
"name": "Graham Campbell",
"email": "hello@gjcampbell.co.uk"
}
],
"description": "Helps class loading performance by generating a single PHP file containing all of the autoloaded files for a specific use case",
"keywords": [
"autoload",
"class",
"preload",
"preloader"
],
"support": {
"issues": "https://github.com/ClassPreloader/ClassPreloader/issues",
"source": "https://github.com/ClassPreloader/ClassPreloader/tree/4.2.0"
},
"funding": [
{
"url": "https://github.com/GrahamCampbell",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/classpreloader/classpreloader",
"type": "tidelift"
}
],
"time": "2021-08-28T21:56:17+00:00"
},
{
"name": "darkaonline/swagger-lume",
"version": "8.0",
@ -930,6 +997,54 @@
},
"time": "2020-06-29T00:56:53+00:00"
},
{
"name": "flipbox/lumen-generator",
"version": "9.1.0",
"source": {
"type": "git",
"url": "https://github.com/flipboxstudio/lumen-generator.git",
"reference": "ee8e6a4feeb751369a3bbf998491143a68989be9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/flipboxstudio/lumen-generator/zipball/ee8e6a4feeb751369a3bbf998491143a68989be9",
"reference": "ee8e6a4feeb751369a3bbf998491143a68989be9",
"shasum": ""
},
"require": {
"classpreloader/classpreloader": "^3.0|^4.0|^4.2",
"illuminate/console": "^5.5|^6.0|^7.0|^8.0|^8.17|^9.0",
"illuminate/filesystem": "^5.5|^6.0|^7.0|^8.0|^8.17|^9.0",
"illuminate/support": "^5.5|^6.0|^7.0|^8.0|^8.17|^9.0",
"psy/psysh": "0.9.*|0.10.*|0.11.*",
"symfony/var-dumper": "^4.2|^4.3|^5.0|^5.1|^5.2|^6.0"
},
"suggest": {
"anik/form-request": "Required to use form request in Lumen."
},
"type": "library",
"autoload": {
"psr-4": {
"Flipbox\\LumenGenerator\\": "src/LumenGenerator/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Krisan Alfa Timur",
"email": "krisan47@gmail.com"
}
],
"description": "A Lumen Generator You Are Missing",
"support": {
"issues": "https://github.com/flipboxstudio/lumen-generator/issues",
"source": "https://github.com/flipboxstudio/lumen-generator/tree/9.1.0"
},
"time": "2022-03-26T00:47:39+00:00"
},
{
"name": "graham-campbell/result-type",
"version": "v1.0.2",
@ -3898,6 +4013,62 @@
},
"time": "2018-02-13T20:26:39+00:00"
},
{
"name": "nikic/php-parser",
"version": "v4.13.0",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
"reference": "50953a2691a922aa1769461637869a0a2faa3f53"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/50953a2691a922aa1769461637869a0a2faa3f53",
"reference": "50953a2691a922aa1769461637869a0a2faa3f53",
"shasum": ""
},
"require": {
"ext-tokenizer": "*",
"php": ">=7.0"
},
"require-dev": {
"ircmaxell/php-yacc": "^0.0.7",
"phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0"
},
"bin": [
"bin/php-parse"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.9-dev"
}
},
"autoload": {
"psr-4": {
"PhpParser\\": "lib/PhpParser"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Nikita Popov"
}
],
"description": "A PHP parser written in PHP",
"keywords": [
"parser",
"php"
],
"support": {
"issues": "https://github.com/nikic/PHP-Parser/issues",
"source": "https://github.com/nikic/PHP-Parser/tree/v4.13.0"
},
"time": "2021-09-20T12:20:58+00:00"
},
{
"name": "opis/closure",
"version": "3.6.2",
@ -4629,6 +4800,84 @@
},
"time": "2017-10-23T01:57:42+00:00"
},
{
"name": "psy/psysh",
"version": "v0.11.2",
"source": {
"type": "git",
"url": "https://github.com/bobthecow/psysh.git",
"reference": "7f7da640d68b9c9fec819caae7c744a213df6514"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bobthecow/psysh/zipball/7f7da640d68b9c9fec819caae7c744a213df6514",
"reference": "7f7da640d68b9c9fec819caae7c744a213df6514",
"shasum": ""
},
"require": {
"ext-json": "*",
"ext-tokenizer": "*",
"nikic/php-parser": "^4.0 || ^3.1",
"php": "^8.0 || ^7.0.8",
"symfony/console": "^6.0 || ^5.0 || ^4.0 || ^3.4",
"symfony/var-dumper": "^6.0 || ^5.0 || ^4.0 || ^3.4"
},
"conflict": {
"symfony/console": "4.4.37 || 5.3.14 || 5.3.15 || 5.4.3 || 5.4.4 || 6.0.3 || 6.0.4"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.2",
"hoa/console": "3.17.05.02"
},
"suggest": {
"ext-pcntl": "Enabling the PCNTL extension makes PsySH a lot happier :)",
"ext-pdo-sqlite": "The doc command requires SQLite to work.",
"ext-posix": "If you have PCNTL, you'll want the POSIX extension as well.",
"ext-readline": "Enables support for arrow-key history navigation, and showing and manipulating command history.",
"hoa/console": "A pure PHP readline implementation. You'll want this if your PHP install doesn't already support readline or libedit."
},
"bin": [
"bin/psysh"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "0.11.x-dev"
}
},
"autoload": {
"files": [
"src/functions.php"
],
"psr-4": {
"Psy\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Justin Hileman",
"email": "justin@justinhileman.info",
"homepage": "http://justinhileman.com"
}
],
"description": "An interactive shell for modern PHP.",
"homepage": "http://psysh.org",
"keywords": [
"REPL",
"console",
"interactive",
"shell"
],
"support": {
"issues": "https://github.com/bobthecow/psysh/issues",
"source": "https://github.com/bobthecow/psysh/tree/v0.11.2"
},
"time": "2022-02-28T15:28:54+00:00"
},
{
"name": "ralouphie/getallheaders",
"version": "3.0.3",
@ -8039,62 +8288,6 @@
],
"time": "2020-11-13T09:40:50+00:00"
},
{
"name": "nikic/php-parser",
"version": "v4.13.0",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
"reference": "50953a2691a922aa1769461637869a0a2faa3f53"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/50953a2691a922aa1769461637869a0a2faa3f53",
"reference": "50953a2691a922aa1769461637869a0a2faa3f53",
"shasum": ""
},
"require": {
"ext-tokenizer": "*",
"php": ">=7.0"
},
"require-dev": {
"ircmaxell/php-yacc": "^0.0.7",
"phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0"
},
"bin": [
"bin/php-parse"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.9-dev"
}
},
"autoload": {
"psr-4": {
"PhpParser\\": "lib/PhpParser"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Nikita Popov"
}
],
"description": "A PHP parser written in PHP",
"keywords": [
"parser",
"php"
],
"support": {
"issues": "https://github.com/nikic/PHP-Parser/issues",
"source": "https://github.com/nikic/PHP-Parser/tree/v4.13.0"
},
"time": "2021-09-20T12:20:58+00:00"
},
{
"name": "phar-io/manifest",
"version": "2.0.3",
@ -9874,7 +10067,8 @@
"prefer-stable": true,
"prefer-lowest": false,
"platform": {
"php": "^7.3|^8.0"
"php": "^7.3|^8.0",
"ext-json": "*"
},
"platform-dev": [],
"plugin-api-version": "2.1.0"