66 $this->paymentMock = $this->getMockBuilder(\
Magento\Sales\Model\
Order\Payment::class)
68 ->disableOriginalConstructor()
71 $this->paymentTokenFactory = $this->getMockBuilder(CreditCardTokenFactory::class)
72 ->disableOriginalConstructor()
73 ->setMethods([
'create'])
76 $this->gatewayMock = $this->getMockBuilder(\
Magento\Paypal\Model\Payflow\Service\Gateway::class)
77 ->setMethods([
'postRequest'])
78 ->disableOriginalConstructor()
80 $this->storeManagerMock = $this->getMockBuilder(\
Magento\
Store\Model\StoreManagerInterface::class)
81 ->setMethods([
'getStore',
'getId'])
82 ->disableOriginalConstructor()
83 ->getMockForAbstractClass();
84 $this->storeManagerMock->method(
'getStore')
86 $this->configMock = $this->getMockBuilder(\
Magento\Paypal\Model\PayflowConfig::class)
87 ->disableOriginalConstructor()
89 $this->configFactoryMock = $this->getMockBuilder(\
Magento\
Payment\Model\Method\ConfigInterfaceFactory::class)
90 ->setMethods([
'create'])
91 ->disableOriginalConstructor()
93 $this->configFactoryMock->method(
'create')
94 ->willReturn($this->configMock);
95 $this->responseMock = new \Magento\Framework\DataObject();
96 $this->responseValidator = $this->getMockBuilder(
98 )->disableOriginalConstructor()
99 ->setMethods([
'validate'])
102 $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
103 $this->
object = $objectHelper->getObject(
104 \
Magento\Paypal\Model\Payflow\Transparent::class,
106 'gateway' => $this->gatewayMock,
107 'storeManager' => $this->storeManagerMock,
108 'configFactory' => $this->configFactoryMock,
109 'responseValidator' => $this->responseValidator,
110 'paymentTokenFactory' => $this->paymentTokenFactory
122 $this->orderMock = $this->getMockBuilder(\
Magento\Sales\Model\Order::class)
124 'getCustomerId',
'getBillingAddress',
'getShippingAddress',
'getCustomerEmail',
125 'getId',
'getIncrementId',
'getBaseCurrencyCode' 127 ->disableOriginalConstructor()
129 $this->addressBillingMock = $this->getMockBuilder(\
Magento\Framework\DataObject::class)
140 )->disableOriginalConstructor()
142 $this->addressShippingMock = $this->getMockBuilder(\
Magento\Framework\DataObject::class)
153 )->disableOriginalConstructor()
164 $this->paymentMock->expects($this->once())
166 ->willReturn($this->orderMock);
167 $this->orderMock->expects($this->once())
168 ->method(
'getBaseCurrencyCode')
170 $this->orderMock->expects($this->once())
171 ->method(
'getBillingAddress')
172 ->willReturn($this->addressBillingMock);
173 $this->orderMock->expects(static::once())
176 $this->orderMock->expects(static::once())
177 ->method(
'getIncrementId')
178 ->willReturn(
'0000001');
179 $this->orderMock->expects($this->once())
180 ->method(
'getShippingAddress')
181 ->willReturn($this->addressShippingMock);
182 $this->addressBillingMock->expects($this->once())
183 ->method(
'getFirstname')
184 ->willReturn(
'Firstname');
185 $this->addressBillingMock->expects($this->once())
186 ->method(
'getLastname')
187 ->willReturn(
'Lastname');
188 $this->addressBillingMock->expects($this->once())
189 ->method(
'getStreet')
190 ->willReturn([
'street-1',
'street-2']);
191 $this->addressBillingMock->expects($this->once())
193 ->willReturn(
'City');
194 $this->addressBillingMock->expects($this->once())
195 ->method(
'getRegionCode')
196 ->willReturn(
'RegionCode');
197 $this->addressBillingMock->expects($this->once())
198 ->method(
'getPostcode')
199 ->willReturn(
'Postcode');
200 $this->addressBillingMock->expects($this->once())
201 ->method(
'getCountryId')
202 ->willReturn(
'CountryId');
203 $this->orderMock->expects($this->once())
204 ->method(
'getCustomerEmail')
206 $this->addressShippingMock->expects($this->once())
207 ->method(
'getFirstname')
208 ->willReturn(
'Firstname');
209 $this->addressShippingMock->expects($this->once())
210 ->method(
'getLastname')
211 ->willReturn(
'Lastname');
212 $this->addressShippingMock->expects($this->once())
213 ->method(
'getStreet')
214 ->willReturn([
'street-1',
'street-2']);
215 $this->addressShippingMock->expects($this->once())
217 ->willReturn(
'City');
218 $this->addressShippingMock->expects($this->once())
219 ->method(
'getRegionCode')
220 ->willReturn(
'RegionCode');
221 $this->addressShippingMock->expects($this->once())
222 ->method(
'getPostcode')
223 ->willReturn(
'Postcode');
224 $this->addressShippingMock->expects($this->once())
225 ->method(
'getCountryId')
226 ->willReturn(
'CountryId');
234 $voidResponseMock = new \Magento\Framework\DataObject(
237 'pnref' =>
'test-pnref' 243 $this->paymentMock->expects($this->once())
244 ->method(
'setParentTransactionId')
245 ->with(
'test-pnref');
246 $this->paymentMock->expects($this->once())
247 ->method(
'getParentTransactionId')
248 ->willReturn(
'test-pnref');
249 $this->paymentMock->expects($this->once())
250 ->method(
'setTransactionId')
253 $this->paymentMock->expects($this->once())
254 ->method(
'setIsTransactionClosed')
257 $this->paymentMock->expects($this->once())
258 ->method(
'setShouldCloseParentTransaction')
261 return $voidResponseMock;
272 $this->gatewayMock->expects($this->once())
273 ->method(
'postRequest')
276 $this->
object->authorize($this->paymentMock, 33);
289 $this->gatewayMock->expects($this->at(0))
290 ->method(
'postRequest')
291 ->willReturn($this->responseMock);
293 $this->responseValidator->expects($this->once())
295 ->with($this->responseMock)
298 $this->gatewayMock->expects($this->at(1))
299 ->method(
'postRequest')
300 ->willReturn($voidResponseMock);
302 $this->paymentMock->expects($this->once())
303 ->method(
'getAdditionalInformation')
305 ->willReturn(
'test-pnref');
309 $this->
object->authorize($this->paymentMock, 33);
326 $this->responseMock->setData(
'result_code', $resultCode);
327 $this->responseMock->setData(
'origresult', $origResult);
329 $this->gatewayMock->expects($this->exactly(1))
330 ->method(
'postRequest')
331 ->willReturn($this->responseMock);
332 $this->
object->authorize($this->paymentMock, 33);
351 'resultCode' => 1111111111
354 'origResult' => 3432432423,
355 'resultCode' => 23233432423
369 $paymentTokenMock = $this->createMock(PaymentTokenInterface::class);
371 ->disableOriginalConstructor()
372 ->setMethods([
'setVaultPaymentToken'])
373 ->getMockForAbstractClass();
376 'cc_number' =>
'1111' 380 $this->responseMock->setData(
'origresult', 0);
381 $this->responseMock->setData(
'pnref',
'test-pnref');
383 $this->gatewayMock->expects($this->once())->method(
'postRequest')->willReturn($this->responseMock);
385 $this->responseValidator->expects($this->once())
387 ->with($this->responseMock);
389 $this->paymentMock->expects($this->once())
390 ->method(
'setTransactionId')
393 $this->paymentMock->expects($this->once())
394 ->method(
'setIsTransactionClosed')
396 $this->paymentMock->expects($this->once())
397 ->method(
'getCcExpYear')
398 ->willReturn(
'2017');
399 $this->paymentMock->expects($this->once())
400 ->method(
'getCcExpMonth')
402 $this->paymentMock->expects(static::any())
403 ->method(
'getAdditionalInformation')
411 $this->paymentTokenFactory->expects(static::once())
413 ->willReturn($paymentTokenMock);
414 $paymentTokenMock->expects(static::once())
415 ->method(
'setGatewayToken')
416 ->with(
'test-pnref');
417 $paymentTokenMock->expects(static::once())
418 ->method(
'setTokenDetails')
419 ->with(json_encode($ccDetails));
420 $paymentTokenMock->expects(static::once())
421 ->method(
'setExpiresAt')
422 ->with(
'2018-01-01 00:00:00');
424 $this->paymentMock->expects(static::once())
425 ->method(
'getExtensionAttributes')
428 ->method(
'setVaultPaymentToken')
429 ->with($paymentTokenMock);
431 $this->paymentMock->expects($this->at(8))
432 ->method(
'unsAdditionalInformation')
434 $this->paymentMock->expects($this->at(9))
435 ->method(
'unsAdditionalInformation')
438 $this->assertSame($this->
object, $this->object->authorize($this->paymentMock, 33));
446 static::assertEquals(Info::class, $this->object->getInfoBlockType());
testAuthorizeValidationException()
initializationAuthorizeMock()
testAuthorizeLocalizedException( $resultCode, $origResult)
authorizeLocalizedExceptionDataProvider()
const RESPONSE_CODE_DECLINED_BY_FILTER
const RESPONSE_CODE_APPROVED
const RESPONSE_CODE_DECLINED
const RESPONSE_CODE_FRAUDSERVICE_FILTER