Skip to content

Commit

Permalink
Merge pull request #35 from agileware/CIVIEWAY-245
Browse files Browse the repository at this point in the history
Version 2.4.4
  • Loading branch information
agileware-justin authored Jan 27, 2023
2 parents e5aca6c + d5db668 commit 88a1d59
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 110 deletions.
35 changes: 35 additions & 0 deletions CRM/eWAYRecurring/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,41 @@
* Collection of upgrade steps.
*/
class CRM_eWAYRecurring_Upgrader extends CRM_Extension_Upgrader_Base {
public function upgrade_6() {
$setting_url = CRM_Utils_System::url('civicrm/admin/paymentProcessor', ['reset' => 1]);
$this->ctx->log->info(E::ts('Version 2.x of the eWay Payment Processor extension uses the new eWay Rapid API. Please go to the <a href="%2">Payment Processor page</a> and update the eWay API credentials with the new API Key and API Password. For more details see the <a href="%1">upgrade notes</a>.', [
1 => 'https://github.com/agileware/au.com.agileware.ewayrecurring/blob/master/UPGRADE.md',
2 => $setting_url,
]));

$this->ctx->log->info('Update Payment Processor labels for Rapid API');
CRM_Core_DAO::executeQuery("UPDATE civicrm_payment_processor_type SET user_name_label = 'API Key', password_label = 'API Password' WHERE name = 'eWay_Recurring'");

$this->ctx->log->info('Create eWAY Contribution Transactions store.');
$query = <<<SQL
CREATE TABLE IF NOT EXISTS `civicrm_eway_contribution_transactions` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Unique EwayContributionTransactions ID',
`contribution_id` INT UNSIGNED COMMENT 'FK to Contact',
`payment_processor_id` INT UNSIGNED COMMENT 'FK to PaymentProcessor',
`access_code` TEXT,
`failed_message` TEXT DEFAULT NULL,
`status` INT UNSIGNED DEFAULT 0,
`tries` INT UNSIGNED DEFAULT 0,
PRIMARY KEY(`id`),
CONSTRAINT FK_civicrm_eway_contribution_transactions_contribution_id FOREIGN KEY(`contribution_id`) REFERENCES `civicrm_contribution` (`id`) ON DELETE CASCADE,
CONSTRAINT FK_civicrm_eway_contribution_transactions_payment_processor_id FOREIGN KEY(`payment_processor_id`) REFERENCES `civicrm_payment_processor` (`id`) ON DELETE CASCADE
);
SQL;
CRM_Core_DAO::executeQuery($query);
return TRUE;
}

