+ Add TreatDemand, CancelDemand and Virement
This commit is contained in:
parent
71b934ee24
commit
04a6cb08e9
|
@ -19,3 +19,7 @@ CACHE_DRIVER=file
|
||||||
QUEUE_CONNECTION=sync
|
QUEUE_CONNECTION=sync
|
||||||
|
|
||||||
ACCEPTED_KEYS=yhSTSSqIO1uSE1icu09edPOeSFGxIDjo
|
ACCEPTED_KEYS=yhSTSSqIO1uSE1icu09edPOeSFGxIDjo
|
||||||
|
|
||||||
|
TWILIO_ACCOUNT_SID="ACacdb9c9601741af001ebbc7eca4969cd"
|
||||||
|
TWILIO_AUTH_TOKEN="e0e2f1176c09b3980c9ecf967187191b"
|
||||||
|
TWILIO_SMS_FROM="+447400348273"
|
||||||
|
|
|
@ -24,18 +24,18 @@ class CommissionController extends Controller
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public function virement(Request $request)
|
public function virement($id_wallet)
|
||||||
{
|
{
|
||||||
$rules = [
|
$wallet = Wallet::findOrFail($id_wallet);
|
||||||
"id_agent" => 'required|integer|min:0'
|
|
||||||
];
|
if($wallet->balance_com <=0 )
|
||||||
$this->validate($request,$rules);
|
return $this->errorResponse('Solde de comission est vide' , Response::HTTP_BAD_REQUEST);
|
||||||
$wallet = Wallet::where('id_networkAgent',$request->get('id_agent'))->firstOrFail();
|
|
||||||
|
|
||||||
$wallet->balance_princ += $wallet->balance_com;
|
$wallet->balance_princ += $wallet->balance_com;
|
||||||
$wallet->balance_com = 0;
|
$wallet->balance_com = 0;
|
||||||
|
$wallet->save();
|
||||||
|
|
||||||
return $this->successResponse('Virement de commission reussie');
|
return $this->successResponse($wallet);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ use App\Models\DemandeCredit;
|
||||||
use App\Models\Wallet;
|
use App\Models\Wallet;
|
||||||
use App\Models\WalletAgent;
|
use App\Models\WalletAgent;
|
||||||
use App\Traits\ApiResponser;
|
use App\Traits\ApiResponser;
|
||||||
|
use App\Twilio;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
@ -25,11 +26,12 @@ class CreditController extends Controller
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public function treatDemand($id_demand){
|
public function treatDemand($id_demand,Twilio $twilio){
|
||||||
$demand = DemandeCredit::where('id',$id_demand)->firstOrFail();
|
$demand = DemandeCredit::where('id',$id_demand)->firstOrFail();
|
||||||
if($demand->status == 1)
|
if($demand->status == 1)
|
||||||
return $this->errorResponse('Demande deja traitée',Response::HTTP_BAD_REQUEST);
|
return $this->errorResponse('Demande deja traitée',Response::HTTP_BAD_REQUEST);
|
||||||
|
|
||||||
|
$agent = AgentPlus::where('code_membre',$demand->code_membre)->firstOrFail();
|
||||||
$parrain = AgentPlus::where('code_membre',$demand->code_parrain)->firstOrFail();
|
$parrain = AgentPlus::where('code_membre',$demand->code_parrain)->firstOrFail();
|
||||||
|
|
||||||
$walletAgentParrain = WalletAgent::where('agent_id',$parrain->id)->firstOrFail();
|
$walletAgentParrain = WalletAgent::where('agent_id',$parrain->id)->firstOrFail();
|
||||||
|
@ -43,9 +45,26 @@ class CreditController extends Controller
|
||||||
$walletAgent->balance_princ += $demand->montant;
|
$walletAgent->balance_princ += $demand->montant;
|
||||||
$walletParrain->balance_princ -= $demand->montant;
|
$walletParrain->balance_princ -= $demand->montant;
|
||||||
|
|
||||||
DB::update('UPDATE demandeCredits SET status = 1 WHERE ( id = ? );',[$demand->id]);
|
DB::update('UPDATE demandeCredits SET status = 1 , date_modification = CURRENT_TIMESTAMP WHERE ( id = ? );',[$demand->id]);
|
||||||
$walletAgent->save();
|
$walletAgent->save();
|
||||||
$walletParrain->save();
|
$walletParrain->save();
|
||||||
return $this->successResponse($walletAgent);
|
|
||||||
|
// try {
|
||||||
|
// $twilio->notify($agent->phone, 'Votre demande de credit de '.$demand->montant .' aupres de '.$parrain->lastname.' '.$parrain->lastname.'a été traitée');
|
||||||
|
// }catch (\Exception $e){
|
||||||
|
// echo "Error: " . $e->getMessage();
|
||||||
|
// }
|
||||||
|
|
||||||
|
return $this->successResponse($walletParrain);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cancelDemand($id_demand ,Twilio $twilio){
|
||||||
|
DB::update('UPDATE demandeCredits SET canceled = 1 WHERE ( id = ? );',[$id_demand]);
|
||||||
|
// try {
|
||||||
|
// $twilio->notify($agent->phone, 'Votre demande de credit de '.$demand->montant .' aupres de '.$parrain->lastname.' '.$parrain->lastname.'a été traitée');
|
||||||
|
// }catch (\Exception $e){
|
||||||
|
// echo "Error: " . $e->getMessage();
|
||||||
|
// }
|
||||||
|
return $this->successResponse('Demande de credit annullée');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Twilio\Rest\Client;
|
||||||
|
|
||||||
|
class Twilio
|
||||||
|
{
|
||||||
|
protected $account_sid;
|
||||||
|
|
||||||
|
protected $auth_token;
|
||||||
|
|
||||||
|
protected $number;
|
||||||
|
|
||||||
|
protected $client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->account_sid = env('TWILIO_ACCOUNT_SID');
|
||||||
|
|
||||||
|
$this->auth_token = env('TWILIO_AUTH_TOKEN');
|
||||||
|
|
||||||
|
$this->number = env('TWILIO_SMS_FROM');
|
||||||
|
|
||||||
|
$this->client = $this->setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
return new Client($this->account_sid, $this->auth_token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function notify($number, string $message)
|
||||||
|
{
|
||||||
|
$message = $this->client->messages->create($number, [
|
||||||
|
'from' => $this->number,
|
||||||
|
'body' => $message
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $message;
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,8 @@
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.2.5",
|
"php": "^7.2.5",
|
||||||
"guzzlehttp/guzzle": "^6.5",
|
"guzzlehttp/guzzle": "^6.5",
|
||||||
"laravel/lumen-framework": "^7.0"
|
"laravel/lumen-framework": "^7.0",
|
||||||
|
"twilio/sdk": "^6.3"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fzaninotto/faker": "^1.9.1",
|
"fzaninotto/faker": "^1.9.1",
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "4f5df1d5bb479b7274f68ed7be7e047b",
|
"content-hash": "3e56a6208178c25d0d589884fc9ea980",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "brick/math",
|
"name": "brick/math",
|
||||||
|
@ -3631,6 +3631,56 @@
|
||||||
],
|
],
|
||||||
"time": "2020-03-27T16:56:45+00:00"
|
"time": "2020-03-27T16:56:45+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "twilio/sdk",
|
||||||
|
"version": "6.3.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/twilio/twilio-php.git",
|
||||||
|
"reference": "1c723c7155e5e41bece4f5c4aca0b28d63778b04"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/twilio/twilio-php/zipball/1c723c7155e5e41bece4f5c4aca0b28d63778b04",
|
||||||
|
"reference": "1c723c7155e5e41bece4f5c4aca0b28d63778b04",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=7.1.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"guzzlehttp/guzzle": "^6.3",
|
||||||
|
"phpunit/phpunit": ">=4.5",
|
||||||
|
"theseer/phpdox": "^0.12.0"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"guzzlehttp/guzzle": "An HTTP client to execute the API requests"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Twilio\\": "src/Twilio/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Twilio API Team",
|
||||||
|
"email": "api@twilio.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "A PHP wrapper for Twilio's API",
|
||||||
|
"homepage": "http://github.com/twilio/twilio-php",
|
||||||
|
"keywords": [
|
||||||
|
"api",
|
||||||
|
"sms",
|
||||||
|
"twilio"
|
||||||
|
],
|
||||||
|
"time": "2020-04-15T20:03:03+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "vlucas/phpdotenv",
|
"name": "vlucas/phpdotenv",
|
||||||
"version": "v4.1.3",
|
"version": "v4.1.3",
|
||||||
|
|
|
@ -24,9 +24,10 @@ $router->group(['prefix' => '/transactions'] , function () use ($router){
|
||||||
// Credits routes
|
// Credits routes
|
||||||
$router->group(['prefix' => '/credits'] , function () use ($router){
|
$router->group(['prefix' => '/credits'] , function () use ($router){
|
||||||
$router->put('treatDemand/{id_demand}','CreditController@treatDemand');
|
$router->put('treatDemand/{id_demand}','CreditController@treatDemand');
|
||||||
|
$router->put('cancelDemand/{id_demand}','CreditController@cancelDemand');
|
||||||
});
|
});
|
||||||
|
|
||||||
$router->post('/virement','CommissionController@virement');
|
$router->put('/virement/{id_wallet}','CommissionController@virement');
|
||||||
|
|
||||||
// Wallets routes
|
// Wallets routes
|
||||||
$router->group(['prefix' => '/wallets'] , function () use ($router){
|
$router->group(['prefix' => '/wallets'] , function () use ($router){
|
||||||
|
|
Loading…
Reference in New Issue