diff --git a/CRM/EasyBatch/BAO/EasyBatch.php b/CRM/EasyBatch/BAO/EasyBatch.php index 51a6332..fe0277e 100644 --- a/CRM/EasyBatch/BAO/EasyBatch.php +++ b/CRM/EasyBatch/BAO/EasyBatch.php @@ -72,7 +72,8 @@ public static function retrieve($params) { public static function getEasyBatches( $paymentProcessorID = NULL, $returnColumn = 'title', - $isAuto = TRUE + $isAuto = TRUE, + $cardTypeID = NULL ) { $status = CRM_Core_PseudoConstant::getKey('CRM_Batch_BAO_Batch', 'status_id', 'Open'); $easyBatches = array(); @@ -84,6 +85,9 @@ public static function getEasyBatches( else { $where[] = "e.payment_processor_id IS NULL"; } + if ($cardTypeID) { + $where[] = "e.card_type_id = {$cardTypeID}"; + } $sql = "SELECT b.id, {$returnColumn} FROM civicrm_batch b LEFT JOIN civicrm_easybatch_entity e ON b.id = e.batch_id @@ -145,6 +149,7 @@ public static function addTransactionsToBatch($batchId, $financialTrxnId, $findC return FALSE; } else { + $tx->commit(); return TRUE; } } @@ -166,7 +171,12 @@ public static function addTransactionsToAutoBatch($financialTrxn) { && Civi::settings()->get("pp_auto_financial_batch_{$financialTrxn->payment_processor_id}") ) { $findCardType = (bool) Civi::settings()->get("pp_cc_financial_batch_{$financialTrxn->payment_processor_id}"); - $batches = CRM_EasyBatch_BAO_EasyBatch::getEasyBatches($financialTrxn->payment_processor_id); + if ($findCardType) { + $batches = CRM_EasyBatch_BAO_EasyBatch::getEasyBatches($financialTrxn->payment_processor_id, 'title', TRUE, $financialTrxn->card_type_id); + } + else { + $batches = CRM_EasyBatch_BAO_EasyBatch::getEasyBatches($financialTrxn->payment_processor_id); + } $financialEasyBatchId = key($batches); } } @@ -222,10 +232,10 @@ public static function createAutoFinancialBatch( //check if batch is still open if ($paymentProcessorID) { - $batches = self::getEasyBatches($paymentProcessorID); + $batches = self::getEasyBatches($paymentProcessorID, 'title', TRUE, $cardTypeID); } else { - $batches = self::getEasyBatches(NULL, 'contact_id'); + $batches = self::getEasyBatches(NULL, 'contact_id', TRUE, $cardTypeID); $batches = array_search($contactId, $batches); } diff --git a/schema/EasyBatchEntity.entityType.php b/schema/EasyBatchEntity.entityType.php index de86f8c..493f528 100644 --- a/schema/EasyBatchEntity.entityType.php +++ b/schema/EasyBatchEntity.entityType.php @@ -67,5 +67,14 @@ 'input_type' => 'Select Date', 'description' => E::ts('Date for the transactions to be included in the batch.'), ], + 'card_type_id' => [ + 'title' => E::ts('Card Type'), + 'sql_type' => 'int unsigned', + 'input_type' => 'Select', + 'unique_name' => 'easy_batch_entity_card_type_id', + 'pseudoconstant' => [ + 'option_group_name' => 'accept_creditcard', + ], + ], ], ];