From ab8492a8b59a3c1f17e5160a444d6b24817db9fc Mon Sep 17 00:00:00 2001 From: Lisa Marie Maginnis Date: Tue, 2 Aug 2016 11:22:40 -0400 Subject: [PATCH] Added a function to count successive failures --- trustcommerceIPN.php | 49 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/trustcommerceIPN.php b/trustcommerceIPN.php index 3b6807e..7727b04 100644 --- a/trustcommerceIPN.php +++ b/trustcommerceIPN.php @@ -15,19 +15,60 @@ * You should have received a copy of the GNU General Public License * along with CiviCRM. If not, see . * - * Copyright (C) 2012 - * Licensed to CiviCRM under the GPL v3 or higher - * - * Modified by Lisa Marie Maginnis (http://www.fsf.org) + * Copyright 2016, Lisa Marie Maginnis (http://www.fsf.org) * */ +/** + * CiviCRM (Instant Payment Notification) IPN processor module for + * TrustCommerece. + * + * For full documentation on the + * TrustCommerece API, please see the TCDevGuide for more information: + * https://vault.trustcommerce.com/downloads/TCDevGuide.htm + * + * This module supports the following features: Single credit/debit card + * transactions, AVS checking, recurring (create, update, and cancel + * subscription) optional blacklist with fail2ban, + * + * @copyright Lisa Marie Maginnis (http://www.fsf.org) + * @version 1.0 + * @package org.fsf.payment.trustcommerce.ipn + */ + +define("MAX_FAILURES", 4) + class CRM_Core_Payment_trustcommerce_IPN extends CRM_Core_Payment_BaseIPN { + + /** + * Inheret + * + * @return void + */ function __construct() { parent::__construct(); } + function getLastFailures($recur_id) { + $sql="SELECT contribution_recur_id, trxn_id, contribution_status_id, + SUM(id > COALESCE( + ( SELECT max(id) FROM civicrm_contribution AS c2 + WHERE c2.id = c.id and c2.contribution_status_id = 1), + 4 )) AS numfails + FROM civicrm_contribution AS c + WHERE c.contribution_recur_id = $recur_id GROUP BY c.contribution_recur_id;" + + $result = CRM_Core_DAO::executeQuery($sql); + if($result->fetch()) { + $failures = $result->numfails; + } else { + $failures = NULL; + } + + return $failures; + } + function main($component = 'contribute') { static $no = NULL; $billingid = CRM_Utils_Request::retrieve('billingid', 'String', $no, FALSE, 'GET'); -- 2.25.1