PHP code example of doocacommerce / paghiper-php-sdk

1. Go to this page and download the library: Download doocacommerce/paghiper-php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

doocacommerce / paghiper-php-sdk example snippets


     

    \PagHipperSDK\Auth::init(
        '{api_key}',
        '{token}'
    );
    

    $pagHiper = new \PagHipperSDK\PagHiper();
    $items = [];
    $items[] = (new \PagHipperSDK\Entities\Item())
        ->setItemId('1')
        ->setDescription('Descrição do produto')
        ->setQuantity(1)
        ->setPriceCents(30.00);
    
    $payer = (new \PagHipperSDK\Entities\Payer())
        ->setPayerEmail('[email protected]')
        ->setPayerName('Webmaster Dooca')
        ->setPayerCpfCnpj('11144477735')
        ->setPayerPhone('5139393660')
        ->setPayerStreet('Rua Sapiranga')
        ->setPayerNumber(90)
        ->setPayerComplement('Sala 204')
        ->setPayerDistrict('Mauá')
        ->setPayerCity('Novo Hamburgo')
        ->setPayerState('RS')
        ->setPayerZipCode(93548192);
    
    $transaction = (new \PagHipperSDK\Entities\Transaction())
        ->setOrderId('TESTE-' . rand(0, 10000))
        ->setNotificationUrl('https://url-de-notificaca.example')
        ->setDiscountCents(10.00)
        ->setShippingPriceCents(19.90)
        ->setShippingMethods('PAC')
        ->setFixedDescription(true)
        ->setDaysDueDate('3')
        ->setPayer($payer)
        ->setItems($items);
    
    try {
        $transaction = $pagHiper->createTransaction($transaction);
    } catch (\PagHipperSDK\Exception\ErrorException $e) {
        // Exception normalmente gerada pelo retorno do PagHiper
        echo $e->getMessage();
        die;
    } catch (Exception $e) {
        // Outras Exceptions, Auth e Invalid Arguments
        echo $e->getMessage();
        die;
    }