PHP Classes

PHP ClearSale: Evaluate the risk of orders with ClearSale

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 46%Total: 225 All time: 8,192 This week: 196Up
Version License PHP version Categories
clearsale 1.0.1BSD License5.0.0PHP 5, E-Commerce, Web services
Description 

Author

This package is specific mainly for applications used in Brazil Brazil .

This class can be used to evaluate the risk of e-commerce orders with ClearSale.

It can take the details of an order items and payment form and it generates a URL of an iframe to display the evaluation of the ClearSale services and a series of buttons for the user take some decisions.

The class can generate HTML for a form input with the details of an item to be submitted to ClearSale.

It can also send a HTTP request to the ClearSale server to record the status of an order.

The class can also generate HTML to display a legend that explains to the user the meaning of the results of the analysis of an order returned by ClearSale.

In Portuguese:

Esta classe pode ser usada para avaliar o risco de pagamentos em sites de e-commerce, usando os serviços do ClearSale.

Devem ser enviados ao ClearSale os detalhes do pedido criado no site, a forma de pagamento, os dados de cobrança e entrega.

O ClearSale retorna o HTML de uma página, onde o nível de risco é exibido, além de botões para o usuário tomar decisões.

Por enquanto, as seguintes operações estão disponíveis:

- Obter o URL do frame de um pedido
- Criar item em um pedido
- Obter o URL de alteração do status de um pedido
- Alterar o status de um pedido
- Obter o HTML da legenda dos status de um pedido
- Obter o HTML da legenda dos níveis de risco

Innovation Award
PHP Programming Innovation award nominee
December 2013
Number 6


Prize: One subscription to the PDF edition of the PHP Architect magazine
One of the main risks for Web sites to take credit card payments, is that the payments be done with stolen cards, and so lose the payments when chargebacks happen.

This class can help detecting and preventing accepting fraudulent payments using the ClearSale Web services.

Manuel Lemos
Picture of Julio Cezar Kronbauer
  Performance   Level  
Name: Julio Cezar Kronbauer <contact>
Classes: 11 packages by
Country: Brazil Brazil
Age: 42
All time rank: 2171144 in Brazil Brazil
Week rank: 312 Up26 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php

require_once $_SERVER['DOCUMENT_ROOT'] . '/ClearSale/ClearSale.Class.php';

$ClearSale1 = new ClearSale;

switch (
$dados_pedido['forma_pagamento_bandeira']) {
    case
'visa':
       
$bandeira = CLEARSALE_CARTAO_VISA;
        break;

    case
'mastercard':
       
$bandeira = CLEARSALE_CARTAO_MASTERCARD;
        break;

    case
'diners':
       
$bandeira = CLEARSALE_CARTAO_DINERS;
        break;

    case
'amex':
    case
'american_express':
       
$bandeira = CLEARSALE_CARTAO_AMERICAN_EXPRESS;
        break;

    case
'hipercard':
       
$bandeira = CLEARSALE_CARTAO_HIPERCARD;
        break;

    case
'aura':
       
$bandeira = CLEARSALE_CARTAO_AURA;
        break;

    default:
       
$bandeira = CLEARSALE_CARTAO_OUTROS;
        break;
}

