/** * Test update of recurring payments after a deferred submission * * @author Björn Endres * @see https://github.com/Project60/sepa_dd/issues/190 */ public function testRCURGracePeriod_190() { $rcur_notice = 6; CRM_Sepa_Logic_Settings::setSetting('batching.RCUR.notice', $rcur_notice); CRM_Sepa_Logic_Settings::setSetting('batching.RCUR.grace', 2 * $rcur_notice); $contactId = $this->individualCreate(); $collection_date = strtotime("+1 days"); $deferred_collection_date = strtotime("+{$rcur_notice} days"); // count the existing contributions $count = $this->callAPISuccess("Contribution", "getcount", array('version' => 3)); // create a mandate, that's already late $parameters = array('version' => 3, 'type' => 'RCUR', 'status' => 'RCUR', 'contact_id' => $contactId, 'financial_type_id' => 1, 'amount' => '6.66', 'start_date' => date('YmdHis'), 'date' => date('YmdHis'), 'cycle_day' => date('d', $collection_date), 'frequency_interval' => 1, 'frequency_unit' => 'month', 'iban' => "BE68844010370034", 'bic' => "TESTTEST", 'creditor_id' => $this->getCreditor(), 'is_enabled' => 1); $this->callAPISuccess("SepaMandate", "createfull", $parameters); // batch it $this->callAPISuccess("SepaAlternativeBatching", "update", array("type" => "RCUR", 'version' => 3)); // check contributions count again $newcount = $this->callAPISuccess("Contribution", "getcount", array('version' => 3)); $this->assertEquals($count + 1, $newcount, "A contribution should have been created!"); // adjust collection date, close the group and thus modify the contribution's receive date $txgroup = $this->callAPISuccess("SepaTransactionGroup", "getsingle", array('version' => 3)); CRM_Sepa_BAO_SEPATransactionGroup::adjustCollectionDate($txgroup['id'], date('Y-m-d', $deferred_collection_date)); CRM_Sepa_Logic_Group::close($txgroup['id']); // batch again $this->callAPISuccess("SepaAlternativeBatching", "update", array("type" => "RCUR", 'version' => 3)); // verify, that NO new contribution is created $newcount = $this->callAPISuccess("Contribution", "getcount", array('version' => 3)); $this->assertEquals($count + 1, $newcount, "Yet another contribution has been created. Issue #190 still active!"); }
/** * Test civicrm_api3_sepa_mandate_create with default creditor * * @author niko bochan */ public function testCreateWithDefaultCreditor() { $contactId = $this->individualCreate(); $contribution = $this->callAPISuccess("Contribution", "create", array('version' => 3, 'financial_type_id' => 1, 'contribution_status_id' => 2, 'total_amount' => '100.00', 'currency' => 'EUR', 'contact_id' => $contactId)); $create_data = array('version' => 3, 'type' => 'OOFF', 'status' => 'INIT', 'entity_id' => $contribution['id'], 'entity_table' => 'civicrm_contribution', 'contact_id' => $contactId, 'start_date' => date('YmdHis'), 'receive_date' => date('YmdHis'), 'date' => date('YmdHis'), 'iban' => "BE68844010370034", 'bic' => "TESTTEST", 'is_enabled' => 1); // this should fail, since no creditor_id is set and no default creditor either $this->callAPIFailure("SepaMandate", "create", $create_data); // set default creditor $creditor_id = $this->getCreditor(); CRM_Sepa_Logic_Settings::setSetting('batching_default_creditor', $creditor_id); // this should work, since no creditor_id is set BUT the default creditor is $this->callAPISuccess("SepaMandate", "create", $create_data); // set bad default creditor CRM_Sepa_Logic_Settings::setSetting('batching_default_creditor', '999'); // this should fail, since no creditor_id is set and the default creditor is bad $this->callAPIFailure("SepaMandate", "create", $create_data); }