Skip to content

Commit

Permalink
fix issue #10
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg, Dake committed Apr 14, 2014
1 parent 2f6583a commit 8e482ab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/code/local/Litle/CreditCard/Model/PaymentLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions test/unit/PaymentLogicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 8e482ab

Please sign in to comment.