kubinyete/pagseguro-edi

There is no license information available for the latest version (1.0.2) of this package.

Quickstart webservice client for extracting EDI data from PagSeguro API

1.0.2 2024-02-20 15:26 UTC

This package is auto-updated.

Last update: 2024-11-24 20:53:41 UTC


README

pt-BR: Uma biblioteca simples e direta para carregar sequencialmente dados do EDI da adquirente PagSeguro

en-US: A straightfoward library for sequential loading of EDI entries from PagSeguro

NOTA: Este guia está primariamente em inglês, caso haja necessidade, será adicionado uma versão em pt-BR no futuro.

Installation

This package is provided via packagist.org, you can install it directly using the following command:

composer require kubinyete/pagseguro-edi

Currently, only PHP versions 8.0 or greater are supported/tested, if you currently need support for older versions, we strongly advice you to test it yourself and then create a pull request to merge any needed changes, any feedback is appreciated.

Usage

First and foremost, this library is a simple webservice client designed to be used for sequential reading, this will speed up your development time as any object, attribute mapping, data fetching and pagination mechanism has already been implemented.

You can start right away by using the following code snippet:

require_once 'vendor/autoload.php';

// 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
);

Fetching transactional movements

// 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;
}

You can also manually fetch single pages or manually increment if necessary

// 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;
}

Fetching finantial movements

// 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;
}

Supported movement types

Transactional

Finantial

Anticipation