diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index b4ca2a6..8c58178 100755 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -117,7 +117,7 @@ class Handler extends ExceptionHandler $message = json_decode($error->message); if(isset($message->errorMessage)) return $this->errorResponse($message->errorMessage,$code); - return $this->errorResponse($message,$code); + return $this->errorResponse($error->message,$code); } return $this->errorResponse($error,$code); } else diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index 9fe707d..2a7f13a 100755 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -79,7 +79,7 @@ class TransactionController extends Controller // Verification faites au niveau du frontend // if($walletAgent->balance_princ >= ($transaction->montant + $frais + $config->frais_min_banque_depot)){ - $response = $client->post('fund-transfer-api/v1/transaction/push', ['json' => $body]); + $response = $request->facade == 'front' ? $client->post('fund-transfer-api/v1/transaction/push', ['json' => $body]) : $client->get('localhost'); $code = $response->getStatusCode(); if ($code == 200) { @@ -130,7 +130,7 @@ class TransactionController extends Controller $body['cvv'] = $request->cvv; $body['expiry_date'] = $data['expiration_date']->format('Y-m'); - $response = $client->post('fund-transfer-api/v1/transaction/pull', ['json' => $body]); + $response = $request->facade == 'front' ? $client->post('fund-transfer-api/v1/transaction/pull', ['json' => $body]) : $client->get('localhost'); $code = $response->getStatusCode(); if($code == 200) { @@ -205,4 +205,31 @@ class TransactionController extends Controller $data['commission'] = $commission; return $this->successResponse($data); } + + public function cancel($id_transaction) + { + $transaction = WalletTransaction::findOrFail($id_transaction); + $walletAgent = $transaction->wallet; + $walletSuperviseur = $transaction->wallet_sup; + $walletHyperviseur = $transaction->wallet_hyp; + + if ($transaction->type == 'credit'){ + //Depot + $walletAgent->balance_princ += $transaction->montant; + }elseif ($transaction->type == 'debit'){ + //Retrait + $walletAgent->balance_princ -= $transaction->montant; + } + + $walletAgent->balance_com -= $transaction->commission_ag; + $walletSuperviseur->balance_com -= $transaction->commission_sup; + $walletHyperviseur->balance_com -= $transaction->commission_hyp; + $transaction->canceled = 1; + + $walletAgent->save(); + $walletSuperviseur->save(); + $walletHyperviseur->save(); + $transaction->save(); + return $this->successResponse($transaction); + } } diff --git a/app/Models/WalletTransaction.php b/app/Models/WalletTransaction.php index e87fa64..cce17a4 100755 --- a/app/Models/WalletTransaction.php +++ b/app/Models/WalletTransaction.php @@ -28,6 +28,7 @@ use phpDocumentor\Reflection\Types\Integer; * @property int $id_wallet * @property int $id_wallet_sup * @property int $id_wallet_hyp + * @property string $canceled * * @property Wallet $wallet * @property Wallet $wallet_sup @@ -70,7 +71,8 @@ class WalletTransaction extends Model 'result', 'id_wallet', 'id_wallet_sup', - 'id_wallet_hyp' + 'id_wallet_hyp', + 'canceled' ]; public function wallet() diff --git a/routes/web.php b/routes/web.php index fd80690..9c7bbf6 100755 --- a/routes/web.php +++ b/routes/web.php @@ -20,6 +20,7 @@ $router->group(['prefix' => '/transactions'] , function () use ($router){ $router->post('','TransactionController@add'); $router->get('{id_wallet}','TransactionController@lastTransactions'); $router->post('commission','TransactionController@calculateCommission'); + $router->delete('{id_transaction}','TransactionController@cancel'); }); // Credits routes