private function getSuccessAndStatus($response, $code, $type, $isRedirect)
    {
        if (!in_array($code, [200, 201, 204])) {
            return [
                'success'       => false,
                'status'        => new Status('failed'),
                'reference'     => Arr::get($response, 'debug_id'),
                'authorization' => null,
            ];
        }

        $success = true;
        $status = null;
        $reference = null;
        $authorization = null;

        if ($type === 'sale') {
            $transaction = Arr::last($response['transactions']);
            $resource = Arr::last($transaction['related_resources']);

            // if there is no payment resource save general state
            $state = $resource ? $resource['sale']['state'] : $response['state'];

            $reference = $resource ? $resource['sale']['id'] : $response['id'];
            $authorization = $resource ? $response['id'] : null;

            $success = in_array($state, $this->successPaymentStatuses);
            $status = $this->getPaymentStatus($state);
        }

        if ($isRedirect) {
            $approvalUrl = null;
            foreach ($response['links'] as $link) {
                if ($link['rel'] === 'approval_url') {
                    $approvalUrl = rawurlencode($link['href']);
                    break;
                }
            }
            $authorization = "{$response['continue_url']}/?approval_url={$approvalUrl}&reference={$reference}";
        }

        return [
            'success'       => $success,
            'status'        => $status,
            'reference'     => $reference,
            'authorization' => $authorization,
        ];
    }