Skip to content

Commit

Permalink
Merge pull request #525 from magento-firedrakes/bugfixes
Browse files Browse the repository at this point in the history
[Firedrakes] Bugfixes
  • Loading branch information
Logvin, Michael(mlogvin) committed Aug 14, 2015
2 parents ddd2dd4 + f04367c commit 6f68ff9
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ public function capture(OrderPaymentInterface $payment, $invoice)
//TODO replace for sale usage
$method->capture($payment, $amountToCapture);

$transaction = $this->transactionBuilder->setPayment($this)
->setOrder($order)
->setFailSafe(true)
->setTransactionId($payment->getTransactionId())
->setAdditionalInformation($payment->getTransactionAdditionalInfo())
->setSalesDocument($invoice)->build(Transaction::TYPE_CAPTURE);
$transactionBuilder = $this->transactionBuilder->setPayment($payment);
$transactionBuilder->setOrder($order);
$transactionBuilder->setFailSafe(true);
$transactionBuilder->setTransactionId($payment->getTransactionId());
$transactionBuilder->setAdditionalInformation($payment->getTransactionAdditionalInfo());
$transactionBuilder->setSalesDocument($invoice);
$transaction = $transactionBuilder->build(Transaction::TYPE_CAPTURE);

$message = $this->stateCommand->execute($payment, $amountToCapture, $order);
if ($payment->getIsTransactionPending()) {
$invoice->setIsPaid(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ public function build($type)
$transaction = $this->transactionRepository->create()->setTxnId($this->transactionId);
}
$transaction->setPaymentId($this->payment->getId())
->setPayment($this->payment)
->setOrderId($this->order->getId())
->setOrder($this->order)
->setTxnType($type)
->isFailsafe($this->failSafe);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Sales\Test\Unit\Model\Order\Payment\Operations;

use Magento\Framework\ObjectManager\ObjectManager;
use Magento\Payment\Model\Method;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;

class CaptureOperationTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $transactionManager;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $eventManager;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $transactionBuilder;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $stateCommand;

/**
* @var \Magento\Sales\Model\Order\Payment\Operations\CaptureOperation
*/
protected $model;

protected function setUp()
{
$transactionClass = 'Magento\Sales\Model\Order\Payment\Transaction\ManagerInterface';
$transactionBuilderClass = 'Magento\Sales\Model\Order\Payment\Transaction\BuilderInterface';
$this->transactionManager = $this->getMockBuilder($transactionClass)
->disableOriginalConstructor()
->getMock();
$this->eventManager = $this->getMockBuilder('Magento\Framework\Event\ManagerInterface')
->disableOriginalConstructor()
->getMock();
$this->transactionBuilder = $this->getMockBuilder($transactionBuilderClass)
->disableOriginalConstructor()
->getMock();
$this->stateCommand = $this->getMockBuilder('Magento\Sales\Model\Order\Payment\State\CommandInterface')
->disableOriginalConstructor()
->getMock();
$objectManagerHelper = new ObjectManagerHelper($this);
$this->model = $objectManagerHelper->getObject(
'Magento\Sales\Model\Order\Payment\Operations\CaptureOperation',
[
'transactionManager' => $this->transactionManager,
'eventManager' => $this->eventManager,
'transactionBuilder' => $this->transactionBuilder,
'stateCommand' => $this->stateCommand
]
);
}

public function testCapture()
{
$baseGrandTotal = 10;

$order = $this->getMockBuilder('Magento\Sales\Model\Order')
->disableOriginalConstructor()
->getMock();

$paymentMethod = $this->getMockBuilder('Magento\Payment\Model\MethodInterface')
->disableOriginalConstructor()
->getMock();

$orderPayment = $this->getMockBuilder('Magento\Sales\Model\Order\Payment')
->disableOriginalConstructor()
->getMock();
$orderPayment->expects($this->any())
->method('formatAmount')
->with($baseGrandTotal)
->willReturnArgument(0);
$orderPayment->expects($this->any())
->method('getOrder')
->willReturn($order);
$orderPayment->expects($this->any())
->method('getMethodInstance')
->willReturn($paymentMethod);
$orderPayment->expects($this->once())
->method('getIsTransactionPending')
->willReturn(true);
$orderPayment->expects($this->once())
->method('getTransactionAdditionalInfo')
->willReturn([]);

$paymentMethod->expects($this->once())
->method('capture')
->with($orderPayment, $baseGrandTotal);

$this->transactionBuilder->expects($this->once())
->method('setPayment')
->with($orderPayment)
->willReturnSelf();

$invoice = $this->getMockBuilder('Magento\Sales\Model\Order\Invoice')
->disableOriginalConstructor()
->getMock();
$invoice->expects($this->any())
->method('getBaseGrandTotal')
->willReturn($baseGrandTotal);

$this->model->capture($orderPayment, $invoice);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ public function testCreate(
$parentTransaction = $this->expectTransaction($orderId, $paymentId);
$transaction = $this->expectTransaction($orderId, $paymentId);
$transaction->expects($this->atLeastOnce())->method('getTxnId')->willReturn($transactionId);
$transaction->expects($this->once())
->method('setPayment')
->withAnyParameters()
->willReturnSelf();
$transaction->expects($this->once())
->method('setOrder')
->withAnyParameters()
->willReturnSelf();

if ($isTransactionExists) {
$this->repositoryMock->method('getByTransactionId')
Expand Down Expand Up @@ -210,7 +218,9 @@ protected function expectTransaction($orderId, $paymentId)
'setAdditionalInformation',
'setParentTxnId',
'close',
'getIsClosed'
'getIsClosed',
'setPayment',
'setOrder'
],
[],
'',
Expand Down

0 comments on commit 6f68ff9

Please sign in to comment.