From: Lisa Marie Maginnis Date: Wed, 20 Apr 2016 18:55:58 +0000 (-0400) Subject: blacklist changes X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=16cc1d5d881c3a3a6f114e750076c25c46d30af1;p=trustcommerce.git blacklist changes --- diff --git a/trustcommerce.php b/trustcommerce.php index c4bec8d..378d13e 100644 --- a/trustcommerce.php +++ b/trustcommerce.php @@ -139,6 +139,23 @@ class org_fsf_payment_trustcommerce extends CRM_Core_Payment { } + /** + * The singleton function used to manage this object + * + * @param string $mode the mode of operation: live or test + * @param CRM_Core_Payment The payment processor object. + * + * @return object + * @static + */ + /* static function &singleton($mode, &$paymentProcessor) { + $processorName = $paymentProcessor['name']; + if (self::$_singleton[$processorName] === NULL) { + self::$_singleton[$processorName] = new org_fsf_payment_trustcommerce($mode, $paymentProcessor); + } + return self::$_singleton[$processorName]; + }*/ + /** * Submit a payment using the TC API * @@ -175,37 +192,39 @@ class org_fsf_payment_trustcommerce extends CRM_Core_Payment { /* This implements a local blacklist, and passes us though as a normal failure * if the luser is on the blacklist. */ - if(!$this->_isBlacklisted()) { + if(!$this->_isBlacklisted($tc_params)) { /* Call the TC API, and grab the reply */ $reply = $this->_sendTCRequest($tc_params); } else { $this->_logger($tc_params); $reply['status'] = self::AUTH_BLACKLIST; + usleep(rand(1000000,10000000)); } /* Parse our reply */ $result = $this->_getTCReply($reply); - if($result == 0) { - /* We were successful, congrats. Lets wrap it up: - * Convert back to dollars - * Save the transaction ID - */ - - if (array_key_exists('billingid', $reply)) { - $params['recurr_profile_id'] = $reply['billingid']; - CRM_Core_DAO::setFieldValue( - 'CRM_Contribute_DAO_ContributionRecur', - $this->_getParam('contributionRecurID'), - 'processor_id', $reply['billingid'] - ); + if(!is_object($result)) { + if($result == 0) { + /* We were successful, congrats. Lets wrap it up: + * Convert back to dollars + * Save the transaction ID + */ + + if (array_key_exists('billingid', $reply)) { + $params['recurr_profile_id'] = $reply['billingid']; + CRM_Core_DAO::setFieldValue( + 'CRM_Contribute_DAO_ContributionRecur', + $this->_getParam('contributionRecurID'), + 'processor_id', $reply['billingid'] + ); + } + $params['trxn_id'] = $reply['transid']; + + $params['gross_amount'] = $tc_params['amount'] / 100; + + return $params; } - $params['trxn_id'] = $reply['transid']; - - $params['gross_amount'] = $tc_params['amount'] / 100; - - return $params; - } else { /* Otherwise we return the error object */ return $result; @@ -299,18 +318,30 @@ class org_fsf_payment_trustcommerce extends CRM_Core_Payment { return "$exp_month$exp_year"; } + private function _isParamsBlacklisted($tc_params) { + if($tc_params['amount'] == 101) { + error_log("TrustCommerce: _isParamsBlacklisted() triggered"); + return TRUE; + } else { + return FALSE; + } + } + /** * Checks to see if the source IP/USERAGENT are blacklisted. * * @return bool TRUE if on the blacklist, FALSE if not. */ - private function _isBlacklisted() { + private function _isBlacklisted($tc_params) { if($this->_isIPBlacklisted()) { return TRUE; - } else if($this->_IsAgentBlacklisted()) { + } else if($this->_isAgentBlacklisted()) { + return TRUE; + } else if($this->_isParamsBlacklisted($tc_params)) { return TRUE; } return FALSE; + } /** @@ -452,7 +483,7 @@ class org_fsf_payment_trustcommerce extends CRM_Core_Payment { switch($reply['status']) { case self::AUTH_BLACKLIST: - return self::error(9001, "Your transaction was declined: error #90210"); + return self::error(9001, "Your transaction was declined for address verification reasons. If your address was correct please contact us at donate@fsf.org before attempting to retry your transaction."); break; case self::AUTH_APPROVED: break;