Initial commit
This commit is contained in:
35
app/Http/Controllers/SendMoneyController.php
Normal file
35
app/Http/Controllers/SendMoneyController.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Actions\PerformWalletTransfer;
|
||||
use App\Exceptions\InsufficientBalance;
|
||||
use App\Http\Requests\SendMoneyRequest;
|
||||
|
||||
class SendMoneyController
|
||||
{
|
||||
public function __invoke(SendMoneyRequest $request, PerformWalletTransfer $performWalletTransfer)
|
||||
{
|
||||
$recipient = $request->getRecipient();
|
||||
|
||||
try {
|
||||
$performWalletTransfer->execute(
|
||||
sender: $request->user(),
|
||||
recipient: $recipient,
|
||||
amount: $request->getAmountInCents(),
|
||||
reason: $request->input('reason'),
|
||||
);
|
||||
|
||||
return redirect()->back()
|
||||
->with('money-sent-status', 'success')
|
||||
->with('money-sent-recipient-name', $recipient->name)
|
||||
->with('money-sent-amount', $request->getAmountInCents());
|
||||
} catch (InsufficientBalance $exception) {
|
||||
return redirect()->back()->with('money-sent-status', 'insufficient-balance')
|
||||
->with('money-sent-recipient-name', $recipient->name)
|
||||
->with('money-sent-amount', $request->getAmountInCents());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user