PHP Classes
elePHPant
Icontem

File: Example.php

Recommend this page to a friend!
  Classes of Julio Cezar Kronbauer  >  PHP Koin  >  Example.php  >  Download  
File: Example.php
Role: Example script
Content type: text/plain
Description: Exemplo de uso
Class: PHP Koin
Send payment order requests to the Koin API
Author: By
Last change:
Date: 5 years ago
Size: 2,835 bytes
 

 

Contents

Class file image Download
<?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>