@@ -78,6 +78,11 @@ class TransparentTest extends TestCase
7878 */
7979 private $ order ;
8080
81+ /**
82+ * @var OrderPaymentExtensionInterface|MockObject
83+ */
84+ private $ paymentExtensionAttributes ;
85+
8186 protected function setUp (): void
8287 {
8388 $ this ->initPayment ();
@@ -97,6 +102,55 @@ protected function setUp(): void
97102 );
98103 }
99104
105+ /**
106+ * Check correct parent transaction ID for Payflow delayed capture.
107+ *
108+ * @dataProvider captureCorrectIdDataProvider
109+ * @param string $parentTransactionId
110+ * @throws InvalidTransitionException
111+ * @throws LocalizedException
112+ */
113+ public function testCaptureCorrectId (string $ parentTransactionId )
114+ {
115+ if (empty ($ parentTransactionId )) {
116+ $ setParentTransactionIdCalls = 1 ;
117+ $ setAdditionalInformationCalls = 1 ;
118+ $ getGatewayTokenCalls = 2 ;
119+ } else {
120+ $ setParentTransactionIdCalls = 0 ;
121+ $ setAdditionalInformationCalls = 0 ;
122+ $ getGatewayTokenCalls = 0 ;
123+ }
124+
125+ $ gatewayToken = 'gateway_token ' ;
126+ $ this ->payment ->expects ($ this ->once ())->method ('getParentTransactionId ' )->willReturn ($ parentTransactionId );
127+ $ this ->payment ->expects ($ this ->exactly ($ setParentTransactionIdCalls ))->method ('setParentTransactionId ' );
128+ $ this ->payment ->expects ($ this ->exactly ($ setAdditionalInformationCalls ))->method ('setAdditionalInformation ' )->with (Payflowpro::PNREF , $ gatewayToken );
129+ $ this ->payment ->expects ($ this ->exactly (4 ))->method ('getAdditionalInformation ' )->withConsecutive (
130+ ['result_code ' ],
131+ [Payflowpro::PNREF ],
132+ [Payflowpro::PNREF ],
133+ [Payflowpro::PNREF ],
134+ )->willReturn (0 , '' , Payflowpro::PNREF , Payflowpro::PNREF );
135+ $ this ->paymentExtensionAttributes ->expects ($ this ->once ())->method ('getVaultPaymentToken ' )->willReturn ($ this ->paymentToken );
136+ $ this ->paymentToken ->expects ($ this ->exactly ($ getGatewayTokenCalls ))->method ('getGatewayToken ' )->willReturn ($ gatewayToken );
137+
138+ $ this ->subject ->capture ($ this ->payment , 100 );
139+ }
140+
141+ /**
142+ * Data provider for testCaptureCorrectId.
143+ *
144+ * @return array
145+ */
146+ public function captureCorrectIdDataProvider (): array
147+ {
148+ return [
149+ 'No Transaction ID ' => ['' ],
150+ 'With Transaction ID ' => ['1 ' ],
151+ ];
152+ }
153+
100154 /**
101155 * Asserts that authorize request to Payflow gateway is valid.
102156 *
@@ -295,7 +349,7 @@ private function initPayment()
295349 $ this ->order = $ this ->getMockBuilder (Order::class)
296350 ->disableOriginalConstructor ()
297351 ->getMock ();
298- $ paymentExtensionAttributes = $ this ->getMockBuilder (OrderPaymentExtensionInterface::class)
352+ $ this -> paymentExtensionAttributes = $ this ->getMockBuilder (OrderPaymentExtensionInterface::class)
299353 ->setMethods (
300354 ['setVaultPaymentToken ' , 'getVaultPaymentToken ' , 'setNotificationMessage ' , 'getNotificationMessage ' ]
301355 )
@@ -305,7 +359,7 @@ private function initPayment()
305359 $ this ->payment ->method ('setIsTransactionClosed ' )->willReturnSelf ();
306360 $ this ->payment ->method ('getCcExpYear ' )->willReturn ('2019 ' );
307361 $ this ->payment ->method ('getCcExpMonth ' )->willReturn ('05 ' );
308- $ this ->payment ->method ('getExtensionAttributes ' )->willReturn ($ paymentExtensionAttributes );
362+ $ this ->payment ->method ('getExtensionAttributes ' )->willReturn ($ this -> paymentExtensionAttributes );
309363
310364 return $ this ->payment ;
311365 }
0 commit comments