Skip to content

Commit

Permalink
Merge pull request #3 from JMAConsulting/refund
Browse files Browse the repository at this point in the history
Fix fatal error during refunding full amount
  • Loading branch information
seamuslee001 authored Feb 1, 2021
2 parents 6d97dcb + abe0537 commit cbd29a6
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions CRM/Moneris/Form/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ class CRM_Moneris_Form_Refund extends CRM_Core_Form {
protected $_contactID;

/**
* Test or live mode
* Payment Processor ID
* @var object
*/
protected $_isTest;

protected $_paymentProcessorID;

/**
* Set variables up before form is built.
Expand All @@ -34,12 +33,20 @@ public function preProcess() {

$this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
$this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
parent::preProcess();

$this->_isTest = 0;
if ($this->_action & CRM_Core_Action::PREVIEW) {
$this->_isTest = 1;
$this->_paymentProcessorID = civicrm_api3('EntityFinancialTrxn', 'get', [
'sequential' => 1,
'return' => ["financial_trxn_id.payment_processor_id"],
'entity_table' => "civicrm_contribution",
'entity_id' => $this->_id,
'options' => ['limit' => 1, 'sort' => "id DESC"],
])['values'][0]['financial_trxn_id.payment_processor_id'];

if (empty($this->_paymentProcessorID)) {
CRM_Core_Error::statusBounce(ts('No payment processor found for this contribution'));
}

parent::preProcess();
}

public function buildQuickForm() {
Expand All @@ -61,9 +68,8 @@ public function buildQuickForm() {
}

public function postProcess() {

// FIXME: doesn't work for multiple Moneris Processors
$payment = Civi\Payment\System::singleton()->getByName('Moneris', $this->_isTest);
$payment = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID);

$urlParams = "reset=1&cid={$this->_contactID}&selectedChild=contribute";
$url = CRM_Utils_System::url('civicrm/contact/view', $urlParams);
Expand Down

0 comments on commit cbd29a6

Please sign in to comment.