✏️ 正在编辑: ApiPartnerController.php
路径:
/srv/systems_dir/koruspay/application/controllers/ApiPartnerController.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php use Modules\Automation\Service\ApiPartnerService; use Zend_Controller_Action as ZendController; class ApiPartnerController extends ZendController { /** @var string */ public const ERRO = 'Ocorreu um erro durante a solicitação.'; public function init() { try { ApiPartnerService::validRequest($this->getRequest()); } catch (Throwable $throwable) { $this->_response->setHttpResponseCode(400); $this->_helper->json(['error' => $throwable->getMessage()]); return; } $this->_helper->viewRenderer->setNoRender(); $this->_helper->layout->disableLayout(); parent::init(); } public function createSplitAction() { $request = $this->getRequest(); if (!$request->isPost()) { $this->_response->setHttpResponseCode(404); $this->_helper->json(['error' => 'Método não permitido!']); } try { $split = ApiPartnerService::createSplit($request); $this->_helper->json(['success' => true, 'msg' => 'Pagamentos enviados com sucesso. Criado o Split nº ' . $split]); } catch (Throwable $erro) { $this->_response->setHttpResponseCode(403); \Yuppie_Log::write("ERRO NO PROCESSAMENTO DO WEBHOOK: " . $erro->getMessage()); $this->_helper->json(['error' => $erro->getMessage()]); } } public function createChargeAction() { $request = $this->getRequest(); if (!$request->isPost()) { $this->_response->setHttpResponseCode(404); $this->_helper->json(['error' => 'Método não permitido!']); } try { $result = ApiPartnerService::processRequest($request); $this->_helper->json(['success' => true, 'msg' => 'Lote em procesamento.', $result]); } catch (Throwable $erro) { $this->_response->setHttpResponseCode(403); \Yuppie_Log::write("ERRO NO PROCESSAMENTO DO WEBHOOK: " . $erro->getMessage()); $this->_helper->json(['error' => $erro->getMessage()]); } } public function balanceAction() { $request = $this->getRequest(); try { $balance = ApiPartnerService::balance($request); $token = Core_Crypt::Encrypt($balance['subtotal'] . '|' . $balance['tax'] . '|' . time()); $balance['token'] = $token; if ($balance) { $this->_helper->json(['success' => true, 'msg' => 'Saldo consultado com sucesso!', 'balance' => $balance]); } $this->_helper->json(['error' => 'Ocorreu um erro ao consultar o saldo.']); } catch (Throwable $erro) { $this->_response->setHttpResponseCode(403); \Yuppie_Log::write("ERRO NO PROCESSAMENTO DO SALDO: " . $erro->getMessage()); $this->_helper->json(['error' => 'Erro ao solicitar saldo: ' . $erro->getMessage()]); } } public function withdrawAction() { $request = $this->getRequest(); $body = json_decode($request->getRawBody()); $timeToken = trim($body->token); $balance = String_Refatorar::parseStringToFloat(trim($body->balance)); $apiKey = trim($request->getHeader('apiKey')); if (empty($timeToken)) { $this->_helper->json(['error' => 'Token não informado.']); } $token = Core_Crypt::Decrypt($timeToken); if (!empty($token)) { $parts = explode('|', $token); if (count($parts) === 3) { $subtotal = (float)$parts[0]; $tax = (float)$parts[1]; $time = (int)$parts[2]; } } $subtotal = ($balance > $subtotal) ? $subtotal : $balance; if (!isset($subtotal) || !isset($tax) || !isset($time)) { $this->_helper->json(['error' => 'Sessão inválida ou expirada.']); } $ttlSeconds = 600; if ((time() - $time) > $ttlSeconds) { $this->_helper->json(['error' => 'Sessão expirada. Consulte o saldo novamente para atualizar.']); } if (!is_numeric($subtotal) || $subtotal <= 0) { $this->_helper->json(['error' => 'Valor para saque inválido.']); } if (!is_numeric($tax) || $tax < 0) { $this->_helper->json(['error' => 'Tarifa inválida.']); } try { if (ApiPartnerService::withdraw($apiKey, $subtotal, $tax)) { $this->_helper->json(['success' => true, 'msg' => 'Saque solicitado com sucesso!']); } $this->_helper->json(['success' => false]); } catch (Throwable $erro) { $this->_response->setHttpResponseCode(403); \Yuppie_Log::write("ERRO NO PROCESSAMENTO DO SAQUE: " . $erro->getMessage()); $this->_helper->json(['error' => 'Erro ao solicitar saque: ' . $erro->getMessage()]); } } public function withdrawHistoryAction() { $request = $this->getRequest(); $body = json_decode($request->getRawBody()); $apiKey = trim($request->getHeader('apiKey')); try { if ($history = ApiPartnerService::withdrawHistory($body, $apiKey)) { $this->_helper->json(['success' => true, 'history' => $history]); } $this->_helper->json(['success' => false]); } catch (Throwable $erro) { $this->_response->setHttpResponseCode(403); \Yuppie_Log::write("ERRO NA CONSULTA DE HISTÓRICO: " . $erro->getMessage()); $this->_helper->json(['error' => 'Erro ao consultar histórico: ' . $erro->getMessage()]); } } public function checkStatusAction() { $request = $this->getRequest(); try { if ($check = ApiPartnerService::checkStatus($request)) { $this->_helper->json(['success' => true, 'charge' => $check]); } $this->_helper->json(['success' => false]); } catch (Throwable $erro) { $this->_response->setHttpResponseCode(403); \Yuppie_Log::write("ERRO NA CONSULTA DE STATUS: " . $erro->getMessage()); $this->_helper->json(['error' => 'Erro ao consultar status' . $erro->getMessage()]); } } }
💾 保存文件
← 返回文件管理器