Пример #1
5
 public static function authFromEnv()
 {
     $apiKey = getenv('IUGU_API_KEY');
     if ($apiKey) {
         Iugu::setApiKey($apiKey);
     }
 }
Пример #2
1
 public function request($method, $url, $data = array())
 {
     global $iugu_last_api_response_code;
     if (Iugu::getApiKey() == null) {
         Iugu_Utilities::authFromEnv();
     }
     if (Iugu::getApiKey() == null) {
         throw new IuguAuthenticationException("Chave de API não configurada. Utilize Iugu::setApiKey(...) para configurar.");
     }
     $headers = $this->_defaultHeaders();
     list($response_body, $response_code) = $this->requestWithCURL($method, $url, $headers, $data);
     $response = json_decode($response_body);
     if (json_last_error() != JSON_ERROR_NONE) {
         throw new IuguObjectNotFound($response_body);
     }
     if ($response_code == 404) {
         throw new IuguObjectNotFound($response_body);
     }
     if (isset($response->errors)) {
         if (gettype($response->errors) != "string" && count(get_object_vars($response->errors)) == 0) {
             unset($response->errors);
         } else {
             if (gettype($response->errors) != "string" && count(get_object_vars($response->errors)) > 0) {
                 $response->errors = (array) $response->errors;
             }
         }
         if (isset($response->errors) && gettype($response->errors) == "string") {
             $response->errors = $response->errors;
         }
     }
     $iugu_last_api_response_code = $response_code;
     return $response;
 }
Пример #3
0
<?php

require_once "Iugu.php";
Iugu::setApiKey($_POST['api_token']);
$criar = Iugu_Invoice::create(array("email" => $_POST['email'], "due_date" => $_POST['due_date'], "return_url" => $_POST['return_url'], "expired_url" => $_POST['expired_url'], "notification_url" => $_POST['notification_url'], "custom_variables" => $_POST['custom_variables'], "items" => $_POST['items'], "ignore_due_email" => true));
if ($criar->secure_url) {
    $retorno = array('status' => 'success', 'url' => $criar->secure_url);
} else {
    $retorno = array('status' => 'error');
}
echo json_encode($retorno);
Пример #4
0
 public static function setApiKey($_api_key)
 {
     self::$api_key = $_api_key;
 }
 public function confirm()
 {
     //5 = Falha no Pagamento
     $this->log->write('Pagamento iugu Boleto - Dentro do confirm()');
     //Carregando os models e linguagem
     $this->load->model('checkout/order');
     $this->load->model('account/customer');
     $this->load->model('payment/iugu_bankslip');
     $this->language->load('payment/iugu_bankslip');
     //Dados do Pedido
     $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
     $cliente = $this->model_account_customer->getCustomer($order_info['customer_id']);
     $produtos = $this->cart->getProducts();
     //Token de Segurança
     Iugu::setApiKey($this->config->get('iugu_bankslip_token'));
     //Montando Dados
     $name = trim($order_info['payment_firstname']) . ' ' . trim($order_info['payment_lastname']);
     $email = trim($order_info['email']);
     //Produtos
     foreach ($produtos as $product) {
         $options_names = '';
         foreach ($product['option'] as $option) {
             $options_names .= ' - ' . $option['name'] . ': ' . $option['option_value'];
         }
         //Até 80 caracteres para a descrição do Produto
         $description = mb_substr($product['name'] . $options_names, 0, 80, 'UTF-8');
         if ($this->currency->format($product['price'], $order_info['currency_code'], false, false) * 100 >= 1) {
             $item[] = array('description' => $description, 'quantity' => $product['quantity'], 'price_cents' => $this->currency->format($product['price'], $order_info['currency_code'], false, false) * 100);
         }
     }
     $desconto = 0;
     $taxa_extra = $this->currency->format($order_info['total'] - $this->cart->getSubTotal(), $order_info['currency_code'], false, false) * 100;
     if ($taxa_extra >= 1) {
         $item[] = array('description' => $this->language->get('text_extra_amount'), 'quantity' => 1, 'price_cents' => $taxa_extra);
     } else {
         $desconto = abs($taxa_extra);
     }
     $this->log->write('Pagamento iugu Boleto - Dados adicionados');
     //PASSO 1
     //Criando Cliente
     //Verificando se existe o cliente cadastrado
     if (empty($cliente['iugu_customer_id'])) {
         //Criando Cliente na iugu
         $this->log->write('Pagamento iugu Boleto - Criando cliente');
         $cliente = Iugu_Customer::create(array("email" => $email, "name" => $name));
         //Adicionando cliente ao Banco de Dados
         if (!empty($cliente['id'])) {
             $this->log->write('Pagamento iugu Boleto - Adicionando referência do cliente ao Banco. ID = ' . $cliente['id']);
             $this->db->query("UPDATE `" . DB_PREFIX . "customer`\r\n              SET iugu_customer_id= '" . $cliente['id'] . "'\r\n              WHERE customer_id = '" . $order_info['customer_id'] . "' ");
             $this->log->write('Pagamento iugu Boleto - Adicionado iugu_customer_id');
         }
     } else {
         $cliente['id'] = $cliente['iugu_customer_id'];
     }
     //Passo 2
     //Criando Boleto
     $this->log->write('Pagamento iugu Boleto - Criando o Boleto');
     if ($this->config->get('iugu_bankslip_cobrança') == 1) {
         $cobranca = 'false';
     } else {
         $cobranca = 'true';
     }
     $p = Iugu_Invoice::create(array("email" => $email, "due_date" => date('Y-m-d', strtotime("+" . $this->config->get('iugu_bankslip_vencimento') . " days")), "items" => $item, "return_url" => $this->url->link('checkout/success', '', 'SSL'), "expired_url" => $this->url->link('checkout/success', '', 'SSL'), "notification_url" => $this->url->link('payment/iugu_bankslip/callback', '', 'SSL'), "discount_cents" => $desconto, "customer_id" => $cliente['id'], "ignore_due_email" => $cobranca));
     //Verificando se Boleto foi criado com sucesso
     if (!empty($p['id']) and !empty($p['secure_url'])) {
         $this->log->write('Pagamento iugu Boleto - Boleto Criado com sucesso');
         $url = $p['secure_url'] . '.pdf?bs=true';
         $boleto = array('url' => $url, 'total' => 'R$ ' . number_format($this->currency->format($order_info['total'], $order_info['currency_code'], false, false), 2, ',', ''), 'barcodel' => $p['bank_slip']->digitable_line, 'barcode' => $p['bank_slip']->barcode);
         $pagamento = "\r\n            Se não tiver pago, abra o Boleto abaixo para pagar<br>\r\n            <a href='{$url}' rel='nofollow' target='_blank'><img src='image/iugu/imprimir-boleto.png'></a>\r\n        ";
         //Confirmando Pedido
         $this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('iugu_bankslip_order_aguardando_pagamento'), $pagamento, true);
         $this->db->query("UPDATE `" . DB_PREFIX . "order` SET iugu_order_id = '" . $p['id'] . "' WHERE order_id = '" . (int) $this->session->data['order_id'] . "'");
         //Adicionando dados do Boleto na sessão, para ser usado no Confirmar
         $this->session->data['boleto'] = $boleto;
         $this->log->write('Pagamento iugu Boleto - Retornando URL do Sucesso');
         echo $this->url->link('checkout/iugu_success');
     } else {
         $this->log->write('Pagamento iugu Boleto - Criação da Fatura falhou');
         echo 5;
     }
 }
