Skip to content

Commit

Permalink
correct partial reversal
Browse files Browse the repository at this point in the history
  • Loading branch information
slogsdon committed Dec 20, 2018
1 parent bbda76c commit 086071b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
12 changes: 9 additions & 3 deletions app/code/community/Hps/Securesubmit/Model/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

/**
* Class HpsReportTransactionDetails
*/
class HpsReportTransactionDetails extends HpsAuthorization
{
public $issuerTransactionId = null;
Expand All @@ -14,7 +17,16 @@ class HpsReportTransactionDetails extends HpsAuthorization
public $invoiceNumber = null;
public $customerId = null;
public $transactionStatus = null;

public $gratuityAmount = null;
public $convenienceAmount = null;
public $shippingAmount = null;
/**
* @param $rsp
* @param $txnType
* @param string $returnType
*
* @return mixed
*/
public static function fromDict($rsp, $txnType, $returnType = 'HpsReportTransactionDetails')
{
$reportResponse = $rsp->Transaction->$txnType;
Expand All @@ -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();
Expand All @@ -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();
}
Expand All @@ -64,4 +80,4 @@ public static function fromDict($rsp, $txnType, $returnType = 'HpsReportTransact

return $details;
}
}
}

0 comments on commit 086071b

Please sign in to comment.