1

I'm using the wonderful civibanking extension to import the bank statments, including creating the contributions from the donors that directly wire money to our bank account

for the "normal" bank transfers (one off) it works great, we lookup the donor, create a new contribution and all is well

However, we have some donors that sends the same amount every month. They have a different transfer type (one of the column in the bank statement), so we can identify them.

Instead of "simply" creating a contribution, we'd like to 1) check if there is an active recurring contribution of type "bank transfer", if not, create it 2) add the contribution as one linked with that recurring contribution

Is this possible to do out of the box? Any guidance on how to code it?

1

I am not sure if Civirules does it(pretty sure it doesn't). Through an extension i would use pre hook to check and create contribution recur when a contribution is created. Here is small snippet

function extension_civicrm_pre($op, $objectName, $id, &$params) {
  if ($objectName == 'Contribution' && $op == 'create') {
    $bankTransferFinancialTypeId = civicrm_api3('FinancialType', 'getvalue', [
      'return' => "id",
      'name' => "Bank Transfer",
    ]);
    if ($bankTransferFinancialTypeId == $params['financial_type_id']) {
      // perform checks if contribution recur exists
      try {
        $recurringcontributionId = civicrm_api3('ContributionRecur', 'getvalue', [
          'return' => "id",
          'contact_id' => $params['contact_id'],
          'amount' => $params['total_amount'],
          'contribution_status_id' => ['IN' => ["Pending", "In Progress"]],
          'options' => ['limit' => 1],
        ]);
      }
      catch (CiviCRM_API3_Exception $e) {
        $recurringcontribution = civicrm_api3('ContributionRecur', 'create', [
          'contact_id' => $params['contact_id'],
          'installments' => '12',
          'frequency_interval' => '1',
          'amount' => $params['total_amount'],
          'contribution_status_id' => 'In Progress',
          'start_date' => date('YmdHis'),
          'currency' => 'USD',
          'frequency_unit' => 'month',
        ]);
        $recurringcontributionId = $recurringcontribution['id'];
      }
      $params['contribution_recur_id'] = $recurringcontributionId;
    }
  }
}

Note: This snippet is not tested since i have just created it and is pure blind coding.

HTH

Pradeep

  • Thanks pradeep, I should have been clearer: the code itself wasn't the question, but more how to do it as one of the matcher/analyser plugins in civibanking. This being said, your idea of using a pre-hook is a nice workaround! – Xavier Jul 25 '18 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.