logger = $logger; $this->session = $session; $this->command = $command; } /** * @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, 'store_id' => $this->session->getStoreId()] ) ->get(); $response->setData(['paymentMethodNonce' => $result['paymentMethodNonce']]); } catch (\Exception $e) { $this->logger->critical($e); return $this->processBadRequest($response); } return $response; } /** * Return response for bad request * @param ResultInterface $response * @return ResultInterface */ private function processBadRequest(ResultInterface $response) { $response->setHttpResponseCode(Exception::HTTP_BAD_REQUEST); $response->setData(['message' => __('Sorry, but something went wrong')]); return $response; } }