13 use Magento\Framework\HTTP\ZendClientFactory;
15 use Magento\Payment\Model\Method\ConfigInterfaceFactory;
24 use PHPUnit_Framework_MockObject_MockObject as MockObject;
64 private $eventManager;
68 $this->configMock = $this->getMockBuilder(PayflowConfig::class)
69 ->disableOriginalConstructor()
71 $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)
72 ->getMockForAbstractClass();
73 $this->gatewayMock = $this->getMockBuilder(Gateway::class)
74 ->disableOriginalConstructor()
76 $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
77 ->getMockForAbstractClass();
79 $configFactoryMock = $this->getMockBuilder(ConfigInterfaceFactory::class)
80 ->setMethods([
'create'])
81 ->disableOriginalConstructor()
83 $configFactoryMock->method(
'create')
84 ->willReturn($this->configMock);
86 $client = $this->getMockBuilder(ZendClient::class)
89 $clientFactory = $this->getMockBuilder(ZendClientFactory::class)
90 ->disableOriginalConstructor()
92 $clientFactory->method(
'create')->will($this->returnValue($client));
94 $this->eventManager = $this->getMockBuilder(ManagerInterface::class)
95 ->getMockForAbstractClass();
97 $this->helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
98 $this->payflowpro = $this->helper->getObject(
99 \
Magento\Paypal\Model\Payflowpro::class,
101 'eventDispatcher' => $this->eventManager,
102 'configFactory' => $configFactoryMock,
103 'httpClientFactory' => $clientFactory,
104 'storeManager' => $this->storeManagerMock,
105 'gateway' => $this->gatewayMock,
106 'scopeConfig' => $this->scopeConfigMock
119 public function testCanVoid(
$message, $amountPaid, $expected)
122 $payment = $this->getMockBuilder(Payment::class)
123 ->disableOriginalConstructor()
125 $payment->method(
'getAmountPaid')->willReturn($amountPaid);
126 $this->payflowpro->setInfoInstance(
$payment);
128 $this->assertEquals($expected, $this->payflowpro->canVoid(),
$message);
137 [
"Can void transaction if order's paid amount not set",
null,
true],
138 [
"Can void transaction if order's paid amount equals zero", 0,
true],
139 [
"Can't void transaction if order's paid amount greater than zero", 10,
false],
145 $this->assertTrue($this->payflowpro->canCapturePartial());
150 $this->assertTrue($this->payflowpro->canRefundPartialPerInvoice());
160 $this->gatewayMock->expects($this->once())
161 ->method(
'postRequest')
164 $this->configMock->expects($this->once())->method(
'getBuildNotationCode')
165 ->will($this->returnValue(
'BNCODE'));
166 $payment = $this->createPartialMock(\
Magento\
Payment\Model\Info::class, [
'setTransactionId',
'__wakeup']);
167 $payment->expects($this->once())->method(
'setTransactionId')->will($this->returnSelf());
168 $this->payflowpro->fetchTransactionInfo(
$payment,
'AD49G8N825');
179 $this->assertEquals($paymentExpected->getData(),
$payment->getData());
189 'response' => new \Magento\Framework\DataObject(
191 'pnref' =>
'V19A3D27B61E',
195 'paymentExpected' => new \Magento\Framework\DataObject(
197 'transaction_id' =>
'V19A3D27B61E',
198 'is_transaction_closed' => 0,
203 'response' => new \Magento\Framework\DataObject(
205 'pnref' =>
'V19A3D27B61E',
209 'paymentExpected' => new \Magento\Framework\DataObject(
211 'transaction_id' =>
'V19A3D27B61E',
212 'is_transaction_closed' => 0,
213 'is_transaction_pending' =>
true,
214 'is_fraud_detected' =>
true,
232 foreach ($expectsMethods as
$method => $isActive) {
233 $this->scopeConfigMock->expects($this->at(
$i++))
236 "payment/{$method}/active",
239 )->willReturn($isActive);
254 $paymentMock->expects(static::once())
255 ->method(
'getAdditionalInformation')
258 $paymentMock->expects(static::once())
259 ->method(
'getParentTransactionId')
262 $paymentMock->expects(static::exactly(2))
264 ->willReturn($orderMock);
268 $this->payflowpro->capture($paymentMock,
$amount);
269 static::assertEquals(
$response[
'pnref'], $paymentMock->getTransactionId());
270 static::assertFalse((
bool)$paymentMock->getIsTransactionPending());
280 'amount' => 14.13999999999999999999999999999999999999999999999999,
281 'setAmount' => 49.99,
282 'expectedResult' => 14.14
285 'amount' => 14.13199999999999999999999999999999999999999999999999,
286 'setAmount' => 49.99,
287 'expectedResult' => 14.13,
291 'setAmount' => 49.99,
292 'expectedResult' => 14.14,
295 'amount' => 14.13999999999999999999999999999999999999999999999999,
296 'setAmount' => 14.14,
297 'expectedResult' => 0,
311 $orderMock = $this->getMockBuilder(\
Magento\Sales\Model\Order::class)
312 ->disableOriginalConstructor()
315 $infoInstanceMock = $this->getMockForAbstractClass(
316 InfoInterface::class,
322 [
'getAmountAuthorized',
'hasAmountPaid']
325 $infoInstanceMock->expects($this->once())
326 ->method(
'getAmountAuthorized')
327 ->willReturn($setAmount);
328 $infoInstanceMock->expects($this->once())
329 ->method(
'hasAmountPaid')
331 $this->payflowpro->setData(
'info_instance', $infoInstanceMock);
334 $paymentMock->expects($this->once())
335 ->method(
'getAdditionalInformation')
338 $paymentMock->expects($this->any())
339 ->method(
'getParentTransactionId')
342 $paymentMock->expects($this->once())
344 ->willReturn($orderMock);
348 $this->gatewayMock->expects($this->once())
349 ->method(
'postRequest')
351 $this->callback(
function (
$request) use ($expectedResult) {
352 return is_callable([
$request,
'getAmt']) &&
$request->getAmt() == $expectedResult;
354 $this->isInstanceOf(PayflowConfig::class)
358 $this->payflowpro->capture($paymentMock,
$amount);
360 $this->assertEquals(
$response[
'pnref'], $paymentMock->getTransactionId());
361 $this->assertFalse((
bool)$paymentMock->getIsTransactionPending());
372 $paymentMock->expects(static::exactly(2))
374 ->willReturn($orderMock);
378 $this->payflowpro->authorize($paymentMock,
$amount);
379 static::assertEquals(
$response[
'pnref'], $paymentMock->getTransactionId());
380 static::assertFalse((
bool)$paymentMock->getIsTransactionPending());
390 'expectsMethods' => [
397 'expectsMethods' => [
403 'expectsMethods' => [
415 public function testRefund()
418 $paymentMock = $this->getPaymentMock();
423 $this->payflowpro->refund($paymentMock,
$amount);
424 static::assertEquals(
$response[
'pnref'], $paymentMock->getTransactionId());
425 static::assertTrue($paymentMock->getIsTransactionClosed());
435 $storeMock = $this->getMockBuilder(\
Magento\
Store\Model\Store::class)
436 ->disableOriginalConstructor()
437 ->setMethods([
'getId'])
439 $this->storeManagerMock->expects(static::once())
441 ->willReturn($storeMock);
442 $storeMock->expects(static::once())
453 return new \Magento\Framework\DataObject(
456 'pnref' =>
'V19A3D27B61E',
457 'respmsg' =>
'Approved',
458 'authcode' =>
'510PNI',
460 'request_id' =>
'f930d3dc6824c1f7230c5529dc37ae5e',
461 'result_code' =>
'0',
474 $this->gatewayMock->expects(static::once())
475 ->method(
'postRequest')
477 $this->isInstanceOf(\
Magento\Framework\DataObject::class),
478 $this->isInstanceOf(PayflowConfig::class)
490 $paymentMock = $this->getMockBuilder(\
Magento\
Payment\Model\Info::class)
491 ->disableOriginalConstructor()
493 'getAdditionalInformation',
'getParentTransactionId',
'getOrder',
494 'getCcNumber',
'getCcExpMonth',
'getCcExpYear',
'getCcCid' 499 'number' => 4111111111111111,
504 $paymentMock->expects(static::any())
505 ->method(
'getCcNumber')
506 ->willReturn($cardData[
'number']);
507 $paymentMock->expects(static::any())
508 ->method(
'getCcExpMonth')
509 ->willReturn($cardData[
'month']);
510 $paymentMock->expects(static::any())
511 ->method(
'getCcExpYear')
512 ->willReturn($cardData[
'year']);
513 $paymentMock->expects(static::any())
515 ->willReturn($cardData[
'cvv']);
528 'increment_id' =>
'0000004' 530 $orderMock = $this->getMockBuilder(\
Magento\Sales\Model\Order::class)
531 ->disableOriginalConstructor()
532 ->setMethods([
'getBaseCurrencyCode',
'getIncrementId',
'getId',
'getBillingAddress',
'getShippingAddress'])
535 $orderMock->expects(static::once())
537 ->willReturn($orderData[
'id']);
538 $orderMock->expects(static::once())
539 ->method(
'getBaseCurrencyCode')
540 ->willReturn($orderData[
'currency']);
541 $orderMock->expects(static::atLeastOnce())
542 ->method(
'getIncrementId')
543 ->willReturn($orderData[
'increment_id']);
547 public function testPostRequest()
554 $config = $this->createMock(ConfigInterface::class);
556 $this->gatewayMock->expects(static::once())
557 ->method(
'postRequest')
559 ->willReturn($expectedResult);
561 static::assertSame($expectedResult, $this->payflowpro->postRequest(
$request,
$config));
568 public function testPostRequestException()
573 $config = $this->createMock(ConfigInterface::class);
575 $this->gatewayMock->expects(static::once())
576 ->method(
'postRequest')
591 'cc_exp_month' => 12,
592 'cc_exp_year' => 2023
596 $infoInstance = $this->getMockForAbstractClass(InfoInterface::class);
597 $this->payflowpro->setData(
'info_instance', $infoInstance);
599 $this->eventManager->expects(static::exactly(2))
600 ->method(
'dispatch');
602 $this->payflowpro->assignData($dataObject);
628 'BILLTONAME' =>
'John Doe',
629 'BILLTOFIRSTNAME' =>
'John',
630 'BILLTOLASTNAME' =>
'Doe',
632 'BILLTOSTREET' =>
'6161 West Centinela Avenue',
633 'BILLTOCITY' =>
'Culver City',
634 'BILLTOSTATE' =>
'CA',
635 'BILLTOZIP' =>
'90230',
636 'BILLTOCOUNTRY' =>
'US',
637 'SHIPTOSTREET' =>
'6161 West Centinela Avenue',
638 'SHIPTOCITY' =>
'Culver City',
639 'SHIPTOSTATE' =>
'CA',
640 'SHIPTOZIP' =>
'90230',
641 'SHIPTOCOUNTRY' =>
'US',
642 'NAMETOSHIP' =>
'John Doe',
643 'ADDRESSTOSHIP' =>
'6161 West Centinela Avenue',
644 'CITYTOSHIP' =>
'Culver City',
645 'STATETOSHIP' =>
'CA',
646 'ZIPTOSHIP' =>
'90230',
647 'COUNTRYTOSHIP' =>
'US',
648 'NAME' =>
'John Doe',
656 'billtoname' =>
'John Doe',
657 'billtofirstname' =>
'John',
658 'billtolastname' =>
'Doe',
660 'billtostreet' =>
'6161 West Centinela Avenue',
661 'billtocity' =>
'Culver City',
662 'billtostate' =>
'CA',
663 'billtozip' =>
'90230',
664 'billtocountry' =>
'US',
665 'shiptostreet' =>
'6161 West Centinela Avenue',
666 'shiptocity' =>
'Culver City',
667 'shiptostate' =>
'CA',
668 'shiptozip' =>
'90230',
669 'shiptocountry' =>
'US',
670 'nametoship' =>
'John Doe',
671 'addresstoship' =>
'6161 West Centinela Avenue',
672 'citytoship' =>
'Culver City',
673 'statetoship' =>
'CA',
674 'ziptoship' =>
'90230',
675 'countrytoship' =>
'US',
676 'name' =>
'John Doe',
682 'firstname' =>
'John',
684 'address' =>
'6161 West Centinela Avenue',
685 'city' =>
'Culver City',
691 'ccavsstatus' =>
'NNN',
dataProviderMapGatewayResponse()
dataProviderCaptureAmountRounding()
testCaptureAmountRounding($amount, $setAmount, $expectedResult)
testCaptureWithBuildPlaceRequest()
testSetTransStatus($response, $paymentExpected)
testCanRefundPartialPerInvoice()
testFetchTransactionInfoForBN()
testIsActive(array $expectsMethods, $result)
setTransStatusDataProvider()
dataProviderForTestIsActive()
testMapGatewayResponse($postData, $expectedResponse)
const RESPONSE_CODE_APPROVED
const RESPONSE_CODE_FRAUDSERVICE_FILTER
getGatewayResponseObject()