Clicky

Jump to content
Portal do Host
  • Sign Up

Sign in to follow this  
traysistemas

duvida código

Recommended Posts

fechei

O erro aparece quando clica para enviar, isto ?


Ajude o fórum! Antes de postar, leiam as regras de postagem aqui.

Share this post


Link to post
Share on other sites
<?php

function gerencianetboleto_config()
{
    $configarray = array(
        "FriendlyName"     => array("Type" => "System", "Value" => "Fortunus"),
        "username"         => array("FriendlyName" => "Token", "Type" => "text", "Size" => "40",),
        "configVencimento" => array(
            "FriendlyName" => "Configurações de Vencimento",
            "Type"         => "yesno",
            "Description"  => "Utilizar configurações de vencimento da GerênciaNet (vencimento informado no WHMCS é ignorado)",
        )
    );
    return $configarray;
}

function gerencianetboleto_link($params)
{
    $urlCallback = $params['systemurl'] . '/modules/gateways/callback/gerencianetboleto.php';

    //data
    $table       = "tblinvoices";
    $fields      = "duedate, userid";
    $where       = array(
        "id" => $params['invoiceid'],
    );
    $sort        = "id";
    $sortorder   = "ASC";
    $limits      = "1";
    $result      = select_query($table, $fields, $where, $sort, $sortorder, $limits);
    $invoiceData = mysql_fetch_array($result);

    $duedate       = $invoiceData['duedate'];
    $camposDueDate = explode('-', $duedate);
    $novoDueDate   = $camposDueDate[2] . '/' . $camposDueDate[1] . '/' . $camposDueDate[0];
    $userId        = $invoiceData['userid'];

    //data - tblclients
    $table       = 'tblclients';
    $fields      = 'id,firstname,lastname,email, address1, address2, city, state, postcode';
    $where       = array(
        'id' => $userId
    );
    $sort        = 'id';
    $sortorder   = "ASC";
    $limits      = 1;
    $usuario     = select_query($table, $fields, $where, $sort, $sortorder, $limits);
    $usuarioData = mysql_fetch_array($usuario);

$postcode = preg_replace("/[()-._]/", '', $usuarioData['postcode']);
if ( strlen($usuarioData['state']) != 2 ) {
$state = '';
} else {
$state = $usuarioData['state'];
}

    $xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><boleto></boleto>');

$xml->addChild('token', $params['username']);
    $clientes = $xml->addChild('clientes');
    $cliente = $clientes->addChild('cliente');
$nomeRazaoSocial = $cliente->addChild('nomeRazaoSocial');
gerencianetboleto_addCData($nomeRazaoSocial, $usuarioData['firstname'] . ' ' . $usuarioData['lastname']);

$opcionais = $cliente->addChild('opcionais');
    $email = $opcionais->addChild('email');
gerencianetboleto_addCData($email, $usuarioData['email']);

$cep = preg_replace("/[()-.]/", "", $order_info['payment_postcode']);
$opcionais->addChild('cep', $postcode);

$rua = $opcionais->addChild('rua');
gerencianetboleto_addCData($rua, $usuarioData['address1']);
$complemento = $opcionais->addChild('complemento');
gerencianetboleto_addCData($complemento, $usuarioData['address2']);

$opcionais->addChild('estado', $state);
$cidade = $opcionais->addChild('cidade');
gerencianetboleto_addCData($cidade, $usuarioData['city']);

$opcionais->addChild('retorno', 'whmcs_' . $params['invoiceid']);

$itens = $xml->addChild('itens');

//data - itens
    $table     = "tblinvoiceitems";
    $fields    = "description,amount";
    $where     = array(
        "invoiceid" => $params['invoiceid'],
    );
    $sort      = "id";
    $sortorder = "ASC";
    $limits    = "";
    $result    = select_query($table, $fields, $where, $sort, $sortorder, $limits);

$totalItem = 0;
    while ($data = mysql_fetch_array($result)) {
$item = $itens->addChild('item');
$descricaoItem = $item->addChild('descricao');
gerencianetboleto_addCData($descricaoItem, str_replace("'", "", $data['description']));

$valorItem = preg_replace("/[.,-]/","", $data['amount']);
$totalItem += $valorItem;

$item->addChild('valor', $valorItem);
$item->addChild('qtde', 1);
    }

if ($params['configVencimento'] != 'on') {
$xml->addChild('vencimento', $novoDueDate);
}

$valor = preg_replace("/[.,-]/", "", $params['amount']);
$desconto = $totalItem - $valor;

if ($desconto > 0) {
$bOpcionais = $xml->addChild('opcionais');
$bOpcionais->addChild('descontoSobreTotal', $desconto);
}

$xmlParaEnvio = $xml->saveXML();

    $code = "<form method='post' action='https://integracao.gerencianet.com.br/whmcs/emitir'>
    <input type='hidden' name='entrada' value='" . $xmlParaEnvio . "' />
<input type='hidden' name='callback' value='" . $urlCallback . "' />
<input type='hidden' name='versao' value='2.0' />
<input type='hidden' name='tipo' value='boleto' />
<input type='hidden' name='token' value='". $params['username'] . "' />
<input type='hidden' name='valor' value='". $valor . "' />
<input type='hidden' name='configVencimento' value='". $params['configVencimento'] . "' />
<input type='hidden' name='vencimento' value='". $novoDueDate . "' />
    <input type='submit' value='Realizar Pagamento' />

</form>";

    return $code;
}

function gerencianetboleto_addCData($path, $string) {
  $dom = dom_import_simplexml($path);
  $cdata = $dom->ownerDocument->createCDATASection($string);
  $dom->appendChild($cdata);
}

Carlos Alves

Share this post


Link to post
Share on other sites