Пример #6
0
<?php

if ($_POST['event'] == "invoice.status_changed") {
    include "../../../dbconnect.php";
    include "../../../includes/functions.php";
    include "../../../includes/gatewayfunctions.php";
    include "../../../includes/invoicefunctions.php";
    require_once "../iugu/Iugu.php";
    $gatewaymodule = "iugu";
    $GATEWAY = getGatewayVariables($gatewaymodule);
    if (!$GATEWAY["type"]) {
        die("Module Not Activated");
    }
    $post_iugu = array("event" => $_POST['event'], "id" => $_POST["data"]["id"], "status" => $_POST["data"]["status"]);
    Iugu::setApiKey($GATEWAY["api_token"]);
    $consultar = Iugu_Invoice::fetch($_POST["data"]["id"]);
    $valor = explode("R\$ ", $consultar->paid);
    $taxa = explode("R\$ ", $consultar->taxes_paid);
    $status = $consultar->status;
    $amount = str_replace(",", ".", $valor[1]);
    $fee = str_replace(",", ".", $taxa[1]);
    foreach ($consultar->variables as $variavel) {
        if ($variavel->variable == "payment_data.transaction_number") {
            $transid = $variavel->value;
        }
    }
    foreach ($consultar->custom_variables as $variavel) {
        if ($variavel->name == "invoice_id") {
            $invoiceid = $variavel->value;
        }
    }
Пример #7
-1
 public static function endpointAPI($object = NULL, $uri_path = "")
 {
     $path = "";
     if (is_string($object)) {
         $path = "/" . $object;
     } else {
         if (is_object($object) && isset($object["id"])) {
             $path = "/" . $object["id"];
         }
     }
     return Iugu::getBaseURI() . $uri_path . "/" . self::objectBaseURI() . $path;
 }