+ Cancel transaction
This commit is contained in:
parent
cbb31f0b97
commit
100194e441
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue