private function setErrorCode($code) { $message = Messages::getByCode($code); if (empty($message)) { throw new Exception(sprintf('Error code <strong>%s</strong> not defined', $code)); } $msg = Messages::getByCode($message['msg']); $this->setError(sprintf('[%s] %s [%s - %s]', $message['code'], $message['message'], $message['msg'], $msg['message'])); }
public function checkTransaction(array $post) { $prefix = 'Ds_'; if (empty($post) || empty($post[$prefix . 'Signature'])) { throw new Exception('_POST data is empty'); } $error = isset($post[$prefix . 'ErrorCode']) ? $post[$prefix . 'ErrorCode'] : null; if ($error) { if ($message = Messages::getByCode($error)) { throw new Exception(sprintf('TPV returned error code %s: %s', $error, $message['message'])); } else { throw new Exception(sprintf('TPV returned unknown error code %s', $error)); } } $response = isset($post[$prefix . 'Response']) ? $post[$prefix . 'Response'] : null; if (is_null($response) || strlen($response) === 0) { throw new Exception('Response code is empty (no length)'); } if ((int) $response < 0 || (int) $response > 99) { if ($message = Messages::getByCode($response)) { throw new Exception(sprintf('Response code is Transaction Denied %s: %s', $response, $message['message'])); } else { throw new Exception(sprintf('Response code is unknown %s', $response)); } } $fields = array('Amount', 'Order', 'MerchantCode', 'Currency', 'Response'); $key = ''; foreach ($fields as $field) { if (empty($post[$prefix . $field])) { throw new Exception(sprintf('Field <strong>%s</strong> is empty and is required to verify transaction')); } $key .= $post[$prefix . $field]; } $signature = strtoupper(sha1($key . $this->options['Key'])); if ($signature !== $post[$prefix . 'Signature']) { throw new Exception(sprintf('Signature not valid (%s != %s)', $signature, $post[$prefix . 'Signature'])); } $response = (int) $post[$prefix . 'Response']; if ($response >= 100 && $response !== 900) { throw new Exception(sprintf('Transaction error. Code: <strong>%s</strong>', $post[$prefix . 'Response'])); } return $post[$prefix . 'Signature']; }
private function checkTransactionResponse(array $data, $prefix) { $response = isset($data[$prefix . 'Response']) ? $data[$prefix . 'Response'] : null; if (is_null($response) || strlen($response) === 0) { throw new Exception('Response code is empty (no length)'); } if ((int) $response < 0 || (int) $response > 99 && $response !== 900) { if ($message = Messages::getByCode($response)) { throw new Exception(sprintf('Response code is Transaction Denied %s: %s', $response, $message['message'])); } else { throw new Exception(sprintf('Response code is unknown %s', $response)); } } }