From 078964d29748ba6ac482138977232e3cfb9bc762 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 18 Jul 2016 21:45:32 +0300 Subject: [PATCH] Improve offsite payment checks --- app/Ninja/PaymentDrivers/BasePaymentDriver.php | 12 ++++++++++++ resources/lang/en/texts.php | 2 ++ 2 files changed, 14 insertions(+) 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.', + );