$receiptSend = FALSE;
$contributionId = $this->ids['Contribution'] ?? CRM_Member_BAO_Membership::getMembershipContributionId($this->getMembershipID());
$membershipIds = $this->_membershipIDs;
- if ($contributionId && !empty($membershipIds)) {
+ if ($this->getSubmittedValue('send_receipt') && $contributionId && !empty($membershipIds)) {
$contributionDetails = CRM_Contribute_BAO_Contribution::getContributionDetails(
CRM_Export_Form_Select::MEMBER_EXPORT, $this->_membershipIDs);
if ($contributionDetails[$this->getMembershipID()]['contribution_status'] === 'Completed') {
- $receiptSend = TRUE;
+ $formValues['contact_id'] = $this->_contactID;
+ $formValues['contribution_id'] = $contributionId;
+ // receipt_text_signup is no longer used in receipts from 5.47
+ // but may linger in some sites that have not updated their
+ // templates.
+ $formValues['receipt_text_signup'] = $this->getSubmittedValue('receipt_text');
+ // send email receipt
+ $this->assignBillingName();
+ $this->emailMembershipReceipt($formValues);
+ $this->addStatusMessage(ts('A membership confirmation and receipt has been sent to %1.', [1 => $this->_contributorEmail]));
}
}
- $receiptSent = FALSE;
- if ($this->getSubmittedValue('send_receipt') && $receiptSend) {
- $formValues['contact_id'] = $this->_contactID;
- $formValues['contribution_id'] = $contributionId;
- // receipt_text_signup is no longer used in receipts from 5.47
- // but may linger in some sites that have not updated their
- // templates.
- $formValues['receipt_text_signup'] = $formValues['receipt_text'];
- // send email receipt
- $this->assignBillingName();
- $mailSend = $this->emailMembershipReceipt($formValues);
- $receiptSent = TRUE;
- }
-
- if ($receiptSent && $mailSend) {
- $this->addStatusMessage(ts('A membership confirmation and receipt has been sent to %1.', [1 => $this->_contributorEmail]));
- }
-
CRM_Core_Session::setStatus($this->getStatusMessage(), ts('Complete'), 'success');
$this->setStatusMessage();
use Civi\Api4\FinancialType;
use Civi\Api4\MembershipType;
+use Civi\Api4\PriceFieldValue;
/**
* Test CRM_Member_Form_Membership functions.
* Test CRM_Member_Form_Membership::formRule() with a parameter
* that has an end date before the start date and a rolling
* membership type
+ *
+ * @throws \CRM_Core_Exception
*/
public function testFormRuleRollingEarlyEnd(): void {
$unixYesterday = time() - (24 * 60 * 60);
* @throws \CRM_Core_Exception
*/
public function testLineItemAmountOnSalesTax(): void {
+ $mailUtil = new CiviMailUtils($this, TRUE);
$this->enableTaxAndInvoicing();
$this->addTaxAccountToFinancialType(2);
- $form = $this->getForm();
- $form->preProcess();
- $this->mut = new CiviMailUtils($this, TRUE);
- $this->createLoggedInUser();
$priceSet = $this->callAPISuccess('PriceSet', 'Get', ['extends' => 'CiviMember']);
- $form->set('priceSetId', $priceSet['id']);
// we are simulating the creation of a Price Set in Administer -> CiviContribute -> Manage Price Sets so set is_quick_config = 0
$this->callAPISuccess('PriceSet', 'Create', ['id' => $priceSet['id'], 'is_quick_config' => 0]);
+ $fieldOption = PriceFieldValue::get()->addWhere('amount', '=', 50)->addSelect('id', 'price_field_id')->execute()->indexBy('id')->first();
// clean the price options static variable to repopulate the options, in order to fetch tax information
\Civi::$statics['CRM_Price_BAO_PriceField']['priceOptions'] = NULL;
- CRM_Price_BAO_PriceSet::buildPriceSet($form);
- // rebuild the price set form variable to include the tax information against each price options
- $form->_priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSet['id']));
$params = [
'cid' => $this->_individualId,
'join_date' => date('Y-m-d'),
// This format reflects the first number being the organisation & the second being the type.
'membership_type_id' => [$this->ids['contact']['organization'], $this->ids['membership_type']['AnnualFixed']],
'record_contribution' => 1,
+ 'price_' . $fieldOption['price_field_id'] => $fieldOption['id'],
'total_amount' => 55,
'receive_date' => date('Y-m-d') . ' 20:36:00',
'payment_instrument_id' => array_search('Check', $this->paymentInstruments, TRUE),
//Member dues, see data.xml
'financial_type_id' => 2,
'payment_processor_id' => $this->_paymentProcessorID,
+ 'send_receipt' => 1,
+ 'from_email_address' => 'bob@example.com',
];
- $form->_contactID = $this->_individualId;
- $form->testSubmit($params);
+
+ $form = $this->getForm($params);
+ $this->createLoggedInUser();
+ $form->postProcess();
+ $email = preg_replace('/\s+/', ' ', $mailUtil->getMostRecentEmail());
+ foreach ($this->getExpectedEmailStrings() as $string) {
+ $this->assertStringContainsString($string, $email);
+ }
$membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
$lineItem = $this->callAPISuccessGetSingle('LineItem', ['entity_id' => $membership['id'], 'entity_table' => 'civicrm_membership']);
$this->assertEquals($contribution['total_amount'], $financialItems_sum);
}
+ /**
+ * Get the expected output from mail.
+ *
+ * @return string[]
+ */
+ private function getExpectedEmailStrings(): array {
+ return [
+ '<table id="crm-membership_receipt"',
+ 'Membership Fee',
+ 'Financial Type',
+ 'Member Dues </td>',
+ '<tr> <td colspan="2" style="padding: 4px; border-bottom: 1px solid #999;"> <table> <tr> <th>Item</th> <th>Fee</th> <th>SubTotal</th> <th>Tax Rate</th> <th>Tax Amount</th> <th>Total</th> <th>Membership Start Date</th> <th>Membership Expiration Date</th> </tr> <tr> <td> Membership Amount - AnnualFixed </td>',
+ '<td> $50.00 </td> <td> $50.00 </td> <td> 10.00% </td> <td> $5.00 </td> <td> $55.00 </td> <td>',
+ 'Amount Before Tax: </td>',
+ '<td style="padding: 4px; border-bottom: 1px solid #999;"> $50.00 </td>',
+ '<td> Sales Tax 10.00%</td> <td> $5.00</td>',
+ 'Total Tax Amount </td> <td style="padding: 4px; border-bottom: 1px solid #999;"> $5.00 </td>',
+ 'Amount </td> <td style="padding: 4px; border-bottom: 1px solid #999;"> $55.00 </td>',
+ 'Paid By </td> <td style="padding: 4px; border-bottom: 1px solid #999;"> Check </td>',
+ ];
+ }
+
/**
* Test that membership end_date is correct for multiple terms for pending contribution
*