Map HTTP response to transaction object.

@param bool  $success
@param array $response

@return \Shoperti\PayMe\Contracts\ResponseInterface
543883
public function mapResponse($success, $response)
    {
        $rawResponse = $response;

        $object = Arr::get($response, 'object');

        if ($object !== 'error' && array_key_exists('type', $response) && isset($response['data']['object'])) {
            $response = $response['data']['object'];
        }

        $type = $this->getType($rawResponse);
        list($reference, $authorization) = $success ? $this->getReferences($response, $type) : [null, null];

        $message = '';

        if ($success) {
            $message = 'Transaction approved';
        } elseif ($object === 'error') {
            foreach (Arr::get($response, 'details') as $detail) {
                $message .= ' '.Arr::get($detail, 'message', '');
            }
            $message = ltrim($message);
        } else {
            $message = Arr::get($response, 'message_to_purchaser') ?: Arr::get($response, 'message', '');
        }

        $isTest = $object === 'error' && isset($response['data'])
            ? !(Arr::get($response['data'], 'livemode', true))
            : !(Arr::get($response, 'livemode', true));

        if ($type === 'refund') {
            $rawResponse['amount_refunded'] = $this->getRefundAmount($rawResponse);
        }

        return (new Response())->setRaw($rawResponse)->map([
            'isRedirect'    => false,
            'success'       => $success,
            'reference'     => $reference,
            'message'       => $message,
            'test'          => $isTest,
            'authorization' => $authorization,
            'status'        => $success ? $this->getStatus(Arr::get($response, 'payment_status', 'paid')) : new Status('failed'),
            'errorCode'     => $success ? null : $this->getErrorCode($response),
            'type'          => $type,
        ]);
    }
