Пример #1
0
 /**
  * Send request to PayfloPro gateway for get Secure Token
  *
  * @return ResultInterface
  */
 public function execute()
 {
     $this->sessionTransparent->setQuoteId($this->sessionManager->getQuote()->getId());
     $token = $this->secureTokenService->requestToken($this->sessionManager->getQuote());
     $result = [];
     $result[$this->transparent->getCode()]['fields'] = $token->getData();
     $result['success'] = $token->getSecuretoken() ? true : false;
     if (!$result['success']) {
         $result['error'] = true;
         $result['error_messages'] = __('Secure Token Error. Try again.');
     }
     return $this->resultJsonFactory->create()->setData($result);
 }
Пример #2
0
 public function testRequestToken()
 {
     $request = new Object();
     $secureTokenID = 'Sdj46hDokds09c8k2klaGJdKLl032ekR';
     $this->transparent->expects($this->once())->method('buildBasicRequest')->willReturn($request);
     $this->transparent->expects($this->once())->method('fillCustomerContacts');
     $this->transparent->expects($this->once())->method('getConfig')->willReturn($this->getMock('Magento\\Paypal\\Model\\PayflowConfig', [], [], '', false));
     $this->transparent->expects($this->once())->method('postRequest')->willReturn(new Object());
     $this->mathRandom->expects($this->once())->method('getUniqueHash')->willReturn($secureTokenID);
     $this->url->expects($this->exactly(3))->method('getUrl');
     $quote = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false);
     $this->model->requestToken($quote);
     $this->assertEquals($secureTokenID, $request->getSecuretokenid());
 }
Пример #3
0
 /**
  * Send request to PayfloPro gateway for get Secure Token
  *
  * @return ResultInterface
  */
 public function executeInternal()
 {
     /** @var Quote $quote */
     $quote = $this->sessionManager->getQuote();
     if (!$quote or !$quote instanceof Quote) {
         return $this->getErrorResponse();
     }
     $this->sessionTransparent->setQuoteId($quote->getId());
     try {
         $token = $this->secureTokenService->requestToken($quote);
         if (!$token->getData('securetoken')) {
             throw new \LogicException();
         }
         return $this->resultJsonFactory->create()->setData([$this->transparent->getCode() => ['fields' => $token->getData()], 'success' => true, 'error' => false]);
     } catch (\Exception $e) {
         return $this->getErrorResponse();
     }
 }
Пример #4
0
 /**
  * Run test execute method
  *
  * @param array $result
  * @param array $resultExpectation
  *
  * @dataProvider executeDataProvider
  */
 public function testExecute(array $result, array $resultExpectation)
 {
     $quoteId = 99;
     $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->getMock();
     $tokenMock = $this->getMockBuilder('Magento\\Framework\\Object')->setMethods(['getData', 'getSecuretoken'])->disableOriginalConstructor()->getMock();
     $jsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock();
     $this->transparentMock->expects($this->once())->method('getCode')->willReturn('transparent');
     $this->sessionManagerMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($quoteMock);
     $quoteMock->expects($this->once())->method('getId')->willReturn($quoteId);
     $this->sessionTransparentMock->expects($this->once())->method('setQuoteId')->with($quoteId);
     $this->secureTokenServiceMock->expects($this->once())->method('requestToken')->with($quoteMock)->willReturn($tokenMock);
     $this->transparentMock->expects($this->once())->method('getCode')->willReturn('transparent');
     $tokenMock->expects($this->once())->method('getData')->willReturn($result['transparent']['fields']);
     $tokenMock->expects($this->once())->method('getSecuretoken')->willReturn($result['success']);
     $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($jsonMock);
     $jsonMock->expects($this->once())->method('setData')->with($resultExpectation)->willReturnSelf();
     $this->assertEquals($jsonMock, $this->controller->execute());
 }
 public function testExecuteTokenRequestException()
 {
     $quoteId = 99;
     $resultExpectation = ['success' => false, 'error' => true, 'error_messages' => __('Your payment has been declined. Please try again.')];
     $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->getMock();
     $jsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock();
     $this->sessionManagerMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($quoteMock);
     $quoteMock->expects($this->once())->method('getId')->willReturn($quoteId);
     $this->sessionTransparentMock->expects($this->once())->method('setQuoteId')->with($quoteId);
     $this->secureTokenServiceMock->expects($this->once())->method('requestToken')->with($quoteMock)->willThrowException(new \Exception());
     $this->resultJsonFactoryMock->expects($this->once())->method('create')->willReturn($jsonMock);
     $jsonMock->expects($this->once())->method('setData')->with($resultExpectation)->willReturnSelf();
     $this->assertEquals($jsonMock, $this->controller->execute());
 }