*/
public function _gatherMessageValues($input, &$values, $ids = []) {
// set display address of contributor
+ $values['billingName'] = '';
if ($this->address_id) {
- $addressParams = ['id' => $this->address_id];
- $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id');
- $addressDetails = array_values($addressDetails);
+ $addressDetails = CRM_Core_BAO_Address::getValues(['id' => $this->address_id], FALSE, 'id');
+ $addressDetails = reset($addressDetails);
+ $values['billingName'] = $addressDetails['name'] ?? '';
}
// Else we assign the billing address of the contribution contact.
else {
- $addressParams = ['contact_id' => $this->contact_id, 'is_billing' => 1];
- $addressDetails = (array) CRM_Core_BAO_Address::getValues($addressParams);
- $addressDetails = array_values($addressDetails);
+ $addressDetails = (array) CRM_Core_BAO_Address::getValues(['contact_id' => $this->contact_id, 'is_billing' => 1]);
+ $addressDetails = reset($addressDetails);
}
+ $values['address'] = $addressDetails['display'] ?? '';
- if (!empty($addressDetails[0]['display'])) {
- $values['address'] = $addressDetails[0]['display'];
- }
-
- if ($this->_component == 'contribute') {
+ if ($this->_component === 'contribute') {
//get soft contributions
$softContributions = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($this->id, TRUE);
if (!empty($softContributions)) {
$template->assign('first_name', $this->_relatedObjects['contact']->first_name);
$template->assign('last_name', $this->_relatedObjects['contact']->last_name);
$template->assign('displayName', $this->_relatedObjects['contact']->display_name);
+ $template->assign('billingName', $values['billingName']);
// For some unit tests contribution cannot contain paymentProcessor information
$billingMode = empty($this->_relatedObjects['paymentProcessor']) ? CRM_Core_Payment::BILLING_MODE_NOTIFY : $this->_relatedObjects['paymentProcessor']['billing_mode'];
* @return array
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
+ * @throws \Exception
*/
public static function sendMail(&$input, &$ids, $contributionID, &$values,
$returnMessageText = FALSE) {
* Test sending a mail via the API.
*
* @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
public function testSendMail() {
$mut = new CiviMailUtils($this, TRUE);
- $contribution = $this->callAPISuccess('contribution', 'create', $this->_params);
+ $orderParams = $this->_params;
+ $orderParams['contribution_status_id'] = 'Pending';
+ $orderParams['api.PaymentProcessor.pay'] = [
+ 'payment_processor_id' => $this->paymentProcessorID,
+ 'credit_card_type' => 'Visa',
+ 'credit_card_number' => 41111111111111,
+ 'amount' => 5,
+ ];
+
+ $order = $this->callAPISuccess('Order', 'create', $orderParams);
+ $this->callAPISuccess('Payment', 'create', ['total_amount' => 5, 'is_send_notification' => 0, 'order_id' => $order['id']]);
+ $address = $this->callAPISuccess('Address', 'create', ['contribution_id' => $order['id'], 'name' => 'bob', 'contact_id' => 1, 'street_address' => 'blah']);
+ $this->callAPISuccess('Contribution', 'create', ['id' => $order['id'], 'address_id' => $address['id']]);
$this->callAPISuccess('contribution', 'sendconfirmation', [
- 'id' => $contribution['id'],
+ 'id' => $order['id'],
'receipt_from_email' => 'api@civicrm.org',
]);
$mut->checkMailLog([
'Event',
]);
- $this->checkCreditCardDetails($mut, $contribution['id']);
+ $this->checkCreditCardDetails($mut, $order['id']);
$mut->stop();
+ $tplVars = CRM_Core_Smarty::singleton()->get_template_vars();
+ $this->assertEquals('bob', $tplVars['billingName']);
+ $this->assertEquals("bob\nblah\n", $tplVars['address']);
}
/**