Skip to content
Snippets Groups Projects
Commit ffdfacdb authored by mattwire's avatar mattwire
Browse files

Fix civicrm-core/#4553 getBillingEmail() function

parent 01c47f8c
No related branches found
No related tags found
No related merge requests found
......@@ -47,24 +47,21 @@ trait CRM_Core_Payment_MJWTrait {
/**
* Get the billing email address
*
* @param \Civi\Payment\PropertyBag|array $params
* @param \Civi\Payment\PropertyBag|array $propertyBag
* @param int $contactID
*
* @return string|NULL
* @return string
*/
public function getBillingEmail($propertyBag, $contactID = NULL) {
public function getBillingEmail($propertyBag, $contactID = NULL): string {
// We want this function to take a single argument - propertyBag but for legacy compatibility
// we still accept an array and the second parameter contactID.
// Start: Hackery to convert this function to take propertyBag
$propertyBag = PropertyBag::cast($propertyBag);
if (empty($contactID) && $propertyBag->has('contactID')) {
$contactID = $propertyBag->getContactID();
}
$params = $this->getPropertyBagAsArray($propertyBag);
// End: Hackery to convert this function to take propertyBag
$billingLocationId = CRM_Core_BAO_LocationType::getBilling();
$emailAddress = $params["email-{$billingLocationId}"] ?? $params['email-Primary'] ?? $params['email'] ?? NULL;
if ($propertyBag->has('email')) {
$emailAddress = $propertyBag->getEmail();
}
if (empty($emailAddress) && !empty($contactID)) {
// Try and retrieve an email address from Contact ID
......@@ -73,6 +70,7 @@ trait CRM_Core_Payment_MJWTrait {
->execute();
$other_options = [];
$billingLocationId = CRM_Core_BAO_LocationType::getBilling();
foreach ($emailAddresses as $row) {
if ($row['location_type_id'] == $billingLocationId) {
return $row['email'];
......@@ -85,11 +83,10 @@ trait CRM_Core_Payment_MJWTrait {
}
}
if ($other_options) {
return $other_options[0];
$emailAddress = $other_options[0];
}
return NULL;
}
return $emailAddress;
return $emailAddress ?? '';
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment