12
12
use Magento \Payment \Model \InfoInterface ;
13
13
use Magento \Payment \Observer \AbstractDataAssignObserver ;
14
14
use Magento \Paypal \Model \Api \Nvp ;
15
+ use Magento \Paypal \Model \Api \ProcessableException ;
15
16
use Magento \Paypal \Model \Api \ProcessableException as ApiProcessableException ;
16
17
use Magento \Paypal \Model \Express ;
17
18
use Magento \Paypal \Model \Pro ;
18
19
use Magento \Quote \Api \Data \PaymentInterface ;
19
20
use Magento \Sales \Model \Order ;
20
21
use Magento \Sales \Model \Order \Payment ;
21
22
use Magento \Sales \Model \Order \Payment \Transaction \BuilderInterface ;
22
- use \ PHPUnit_Framework_MockObject_MockObject as MockObject ;
23
+ use PHPUnit_Framework_MockObject_MockObject as MockObject ;
23
24
24
25
/**
25
26
* Class ExpressTest
26
27
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27
28
*/
28
29
class ExpressTest extends \PHPUnit \Framework \TestCase
29
30
{
31
+ /**
32
+ * @var string
33
+ */
34
+ private static $ authorizationExpiredCode = 10601 ;
35
+
30
36
/**
31
37
* @var array
32
38
*/
33
- protected $ errorCodes = [
39
+ private $ errorCodes = [
34
40
ApiProcessableException::API_INTERNAL_ERROR ,
35
41
ApiProcessableException::API_UNABLE_PROCESS_PAYMENT_ERROR_CODE ,
36
42
ApiProcessableException::API_DO_EXPRESS_CHECKOUT_FAIL ,
@@ -40,7 +46,7 @@ class ExpressTest extends \PHPUnit\Framework\TestCase
40
46
ApiProcessableException::API_COUNTRY_FILTER_DECLINE ,
41
47
ApiProcessableException::API_MAXIMUM_AMOUNT_FILTER_DECLINE ,
42
48
ApiProcessableException::API_OTHER_FILTER_DECLINE ,
43
- ApiProcessableException::API_ADDRESS_MATCH_FAIL
49
+ ApiProcessableException::API_ADDRESS_MATCH_FAIL ,
44
50
];
45
51
46
52
/**
@@ -80,6 +86,7 @@ class ExpressTest extends \PHPUnit\Framework\TestCase
80
86
81
87
protected function setUp ()
82
88
{
89
+ $ this ->errorCodes [] = self ::$ authorizationExpiredCode ;
83
90
$ this ->checkoutSession = $ this ->createPartialMock (
84
91
Session::class,
85
92
['getPaypalTransactionData ' , 'setPaypalTransactionData ' ]
@@ -104,16 +111,20 @@ protected function setUp()
104
111
);
105
112
$ this ->pro = $ this ->createPartialMock (
106
113
Pro::class,
107
- ['setMethod ' , 'getApi ' , 'importPaymentInfo ' , 'resetApi ' ]
114
+ ['setMethod ' , 'getApi ' , 'importPaymentInfo ' , 'resetApi ' , ' void ' ]
108
115
);
109
116
$ this ->eventManager = $ this ->getMockBuilder (ManagerInterface::class)
110
117
->setMethods (['dispatch ' ])
111
118
->getMockForAbstractClass ();
112
119
113
- $ this ->pro ->expects ($ this ->any ())->method ('getApi ' )->will ($ this ->returnValue ($ this ->nvp ));
120
+ $ this ->pro ->method ('getApi ' )
121
+ ->willReturn ($ this ->nvp );
114
122
$ this ->helper = new ObjectManager ($ this );
115
123
}
116
124
125
+ /**
126
+ * Tests setting the list of processable errors.
127
+ */
117
128
public function testSetApiProcessableErrors ()
118
129
{
119
130
$ this ->nvp ->expects ($ this ->once ())->method ('setProcessableErrors ' )->with ($ this ->errorCodes );
@@ -128,6 +139,32 @@ public function testSetApiProcessableErrors()
128
139
);
129
140
}
130
141
142
+ /**
143
+ * Tests canceling order payment when expired authorization generates exception on a client.
144
+ */
145
+ public function testCancelWithExpiredAuthorizationTransaction ()
146
+ {
147
+ $ this ->pro ->method ('void ' )
148
+ ->willThrowException (
149
+ new ProcessableException (__ ('PayPal gateway has rejected request. ' ), null , 10601 )
150
+ );
151
+
152
+ $ this ->model = $ this ->helper ->getObject (Express::class, ['data ' => [$ this ->pro ]]);
153
+ /** @var Payment|MockObject $paymentModel */
154
+ $ paymentModel = $ this ->createMock (Payment::class);
155
+ $ paymentModel ->expects ($ this ->once ())
156
+ ->method ('setTransactionId ' )
157
+ ->with (null );
158
+ $ paymentModel ->expects ($ this ->once ())
159
+ ->method ('setIsTransactionClosed ' )
160
+ ->with (true );
161
+ $ paymentModel ->expects ($ this ->once ())
162
+ ->method ('setShouldCloseParentTransaction ' )
163
+ ->with (true );
164
+
165
+ $ this ->model ->cancel ($ paymentModel );
166
+ }
167
+
131
168
/**
132
169
* Tests order payment action.
133
170
*/
@@ -162,6 +199,11 @@ public function testOrder()
162
199
static ::assertEquals ($ this ->model , $ this ->model ->order ($ paymentModel , 12.3 ));
163
200
}
164
201
202
+ /**
203
+ * Tests data assigning.
204
+ *
205
+ * @throws \Magento\Framework\Exception\LocalizedException
206
+ */
165
207
public function testAssignData ()
166
208
{
167
209
$ transportValue = 'something ' ;
0 commit comments