$url = $ClearSale1->getPedidoFrameURL(CLEARSALE_CODIGO_INTEGRACAO, $dados_pedido['id'], $dados_pedido['data_cadastro'], '', $dados_pedido['valor_pedido'], CLEARSALE_TIPO_PAGAMENTO_CARTAO_CREDITO, $bandeira, $dados_pedido['forma_pagamento_parcelas'],
   
                                     
$dados_pedido['cliente_nome'], $dados_pedido['cliente_email'], $dados_pedido['cpf_cnpj'], $dados_pedido['endereco_cobranca'],
                                     
$dados_pedido['numero_cobranca'], $dados_pedido['complemento_cobranca'], $dados_pedido['bairro_cobranca'],
                                     
$dados_pedido['cidade_cobranca'], $dados_pedido['uf_cobranca'], $dados_pedido['cep_cobranca'],
                                     
$dados_pedido['pais_cobranca'], $dados_pedido['ddd_telefone_cobranca'], $dados_pedido['telefone_cobranca'],
                                     
$dados_pedido['ddd_celular_cobranca'], $dados_pedido['celular_cobranca'],
                                     
                                     
$dados_pedido['cliente_nome'], $dados_pedido['cliente_email'], $dados_pedido['cpf_cnpj'], $dados_pedido['endereco_entrega_endereco'],
                                     
$dados_pedido['endereco_entrega_numero'], $dados_pedido['endereco_entrega_complemento'], $dados_pedido['endereco_entrega_bairro'],
                                     
$dados_pedido['endereco_entrega_cidade'], $dados_pedido['endereco_entrega_estado'], $dados_pedido['endereco_entrega_cep'],
                                     
$dados_pedido['endereco_entrega_pais'], $dados_pedido['ddd_telefone_cobranca'], $dados_pedido['telefone_cobranca'],
                                     
$dados_pedido['ddd_celular_cobranca'], $dados_pedido['celular_cobranca']);

?><span class="ClearSale">
    <input type="hidden" class="pedidoStatusURL" value="<?php echo $url ?>" />
    <iframe id="ClearSale_iframe" src="<?php echo $url ?>" width="<?php echo CLEARSALE_PEDIDO_FRAME_WIDTH ?>" height="<?php echo CLEARSALE_PEDIDO_FRAME_HEIGHT ?>" frameborder="0" scrolling="no"><a href="<?php echo $url ?>"><?php echo $url ?></a></iframe><?php

   
echo $ClearSale1->getNivelRiscoLegenda('NivelRisco-legenda');
    echo
$ClearSale1->getPedidoStatusLegenda('PedidoStatus-legenda');

   
?>Alterar status:<br/>
    <input type="radio" onclick="ClearSale_setPedidoStatus(<?php echo $dados_pedido['id'] ?>, this.value)" name="clearsale_pedido_status" value="<?php echo CLEARSALE_PEDIDO_STATUS_CANCELADO_CLIENTE ?>" id="clearsale_pedido_status_<?php echo CLEARSALE_PEDIDO_STATUS_CANCELADO_CLIENTE ?>" /><label for="clearsale_pedido_status_<?php echo CLEARSALE_PEDIDO_STATUS_CANCELADO_CLIENTE ?>">Cancelado pelo cliente</label><br/>
    <input type="radio" onclick="ClearSale_setPedidoStatus(<?php echo $dados_pedido['id'] ?>, this.value)" name="clearsale_pedido_status" value="<?php echo CLEARSALE_PEDIDO_STATUS_SUSPEITO ?>" id="clearsale_pedido_status_<?php echo CLEARSALE_PEDIDO_STATUS_SUSPEITO ?>" /><label for="clearsale_pedido_status_<?php echo CLEARSALE_PEDIDO_STATUS_SUSPEITO ?>">Suspeito</label><br/>
    <input type="radio" onclick="ClearSale_setPedidoStatus(<?php echo $dados_pedido['id'] ?>, this.value)" name="clearsale_pedido_status" value="<?php echo CLEARSALE_PEDIDO_STATUS_APROVADO ?>" id="clearsale_pedido_status_<?php echo CLEARSALE_PEDIDO_STATUS_APROVADO ?>" /><label for="clearsale_pedido_status_<?php echo CLEARSALE_PEDIDO_STATUS_APROVADO ?>">Aprovado</label><br/>
    <input type="radio" onclick="ClearSale_setPedidoStatus(<?php echo $dados_pedido['id'] ?>, this.value)" name="clearsale_pedido_status" value="<?php echo CLEARSALE_PEDIDO_STATUS_FRAUDE_CONFIRMADA ?>" id="clearsale_pedido_status_<?php echo CLEARSALE_PEDIDO_STATUS_FRAUDE_CONFIRMADA ?>" /><label for="clearsale_pedido_status_<?php echo CLEARSALE_PEDIDO_STATUS_FRAUDE_CONFIRMADA ?>">Fraude confirmada</label><br/>
    <input type="radio" onclick="ClearSale_setPedidoStatus(<?php echo $dados_pedido['id'] ?>, this.value)" name="clearsale_pedido_status" value="<?php echo CLEARSALE_PEDIDO_STATUS_REPROVADO ?>" id="clearsale_pedido_status_<?php echo CLEARSALE_PEDIDO_STATUS_REPROVADO ?>" /><label for="clearsale_pedido_status_<?php echo CLEARSALE_PEDIDO_STATUS_REPROVADO ?>">Reprovado</label>
    <div class="loading"></div>
