/**
  * @inheritdoc
  */
 public function execute()
 {
     $response = $this->resultFactory->create(ResultFactory::TYPE_JSON);
     try {
         $publicHash = $this->getRequest()->getParam('public_hash');
         $customerId = $this->session->getCustomerId();
         $result = $this->command->execute(['public_hash' => $publicHash, 'customer_id' => $customerId])->get();
         $response->setData(['paymentMethodNonce' => $result['paymentMethodNonce']]);
     } catch (\Exception $e) {
         $this->logger->critical($e);
         return $this->processBadRequest($response);
     }
     return $response;
 }
 /**
  * @covers \Magento\BraintreeTwo\Gateway\Command\GetPaymentNonceCommand::execute
  */
 public function testExecute()
 {
     $publicHash = '3wv2m24d2er3';
     $customerId = 1;
     $token = 'jd2vnq';
     $nonce = 's1dj23';
     $this->subjectReader->expects(static::once())->method('readPublicHash')->willReturn($publicHash);
     $this->subjectReader->expects(static::once())->method('readCustomerId')->willReturn($customerId);
     $this->tokenManagement->expects(static::once())->method('getByPublicHash')->with($publicHash, $customerId)->willReturn($this->paymentToken);
     $this->paymentToken->expects(static::once())->method('getGatewayToken')->willReturn($token);
     $obj = new \stdClass();
     $obj->success = true;
     $obj->paymentMethodNonce = new \stdClass();
     $obj->paymentMethodNonce->nonce = $nonce;
     $this->adapter->expects(static::once())->method('createNonce')->with($token)->willReturn($obj);
     $this->responseValidator->expects(static::once())->method('validate')->with(['response' => ['object' => $obj]])->willReturn($this->validationResult);
     $this->validationResult->expects(static::once())->method('isValid')->willReturn(true);
     $this->validationResult->expects(static::never())->method('getFailsDescription');
     $expected = $this->getMockBuilder(ArrayResult::class)->disableOriginalConstructor()->setMethods(['get'])->getMock();
     $expected->expects(static::once())->method('get')->willReturn(['paymentMethodNonce' => $nonce]);
     $this->resultFactory->expects(static::once())->method('create')->willReturn($expected);
     $actual = $this->command->execute(['publicHash' => $publicHash, 'customerId' => $customerId]);
     static::assertEquals($expected, $actual);
     static::assertEquals($nonce, $actual->get()['paymentMethodNonce']);
 }
 /**
  * @covers \Magento\BraintreeTwo\Controller\Payment\GetNonce::execute
  */
 public function testExecute()
 {
     $customerId = 1;
     $publicHash = '65b7bae0dcb690d93';
     $nonce = 'f1hc45';
     $this->request->expects(static::once())->method('getParam')->with('public_hash')->willReturn($publicHash);
     $this->session->expects(static::once())->method('getCustomerId')->willReturn($customerId);
     $this->commandResult->expects(static::once())->method('get')->willReturn(['paymentMethodNonce' => $nonce]);
     $this->command->expects(static::once())->method('execute')->willReturn($this->commandResult);
     $this->result->expects(static::once())->method('setData')->with(['paymentMethodNonce' => $nonce]);
     $this->logger->expects(static::never())->method('critical');
     $this->result->expects(static::never())->method('setHttpResponseCode');
     $this->action->execute();
 }