865313
public function mapResponse($success, $response)
    {
        $rawResponse = $response;

        unset($rawResponse['isRedirect']);

        if (array_key_exists('INVALID', $response) || array_key_exists('VERIFIED', $response)) {
            $success = array_key_exists('VERIFIED', $response);

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

        return (new Response())->setRaw($rawResponse)->map([
            'isRedirect'      => $response['isRedirect'],
            'success'         => $response['isRedirect'] ? false : $success,
            'reference'       => $success ? $this->getReference($response, $response['isRedirect']) : false,
            'message'         => $success ? Arr::get($response, 'ACK', 'Transaction approved') : $response['L_LONGMESSAGE0'],
            'test'            => $this->config['test'],
            'authorization'   => $this->getAuthorization($response, $success, $response['isRedirect']),
            'status'          => $success ? $this->getStatus($response, $response['isRedirect']) : new Status('failed'),
            'errorCode'       => $success ? null : $this->getErrorCode($response['L_ERRORCODE0']),
            'type'            => null,
        ]);
    }
446061
protected function respond($response, $code)
    {
        if (isset($response[0])) {
            foreach ($response as $responseItem) {
                $responses[] = $this->respond($responseItem, $code);
            }

            return $responses;
        }

        return $this->mapResponse($this->isSuccess($response, $code), $response);
    }
292080
public function completedResponse(JsonResponse $response)
    {
        $data = $response->getData();
        $data->success = true;
        $data->uuid = $this->request->get('dzuuid');
        $response->setData($data);

        return $response;
    }
301231
public function setFromResponseObj(HttpResponse $response)
    {
        if ($response->isSuccess()) {
            $body = json_decode($response->getBody(), true);
            $this->setStatus((bool) isset($body['success']) ? $body['success'] : false);
        } else {
            $this->setError($response->getReasonPhrase());
        }

        return $this;
    }
482514
protected function encodeJsonSerializable(JsonSerializable $action_result, ResponseInterface $response, $status = 200)
    {
        return $response->write(json_encode($action_result))->withStatus($status);
    }
524250
private function getHttpResponse(&$header, &$response)
    {
        if (isset($header) && is_array($header) && (0 < count($header))) {
            $response = new HttpResponse($header);
            return true;
        }

        return false;
    }
14455
protected function IsSuccessResponse($response = '')
    {
        $bPaymentOk = false;
        $oGlobal = TGlobal::instance();
        if (empty($response)) {
            $aResult = $this->GetNeedeResponsePostParameterForSecurityCheck();
            $aResult['ret_status'] = $oGlobal->GetUserData('ret_status');
        } else {
            $aResult = $this->GetResultFormResponse($response);
        }

        if (count($aResult) > 0 && array_key_exists('ret_status', $aResult) && 'SUCCESS' == $aResult['ret_status']) {
            $bPaymentOk = true;
        }
        if ($bPaymentOk) {
            $bPaymentOk = $this->IsSecurityCheckOk($aResult['trxuser_id'], $aResult['trx_amount'], $aResult['trx_currency'], $aResult['ret_authcode'], $aResult['ret_trx_number'], $aResult['ret_param_checksum']);
        }

        return $bPaymentOk;
    }
1158296
protected function getResponseTransfer(array $response): ComputopApiReverseResponseTransfer
    {
        $computopApiResponseTransfer = new ComputopApiReverseResponseTransfer();
        $computopApiResponseTransfer->setHeader(
            $this->computopApiService->extractResponseHeader($response, $this->config->getReverseMethodName())
        );
        //optional fields
        $computopApiResponseTransfer->setAId($this->computopApiService->getResponseValue($response, ComputopApiConfig::A_ID));
        $computopApiResponseTransfer->setTransactionId($this->computopApiService->getResponseValue($response, ComputopApiConfig::TRANSACTION_ID));
        $computopApiResponseTransfer->setCodeExt($this->computopApiService->getResponseValue($response, ComputopApiConfig::CODE_EXT));
        $computopApiResponseTransfer->setErrorText($this->computopApiService->getResponseValue($response, ComputopApiConfig::ERROR_TEXT));
        $computopApiResponseTransfer->setRefNr($this->computopApiService->getResponseValue($response, ComputopApiConfig::REF_NR));

        return $computopApiResponseTransfer;
    }
50690
public function handleResponse($response)
    {
        // recursion for batch
        if (is_array($response)) {
            $response_arr = array();
            foreach ($response as $res) {
                $response_arr[$res->id] = $this->handleResponse($res);
            }
            return $response_arr;
        }

        // return error response
        if (property_exists($response, 'error')) {
            return new Response(null, $response->id, $response->error->code, $response->error->message);
        }

        // return successful response
        return new Response($response->result, $response->id);
    }
22697
public static function isSuccess(stdClass $response)
    {
        if (is_object($response) && $response->success == true) {
            return HttpCodes::isOk($response->http_code);
        } else {
            return false;
        }
    }
1039320
public function mapResponse($success, $response)
    {
        return (new Response())->setRaw($response)->map([
            'isRedirect'    => false,
            'success'       => $success,
            'reference'     => $success ? '12345' : null,
            'message'       => $success ? 'Approved' : 'Error',
            'test'          => false,
            'authorization' => $success ? '123' : '',
            'status'        => $success ? new Status('paid') : new Status('failed'),
            'errorCode'     => $success ? false : new ErrorCode('card_declined'),
            'type'          => 'charge',
        ]);
    }
187222
protected function respond($response)
    {
        $success = Arr::get($response, 'success');

        return $this->mapResponse($success, $response);
    }
11117
public function getResponse(\Phalcon\Http\Client\Response $response)
    {
        // parse json response
        $data = json_decode($response->body, true);

        if (isset($data['errors']) === true || $response->header->statusCode > self::MAX_SUCCESS_CODE) {

            $error = $data['errors'][0]['description'];
            throw new BaseException((new \ReflectionClass($this->config))->getShortName(), $error);
        }

        return ($this->debug === true) ? [$response->header, $data] : $data;
    }
559497
private function _createPayment(array $response)
    {
        $model = new Payment();
        $model->setId($response['id']);
        $model->setType($response['type']);
        $model->setClient($this->_convertResponseToModel($response['client'], "client"));
        if ($response['type'] === "creditcard") {
            $model->setCardType($response['card_type']);
            $model->setCountry($response['country']);
            $model->setExpireMonth($response['expire_month']);
            $model->setExpireYear($response['expire_year']);
            $model->setCardHolder($response['card_holder']);
            $model->setLastFour($response['last4']);
        } elseif ($response['type'] === "debit") {
            $model->setHolder($response['holder']);
            $model->setCode($response['code']);
            $model->setAccount($response['account']);
            $model->setBic($response['bic']);
            $model->setIban($response['iban']);
        } elseif ($response['type'] === "paypal") {
            $model->setHolder($response['holder']);
            $model->setAccount($response['account']);
        }
        $model->setCreatedAt($response['created_at']);
        $model->setUpdatedAt($response['updated_at']);
        $model->setAppId($response['app_id']);
        return $model;
    }
276505
public function response($success, $data = '', $code = null) {
        $this->_success = (bool) $success;
        $this->_data = $data;
        $this->_code = $code;
    }
856760
private function _createClient(array $response)
    {
        $model = new Client();
        $model->setId($response['id']);
        $model->setEmail($response['email']);
        $model->setDescription($response['description']);
        $model->setCreatedAt($response['created_at']);
        $model->setUpdatedAt($response['updated_at']);
        $model->setSubscription($this->_handleRecursive($response['subscription'], 'subscription'));
        $model->setAppId($response['app_id']);
        $model->setPayment($this->_handleRecursive($response['payment'], 'payment'));
        return $model;
    }