From 086071b43b8be50e31b20b3756745201b9e9f3a3 Mon Sep 17 00:00:00 2001 From: Shane Logsdon Date: Thu, 20 Dec 2018 09:57:25 -0500 Subject: [PATCH] correct partial reversal --- .../Hps/Securesubmit/Model/Payment.php | 12 +++++++--- .../Credit/HpsReportTransactionDetails.php | 22 ++++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/code/community/Hps/Securesubmit/Model/Payment.php b/app/code/community/Hps/Securesubmit/Model/Payment.php index 19ed9f3..462cc19 100644 --- a/app/code/community/Hps/Securesubmit/Model/Payment.php +++ b/app/code/community/Hps/Securesubmit/Model/Payment.php @@ -522,7 +522,7 @@ public function refund(Varien_Object $payment, $amount) { $transactionDetails = $this->getTransactionDetails($payment); if ($this->canVoid($payment) && $this->transactionActiveOnGateway($transactionDetails)) { - if ($transactionDetails->settlementAmt > $amount) { + if ($this->getCurrentAuthorizationAmount($transactionDetails) > $amount) { $this->_reversal($payment, $transactionDetails, $amount); } else { $this->void($payment); @@ -534,6 +534,13 @@ public function refund(Varien_Object $payment, $amount) return $this; } + public function getCurrentAuthorizationAmount($transactionDetails) + { + if (floatval($transactionDetails->settlementAmount) > 0) { + return floatval($transactionDetails->settlementAmount); + } + return floatval($transactionDetails->authorizedAmount); + } public function getTransactionDetails(Varien_Object $payment) { @@ -665,7 +672,7 @@ public function _reversal(Varien_Object $payment, HpsReportTransactionDetails $t } else { $transactionId = $payment->getCcTransId(); } - $newAuthAmount = $transactionDetails->settlementAmt-$newAuthAmount; + $newAuthAmount = $this->getCurrentAuthorizationAmount($transactionDetails) - $newAuthAmount; $order = $payment->getOrder(); /* @var $order Mage_Sales_Model_Order */ $chargeService = $this->_getChargeService(); @@ -684,7 +691,6 @@ public function _reversal(Varien_Object $payment, HpsReportTransactionDetails $t ->setIsTransactionClosed(1) ->setShouldCloseParentTransaction(1); } catch (HpsException $e) { - $this->_debugChargeService($chargeService, $e); $this->throwUserError($e->getMessage()); } catch (Exception $e) { diff --git a/lib/SecureSubmit/src/Entities/Credit/HpsReportTransactionDetails.php b/lib/SecureSubmit/src/Entities/Credit/HpsReportTransactionDetails.php index 9f9bbf7..229a632 100644 --- a/lib/SecureSubmit/src/Entities/Credit/HpsReportTransactionDetails.php +++ b/lib/SecureSubmit/src/Entities/Credit/HpsReportTransactionDetails.php @@ -1,5 +1,8 @@ Transaction->$txnType; @@ -37,6 +49,10 @@ public static function fromDict($rsp, $txnType, $returnType = 'HpsReportTransact $details->responseCode = (isset($reportResponse->Data->RspCode) ? (string)$reportResponse->Data->RspCode : null); $details->responseText = (isset($reportResponse->Data->RspText) ? (string)$reportResponse->Data->RspText : null); $details->transactionStatus = (isset($reportResponse->Data->TxnStatus) ? (string)$reportResponse->Data->TxnStatus : null); + $details->gratuityAmount = (isset($reportResponse->Data->GratuityAmtInfo) ? (string)$reportResponse->Data->GratuityAmtInfo : null); + $details->settlementAmount = (isset($reportResponse->Data->SettlementAmt) ? (string)$reportResponse->Data->SettlementAmt : null); + $details->convenienceAmount = (isset($reportResponse->Data->ConvenienceAmtInfo) ? (string)$reportResponse->Data->ConvenienceAmtInfo : null); + $details->shippingAmount = (isset($reportResponse->Data->ShippingAmtInfo) ? (string)$reportResponse->Data->ShippingAmtInfo : null); if (isset($reportResponse->Data->TokenizationMsg)) { $details->tokenData = new HpsTokenData(); @@ -50,7 +66,7 @@ public static function fromDict($rsp, $txnType, $returnType = 'HpsReportTransact $details->customerId = (isset($additionalTxnFields->CustomerID) ? (string)$additionalTxnFields->CustomerID : null); } - if ((string)$reportResponse->Data->RspCode != '00') { + if ((string)$reportResponse->GatewayRspCode != '0' && (string)$reportResponse->Data->RspCode != '00') { if ($details->exceptions == null) { $details->exceptions = new HpsChargeExceptions(); } @@ -64,4 +80,4 @@ public static function fromDict($rsp, $txnType, $returnType = 'HpsReportTransact return $details; } -} +} \ No newline at end of file