Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch PaymentClosed Exception #2764

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use App\AccountancyModule\PaymentModule\Factories\IPaymentNoteDialogFactory;
use App\AccountancyModule\PaymentModule\Factories\IRemoveGroupDialogFactory;
use DateTimeImmutable;
use Model\Common\UserNotFound;
use Model\DTO\Payment\Payment;
use Model\DTO\Payment\Person;
use Model\ExcelService;
Expand Down Expand Up @@ -250,8 +251,10 @@ public function handleComplete(int $pid): void
$this->flashMessage('Platba byla zaplacena.');
} catch (PaymentClosed) {
$this->flashMessage('Tato platba už je uzavřená', 'danger');
} catch (InvalidOAuth $exc) {
$this->flashMessage($exc->getExplainedMessage(), 'danger');
} catch (UserNotFound) {
$this->flashMessage('Uživatel nebyl nalezen', 'danger');
} catch (PaymentNotFound) {
$this->flashMessage('Platba nebyla nalezena', 'danger');
}

$this->redirect('this');
Expand Down
3 changes: 3 additions & 0 deletions app/model/Bank/BankService.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Model\Payment\Group;
use Model\Payment\Payment;
use Model\Payment\Payment\Transaction;
use Model\Payment\PaymentClosed;
use Model\Payment\Repositories\IBankAccountRepository;
use Model\Payment\Repositories\IGroupRepository;
use Model\Payment\Repositories\IPaymentRepository;
Expand Down Expand Up @@ -141,6 +142,8 @@ private function resolvePairingIntervalStart(array $groups): ChronosDate
* @param Payment[] $payments
*
* @return Payment[]
*
* @throws PaymentClosed
*/
private function markPaymentsAsComplete(array $transactions, array $payments): array
{
Expand Down
3 changes: 3 additions & 0 deletions app/model/Payment/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,23 @@ public function update(
$this->amount = $amount;
}

/** @throws PaymentClosed */
private function complete(DateTimeImmutable $time): void
{
$this->checkNotClosed();
$this->state = State::get(State::COMPLETED);
$this->closedAt = $time;
}

/** @throws PaymentClosed */
public function completeManually(DateTimeImmutable $time, string $userFullName): void
{
$this->complete($time);
$this->closedByUsername = $userFullName;
$this->raise(new PaymentWasCompleted($this->id));
}

/** @throws PaymentClosed */
public function pairWithTransaction(DateTimeImmutable $time, Transaction $transaction): void
{
$this->complete($time);
Expand Down
7 changes: 7 additions & 0 deletions app/model/Payment/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use InvalidArgumentException;
use Model\Common\Repositories\IParticipantRepository;
use Model\Common\Repositories\IUserRepository;
use Model\Common\UserNotFound;
use model\DTO\Participant\PaymentDetails;
use Model\DTO\Payment as DTO;
use model\Event\Exception\CampInvitationNotFound;
Expand All @@ -24,6 +25,7 @@
use Model\Payment\MissingVariableSymbol;
use Model\Payment\Payment;
use Model\Payment\Payment\State;
use Model\Payment\PaymentClosed;
use Model\Payment\PaymentNotFound;
use Model\Payment\Repositories\IBankAccountRepository;
use Model\Payment\Repositories\IGroupRepository;
Expand Down Expand Up @@ -80,6 +82,11 @@ public function cancelPayment(int $pid): void
$this->payments->save($payment);
}

/**
* @throws PaymentClosed
* @throws UserNotFound
* @throws PaymentNotFound
*/
public function completePayment(int $id): void
{
$payment = $this->payments->find($id);
Expand Down