Handles response

@param array $handlingSubject
@param array $response
@return void
@throws \Exception
321281
public function handle(array $handlingSubject, array $response) {
       
        /** @var $payment Payment */
        $paymentDO  = SubjectReader::readPayment($handlingSubject);
        $payment    = $paymentDO->getPayment();
        $order      = $payment->getOrder();

        if($order->canCreditmemo()) {
            $invoice    = $this->getInvoiceByTransactionId($response['originalId'], $order);
            $amount     = ChargeAmountAdapter::getStoreAmountOfCurrency($response['value'], $response['currency']);

            $creditMemo = $this->creditMemoFactory->createByInvoice($invoice);
            $creditMemo->setBaseGrandTotal($amount);
            $creditMemo->setInvoice($invoice);

            $payment->setCreditmemo($creditMemo);

            $this->orderPaymentRepository->save($payment);
            $this->creditMemoService->refund($creditMemo);
            $this->invoiceRepository->save($invoice);
        }
    }
749041
protected function handleErrorResponse( ResponseInterface $response ){

        $body = json_decode($response->getBody(), true);

        $message = "HTTP:{$response->getStatusCode()}";

        throw new Exception\ApiException( $message, $response->getStatusCode(), $body, $response );

    }
856767
protected function onSuccess(ResponseInterface $response, ?callable $callback = null) : void
    {
        if (!is_null($callback)) {
            $callback($response);
        }
    }
378693
protected function handleErrorResponse(Response $response)
    {
        $exception = $response->exception;

        $error = new MessageBag([
            'type'    => get_class($exception),
            'message' => $exception->getMessage(),
            'file'    => $exception->getFile(),
            'line'    => $exception->getLine(),
        ]);

        return back()->withInput()->withErrors($error, 'exception');
    }
155261
public function handle(
        ServerRequestInterface $request,
        ResponseInterface $response = null,
        $catch = self::DEFAULT_ERROR_CATCH
    )
    {
        /** @var ResponseInterface $response */
        // Passes the request to the container
        if (!$this->getContainer()->has(ServerRequestInterface::class)) {
            $this->getContainer()->share(ServerRequestInterface::class, $request);
        }

        //inject request content type
        $contentType = ServerRequestFactory::getHeader('content-type', $this->getRequest()->getHeaders(), '');
        $this->setContentType($contentType);

        if ($response === null) {
            $response = $this->getResponse();
        }

        $applicationEvent = $this->getApplicationEvent();
        $applicationEvent->setRequest($request);
        $applicationEvent->setResponse($response);

        try {
            $response = $this->handleResponse($this->handleRequest($request), $response);
        }catch (\Exception $exception){
            $notFoundException = $exception instanceof NotFoundException;
            $response = $this->handleError($exception, $request, $response, $catch)
                ->withStatus($notFoundException ? 404 : 500);
        }

        // validate response
        $response = $this->validateContract($response, ResponseInterface::class);

        // update content type
        $this->setContentType(ServerRequestFactory::getHeader('content-type', $response->getHeaders(), ''));

        return $response;
    }
15532
public function getResponse(array $response)
    {
        if (isset($response['error']['code'])) {
            $this->handleRpcErrors($response['error']);
        }

        return isset($response['result']) ? $response['result'] : null;
    }
751721
public function execute(ResponseInterface $response): ResponseInterface
    {
        if ($response->getStatusCode() !== self::STATUS_CODE_OK) {
            throw ExceptionFactory::createExceptionForResponse(
                $this->fetchErrorMessages($response),
                $response->getStatusCode(),
                $this->getResponseId($response)
            );
        }

        return $response;
    }
1065864
private static function handleErrors($response)
    {
        switch ($response->getStatusCode()) {
            case 200:
                return json_decode($response->getBody());
                break;
            case 401:
                throw new UnauthorizedException('Unauthorized (Invalid API key or insufficient permissions)');
                break;
            case 404:
                throw new NotFoundException('Object not found within your account scope');
                break;
            case 406:
                throw new InvalidFormatException('Requested format is not supported - request JSON or XML only');
                break;
            case 422:
                throw new ValidationException('Validation error(s) for create or update method');
                break;
            case 500:
                throw new ServerException('Something went wrong on Challonge\'s end');
                break;
            default:
                $decodedResponse = json_decode($response->getBody());
                throw new UnexpectedErrorException($decodedResponse);
                break;
        }
    }
