Skip to content

Commit

Permalink
CIVIEWAY-263 Refactor out more deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
agileware-fj committed Dec 14, 2023
1 parent be4c8b2 commit edce66d
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 39 deletions.
9 changes: 4 additions & 5 deletions CRM/Core/Payment/eWAYRecurring.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public static function getInstance(&$paymentProcessor) {
function __construct($mode, &$paymentProcessor) {
$this->_mode = $mode; // live or test
$this->_paymentProcessor = $paymentProcessor;
$this->_processorName = ts('eWay Recurring');
}

/**
Expand All @@ -58,7 +57,7 @@ function validateContribution($eWayAccessCode, $contribution, $qfKey, $paymentPr
if ($hasTransactionFailed) {
civicrm_api3('Contribution', 'create', [
'id' => $contributionID,
'contribution_status_id' => _contribution_status_id('Failed'),
'contribution_status_id' => CRM_eWAYRecurring_Utils::contribution_status_id('Failed'),
'trxn_id' => $transactionID,
]);

Expand Down Expand Up @@ -280,7 +279,7 @@ public function doPayment(&$params, $component = 'contribute') {
}

if (!defined('CURLOPT_SSLCERT')) {
CRM_Core_Error::fatal(ts('eWay - Gateway requires curl with SSL support'));
throw new CRM_Core_Exception(ts('eWay - Gateway requires curl with SSL support'));
}

$eWayClient = $this->getEWayClient();
Expand Down Expand Up @@ -739,10 +738,10 @@ function updateSubscriptionBillingInfo(&$message = '', $params = []) {
//----------------------------------------------------------------------------------------------------

switch ($contribution['contribution_status_id']) {
case _contribution_status_id('Completed'):
case CRM_eWAYRecurring_Utils::contribution_status_id('Completed', TRUE):
throw new Exception(ts('Attempted to update billing details for a completed contribution.'));
break;
case _contribution_status_id('Cancelled'):
case CRM_eWAYRecurring_Utils::contribution_status_id('Cancelled', TRUE):
throw new Exception(ts('Attempted to update billing details for a cancelled contribution.'));
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion CRM/eWAYRecurring/Form/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function addFormElements() {
if (isset($setting['quick_form_type'])) {
$add = 'add' . $setting['quick_form_type'];
if ($add == 'addElement') {
$this->$add($setting['html_type'], $name, $setting['title'], $setting['html_attributes'] ?? [], TRUE);
$this->$add($setting['html_type'], $name, $setting['title'], $setting['html_attributes'], TRUE);
}
elseif ($setting['html_type'] == 'Select') {
$optionValues = [];
Expand Down
11 changes: 6 additions & 5 deletions CRM/eWAYRecurring/Page/VerifyUpdateToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class CRM_eWAYRecurring_Page_VerifyUpdateToken extends CRM_Core_Page {

public function run() {
$store = NULL;
$store = $form = NULL;

$recurringContributionID = CRM_Utils_Request::retrieve('recurringContributionID', 'String', $store, FALSE, "");
$eWayAccessCode = CRM_Utils_Request::retrieve('AccessCode', 'String', $form, FALSE, "");
Expand All @@ -28,7 +28,7 @@ public function run() {
$paymentProcessorInfo = $paymentProcessorInfo[0];
//$paymentProcessorInfo['is_test'] = 1;

$response = CRM_eWAYRecurring_Utils::validateEwayAccessCode($eWayAccessCode, $paymentProcessorInfo, TRUE);
$response = \CRM_eWAYRecurring_Utils::validateEwayAccessCode($eWayAccessCode, $paymentProcessorInfo, TRUE);
$hasTransactionFailed = $response['hasTransactionFailed'];
$transactionResponseError = $response['transactionResponseError'];

Expand All @@ -48,13 +48,14 @@ public function run() {
// Updating the billing details should fixed failed contributions
//----------------------------------------------------------------------------------------------------

CRM_eWAYRecurring_Utils::updateCustomerDetails($response, $recurringContribution);
\CRM_eWAYRecurring_Utils::updateCustomerDetails($response, $recurringContribution);

if (_contribution_status_id('Failed') == $recurringContribution['contribution_status_id']) {
if ( \CRM_eWAYRecurring_Utils::contribution_status_id('Failed', TRUE) == $recurringContribution['contribution_status_id']) {
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionRecur',
$recurringContribution['id'],
'contribution_status_id',
_contribution_status_id('In Progress'));
\CRM_eWAYRecurring_Utils::contribution_status_id('In Progress', TRUE)
);
}

CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionRecur',
Expand Down
35 changes: 15 additions & 20 deletions CRM/eWAYRecurring/ProcessTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,11 @@ public function process_recurring_payments() {
else {
$next_sched = NULL;
/* Mark recurring contribution as complteted*/
civicrm_api(
civicrm_api3(
'ContributionRecur', 'create',
[
'version' => '3',
'id' => $contribution->id,
'contribution_recur_status_id' => _contribution_status_id('Completed'),
'contribution_recur_status_id' => CRM_eWAYRecurring_Utils::contribution_status_id('Completed', TRUE),
]
);
}
Expand All @@ -93,11 +92,7 @@ public function process_recurring_payments() {
$amount_in_cents = preg_replace('/\.([0-9]{0,2}).*$/', '$1',
$contribution->amount);

$addresses = civicrm_api('Address', 'get',
[
'version' => '3',
'contact_id' => $contribution->contact_id,
]);
$addresses = civicrm_api3('Address', 'get', ['contact_id' => $contribution->contact_id,]);

$billing_address = array_shift($addresses['values']);

Expand All @@ -118,7 +113,7 @@ public function process_recurring_payments() {

$repeat_params = [
'contribution_recur_id' => $contribution->id,
'contribution_status_id' => _contribution_status_id('Pending'),
'contribution_status_id' => CRM_eWAYRecurring_Utils::contribution_status_id('Pending'),
'total_amount' => $contribution->amount,
'is_email_receipt' => 0,
];
Expand Down Expand Up @@ -226,23 +221,23 @@ public function process_recurring_payments() {

if (count($responseErrors)) {
// Mark transaction as failed
$new_contribution_record['contribution_status_id'] = _contribution_status_id('Failed');
$new_contribution_record['contribution_status_id'] = CRM_eWAYRecurring_Utils::contribution_status_id('Failed');
$this->mark_recurring_contribution_failed($contribution);
}
else {
// $this->send_receipt_email($new_contribution_record->id);
$new_contribution_record['contribution_status_id'] = _contribution_status_id('Completed');
$new_contribution_record['contribution_status_id'] = CRM_eWAYRecurring_Utils::contribution_status_id('Completed');

$new_contribution_record['is_email_receipt'] = Civi::settings()
->get('eway_recurring_keep_sending_receipts');

if ($contribution->failure_count > 0 && $contribution->contribution_status_id == _contribution_status_id('Failed')) {
if ($contribution->failure_count > 0 && $contribution->contribution_status_id == CRM_eWAYRecurring_Utils::contribution_status_id('Failed')) {
// Failed recurring contribution completed successfuly after several retry.
$this->update_contribution_status($next_sched, $contribution);
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionRecur',
$contribution->id,
'contribution_status_id',
_contribution_status_id('In Progress'));
CRM_eWAYRecurring_Utils::contribution_status_id('In Progress', TRUE));

try {
civicrm_api3('Activity', 'create', [
Expand All @@ -266,7 +261,7 @@ public function process_recurring_payments() {
}

$api_action = (
$new_contribution_record['contribution_status_id'] == _contribution_status_id('Completed')
$new_contribution_record['contribution_status_id'] == CRM_eWAYRecurring_Utils::contribution_status_id('Completed')
? 'completetransaction'
: 'create'
);
Expand Down Expand Up @@ -303,10 +298,10 @@ public function process_recurring_payments() {

// already talk to eway? then we need to check the payment status
if ($eWayResponse) {
$new_contribution_record['contribution_status_id'] = _contribution_status_id('Pending');
$new_contribution_record['contribution_status_id'] = CRM_eWAYRecurring_Utils::contribution_status_id('Pending');
}
else {
$new_contribution_record['contribution_status_id'] = _contribution_status_id('Failed');
$new_contribution_record['contribution_status_id'] = CRM_eWAYRecurring_Utils::contribution_status_id('Failed');
}

try {
Expand Down Expand Up @@ -364,7 +359,7 @@ protected function update_contribution_status($next_sched, $contribution) {
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionRecur',
$contribution->id,
'contribution_status_id',
_contribution_status_id('Completed'));
CRM_eWAYRecurring_Utils::contribution_status_id('Completed', TRUE));
CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionRecur',
$contribution->id,
'end_date',
Expand Down Expand Up @@ -422,8 +417,8 @@ protected function get_scheduled_contributions() {

// Don't get cancelled or failed contributions
$status_ids = implode(', ', [
_contribution_status_id('In Progress'),
_contribution_status_id('Pending'),
CRM_eWAYRecurring_Utils::contribution_status_id('In Progress', TRUE),
CRM_eWAYRecurring_Utils::contribution_status_id('Pending', TRUE),
]);
$scheduled_today->whereAdd("`contribution_status_id` IN ({$status_ids})");

Expand Down Expand Up @@ -469,7 +464,7 @@ public function get_scheduled_failed_contributions() {

$scheduled_today->whereAdd("`failure_retry_date` <= now()");

$scheduled_today->contribution_status_id = _contribution_status_id('In Progress');
$scheduled_today->contribution_status_id = CRM_eWAYRecurring_Utils::contribution_status_id('In Progress', TRUE);
$scheduled_today->whereAdd("`failure_count` < " . $maxFailRetry);
$scheduled_today->whereAdd("`failure_count` > 0");

Expand Down
8 changes: 7 additions & 1 deletion CRM/eWAYRecurring/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ private static function updateRecurringContribution($contribution, $customerToke
$recurringContribution['processor_id'] = $customerTokenId;
$recurringContribution['payment_token_id'] = $paymentTokenID;
$recurringContribution['create_date'] = CRM_Utils_Date::isoToMysql(date('Y-m-d H:i:s'));
$recurringContribution['contribution_status_id'] = _contribution_status_id('In Progress');
$recurringContribution['contribution_status_id'] = self::contribution_status_id('In Progress', TRUE);
$recurringContribution['trxn_id'] = $transactionID;

civicrm_api3('ContributionRecur', 'create', $recurringContribution);
Expand Down Expand Up @@ -469,4 +469,10 @@ public static function validateEwayContribution($paymentProcessor, $invoiceID) {
}
return NULL;
}

public static function contribution_status_id($name, $for_recur = FALSE) {
$baoName = $for_recur ? 'CRM_Contribute_BAO_ContributionRecur' : 'CRM_Contribute_BAO_Contribution';
return \CRM_Core_PseudoConstant::getKey($baoName, 'contribution_status_id', $name);
}

}
15 changes: 9 additions & 6 deletions eWAYRecurring.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ function ewayrecurring_civicrm_entityTypes(&$entityTypes) {
];
}

function _contribution_status_id($name) {
return CRM_Utils_Array::key($name, \CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'));
}

/**
* @param $formName
* @param $form CRM_Core_Form
Expand All @@ -186,7 +182,7 @@ function ewayrecurring_civicrm_buildForm($formName, &$form) {
($crid = $form->getVar('contributionRecurID')) || ($crid = $form->getVar('_crid'));
if ($crid) {
$sql = 'SELECT next_sched_contribution_date FROM civicrm_contribution_recur WHERE id = %1';
$form->addDateTime('next_scheduled_date', ts('Next Scheduled Date'), FALSE, ['formatType' => 'activityDateTime']);
$form->add('datepicker', 'next_scheduled_date', ts('Next Scheduled Date'), NULL, FALSE, ['formatType' => 'activityDateTime']);
if ($default_nsd = CRM_Core_DAO::singleValueQuery($sql, [
1 => [
$crid,
Expand Down Expand Up @@ -222,7 +218,14 @@ function ewayrecurring_civicrm_buildForm($formName, &$form) {
}

function ewayrecurring_civicrm_validateForm($formName, &$fields, &$files, &$form, &$errors) {
$paymentProcessorID = CRM_Core_ManagedEntities::singleton()->get('au.com.agileware.ewayrecurring', 'eWay_Recurring')['id'];
$paymentProcessorID = \Civi\Api4\Managed::get(FALSE)
->addSelect('entity_id')
->addWhere('module', '=', 'au.com.agileware.ewayrecurring')
->addWhere('name', '=', 'eWay_Recurring')
->setLimit(1)
->execute()
->first()
['entity_id'];

switch($formName) {
case'CRM_Admin_Form_PaymentProcessor':
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/EwayRecurring/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ protected function eventPriceSetCreate($feeTotal, $minAmt = 0, $type = 'Text') {
$priceSet = CRM_Price_BAO_PriceSet::findById($result['id']);
}
else {
$priceSet = CRM_Price_BAO_PriceSet::create($paramsSet);
$priceSet = CRM_Price_BAO_PriceSet::writeRecord($paramsSet);
}
$this->_ids['price_set'] = $priceSet->id;

Expand Down

0 comments on commit edce66d

Please sign in to comment.