Skip to content

Commit 6f68ff9

Browse files
author
Logvin, Michael(mlogvin)
committed
Merge pull request #525 from magento-firedrakes/bugfixes
[Firedrakes] Bugfixes
2 parents ddd2dd4 + f04367c commit 6f68ff9

File tree

4 files changed

+139
-7
lines changed

4 files changed

+139
-7
lines changed

app/code/Magento/Sales/Model/Order/Payment/Operations/CaptureOperation.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,14 @@ public function capture(OrderPaymentInterface $payment, $invoice)
8181
//TODO replace for sale usage
8282
$method->capture($payment, $amountToCapture);
8383

84-
$transaction = $this->transactionBuilder->setPayment($this)
85-
->setOrder($order)
86-
->setFailSafe(true)
87-
->setTransactionId($payment->getTransactionId())
88-
->setAdditionalInformation($payment->getTransactionAdditionalInfo())
89-
->setSalesDocument($invoice)->build(Transaction::TYPE_CAPTURE);
84+
$transactionBuilder = $this->transactionBuilder->setPayment($payment);
85+
$transactionBuilder->setOrder($order);
86+
$transactionBuilder->setFailSafe(true);
87+
$transactionBuilder->setTransactionId($payment->getTransactionId());
88+
$transactionBuilder->setAdditionalInformation($payment->getTransactionAdditionalInfo());
89+
$transactionBuilder->setSalesDocument($invoice);
90+
$transaction = $transactionBuilder->build(Transaction::TYPE_CAPTURE);
91+
9092
$message = $this->stateCommand->execute($payment, $amountToCapture, $order);
9193
if ($payment->getIsTransactionPending()) {
9294
$invoice->setIsPaid(false);

app/code/Magento/Sales/Model/Order/Payment/Transaction/Builder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ public function build($type)
186186
$transaction = $this->transactionRepository->create()->setTxnId($this->transactionId);
187187
}
188188
$transaction->setPaymentId($this->payment->getId())
189+
->setPayment($this->payment)
189190
->setOrderId($this->order->getId())
191+
->setOrder($this->order)
190192
->setTxnType($type)
191193
->isFailsafe($this->failSafe);
192194

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Sales\Test\Unit\Model\Order\Payment\Operations;
8+
9+
use Magento\Framework\ObjectManager\ObjectManager;
10+
use Magento\Payment\Model\Method;
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
12+
13+
class CaptureOperationTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/**
16+
* @var \PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $transactionManager;
19+
20+
/**
21+
* @var \PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
protected $eventManager;
24+
25+
/**
26+
* @var \PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
protected $transactionBuilder;
29+
30+
/**
31+
* @var \PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
protected $stateCommand;
34+
35+
/**
36+
* @var \Magento\Sales\Model\Order\Payment\Operations\CaptureOperation
37+
*/
38+
protected $model;
39+
40+
protected function setUp()
41+
{
42+
$transactionClass = 'Magento\Sales\Model\Order\Payment\Transaction\ManagerInterface';
43+
$transactionBuilderClass = 'Magento\Sales\Model\Order\Payment\Transaction\BuilderInterface';
44+
$this->transactionManager = $this->getMockBuilder($transactionClass)
45+
->disableOriginalConstructor()
46+
->getMock();
47+
$this->eventManager = $this->getMockBuilder('Magento\Framework\Event\ManagerInterface')
48+
->disableOriginalConstructor()
49+
->getMock();
50+
$this->transactionBuilder = $this->getMockBuilder($transactionBuilderClass)
51+
->disableOriginalConstructor()
52+
->getMock();
53+
$this->stateCommand = $this->getMockBuilder('Magento\Sales\Model\Order\Payment\State\CommandInterface')
54+
->disableOriginalConstructor()
55+
->getMock();
56+
$objectManagerHelper = new ObjectManagerHelper($this);
57+
$this->model = $objectManagerHelper->getObject(
58+
'Magento\Sales\Model\Order\Payment\Operations\CaptureOperation',
59+
[
60+
'transactionManager' => $this->transactionManager,
61+
'eventManager' => $this->eventManager,
62+
'transactionBuilder' => $this->transactionBuilder,
63+
'stateCommand' => $this->stateCommand
64+
]
65+
);
66+
}
67+
68+
public function testCapture()
69+
{
70+
$baseGrandTotal = 10;
71+
72+
$order = $this->getMockBuilder('Magento\Sales\Model\Order')
73+
->disableOriginalConstructor()
74+
->getMock();
75+
76+
$paymentMethod = $this->getMockBuilder('Magento\Payment\Model\MethodInterface')
77+
->disableOriginalConstructor()
78+
->getMock();
79+
80+
$orderPayment = $this->getMockBuilder('Magento\Sales\Model\Order\Payment')
81+
->disableOriginalConstructor()
82+
->getMock();
83+
$orderPayment->expects($this->any())
84+
->method('formatAmount')
85+
->with($baseGrandTotal)
86+
->willReturnArgument(0);
87+
$orderPayment->expects($this->any())
88+
->method('getOrder')
89+
->willReturn($order);
90+
$orderPayment->expects($this->any())
91+
->method('getMethodInstance')
92+
->willReturn($paymentMethod);
93+
$orderPayment->expects($this->once())
94+
->method('getIsTransactionPending')
95+
->willReturn(true);
96+
$orderPayment->expects($this->once())
97+
->method('getTransactionAdditionalInfo')
98+
->willReturn([]);
99+
100+
$paymentMethod->expects($this->once())
101+
->method('capture')
102+
->with($orderPayment, $baseGrandTotal);
103+
104+
$this->transactionBuilder->expects($this->once())
105+
->method('setPayment')
106+
->with($orderPayment)
107+
->willReturnSelf();
108+
109+
$invoice = $this->getMockBuilder('Magento\Sales\Model\Order\Invoice')
110+
->disableOriginalConstructor()
111+
->getMock();
112+
$invoice->expects($this->any())
113+
->method('getBaseGrandTotal')
114+
->willReturn($baseGrandTotal);
115+
116+
$this->model->capture($orderPayment, $invoice);
117+
}
118+
}

app/code/Magento/Sales/Test/Unit/Model/Order/Payment/Transaction/BuilderTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ public function testCreate(
9999
$parentTransaction = $this->expectTransaction($orderId, $paymentId);
100100
$transaction = $this->expectTransaction($orderId, $paymentId);
101101
$transaction->expects($this->atLeastOnce())->method('getTxnId')->willReturn($transactionId);
102+
$transaction->expects($this->once())
103+
->method('setPayment')
104+
->withAnyParameters()
105+
->willReturnSelf();
106+
$transaction->expects($this->once())
107+
->method('setOrder')
108+
->withAnyParameters()
109+
->willReturnSelf();
102110

103111
if ($isTransactionExists) {
104112
$this->repositoryMock->method('getByTransactionId')
@@ -210,7 +218,9 @@ protected function expectTransaction($orderId, $paymentId)
210218
'setAdditionalInformation',
211219
'setParentTxnId',
212220
'close',
213-
'getIsClosed'
221+
'getIsClosed',
222+
'setPayment',
223+
'setOrder'
214224
],
215225
[],
216226
'',

0 commit comments

Comments
 (0)