diff --git a/app/Ninja/PaymentDrivers/BasePaymentDriver.php b/app/Ninja/PaymentDrivers/BasePaymentDriver.php index 9cc7c405431f..c342b8500b19 100644 --- a/app/Ninja/PaymentDrivers/BasePaymentDriver.php +++ b/app/Ninja/PaymentDrivers/BasePaymentDriver.php @@ -715,6 +715,18 @@ class BasePaymentDriver } } + // check invoice still has balance + if ( ! $this->invoice()->balance) { + throw new Exception(trans('texts.payment_error_code', ['code' => 'NB'])); + } + + // check this isn't a duplicate transaction reference + if (Payment::whereAccountId($this->invitation->account_id) + ->whereTransactionReference($ref) + ->first()) { + throw new Exception(trans('texts.payment_error_code', ['code' => 'DT'])); + } + return $this->createPayment($ref); } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 32a21567b3a3..02dc17530751 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2040,6 +2040,8 @@ $LANG = array( 'enable_buy_now_buttons_help' => 'Enable support for buy now buttons', 'changes_take_effect_immediately' => 'Note: changes take effect immediately', 'wepay_account_description' => 'Payment gateway for Invoice Ninja', + 'payment_error_code' => 'There was an error processing your payment [:code]. Please try again later.', + );