PHP Classes

PHP Koin: Send payment order requests to the Koin API

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 81 All time: 10,095 This week: 524Up
Version License PHP version Categories
koin 1.0BSD License5.0PHP 5, E-Commerce, Web services
Description 

Author

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

This class can send payment order requests to Koin API.

It takes the details for the payment of a shopping order, like the items being purchased, the buyer details, and shipping address.

The class can send a HTTP request to the Koin API to submit the order payment and retrieves the results of whether the transaction was accepted or denied.

In Portuguese:

A Koin é uma empresa brasileira que opera um sistema de pagamento onde o usuário paga depois de receber a mercadoria.

A loja virtual disponibiliza a forma de pagamento Koin. Quando o usuário a seleciona e finaliza o pedido, é feita uma análise de crédito em tempo real, usando os dados do comprador cadastrados na loja, e a Koin autoriza ou não a transação.

Se a compra é autorizada, a Koin envia um boleto bancário para o comprador pagar a mercadoria, e a loja recebe o valor da transação subtraída de uma taxa de operação.

Picture of Julio Cezar Kronbauer
  Performance   Level  
Name: Julio Cezar Kronbauer <contact>
Classes: 11 packages by
Country: Brazil Brazil
Age: 42
All time rank: 2172145 in Brazil Brazil
Week rank: 215 Up19 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php

include dirname(__FILE__) . '/Koin.Class.php';

$ConsumerKey = 'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC';
$SecretKey = 'SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS';
$Reference = rand();
$FraudID = isset($_POST['FraudID']) ? $_POST['FraudID'] : (isset($_GET['FraudID']) ? $_GET['FraudID'] : '');

if (
strlen($FraudID)) {
   
// Requisição de compra //
   
$Koin = new Koin;

   
$Koin->addItem('CODITEM01', 'TV LED', 'Eletronico', 3, 2199.90, array(0 => Koin::getItemAttribute('Tamanho', 43), 1 => Koin::getItemAttribute('Cor', 'Preta'), 2 => Koin::getItemAttribute('Peso', '7 kg')));
   
$Koin->addItem('CODITEM02', 'PlayStation 4', 'Games', 1, 3999.90);

   
$Koin->setBuyerInfo('Nome do comprador', KOIN_BUYER_TYPE_PESSOA_FISICA, 'emailcomprador@email.com',
                        array(
0 => Koin::getBuyerDocument(KOIN_BUYER_DOCUMENT_CPF_KEY_NAME, '123.456.798-91'), 1 => Koin::getBuyerDocument(KOIN_BUYER_DOCUMENT_RG_KEY_NAME, '1703912312')),
                        array(
0 => Koin::getBuyerAdditionalInfo(KOIN_BUYER_ADDITIONAL_INFO_BIRTHDAY_KEY_NAME, '1988-08-02'), 1 => Koin::getBuyerAdditionalInfo(KOIN_BUYER_ADDITIONAL_INFO_MOTHERNAME_KEY_NAME, 'Fulana de Souza')),
                        array(
0 => Koin::getPhone(11, '1111-1111', KOIN_PHONE_TYPE_COMERCIAL), 1 => Koin::getPhone(21, '2222-2222', KOIN_PHONE_TYPE_RESIDENCIAL)),
                       
Koin::getAddress('Brasil', 'SP', 'São Paulo', 'Santa Cecilia', '01231-154', 'Rua Dr Albuquerque Lins', 145, NULL, KOIN_ADDRESS_TYPE_RESIDENCIAL),
                       
$_SERVER['REMOTE_ADDR'], false, false);

   
$Koin->setShippingInfo(KOIN_SHIPPING_TYPE_CORREIOS, '2014-06-27',
                          
Koin::getAddress('Brasil', 'SP', 'São Paulo', 'Santa Cecilia', '01230-000', 'Rua Dr Albuquerque Lins', 683, '2 andar, fundos', KOIN_ADDRESS_TYPE_COMERCIAL),
                          
149.57);

   
$result = $Koin->orderRequest($ConsumerKey, $SecretKey, $FraudID, $Reference);

    echo (
$result['OK'] ? 'Compra efetuada com sucesso!' : 'Erro ' . $result['Code'] . ': ' . htmlentities($result['Message'])) .
         (
count($result['AdditionalInfo']) ? '<br/><br/>Informa&ccedil;&otilde;es Adicionais:<br/>' . implode('<br/>', $result['AdditionalInfo']) : '');
   
// ==================== //
}

?><html>
<head>
    <script type="text/javascript" src="<?php echo KOIN_FRAUDID_JS_URL ?>"></script>

    <style type="text/css">
        #koin-frame { display: none; }
    </style>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
    Koin FraudID: <input type="text" name="FraudID" value="" size="32" readonly />
    <input type="submit" value="Send" />
</form>

<script type="text/javascript">
<!--
    <?php echo KOIN_FRAUDID_JS_FUNCTION ?> (function (GUID) {
        document.forms[0].FraudID.value = GUID;
    });

    document.forms[0].onsubmit = function () {
        if (!document.forms[0].FraudID.value.length) alert('Invalid Koin FraudID!');
    }
-->
</script>
</body>
</html>


  Files folder image Files (3)  
File Role Description
Files folder imagejs (1 file)
Plain text file Koin.Class.php Class The main file
Accessible without login Plain text file Example.php Example Exemplo de uso

  Files folder image Files (3)  /  js  
File Role Description
  Accessible without login Plain text file koin.php Aux. This script is for secure pages include, because KOIN_FRAUDID_JS_URL doesn't have a https version

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:81
This week:0
All time:10,095
This week:524Up