✏️ 正在编辑: OrendaPay.php
路径:
/srv/systems_dir/koruspay/library/Core/Service/OrendaPay.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php use Carbon\Carbon; class Core_Service_OrendaPay { private $_url = "https://www.orendapay.com.br/api/v1"; private $_secretKey; private $_sellerId; private $_companyId; const NOME_API = 'OrendaPay'; public function __construct($companyId = null) { $config = new Zend_Config_Ini(CLIENT_PATH . "/configs/application.ini"); $serviceKey = $config->production->orendapay; if (empty($serviceKey)) { throw new Core_Exception("Dados de integração com o " . self::NOME_API . " não estão configurados." ); } $this->_sellerId = $serviceKey->seller_id; $this->_secretKey = $serviceKey->secret_key; $this->_companyId = $companyId; } protected function getResponse($endPoint, $params, $method = 'POST') { $url = $this->_url . $endPoint; if ($method == 'GET') { $url .= !empty($params) ? '?' . http_build_query($params) : ''; } $options = [ CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => $method, CURLOPT_HTTPHEADER => [ "x-ID:{$this->_sellerId}", "x-Token:{$this->_secretKey}", "Content-type: application/json" ], ]; if ($method == 'POST') { $options[CURLOPT_POSTFIELDS] = json_encode($params); } $curl = curl_init(); curl_setopt_array($curl, $options); $json = curl_exec($curl); $response = json_decode($json); $info = curl_getinfo($curl); $codeError = [400, 422, 429, 499]; curl_close($curl); Yuppie_Log::write("getResponse " . self::NOME_API . ", parâmetros enviados para url {$url}:" . print_r($params, true), $this); Yuppie_Log::write("Retorno do getResponse " . self::NOME_API . ": Code HTTP - " . $info['http_code'] . ' - ' . print_r($response, true), $this); Model_RequestsHistory::saveRequest(json_encode($params), 'output', $this->_companyId, $url); Model_RequestsHistory::saveRequest($json, 'input', $this->_companyId, $url); if (in_array($info['http_code'], $codeError) || !empty($response->msg)) { $retorno = new stdClass(); $retorno->error = $response->msg; $retorno->msg = $response->msg; return $retorno; } return $response; } public function createInvoice(array $invoice, $type = 'pix') { $endPoint = "/cobranca"; $params = [ "seu_codigo" => $invoice['id'], "descricao" => $invoice['description'], "vencimento" => $invoice['due_date'] ? Carbon::make($invoice['due_date'])->format('d/m/Y') : Carbon::now()->format('d/m/Y'), "valor" => String_Refatorar::parseStringToFloat($invoice['amount']), "multa" => $invoice['penalty'] ?: 0.00, "juros" => $invoice['fees'] ?: 0.00, "cliente_nome" => $invoice['payer'], "cliente_cpf_cnpj" => $invoice['doc_number'], "cliente_telefone" => $invoice['cell'] ?: "", "cliente_email" => $invoice['email'] ?: "teste@teste.com.br", "cliente_endereco" => $invoice['street'] ?: "...", "cliente_cidade" => $invoice['city'] ?: "...", "cliente_uf" => $invoice['state'] ?: "...", "cliente_cep" => $invoice['zip_code'] ?: "000", "TIPO" => $type, // "NUMERO_PARCELAS" => $invoice['payer'], "RECORRENCIA" => "0", "ENVIAR_EMAIL" => "0", "ENVIAR_SMS" => "0", "ENVIO_IMEDIATO" => "0", // "SPLIT" => [ // ['percentual'=>'25','email'=>'beneficiario1@email.com.br'], // ['percentual'=>'25','email'=>'beneficiario2@email.com.br'] // ], // "SPLIT_TIPO" => "D", "URL_CALLBACK" => domain('/public/automations/callback-orenda-pay'), "UTILIZACAO" => "ERP" ]; $charges = $this->getResponse($endPoint, $params); if ($charges->error) { throw new Exception($charges->error); } return current($charges->cobrancas); } public function createInvoicePix(array $invoice) { return $this->createInvoice($invoice, 'pix'); } public function createInvoiceBankSlip(array $invoice) { return $this->createInvoice($invoice, 'boleto'); } public function getInvoiceDetail(int $id) { $endPoint = "/cobranca/{$id}"; $charges = $this->getResponse($endPoint, [], 'GET'); if ($charges->msg) { throw new Exception($charges->msg); } return current($charges->cobrancas); } public function createTransfer(array $transfer) { if (empty($transfer['pix_key'])) { throw new Exception('Chave Pix é obrigatória para transferência.'); } $endPoint = "/pixout-init"; $params = [ "chave" => $transfer['pix_key'] ]; $response = $this->getResponse($endPoint, $params, 'POST'); if (empty($response->cod_favorito)) { throw new Exception('Chave Pix não encontrada no DICT.'); } $endPoint = "/pixout-process"; $params = [ "cod_favorito" => $response->cod_favorito, "valor" => abs($transfer['amount']), "descricao" => $transfer['description'] ]; return $this->getResponse($endPoint, $params, 'POST'); } }
💾 保存文件
← 返回文件管理器