protected function parse3DRequestResponse($rawResponse) { $response = new PaymentResponse(); try { $resultObject = simplexml_load_string($rawResponse); $approved = (string) $resultObject->approved; $respCode = (string) $resultObject->respCode; $respMessage = (string) $resultObject->respText; $response->setIsSuccess($approved == 1); if ($approved == 1) { $data1 = (string) $resultObject->oosRequestDataResponse->data1; $data2 = (string) $resultObject->oosRequestDataResponse->data2; $sign = (string) $resultObject->oosRequestDataResponse->sign; $data = ['data1' => $data1, 'data2' => $data2, 'sign' => $sign]; $response->setData($data); } $response->setResponseCode($respCode); $response->setResponseMessage(utf8_encode($respMessage)); } catch (Exception $e) { $response->setIsSuccess(false); $response->setResponseMessage($e->getMessage()); } $response->setRawResponse(utf8_encode($rawResponse)); return $response; }
/** * {@inheritdoc} * @see Paranoia\Payment\Adapter\AdapterAbstract::parseResponse() */ protected function parseResponse($rawResponse, $transactionType) { $response = new PaymentResponse(); try { /** * @var object $xml */ $xml = new \SimpleXmlElement($rawResponse); } catch (\Exception $e) { $exception = new UnexpectedResponse('Provider returned unexpected response: ' . $rawResponse); $eventArg = new PaymentEventArg(null, null, $transactionType, $exception); $this->getDispatcher()->dispatch(self::EVENT_ON_EXCEPTION, $eventArg); throw $exception; } $response->setRawResponse($xml); $response->setIsSuccess((string) $xml->Response == 'Approved'); $response->setResponseCode((string) $xml->ProcReturnCode); if (!$response->isSuccess()) { $errorMessages = array(); if (property_exists($xml, 'Error')) { $errorMessages[] = sprintf('Error: %s', (string) $xml->Error); } if (property_exists($xml, 'ErrMsg')) { $errorMessages[] = sprintf('Error Message: %s ', (string) $xml->ErrMsg); } if (property_exists($xml, 'Extra') && property_exists($xml->Extra, 'HOSTMSG')) { $errorMessages[] = sprintf('Host Message: %s', (string) $xml->Extra->HOSTMSG); } $errorMessage = implode(' ', $errorMessages); $response->setResponseMessage($errorMessage); } else { $response->setResponseMessage('Success'); $response->setOrderId((string) $xml->OrderId); $response->setAuthCode((string) $xml->AuthCode); $response->setTransactionId((string) $xml->TransId); } $event = $response->isSuccess() ? self::EVENT_ON_TRANSACTION_SUCCESSFUL : self::EVENT_ON_TRANSACTION_FAILED; $this->getDispatcher()->dispatch($event, new PaymentEventArg(null, $response, $transactionType)); return $response; }