diff --git a/app/code/local/Litle/CreditCard/Model/PaymentLogic.php b/app/code/local/Litle/CreditCard/Model/PaymentLogic.php index 0cd487f..350fc80 100644 --- a/app/code/local/Litle/CreditCard/Model/PaymentLogic.php +++ b/app/code/local/Litle/CreditCard/Model/PaymentLogic.php @@ -806,7 +806,7 @@ public function refund(Varien_Object $payment, $amount) $amountToPass = Mage::helper('creditcard')->formatAmount($amount, true); if (! empty($order)) { $hash = array( - 'litleTxnId' => $payment->getCcTransId(), + 'litleTxnId' => $this->findCaptureLitleTxnToRefundForPayment($payment), 'amount' => $amountToPass ); $merchantData = $this->merchantData($payment); @@ -818,6 +818,11 @@ public function refund(Varien_Object $payment, $amount) return $this; } + + function findCaptureLitleTxnToRefundForPayment($payment) { + $capture = $payment->lookupTransaction(false, Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE); + return $capture->getTxnId(); + } /** * called if voiding a payment diff --git a/test/unit/PaymentLogicTest.php b/test/unit/PaymentLogicTest.php index 5752412..a347493 100644 --- a/test/unit/PaymentLogicTest.php +++ b/test/unit/PaymentLogicTest.php @@ -45,4 +45,22 @@ public function testGenerateUniqueId() $hash = $litle->generateAuthorizationHash('123','100', $mock, $payment); $this->assertEquals('123', $hash['id']); } + + public function testFindCaptureLitleTxnToRefundForPayment() + { + $capture = new Varien_Object(); + $capture->setTxnId(2); + $payment = $this->getMock('Mage_Sales_Model_Order_Payment'); + $payment->expects($this->any()) + ->method('lookupTransaction') + ->with($this->equalTo(false), + $this->equalTo(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE)) + ->will($this->returnValue($capture)); + + $litle = new Litle_CreditCard_Model_PaymentLogic(); + + $litleTxnId = $litle->findCaptureLitleTxnToRefundForPayment($payment); + + $this->assertEquals(2, $litleTxnId); + } }