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

Update some functions to use API4 internally

parent 42d921ea
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,9 @@
+--------------------------------------------------------------------+
*/
use Civi\Api4\Contribution;
use Civi\Api4\ContributionRecur;
use Civi\Api4\Phone;
use Civi\Payment\Exception\PaymentProcessorException;
use Civi\Payment\PropertyBag;
use CRM_Mjwshared_ExtensionUtil as E;
......@@ -92,28 +94,27 @@ trait CRM_Core_Payment_MJWTrait {
/**
* Get the billing email address
*
* @deprecated This is not used anywhere and will be removed in a future version
*
* @param array $params
* @param int $contactId
* @param int $contactID
*
* @return string|NULL
*/
protected function getBillingPhone($params, $contactId) {
$billingLocationId = CRM_Core_BAO_LocationType::getBilling();
$phoneNumber = $params["phone-{$billingLocationId}"] ?? $params['phone-Primary'] ?? $params['phone'] ?? NULL;
protected function getBillingPhone($params, $contactID) {
$billingLocationTypeID = CRM_Core_PseudoConstant::getKey('CRM_Core_DAO_Address', 'location_type_id', 'Billing');
$phoneNumber = $params["phone-{$billingLocationTypeID}"] ?? $params['phone-Primary'] ?? $params['phone'] ?? NULL;
if (empty($phoneNumber) && !empty($contactId)) {
if (empty($phoneNumber) && !empty($contactID)) {
// Try and retrieve a phone number from Contact ID
try {
$phoneNumber = civicrm_api3('Phone', 'getvalue', [
'contact_id' => $contactId,
'return' => ['phone'],
]);
}
catch (CiviCRM_API3_Exception $e) {
return NULL;
}
$phone = Phone::get(FALSE)
->addSelect('phone')
->addWhere('contact_id', '=', $contactID)
->addOrderBy('is_primary', 'DESC')
->execute()
->first();
}
return $phoneNumber;
return $phone['phone'] ?? '';
}
/**
......@@ -159,15 +160,22 @@ trait CRM_Core_Payment_MJWTrait {
}
if ($propertyBag->has('contributionID')) {
return (int) civicrm_api3('Contribution', 'getvalue', ['id' => $propertyBag->getContributionID(), 'return' => 'contribution_recur_id']);
return Contribution::get(FALSE)
->addSelect('contribution_recur_id')
->addWhere('id', '=', $propertyBag->getContributionID())
->addWhere('is_test', 'IN', [TRUE, FALSE])
->execute()
->first()['contribution_recur_id'] ?? NULL;
}
if ($propertyBag->has('processorID')) {
$propertyBag->getRecurProcessorID();
return (int) civicrm_api3('ContributionRecur', 'getvalue', [
'processor_id' => $propertyBag->getRecurProcessorID(),
'return' => 'id'
]);
return ContributionRecur::get(FALSE)
->addSelect('id')
->addWhere('processor_id', '=', $propertyBag->getRecurProcessorID())
->addWhere('is_test', 'IN', [TRUE, FALSE])
->execute()
->first()['id'] ?? NULL;
}
return NULL;
}
......
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