117135
private function handle(Response $response, $count = false)
    {
        $responseData = json_decode($response->getContent(), true);

        if (!$response->isSuccessful()) {
            // @todo get better error
            throw new \RuntimeException($response->getContent());
        }

        if (true === $count) {
            switch ($responseData['kind']) {
                case 'youtube#playlistItemListResponse':
                    return (int) $responseData['pageInfo']['totalResults'];
                    break;

                default:
                    throw new \Exception('unsupported count operation');
                    break;
            }
        }

        if (isset($responseData['nextPageToken'])) {
            $this->nextPageToken = $responseData['nextPageToken'];
        } else {
            $this->nextPageToken = null;
        }
        return $responseData['items'];
    }
346708
public function handleResponse(Response $response) : void
    {
        if ($this->id === null) {
            // The request was not associated with an existing session, and no session writes occurred.
            // Sending a session cookie is unnecessary.
            return;
        }

        // Note: we re-send the session cookie even if it was part of the request, to refresh the expiration time.

        $this->writeSessionId($response);
        $this->reset();
    }
1044093
protected function _handleCallbackAction(ServerRequest $request, Response $response)
    {
        $this->_setupModelInstances();

        $config = $this->getConfig();
        $providerName = $request->getParam('provider');

        $profile = $this->_getProfile($providerName, $request);
        if (!$profile) {
            return $response->withLocation(
                Router::url($config['loginUrl'], true) . '?error=' . $this->_error
            );
        }

        $user = $this->_getUser($profile);
        if (!$user) {
            return $response->withLocation(
                Router::url($config['loginUrl'], true) . '?error=' . $this->_error
            );
        }

        $user->unsetProperty($config['fields']['password']);

        if (!$config['userEntity']) {
            $user = $user->toArray();
        }

        $event = $this->dispatchEvent(self::EVENT_AFTER_IDENTIFY, ['user' => $user]);
        $result = $event->getResult();
        if ($result !== null) {
            $user = $event->getResult();
        }

        $request->getSession()->write($config['sessionKey'], $user);

        return $response->withLocation(
            Router::url($this->_getRedirectUrl($request), true)
        );
    }
607601
public function invokeOnSubmitCallbacks(ITypedObject $object, array $input)
    {
        foreach ($this->onSubmitCallbacks as $callback) {
            $callback($object, $input);
        }
    }
897507
protected function handleResponse(ResponseInterface $response)
    {
        $status = $response->getStatusCode();

        $data = (string) $response->getBody();
        $jsonResponseData = json_decode($data, false);
        $body = $data && $jsonResponseData === null ? $data : $jsonResponseData;

        return ['status_code' => $status, 'body' => $body];
    }
1069472
private function handleResponse($response)
    {
        if ($this->client->newFormatModeEnabled === true) {
            return $response;
        }

        return $this->client->handleHttpResponse($response);
    }
1352418
private function executeCallable($target, RequestInterface $request, ResponseInterface $response)
    {
        ob_start();
        $level = ob_get_level();

        try {
            $arguments = array_merge([$request, $response], $this->arguments);
            $target = self::getCallable($target, $arguments);
            $return = call_user_func_array($target, $arguments);

            if ($return instanceof ResponseInterface) {
                $response = $return;
                $return = '';
            }

            $return = Utils\Helpers::getOutput($level).$return;
            $body = $response->getBody();

            if ($return !== '' && $body->isWritable()) {
                $body->write($return);
            }

            return $response;
        } catch (\Exception $exception) {
            Utils\Helpers::getOutput($level);
            throw $exception;
        }
    }
580572
protected function handleErrors(ResponseInterface $response)
    {
        $statusCode = $response->getStatusCode();
        switch ($statusCode) {
            case 400:
                throw HttpClientException::badRequest($response);
            case 401:
                throw HttpClientException::unauthorized($response);
            case 402:
                throw HttpClientException::requestFailed($response);
            case 404:
                throw HttpClientException::notFound($response);
            case 413:
                throw HttpClientException::payloadTooLarge($response);
            case 500 <= $statusCode:
                throw HttpServerException::serverError($statusCode);
            default:
                throw new UnknownErrorException();
        }
    }
1041445
public function execute(array $commandSubject) {
        $response = $this->gatewayResponseHolder->getGatewayResponse();

        $this->handler->handle($commandSubject, $response);
    }