@traysistemas, funcionou aqui. Veja: Eu apenas deixei a função de enviar padrão ocultada, assim o botão lê a função enviar.

<?php

function gerencianetboleto_config()
{
    $configarray = array(
        "FriendlyName"     => array("Type" => "System", "Value" => "Fortunus"),
        "username"         => array("FriendlyName" => "Token", "Type" => "text", "Size" => "40",),
        "configVencimento" => array(
            "FriendlyName" => "Configurações de Vencimento",
            "Type"         => "yesno",
            "Description"  => "Utilizar configurações de vencimento da GerênciaNet (vencimento informado no WHMCS é ignorado)",
        )
    );
    return $configarray;
}

function gerencianetboleto_link($params)
{
    $urlCallback = $params['systemurl'] . '/modules/gateways/callback/gerencianetboleto.php';

    //data
    $table       = "tblinvoices";
    $fields      = "duedate, userid";
    $where       = array(
        "id" => $params['invoiceid'],
    );
    $sort        = "id";
    $sortorder   = "ASC";
    $limits      = "1";
    $result      = select_query($table, $fields, $where, $sort, $sortorder, $limits);
    $invoiceData = mysql_fetch_array($result);

    $duedate       = $invoiceData['duedate'];
    $camposDueDate = explode('-', $duedate);
    $novoDueDate   = $camposDueDate[2] . '/' . $camposDueDate[1] . '/' . $camposDueDate[0];
    $userId        = $invoiceData['userid'];

    //data - tblclients
    $table       = 'tblclients';
    $fields      = 'id,firstname,lastname,email, address1, address2, city, state, postcode';
    $where       = array(
        'id' => $userId
    );
    $sort        = 'id';
    $sortorder   = "ASC";
    $limits      = 1;
    $usuario     = select_query($table, $fields, $where, $sort, $sortorder, $limits);
    $usuarioData = mysql_fetch_array($usuario);

$postcode = preg_replace("/[()-._]/", '', $usuarioData['postcode']);
if ( strlen($usuarioData['state']) != 2 ) {
$state = '';
} else {
$state = $usuarioData['state'];
}

    $xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><boleto></boleto>');

$xml->addChild('token', $params['username']);
    $clientes = $xml->addChild('clientes');
    $cliente = $clientes->addChild('cliente');
$nomeRazaoSocial = $cliente->addChild('nomeRazaoSocial');
gerencianetboleto_addCData($nomeRazaoSocial, $usuarioData['firstname'] . ' ' . $usuarioData['lastname']);

$opcionais = $cliente->addChild('opcionais');
    $email = $opcionais->addChild('email');
gerencianetboleto_addCData($email, $usuarioData['email']);

$cep = preg_replace("/[()-.]/", "", $order_info['payment_postcode']);
$opcionais->addChild('cep', $postcode);

$rua = $opcionais->addChild('rua');
gerencianetboleto_addCData($rua, $usuarioData['address1']);
$complemento = $opcionais->addChild('complemento');
gerencianetboleto_addCData($complemento, $usuarioData['address2']);

$opcionais->addChild('estado', $state);
$cidade = $opcionais->addChild('cidade');
gerencianetboleto_addCData($cidade, $usuarioData['city']);

$opcionais->addChild('retorno', 'whmcs_' . $params['invoiceid']);

$itens = $xml->addChild('itens');

//data - itens
    $table     = "tblinvoiceitems";
    $fields    = "description,amount";
    $where     = array(
        "invoiceid" => $params['invoiceid'],
    );
    $sort      = "id";
    $sortorder = "ASC";
    $limits    = "";
    $result    = select_query($table, $fields, $where, $sort, $sortorder, $limits);

$totalItem = 0;
    while ($data = mysql_fetch_array($result)) {
$item = $itens->addChild('item');
$descricaoItem = $item->addChild('descricao');
gerencianetboleto_addCData($descricaoItem, str_replace("'", "", $data['description']));

$valorItem = preg_replace("/[.,-]/","", $data['amount']);
$totalItem += $valorItem;

$item->addChild('valor', $valorItem);
$item->addChild('qtde', 1);
    }

if ($params['configVencimento'] != 'on') {
$xml->addChild('vencimento', $novoDueDate);
}

$valor = preg_replace("/[.,-]/", "", $params['amount']);
$desconto = $totalItem - $valor;

if ($desconto > 0) {
$bOpcionais = $xml->addChild('opcionais');
$bOpcionais->addChild('descontoSobreTotal', $desconto);
}

$xmlParaEnvio = $xml->saveXML();

    $code = "<form method='post' action='https://integracao.gerencianet.com.br/whmcs/emitir'>
    <input type='hidden' name='entrada' value='" . $xmlParaEnvio . "' />
<input type='hidden' name='callback' value='" . $urlCallback . "' />
<input type='hidden' name='versao' value='2.0' />
<input type='hidden' name='tipo' value='boleto' />
<input type='hidden' name='token' value='". $params['username'] . "' />
<input type='hidden' name='valor' value='". $valor . "' />
<input type='hidden' name='configVencimento' value='". $params['configVencimento'] . "' />
<input type='hidden' name='vencimento' value='". $novoDueDate . "' />
<!-- <input type='submit' value='Realizar Pagamento' /> -->
  <input type="image" src="http://www.linhadecodigo.com.br/artigos/img_artigos/AndersonWeschnhoski/BotaoCSS3/botaoCSS301.jpg" alt="Enviar" />

</form>";

    return $code;
}

function gerencianetboleto_addCData($path, $string) {
  $dom = dom_import_simplexml($path);
  $cdata = $dom->ownerDocument->createCDATASection($string);
  $dom->appendChild($cdata);
}

Ajude o fórum! Antes de postar, leiam as regras de postagem aqui.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.



×
×
  • Create New...