public function upgrade_7() {
$this->ctx->log->info('Add email receipt field to eWAY Contribution Transactions store.');
CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_eway_contribution_transactions` ADD `is_email_receipt` TINYINT(1) DEFAULT 1");
return TRUE;
}

public function upgrade_20201() {
$this->ctx->log->info('Applying 2.2.1 update; Fix billing mode for payment processor.');
CRM_Core_DAO::executeQuery("UPDATE civicrm_payment_processor_type SET billing_mode = 4 WHERE name = 'eWay_Recurring'");
Expand Down
117 changes: 9 additions & 108 deletions eWAYRecurring.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ function ewayrecurring_civicrm_install() {
function ewayrecurring_civicrm_postInstall() {
// Update schemaVersion if added new version in upgrade process.
CRM_Core_BAO_Extension::setSchemaVersion('au.com.agileware.ewayrecurring', 20200);
_ewayrecurring_civix_civicrm_postInstall();
}

/**
* Implements hook_civicrm_uninstall().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall
*/
function ewayrecurring_civicrm_uninstall() {
_ewayrecurring_civix_civicrm_uninstall();
}

/**
Expand All @@ -51,109 +41,19 @@ function ewayrecurring_civicrm_uninstall() {
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
*/
function ewayrecurring_civicrm_enable() {
// Ensure payment processor is active, will be deactivated if extension is disabled and user has no way to reactivate
\Civi\Api4\PaymentProcessorType::update()
->addValue('is_active', TRUE)
->addWhere('name', '=', 'eWay_Recurring')
->execute();
_ewayrecurring_civix_civicrm_enable();
}

/**
* Implements hook_civicrm_disable().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable
*/
function ewayrecurring_civicrm_disable() {
_ewayrecurring_civix_civicrm_disable();
}

/**
* Implements hook_civicrm_upgrade().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_upgrade
*/
function ewayrecurring_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
$schemaVersion = intval(CRM_Core_BAO_Extension::getSchemaVersion('au.com.agileware.ewayrecurring'));
$upgrades = [];

if ($op == 'check') {
if ($schemaVersion < 6) {
$setting_url = CRM_Utils_System::url('civicrm/admin/paymentProcessor', ['reset' => 1]);
CRM_Core_Session::setStatus(ts('Version 2.x of the eWay Payment Processor extension uses the new eWay Rapid API. Please go to the <a href="%2">Payment Processor page</a> and update the eWay API credentials with the new API Key and API Password. For more details see the <a href="%1">upgrade notes</a>.', [
1 => 'https://github.com/agileware/au.com.agileware.ewayrecurring/blob/master/UPGRADE.md',
2 => $setting_url,
]), ts('eWay Payment Processor Update'));
}
if ($schemaVersion < 7) {
CRM_Core_Session::setStatus(ts('Please edit and save (without any changes) your existing eWay payment processor after updating.'), ts('eWay Payment Processor Update'));
}
return [$schemaVersion < 20201];
}
elseif ($op == 'enqueue') {
if (NULL == $queue) {
return CRM_Core_Error::fatal('au.com.agileware.ewayrecurring: No Queue supplied for upgrade');
}
if ($schemaVersion < 5) {
$queue->createItem(
new CRM_Queue_Task('_ewayrecurring_upgrade_schema_version', [
5,
],
'Update schema version'
)
);
}
if ($schemaVersion < 6) {
$queue->createItem(
new CRM_Queue_Task('_ewayrecurring_upgrade_schema', [
6,
"UPDATE civicrm_payment_processor_type SET user_name_label = 'API Key', password_label = 'API Password' WHERE name = 'eWay_Recurring'",
],
'Perform Rapid API related changes'
)
);

// add the table if not exist
$queue->createItem(
new CRM_Queue_Task('_ewayrecurring_upgrade_schema', [
6,
"CREATE TABLE IF NOT EXISTS `civicrm_eway_contribution_transactions`(
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Unique EwayContributionTransactions ID',
`contribution_id` INT UNSIGNED COMMENT 'FK to Contact',
`payment_processor_id` INT UNSIGNED COMMENT 'FK to PaymentProcessor',
`access_code` TEXT,
`failed_message` TEXT DEFAULT NULL,
`status` INT UNSIGNED DEFAULT 0,
`tries` INT UNSIGNED DEFAULT 0,
PRIMARY KEY(`id`),
CONSTRAINT FK_civicrm_eway_contribution_transactions_contribution_id FOREIGN KEY(`contribution_id`) REFERENCES `civicrm_contribution`(`id`) ON DELETE CASCADE,
CONSTRAINT FK_civicrm_eway_contribution_transactions_payment_processor_id FOREIGN KEY(`payment_processor_id`) REFERENCES `civicrm_payment_processor`(`id`) ON DELETE CASCADE
);",
],
'Create the table if not exist.'
)
);
}
if ($schemaVersion < 7) {
// CIVIEWAY-76 remember the send email option
$queue->createItem(
new CRM_Queue_Task('_ewayrecurring_upgrade_schema', [
7,
"ALTER TABLE `civicrm_eway_contribution_transactions` ADD `is_email_receipt` TINYINT(1) DEFAULT 1",
],
'Save the send email option.'
)
);
}

if ($schemaVersion < 20200) {
$queue->createItem(
new CRM_Queue_Task('_ewayrecurring_upgrade_schema', [
20200,
"UPDATE civicrm_payment_processor SET billing_mode = 4 WHERE payment_processor_type_id = (SELECT id FROM civicrm_payment_processor_type WHERE name = 'eWay_Recurring')",
],
'Updating existing processors.'
)
);
}
}
return _ewayrecurring_civix_civicrm_upgrade($op, $queue);
}

/**
* Implements hook_civicrm_managed().
Expand Down Expand Up @@ -243,7 +143,6 @@ function ewayrecurring_civicrm_managed(&$entities) {
'is_active' => '1',
],
];
_ewayrecurring_civix_civicrm_managed($entities);
}

/**
Expand Down Expand Up @@ -423,10 +322,12 @@ function validateEwayContribution($paymentProcessor, $invoiceID) {
if (count($contribution['values']) > 0 && $contribution['values'][0]['total_amount'] > 0) {
// Include eWay SDK.
require_once extensionPath('vendor/autoload.php');
$store = NULL;

$contribution = $contribution['values'][0];
$eWayAccessCode = CRM_Utils_Request::retrieve('AccessCode', 'String', $form, FALSE, "");
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form, FALSE, "");
// @TODO $form is an undefined variable
$eWayAccessCode = CRM_Utils_Request::retrieve('AccessCode', 'String', $store, FALSE, "");
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $store, FALSE, "");

$paymentProcessor->validateContribution($eWayAccessCode, $contribution, $qfKey, $paymentProcessor->getPaymentProcessor());

Expand Down
4 changes: 2 additions & 2 deletions info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<email>support@agileware.com.au</email>
</maintainer>
<develStage>stable</develStage>
<releaseDate>2023-01-25</releaseDate>
<version>2.4.3</version>
<releaseDate>2023-01-27</releaseDate>
<version>2.4.4</version>
<compatibility>
<ver>5.38</ver>
</compatibility>
Expand Down

0 comments on commit 88a1d59

Please sign in to comment.