Map the HTTP response to a response object.

@param array $response
@param int   $statusCode

@return \Shoperti\PayMe\Contracts\ResponseInterface
329255
public function mapResponse($response, $statusCode)
    {
        // IPN response
        if (in_array(Arr::get($response, 'body'), ['VERIFIED', 'INVALID'])) {
            $success = $response['body'] === 'VERIFIED';

            return (new Response())->setRaw($response)->map([
                'isRedirect'      => false,
                'success'         => $success,
                'reference'       => $success ? Arr::get($response, 'invoice') : false,
                'message'         => $response['body'],
                'test'            => $this->config['test'],
                'authorization'   => $success ? Arr::get($response, 'txn_id') : '',
                'status'          => $success ?
                    $this->getPaymentStatus(Arr::get($response, 'payment_status'))
                    : new Status('failed'),
                'errorCode'       => null,
                'type'            => $success ? Arr::get($response, 'txn_type') : null,
            ]);
        }

        $isRedirect = isset($response['is_redirect']) ? $response['is_redirect'] : false;
        if ($isRedirect) {
            unset($response['is_redirect']);
        }

        // Payment request / execute response
        $type = $this->getType($response);
        $state = $this->getSuccessAndStatus($response, $statusCode, $type, $isRedirect);
        $success = $state['success'];
        $status = $state['status'];
        $reference = $state['reference'];
        $authorization = $state['authorization'];
        $message = $success ? 'Transaction approved' : Arr::get($response, 'message', '');

        return (new Response())->setRaw($response)->map([
            'isRedirect'    => $isRedirect,
            'success'       => $success,
            'reference'     => $reference,
            'message'       => $message,
            'test'          => $this->config['test'],
            'authorization' => $authorization,
            'status'        => $status,
            'errorCode'     => $success ? null : $this->getErrorCode(Arr::get($response, 'name')),
            'type'          => $type,
        ]);
    }
159773
protected function respond($response, $request, $options, $statusCode)
    {
        if (array_key_exists('webhooks', $response)) {
            $results = [];
            foreach ($response['webhooks'] as $result) {
                $results[] = $this->mapResponse($result, $statusCode);
            }

            return $results;
        }

        // IPN response
        if (in_array(Arr::get($response, 'body'), ['VERIFIED', 'INVALID'])) {
            $response = array_merge($request, $response);
        }
        // charge request
        elseif (array_key_exists('continue_url', $options)) {
            $response['continue_url'] = $options['continue_url'];
            $response['is_redirect'] = true;
        }

        return $this->mapResponse($response, $statusCode);
    }
710316
public static function createFromArray($statusCode, array $data = [])
    {
        $response = new static($statusCode);

        if (isset($data['body']) && \is_array($data['body'])) {
            foreach ($data['body'] as $key => $bodyData) {
                $response->addBody(Body::createFromArray($key, $bodyData ?: []));
            }
        }

        if (isset($data['description'])) {
            $response->setDescription($data['description']);
        }

        if (isset($data['headers'])) {
            foreach ($data['headers'] as $key => $header) {
                $response->addHeader(NamedParameter::createFromArray($key, $header));
            }
        }

        return $response;
    }
1358633
public function setStatus($statusCode)
    {
        if ($this->statusCode === null) {
            $this->statusCode = $statusCode;
            $this->response->setStatusCode($statusCode);
        }
    }
1289552
public function success(int $statusCode, string $message, $data = null): JsonResponse
    {

        $this->setStatusCode($statusCode);

        $this->setMessage($message);

        $this->setData($data);


        $content['message'] = $this->getMessage();


        if (null !== $this->getCode()) {
            $content['code'] = $this->getCode();
        }


        $content['status_code'] = $this->getStatusCode();


        if (null !== $this->getData() && $this->getErrors() !== $this->getData()) {
            $content['data'] = $this->getData();
        }

        if (null !== $this->getErrors()) {
            $content['errors'] = $this->getErrors();
        }

        $content += $this->Hypermedia;

        return new JsonResponse($content, $this->getHttpStatusCode() ?: $this->getStatusCode());
    }
479457
protected function respond($response, $status, $body)
    {
        $response->status($status);

        $response->end($body);
    }
482302
protected function json(array $data = [], string $status = Response::HTTP_OK): JsonResponse
    {
        $headers = $this->getResponse()->headers->all();

        $serializedData = [];

        foreach ($data as $key => $item) {
            if (is_array($item) && is_object($item[0])) {
                $serializedData[$key] = EntityNormalizer::normalize($item);

                unset($data[$key]);
            }

            if (is_object($item)) {
                $serializedData[$key] = EntityNormalizer::normalize([$item])[0];

                unset($data[$key]);
            }
        }

        $serializedData = array_merge($serializedData, $data);

        return new JsonResponse($serializedData, $status, $headers);
    }
281370
public function mapResponse($success, $response)
    {
        return (new Response())->setRaw($response)->map([
            'isRedirect'    => false,
            'success'       => true,
            'reference'     => null,
            'message'       => null,
            'test'          => false,
            'authorization' => null,
            'status'        => $response['status'],
            'errorCode'     => false,
            'type'          => $response['type'],
        ]);
    }
1299511
protected function respond($data, $status = Response::HTTP_OK, $headers = []) : JsonResponse
    {
        if ($data instanceof ElementInterface) {
            $data = new Document($data);
        }

        if ($data instanceof Document) {
            $data = $data->toArray();
        }

        return response()->json($data, $status, $headers)
            ->header('Content-Type', ApiRequestHandler::CONTENT_TYPE);
    }
427102
public function makeJsonReponse($status_code, $body)
    {
        $this->getResponse()->setBody(json_encode($body, JSON_UNESCAPED_SLASHES));
        $this->getResponse()->setStatusCode($status_code);
        $this->getResponse()->addHeader("Content-type", "application/json");

        return $this->getResponse();
    }
975838
public function response($content, $statusCode = 200)
    {
        return response()
            ->json($this->convertContent($content))
            ->setStatusCode($statusCode);
    }
255125
protected function mapResponse($success, array $response)
    {
        return (new Response())->setRaw($response)->map([
            'success' => $success,
            'message' => $success ? 'Message sent' : $response['message'],
        ]);
    }
797884
public function write(Response $response, $data, $status = 200)
    {
        return $response->withStatus($status)->getBody()->write($data);
    }
20324
protected function jsonResponse($data = array(), $status = 200, array $headers = array(), $options = 0)
	{
		if ($data instanceof JsonSerializable) {
			$data = $data->jsonSerialize();
		} else if ($data instanceof ArrayableInterface) {
			$data = $data->toArray();
		}

		return new JsonResponse($data, $status, $headers, $options);
	}
372774
public function respond($response, $status, $headers, $options)
    {
        switch ($this->getRequestFormat()) {
            case 'html' :
            case 'text/html' :
                return Response::make($response, $status, $headers, $options)
                    ->header('Content-Type', 'text/html');
            default :
                // whether 'Content-Type' is NULL or equal to anything such as 'application/json' response will be JSON
                return Response::json($response, $status, $headers, $options);
        }
    }
1044244
public function fill($success, $statusCode, $statusText, $response)
    {
        $this->success = $success;
        $this->statusCode = $statusCode;
        $this->statusText = $statusText;
        $this->response = $response;
    }
487364
public function toResponse($status = 200, array $headers = [], $options = 0)
    {
        return new JsonResponse($this->transform(), $status, $headers, $options);
    }