PHP code example of kubinyete / pagseguro-edi

1. Go to this page and download the library: Download kubinyete/pagseguro-edi 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/ */

    

kubinyete / pagseguro-edi example snippets




// Provided user
$credentialsUsername = getenv('USER');
// Provider secret token
$credentialsToken = getenv('TOKEN');

// Selected environment (production only)
$environment = \Kubinyete\Edi\PagSeguro\Core\PagSeguroEdiEnvironment::production();
// Selected EDI version (prefer latest)
$version = \Kubinyete\Edi\PagSeguro\Core\PagSeguroEdiClient::VERSION_LATEST;

$client = new \Kubinyete\Edi\PagSeguro\Core\PagSeguroEdiClient(
    env: $environment, 
    clientId: $credentialsUsername, token: $credentialsToken, 
    version: $version
);

// Creates a new paginator for any transactional movements from today, fetching every page with size 500
$paginator = $client->getTransactionalMovements(date: new DateTime('now'), pageSize: 500);

// Iterating over every page available
foreach ($paginator as $item) {
    // You can also manually configure or extract attributes from our paginator object
    echo "Found movement code {$item->getMovimentoApiCodigo()} on page {$paginator->getPage()}/{$paginator->getTotalPages()}" . PHP_EOL;
}

// Manually fetching first page
$paginator->setPage(1);
$items = $paginator-getItems();

// Increment +1 page
$paginator->incrementPage();
$items = $paginator-getItems();

// Decrement -1 page
$paginator->decrementPage();
$items = $paginator-getItems();

// Manually iterating (without an iterator)
while ($items = $paginator->nextItems()) {
    echo "Found movement code {$item->getMovimentoApiCodigo()} on page {$paginator->getPage()}/{$paginator->getTotalPages()}" . PHP_EOL;
}

// Creates a new paginator for any finantial movements from today, fetching every page with size 500
$paginator = $client->getFinantialMovements(date: new DateTime('now'), pageSize: 500);

// Iterating over every page available
foreach ($paginator as $item) {
    // You can also manually configure or extract attributes from our paginator object
    echo "Found movement code {$item->getMovimentoApiCodigo()} on page {$paginator->getPage()}/{$paginator->getTotalPages()}" . PHP_EOL;
}