From d253aeb84653a98b779f1629316221f988b42ecc Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 25 Jun 2015 11:43:16 +1200 Subject: [PATCH] CRM-16471 since pending payments exist now the checkDupe function needs to include the contribution ID in the check --- CRM/Core/Payment.php | 23 +++++++++++++++++++++++ CRM/Core/Payment/AuthorizeNet.php | 17 +---------------- CRM/Core/Payment/Elavon.php | 17 +---------------- CRM/Core/Payment/FirstData.php | 17 +---------------- CRM/Core/Payment/PayflowPro.php | 18 +----------------- CRM/Core/Payment/Realex.php | 17 +---------------- CRM/Core/Payment/eWAY.php | 17 +---------------- 7 files changed, 29 insertions(+), 97 deletions(-) diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 7b05870802..69c48b9570 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -855,6 +855,29 @@ abstract class CRM_Core_Payment { return FALSE; } + /** + * Checks to see if invoice_id already exists in db. + * + * It's arguable if this belongs in the payment subsystem at all but since several processors implement it + * it is better to standardise to being here. + * + * @param int $invoiceId The ID to check. + * + * @param null $contributionID + * If a contribution exists pass in the contribution ID. + * + * @return bool + * True if invoice ID otherwise exists, else false + */ + protected function checkDupe($invoiceId, $contributionID = NULL) { + $contribution = new CRM_Contribute_DAO_Contribution(); + $contribution->invoice_id = $invoiceId; + if ($contributionID) { + $contribution->whereAdd("id <> $contributionID"); + } + return $contribution->find(); + } + /** * Get url for users to manage this recurring contribution for this processor. * diff --git a/CRM/Core/Payment/AuthorizeNet.php b/CRM/Core/Payment/AuthorizeNet.php index 1d59f6cc1f..4e1eee9334 100644 --- a/CRM/Core/Payment/AuthorizeNet.php +++ b/CRM/Core/Payment/AuthorizeNet.php @@ -128,7 +128,7 @@ class CRM_Core_Payment_AuthorizeNet extends CRM_Core_Payment { } // Authorize.Net will not refuse duplicates, so we should check if the user already submitted this transaction - if ($this->_checkDupe($authorizeNetFields['x_invoice_num'])) { + if ($this->checkDupe($authorizeNetFields['x_invoice_num'], CRM_Utils_Array::value('contributionID', $params))) { return self::error(9004, 'It appears that this transaction is a duplicate. Have you already submitted the form once? If so there may have been a connection problem. Check your email for a receipt from Authorize.net. If you do not receive a receipt within 2 hours you can try your transaction again. If you continue to have problems please contact the site administrator.'); } @@ -373,21 +373,6 @@ class CRM_Core_Payment_AuthorizeNet extends CRM_Core_Payment { return $fields; } - /** - * Checks to see if invoice_id already exists in db. - * - * @param int $invoiceId - * The ID to check. - * - * @return bool - * True if ID exists, else false - */ - public function _checkDupe($invoiceId) { - $contribution = new CRM_Contribute_DAO_Contribution(); - $contribution->invoice_id = $invoiceId; - return $contribution->find(); - } - /** * Generate HMAC_MD5 * diff --git a/CRM/Core/Payment/Elavon.php b/CRM/Core/Payment/Elavon.php index a45c07c0bd..bcbe845b7d 100644 --- a/CRM/Core/Payment/Elavon.php +++ b/CRM/Core/Payment/Elavon.php @@ -145,7 +145,7 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment { CRM_Utils_Hook::alterPaymentProcessorParams($this, $params, $requestFields); // Check to see if we have a duplicate before we send - if ($this->_checkDupe($params['invoiceID'])) { + if ($this->checkDupe($params['invoiceID'], CRM_Utils_Array::value('contributionID', $params))) { return self::errorExit(9003, 'It appears that this transaction is a duplicate. Have you already submitted the form once? If so there may have been a connection problem. Check your email for a receipt. If you do not receive a receipt within 2 hours you can try your transaction again. If you continue to have problems please contact the site administrator.'); } @@ -259,21 +259,6 @@ class CRM_Core_Payment_Elavon extends CRM_Core_Payment { } } - /** - * Checks to see if invoice_id already exists in db. - * - * @param int $invoiceId - * The ID to check. - * - * @return bool - * True if ID exists, else false - */ - public function _checkDupe($invoiceId) { - $contribution = new CRM_Contribute_DAO_Contribution(); - $contribution->invoice_id = $invoiceId; - return $contribution->find(); - } - /** * Produces error message and returns from class. * @param string $errorCode diff --git a/CRM/Core/Payment/FirstData.php b/CRM/Core/Payment/FirstData.php index 9055fcb509..810e7b2d89 100644 --- a/CRM/Core/Payment/FirstData.php +++ b/CRM/Core/Payment/FirstData.php @@ -178,7 +178,7 @@ class CRM_Core_Payment_FirstData extends CRM_Core_Payment { //---------------------------------------------------------------------------------------------------- // Check to see if we have a duplicate before we send //---------------------------------------------------------------------------------------------------- - if ($this->_checkDupe($params['invoiceID'])) { + if ($this->checkDupe($params['invoiceID'], CRM_Utils_Array::value('contributionID', $params))) { return self::errorExit(9003, 'It appears that this transaction is a duplicate. Have you already submitted the form once? If so there may have been a connection problem. Check your email for a receipt from eWAY. If you do not receive a receipt within 2 hours you can try your transaction again. If you continue to have problems please contact the site administrator.'); } //---------------------------------------------------------------------------------------------------- @@ -300,21 +300,6 @@ class CRM_Core_Payment_FirstData extends CRM_Core_Payment { } // end function doDirectPayment - /** - * Checks to see if invoice_id already exists in db. - * - * @param int $invoiceId - * The ID to check. - * - * @return bool - * True if ID exists, else false - */ - public function _checkDupe($invoiceId) { - $contribution = new CRM_Contribute_DAO_Contribution(); - $contribution->invoice_id = $invoiceId; - return $contribution->find(); - } - /** * Produces error message and returns from class. */ diff --git a/CRM/Core/Payment/PayflowPro.php b/CRM/Core/Payment/PayflowPro.php index c50c11d44a..f89201a8e0 100644 --- a/CRM/Core/Payment/PayflowPro.php +++ b/CRM/Core/Payment/PayflowPro.php @@ -260,7 +260,7 @@ class CRM_Core_Payment_PayflowPro extends CRM_Core_Payment { /* * Check to see if we have a duplicate before we send */ - if ($this->_checkDupe($params['invoiceID'])) { + if ($this->checkDupe($params['invoiceID'], CRM_Utils_Array::value('contributionID', $params))) { return self::errorExit(9003, 'It appears that this transaction is a duplicate. Have you already submitted the form once? If so there may have been a connection problem. Check your email for a receipt. If you do not receive a receipt within 2 hours you can try your transaction again. If you continue to have problems please contact the site administrator.'); } @@ -345,22 +345,6 @@ class CRM_Core_Payment_PayflowPro extends CRM_Core_Payment { return self::errorExit(9014, "Check the code - all transactions should have been headed off before they got here. Something slipped through the net"); } - /** - * Checks to see if invoice_id already exists in db. - * - * @param int $invoiceId - * The ID to check. - * - * @return bool - * True if ID exists, else false - */ - public function _checkDupe($invoiceId) { - //copied from Eway but not working and not really sure it should! - $contribution = new CRM_Contribute_DAO_Contribution(); - $contribution->invoice_id = $invoiceId; - return $contribution->find(); - } - /* * Produces error message and returns from class */ diff --git a/CRM/Core/Payment/Realex.php b/CRM/Core/Payment/Realex.php index 8665b5d02b..474d8f9423 100644 --- a/CRM/Core/Payment/Realex.php +++ b/CRM/Core/Payment/Realex.php @@ -136,7 +136,7 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment { /********************************************************** * Check to see if we have a duplicate before we send **********************************************************/ - if ($this->_checkDupe($this->_getParam('order_id'))) { + if ($this->checkDupe($params['invoiceID'], CRM_Utils_Array::value('contributionID', $params))) { return self::error(9004, ts('It appears that this transaction is a duplicate. Have you already submitted the form once? If so there may have been a connection problem. Check your email for a receipt from Authorize.net. If you do not receive a receipt within 2 hours you can try your transaction again. If you continue to have problems please contact the site administrator.')); } @@ -427,21 +427,6 @@ class CRM_Core_Payment_Realex extends CRM_Core_Payment { return TRUE; } - /** - * Checks to see if invoice_id already exists in db. - * - * @param int $invoiceId - * The ID to check. - * - * @return bool - * True if ID exists, else false - */ - public function _checkDupe($invoiceId) { - $contribution = new CRM_Contribute_DAO_Contribution(); - $contribution->invoice_id = $invoiceId; - return $contribution->find(); - } - /** * Get the value of a field if set. * diff --git a/CRM/Core/Payment/eWAY.php b/CRM/Core/Payment/eWAY.php index 16fec49e81..7360555dad 100644 --- a/CRM/Core/Payment/eWAY.php +++ b/CRM/Core/Payment/eWAY.php @@ -256,7 +256,7 @@ class CRM_Core_Payment_eWAY extends CRM_Core_Payment { //---------------------------------------------------------------------------------------------------- // Check to see if we have a duplicate before we send //---------------------------------------------------------------------------------------------------- - if ($this->_checkDupe($params['invoiceID'])) { + if ($this->checkDupe($params['invoiceID'], CRM_Utils_Array::value('contributionID', $params))) { return self::errorExit(9003, 'It appears that this transaction is a duplicate. Have you already submitted the form once? If so there may have been a connection problem. Check your email for a receipt from eWAY. If you do not receive a receipt within 2 hours you can try your transaction again. If you continue to have problems please contact the site administrator.'); } @@ -408,21 +408,6 @@ class CRM_Core_Payment_eWAY extends CRM_Core_Payment { } // end function doDirectPayment - /** - * Checks to see if invoice_id already exists in db. - * - * @param int $invoiceId - * The ID to check. - * - * @return bool - * True if ID exists, else false - */ - public function _checkDupe($invoiceId) { - $contribution = new CRM_Contribute_DAO_Contribution(); - $contribution->invoice_id = $invoiceId; - return $contribution->find(); - } - /** * ********************************************************************************************** * This function checks the eWAY response status - returning a boolean false if status != 'true' -- 2.25.1