diff --git a/CRM/Core/Payment/Faps.php b/CRM/Core/Payment/Faps.php index d2aaa39d..88dafa40 100644 --- a/CRM/Core/Payment/Faps.php +++ b/CRM/Core/Payment/Faps.php @@ -455,15 +455,11 @@ public function doRefund($params = []) { if (!empty($result['authResponse'] == 'ACCEPTED')) { $refundParams = [ 'refund_trxn_id' => $result['referenceNumber'], - 'refund_status_id' => $refundStatus, - 'refund_status_name' => $refundStatusName, - 'processor_result' => $refund->jsonSerialize(), + 'refund_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'), + 'refund_status_name' => 'Completed', ]; return $refundParams; } - - return $params; - } /** diff --git a/CRM/Core/Payment/iATSService.php b/CRM/Core/Payment/iATSService.php index f2dd5c4f..d1948eba 100644 --- a/CRM/Core/Payment/iATSService.php +++ b/CRM/Core/Payment/iATSService.php @@ -303,19 +303,6 @@ public function doPayment(&$params, $component = 'contribute') { } } - /** - * Does this payment processor support refund? - * - * @return bool - */ - public function supportsRefund() { - return TRUE; - } - - // might become a supported core function but for now just create our own function name - public function doRefund($params = []) { - return $params; - } /** * support corresponding CiviCRM method */ diff --git a/CRM/Core/Payment/iATSServiceACHEFT.php b/CRM/Core/Payment/iATSServiceACHEFT.php index 5332d44c..11d94efc 100644 --- a/CRM/Core/Payment/iATSServiceACHEFT.php +++ b/CRM/Core/Payment/iATSServiceACHEFT.php @@ -197,7 +197,47 @@ protected function buildForm_CAD(&$form) { )); } + /** + * Does this payment processor support refund? + * + * @return bool + */ + public function supportsRefund() { + return TRUE; + } + // might become a supported core function but for now just create our own function name + public function doRefund($params = []) { + $iats = new CRM_Iats_iATSServiceRequest([ + 'type' => 'process', + 'method' => 'acheft_refund', + 'iats_domain' => $this->_profile['iats_domain'], + ]); + $request = [ + 'transactionId' => $params['trxn_id'], + 'total' => (-1 * sprintf('%01.2f', CRM_Utils_Rule::cleanMoney($params['total_amount']))), + 'customerIPAddress' => (function_exists('ip_address') ? ip_address() : $_SERVER['REMOTE_ADDR']), + ]; + $credentials = [ + 'agentCode' => $this->_paymentProcessor['user_name'], + 'password' => $this->_paymentProcessor['password'], + ]; + // Make the soap request. + $response = $iats->request($credentials, $request); + + $result = $iats->result($response); + if ($result['status']) { + $refundParams = [ + 'refund_trxn_id' => trim($result['remote_id']) . ':' . time(), + 'refund_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'), + 'refund_status_name' => 'Completed', + ]; + return $refundParams; + } + else { + return self::error($result['reasonMessage']); + } + } /** * */ diff --git a/CRM/Iats/Form/Refund.php b/CRM/Iats/Form/Refund.php index e406ed81..7fa88443 100644 --- a/CRM/Iats/Form/Refund.php +++ b/CRM/Iats/Form/Refund.php @@ -98,7 +98,7 @@ public function postProcess() { $refundPaymentParams = [ 'contribution_id' => $this->_id, 'trxn_id' => $refund['refund_trxn_id'], - 'total_amount' => (-$contribution['total_amount']), + 'total_amount' => (-1 * $contribution['total_amount']), 'payment_processor_id' => $this->_paymentProcessorID, ]; $trxn = CRM_Financial_BAO_Payment::create($refundPaymentParams); diff --git a/CRM/Iats/iATSServiceRequest.php b/CRM/Iats/iATSServiceRequest.php index 13700124..c9263cee 100644 --- a/CRM/Iats/iATSServiceRequest.php +++ b/CRM/Iats/iATSServiceRequest.php @@ -481,6 +481,13 @@ public function methodInfo($type = '', $method = '') { 'message' => 'ProcessACHEFTWithCustomerCode', 'response' => 'ProcessACHEFTWithCustomerCodeResult', ), + 'acheft_refund' => array( + 'title' => 'Refund a specific ACH / EFT transaction', + 'description' => $desc . 'ProcessACHEFTRefundWithTransactionId', + 'method' => 'ProcessACHEFTRefundWithTransactionId', + 'message' => 'ProcessACHEFTRefundWithTransactionId', + 'response' => 'ProcessACHEFTRefundWithTransactionIdResult', + ), ); break; case 'report':