Skip to content

Commit

Permalink
[FINNA-855] Display a warning in online payment about a recently star…
Browse files Browse the repository at this point in the history
…ted transaction.

Does not prevent starting the payment process again but warns about it.
  • Loading branch information
EreMaijala committed Aug 11, 2023
1 parent 681a2cd commit ecff65a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions local/languages/finna/en-gb.ini
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ online_payment_failed = "Payment failed"
online_payment_fines_changed = "Fines list has been updated after previous page load."
online_payment_fines_contain_nonpayable_fees = "You have fees that cannot be paid online. Contact library customer service."
online_payment_go_to_pay = "Pay online %%amount%%"
online_payment_in_progress_warning = "Earlier payment was started at %%startDateTime%%. Start a new payment only if the earlier one was interrupted."
online_payment_minimum_fee = "Minimum amount of online payment"
online_payment_nonpayable_fees = "This fee cannot be paid online"
online_payment_payable_online = "Payable online"
Expand Down
1 change: 1 addition & 0 deletions local/languages/finna/fi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ online_payment_failed = "Maksutapahtuma epäonnistui."
online_payment_fines_changed = "Maksulista on päivittynyt edellisen sivunlatauksen jälkeen."
online_payment_fines_contain_nonpayable_fees = "Sinulla on maksuja, joita ei voi maksaa verkkomaksuna. Ota yhteyttä kirjaston asiakaspalveluun."
online_payment_go_to_pay = "Siirry maksamaan %%amount%%"
online_payment_in_progress_warning = "Aiempi maksutapahtuma aloitettu %%startDateTime%%. Aloita maksaminen uudelleen vain, jos edellinen tapahtuma keskeytyi."
online_payment_minimum_fee = "Verkkomaksamisen minimisumma"
online_payment_nonpayable_fees = "Tätä maksua ei voi maksaa verkossa"
online_payment_payable_online = "Maksettavissa verkossa"
Expand Down
1 change: 1 addition & 0 deletions local/languages/finna/sv.ini
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ online_payment_failed = "Betalning mislyckades"
online_payment_fines_changed = "Avgiftslistan har uppdaterats efter föregående sidhämtning."
online_payment_fines_contain_nonpayable_fees = "Du har avgifter som inte kan betalas på nätet. Kontakta bibliotekets kundtjänst."
online_payment_go_to_pay = "Betala på nätet %%amount%%"
online_payment_in_progress_warning = "Tidigare betalning startade vid %%startDateTime%%. Starta en ny betalning endast om den tidigare avbröts."
online_payment_minimum_fee = "Det minsta beloppet som kan betalas på nätet"
online_payment_nonpayable_fees = "Denna avgift kan inte betalas på nätet"
online_payment_payable_online = "Kan betalas på nätet"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ protected function handleOnlinePayment($patron, $fines, $view)
'Helpers/OnlinePayment/terms-' . $view->paymentHandler
. '.phtml'
);
} else {
// Check for a started transaction:
$view->startedTransaction = $trTable->getStartedPayment(
$patron['cat_username'],
(int)($paymentConfig['transactionMaxDuration'] ?? 15)
);
}
}
}
Expand Down
30 changes: 27 additions & 3 deletions module/Finna/src/Finna/Db/Table/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function __construct(
* @param int $transactionFee Transaction fee
* @param string $currency Currency
*
* @return Finna\Db\Row\Transaction
* @return TransactionRow
*/
public function createTransaction(
$id,
Expand All @@ -116,12 +116,36 @@ public function createTransaction(
return $t;
}

/**
* Check if payment is started for the patron, but not progressed further.
*
* Payment is not permitted if:
* - patron has a transaction with "in progress" status and maximum duration
* has not been reached
*
* @param string $patronId Patron's Catalog username (barcode)
* @param int $transactionMaxDuration Max duration for a transaction in minutes
*
* @return TransactionRow|null Current transaction or null if not started
*/
public function getStartedPayment(string $patronId, int $transactionMaxDuration): ?TransactionRow
{
$callback = function ($select) use ($patronId, $transactionMaxDuration) {
$select->where->equalTo('cat_username', $patronId);
$select->where->equalTo('complete', self::STATUS_PROGRESS);
$select->where(
"NOW() < DATE_ADD(created, INTERVAL $transactionMaxDuration MINUTE)"
);
};

return $this->select($callback)->current();
}

/**
* Check if payment is in progress for the patron.
*
* Payment is not permitted if:
* - patron has a transaction in progress and translation maximum duration
* has not been exceeded
* - patron has a transaction in progress
* - patron has a paid transaction that has not been registered as paid
* to the ILS
*
Expand Down
5 changes: 5 additions & 0 deletions themes/finna2/templates/myresearch/fines.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
</p>
</div>
<?php endif; ?>
<?php if ($this->startedTransaction): ?>
<div class="alert alert-danger">
<?=$this->transEsc('online_payment_in_progress_warning', ['%%startDateTime%%' => $this->dateTime()->convertToDisplayDateAndTime('Y-m-d H:i:s', $this->startedTransaction->created)]); ?>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
<?php if ($this->onlinePayment): ?>
Expand Down

0 comments on commit ecff65a

Please sign in to comment.