</span>

<script type="text/javascript">
<!--
    /* Função para atualizar o status do pedido no ClearSale */
ClearSale_setPedidoStatus = function (id_pedido, status) {
    try { ClearSale_setPedidoStatus_XMLHTTP.abort(); } catch (e) {}

    ClearSale_setPedidoStatus_XMLHTTP = $j.ajax({
        type: "POST",
        url: "SetaStatusPedido.php",
        data: "id=" + id_pedido + "&status=" + status,
        dataType: "html",
        error: function (HTML) {
            alert("Erro!");
        },
        success: function (result) {
            switch (result) {
                case "<?php echo CLEARSALE_PEDIDO_STATUS_RESPONSE_OK ?>":
                    document.getElementById("ClearSale_iframe").src = $j(".ClearSale .pedidoStatusURL").val() + "&amp;var=" + Math.random();
                    break;

                default:
                    alert("Erro " + result);
                    break;
            }
          }
       });
}
/* ===================================================== */
-->
</script>

<style type="text/css">
.ClearSale .PedidoStatus-legenda,
.ClearSale .NivelRisco-legenda {
    display: block;
    float: left;
    margin: 0px 0px 0px 10px;
    border: 1px solid #D4D4D4;
}

.ClearSale .PedidoStatus-legenda { margin-right: 10px; }

.ClearSale .PedidoStatus-legenda,
.ClearSale .PedidoStatus-legenda tr th,
.ClearSale .PedidoStatus-legenda tr td,
.ClearSale .NivelRisco-legenda,
.ClearSale .NivelRisco-legenda tr th,
.ClearSale .NivelRisco-legenda tr td { border: 1px solid #D4D4D4; }

.ClearSale .PedidoStatus-legenda,
.ClearSale .NivelRisco-legenda { border-right: none; border-bottom: none; }

.ClearSale .PedidoStatus-legenda tr th,
.ClearSale .PedidoStatus-legenda tr td,
.ClearSale .NivelRisco-legenda tr th,
.ClearSale .NivelRisco-legenda tr td {
    padding: 2px;
    border-top: none;
    border-left: none;
    background-color: #fff;
}

.ClearSale .PedidoStatus-legenda tr th,
.ClearSale .NivelRisco-legenda tr th { text-align: center; background-color: #868686; color: #fff; font-weight: bolder; }

.ClearSale .PedidoStatus-legenda tr td:first-child { text-align: right; background-color: #868686; color: #fff; font-weight: bolder; }
.ClearSale .PedidoStatus-legenda tr td:last-child { text-align: left; }

.ClearSale .NivelRisco-legenda tr td { padding: 5px; text-align: left; color: #fff; }

.ClearSale .loading {
    display: none;
    width: 220px;
    height: 19px;
    background-image: url('../images/loading1.gif');
    background-repeat: no-repeat;
    background-position: center center;
}
</style>


  Files folder image Files  
File Role Description
Plain text file ClearSale.Class.php Class The main file
Accessible without login Plain text file UserInterface.php Example Exemplo de interface para o usuário
Accessible without login Plain text file SetaStatusPedido.php Example Envia comando à ClearSale para alterar o status de um pedido

 Version Control Unique User Downloads Download Rankings  
 0%
Total:225
This week:0
All time:8,192
This week:196Up
User Ratings User Comments (1)
 All time
Utility:66%StarStarStarStar
Consistency:66%StarStarStarStar
Documentation:-
Examples:66%StarStarStarStar
Tests:-
Videos:-
Overall:46%StarStarStar
Rank:3128