Skip to content

Commit

Permalink
Merge pull request #15688 from eileenmcnaughton/billing_name
Browse files Browse the repository at this point in the history
Fix BillingName to be assigned in email receipts IF available
  • Loading branch information
eileenmcnaughton authored Nov 1, 2019
2 parents d7f426c + 49cba3a commit 677e677
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
21 changes: 10 additions & 11 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -3054,23 +3054,20 @@ public function composeMessageArray(&$input, &$ids, &$values, $returnMessageText
*/
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)) {
Expand Down Expand Up @@ -3187,6 +3184,7 @@ public function _assignMessageVariablesToTemplate(&$values, $input, $returnMessa
$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'];
Expand Down Expand Up @@ -4668,6 +4666,7 @@ public static function completeOrder(&$input, &$ids, $objects, $transaction, $re
* @return array
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @throws \Exception
*/
public static function sendMail(&$input, &$ids, $contributionID, &$values,
$returnMessageText = FALSE) {
Expand Down
1 change: 1 addition & 0 deletions api/v3/PaymentProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ function _civicrm_api3_payment_processor_pay_spec(&$params) {
'api.required' => TRUE,
'title' => ts('Contribution ID'),
'type' => CRM_Utils_Type::T_INT,
'api.aliases' => ['order_id'],
];
$params['contact_id'] = [
'title' => ts('Contact ID'),
Expand Down
22 changes: 19 additions & 3 deletions tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3346,12 +3346,25 @@ public function setUpPendingContribution($priceFieldValueID, $contriParams = [])
* 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([
Expand All @@ -3361,8 +3374,11 @@ public function testSendMail() {
'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']);
}

/**
Expand Down

0 comments on commit 677e677

Please sign in to comment.