Skip to content

Commit

Permalink
Support Refund for ACHEFT payment processor
Browse files Browse the repository at this point in the history
  • Loading branch information
monishdeb committed Aug 11, 2021
1 parent 6705570 commit 15ee41d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 20 deletions.
8 changes: 2 additions & 6 deletions CRM/Core/Payment/Faps.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}

/**
Expand Down
13 changes: 0 additions & 13 deletions CRM/Core/Payment/iATSService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
40 changes: 40 additions & 0 deletions CRM/Core/Payment/iATSServiceACHEFT.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
/**
*
*/
Expand Down
2 changes: 1 addition & 1 deletion CRM/Iats/Form/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions CRM/Iats/iATSServiceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit 15ee41d

Please sign in to comment.