$recurParams['invoice_id'] = $params['invoiceID'] ?? NULL;
$recurParams['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
$recurParams['payment_processor_id'] = $params['payment_processor_id'] ?? NULL;
- $recurParams['is_email_receipt'] = $params['is_email_receipt'] ?? NULL;
+ $recurParams['is_email_receipt'] = (bool) ($params['is_email_receipt'] ?? FALSE);
// we need to add a unique trxn_id to avoid a unique key error
// in paypal IPN we reset this when paypal sends us the real trxn id, CRM-2991
$recurParams['trxn_id'] = $params['trxn_id'] ?? $params['invoiceID'];
$recurParams['invoice_id'] = $params['invoiceID'] ?? NULL;
$recurParams['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending');
$recurParams['payment_processor_id'] = $params['payment_processor_id'] ?? NULL;
- $recurParams['is_email_receipt'] = $params['is_email_receipt'] ?? NULL;
+ $recurParams['is_email_receipt'] = (bool) ($params['is_email_receipt'] ?? FALSE);
// we need to add a unique trxn_id to avoid a unique key error
// in paypal IPN we reset this when paypal sends us the real trxn id, CRM-2991
$recurParams['trxn_id'] = $params['trxn_id'] ?? $params['invoiceID'];
];
}
+ /**
+ * Test Recurring Contribution Email Receipt Flag
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function testContributionEmailReceipt() {
+ $createParams = $this->_params;
+ unset($createParams['trxn_id'], $createParams['invoice_id']);
+
+ // pass null value to is_email_receipt
+ $createParams['is_email_receipt'] = NULL;
+ $recurring1 = CRM_Contribute_BAO_ContributionRecur::add($createParams);
+ $recurring1Get = $this->callAPISuccess('ContributionRecur', 'getsingle', ['id' => $recurring1->id]);
+ // default is_email_receipt column value is 1
+ $this->assertEquals('1', $recurring1Get['is_email_receipt']);
+
+ // pass empty value to is_email_receipt
+ $createParams['is_email_receipt'] = '';
+ $recurring2 = CRM_Contribute_BAO_ContributionRecur::add($createParams);
+ $this->assertEquals('null', $recurring2->is_email_receipt);
+
+ // pass 0 value to is_email_receipt
+ $createParams['is_email_receipt'] = 0;
+ $recurring3 = CRM_Contribute_BAO_ContributionRecur::add($createParams);
+ $recurring3Get = $this->callAPISuccess('ContributionRecur', 'getsingle', ['id' => $recurring3->id]);
+ $this->assertEquals('0', $recurring3Get['is_email_receipt']);
+ }
+
}