コード例 #1
0
 /**
  * See if the is_test flag is properly passed on through batching
  * 
  * @see https://github.com/Project60/sepa_dd/issues/114
  * @author endres -at- systopia.de
  */
 public function testTestMandates()
 {
     $frst_notice = CRM_Core_BAO_Setting::getItem('SEPA Direct Debit Preferences', 'batching_FRST_notice');
     $this->assertNotEmpty($frst_notice, "No FRST notice period specified!");
     CRM_Core_BAO_Setting::setItem('SEPA Direct Debit Preferences', 'batching_RCUR_notice', $frst_notice);
     $rcur_notice = CRM_Core_BAO_Setting::getItem('SEPA Direct Debit Preferences', 'batching_RCUR_notice');
     $this->assertNotEmpty($rcur_notice, "No RCUR notice period specified!");
     $this->assertEquals($frst_notice, $rcur_notice, "Notice periods should be the same.");
     $cycle_day = date("d", strtotime("+{$frst_notice} days"));
     // 2) create a RCUR mandate, due for collection right now
     $mandate = $this->createMandate(array('type' => 'RCUR', 'status' => 'FRST'), array('cycle_day' => $cycle_day));
     CRM_Sepa_Logic_Batching::updateRCUR($mandate['creditor_id'], 'FRST');
     $rcontrib = $this->callAPISuccess("ContributionRecur", "getsingle", array("id" => $mandate['entity_id']));
     $this->assertEquals('0', $rcontrib['is_test'], "Test flag should not be set!");
     $contrib = $this->callAPISuccess("Contribution", "getsingle", array("contribution_recur_id" => $rcontrib['id']));
     $this->assertEquals('0', $contrib['is_test'], "Test flag should not be set!");
     // 3) create a RCUR TEST mandate, due for collection right now
     $ccount = CRM_Core_DAO::singleValueQuery("SELECT count(id) FROM civicrm_contribution;");
     $tccount = CRM_Core_DAO::singleValueQuery("SELECT count(id) FROM civicrm_contribution WHERE is_test=1;");
     $mandate = $this->createMandate(array('type' => 'RCUR', 'status' => 'FRST'), array('is_test' => 1, 'cycle_day' => $cycle_day));
     CRM_Sepa_Logic_Batching::updateRCUR($mandate['creditor_id'], 'FRST');
     $this->assertDBQuery($ccount + 1, "SELECT count(id) FROM civicrm_contribution;");
     $rcontrib = $this->callAPISuccess("ContributionRecur", "getsingle", array("id" => $mandate['entity_id']));
     $this->assertEquals('1', $rcontrib['is_test'], "Test flag should be set!");
     // cannot use API for Contribution, wouldn't load test contributions
     $this->assertDBQuery($tccount + 1, "SELECT count(id) FROM civicrm_contribution WHERE is_test=1;");
     // 4) create a OOFF TEST mandate
     $mandate = $this->createMandate(array('type' => 'OOFF', 'status' => 'INIT'), array('is_test' => 1));
     CRM_Sepa_Logic_Batching::updateRCUR($mandate['creditor_id'], 'FRST');
     $contrib = $this->callAPISuccess("Contribution", "getsingle", array("id" => $mandate['entity_id']));
     $this->assertEquals('1', $contrib['is_test'], "Test flag should be set!");
 }
コード例 #2
0
/**
 * API CALL TO UPDATE TXGROUPs ("Batching")
 *
 * @package CiviCRM_SEPA
 *
 */
function civicrm_api3_sepa_alternative_batching_update($params)
{
    // get creditor list
    $creditor_query = civicrm_api('SepaCreditor', 'get', array('version' => 3, 'option.limit' => 99999));
    if (!empty($creditor_query['is_error'])) {
        return civicrm_api3_create_error("Cannot get creditor list: " . $creditor_query['error_message']);
    } else {
        $creditors = array();
        foreach ($creditor_query['values'] as $creditor) {
            $creditors[] = $creditor['id'];
        }
    }
    if ($params['type'] == 'OOFF') {
        foreach ($creditors as $creditor_id) {
            CRM_Sepa_Logic_Batching::updateOOFF($creditor_id);
        }
    } elseif ($params['type'] == 'RCUR' || $params['type'] == 'FRST') {
        // first: make sure, that there are no outdated mandates:
        CRM_Sepa_Logic_Batching::closeEnded();
        // then, run the update for recurring mandates
        foreach ($creditors as $creditor_id) {
            CRM_Sepa_Logic_Batching::updateRCUR($creditor_id, $params['type']);
        }
    } else {
        return civicrm_api3_create_error(sprintf("Unknown batching mode '%s'.", $params['type']));
    }
    return civicrm_api3_create_success();
}