@@ -251,6 +251,103 @@ public function testCapture()
251251 $ model ->capture ($ paymentModel , 0 );
252252 }
253253
254+ public function testCaptureSuccess ()
255+ {
256+ $ customerId = 1 ;
257+ $ publicHash = 'token_public_hash ' ;
258+ $ vaultProviderCode = 'vault_provider_code ' ;
259+ $ amount = 10.01 ;
260+
261+ $ paymentModel = $ this ->getMockBuilder (Payment::class)
262+ ->disableOriginalConstructor ()
263+ ->getMock ();
264+ $ extensionAttributes = $ this ->getMockBuilder (OrderPaymentExtensionInterface::class)
265+ ->addMethods (['setVaultPaymentToken ' , 'getVaultPaymentToken ' ])
266+ ->getMockForAbstractClass ();
267+
268+ $ commandManagerPool = $ this ->getMockForAbstractClass (CommandManagerPoolInterface::class);
269+ $ commandManager = $ this ->getMockForAbstractClass (CommandManagerInterface::class);
270+
271+ $ tokenManagement = $ this ->getMockForAbstractClass (PaymentTokenManagementInterface::class);
272+ $ token = $ this ->getMockForAbstractClass (PaymentTokenInterface::class);
273+
274+ $ tokenDetails = [
275+ 'cc_last4 ' => '1111 ' ,
276+ 'cc_type ' => 'VI ' ,
277+ 'cc_exp_year ' => '2020 ' ,
278+ 'cc_exp_month ' => '01 ' ,
279+ ];
280+
281+ $ extensionAttributes ->method ('getVaultPaymentToken ' )
282+ ->willReturn ($ token );
283+
284+ $ token ->expects (static ::atLeastOnce ())
285+ ->method ('getTokenDetails ' )
286+ ->willReturn (json_encode ($ tokenDetails ));
287+
288+ $ this ->jsonSerializer ->expects (static ::once ())
289+ ->method ('unserialize ' )
290+ ->with (json_encode ($ tokenDetails ))
291+ ->willReturn ($ tokenDetails );
292+
293+ $ paymentModel ->expects (static ::once ())
294+ ->method ('getAdditionalInformation ' )
295+ ->willReturn (
296+ [
297+ PaymentTokenInterface::CUSTOMER_ID => $ customerId ,
298+ PaymentTokenInterface::PUBLIC_HASH => $ publicHash
299+ ]
300+ );
301+ $ paymentModel ->expects (static ::once ())
302+ ->method ('getAuthorizationTransaction ' )
303+ ->willReturn (null );
304+ $ tokenManagement ->expects (static ::once ())
305+ ->method ('getByPublicHash ' )
306+ ->with ($ publicHash , $ customerId )
307+ ->willReturn ($ token );
308+ $ paymentModel ->method ('getExtensionAttributes ' )
309+ ->willReturn ($ extensionAttributes );
310+ $ extensionAttributes ->expects (static ::once ())
311+ ->method ('setVaultPaymentToken ' )
312+ ->with ($ token );
313+ $ paymentModel ->expects (static ::once ())
314+ ->method ('addData ' )
315+ ->with ($ tokenDetails );
316+
317+ $ this ->vaultProvider ->expects (static ::atLeastOnce ())
318+ ->method ('getCode ' )
319+ ->willReturn ($ vaultProviderCode );
320+ $ commandManagerPool ->expects (static ::once ())
321+ ->method ('get ' )
322+ ->with ($ vaultProviderCode )
323+ ->willReturn ($ commandManager );
324+ $ commandManager ->expects (static ::once ())
325+ ->method ('executeByCode ' )
326+ ->with (
327+ VaultPaymentInterface::VAULT_SALE_COMMAND ,
328+ $ paymentModel ,
329+ [
330+ 'amount ' => $ amount
331+ ]
332+ );
333+
334+ $ paymentModel ->expects (static ::once ())
335+ ->method ('setMethod ' )
336+ ->with ($ vaultProviderCode );
337+
338+ /** @var Vault $model */
339+ $ model = $ this ->objectManager ->getObject (
340+ Vault::class,
341+ [
342+ 'tokenManagement ' => $ tokenManagement ,
343+ 'commandManagerPool ' => $ commandManagerPool ,
344+ 'vaultProvider ' => $ this ->vaultProvider ,
345+ 'jsonSerializer ' => $ this ->jsonSerializer ,
346+ ]
347+ );
348+ $ model ->capture ($ paymentModel , $ amount );
349+ }
350+
254351 /**
255352 * @covers \Magento\Vault\Model\Method\Vault::isAvailable
256353 * @dataProvider isAvailableDataProvider
0 commit comments