PHP code example of wc-develop / php-ofx-reader

1. Go to this page and download the library: Download wc-develop/php-ofx-reader 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/ */

    

wc-develop / php-ofx-reader example snippets




cDeveloper\PhpOfxReader\OfxReader;

$path = '/var/www/html/arquivo.ofx';
$ofxReader = new OfxReader($path);
$transactions = $ofxReader->getTransactions();



namespace Seu\NameSpace;

use WcDeveloper\PhpOfxReader\TemplateInterface;

class CustomTemplate implements TemplateInterface
{
    // Informe a tag root do arquivo, na maioria dos casos será ofx
    public function rootTag() : string
    {
        return 'ofx';
    }

    // informe o caminho completo dentro do seu arquivo para chegar até as transações
    // separe com ->
    public function mapTransactions() : string
    {
        return 'BANKMSGSRSV1->STMTTRNRS->STMTRS->BANKTRANLIST->STMTTRN';
    }

    /**
     * Mapeie as transações do seu arquivo OFX
     * Tipo de dados disponíveis:
     *  - money
     *  - date
     *  - string
     * 
     * Estrutura de retorno da array:
     * [
     *  'qualquer-key' => ['key' => 'tag-dentro-do-arquivo-ofx', 'type' => 'tipo-do-dado'],
     *  'key-qualquer' => ['key' => 'tag-dentro-do-arquivo-ofx', 'type' => 'tipo-do-dado'],
     * ]
     *
     * @return array
     */
    public function mapTransaction() : array
    {
        return [
            'valor' => ['key' => 'TRNAMT', 'type' => 'money'],
            'identificacao'=> ['key' => 'CHECKNUM', 'type' => 'string'],
            'historico' => ['key' => 'MEMO', 'type' => 'string'],
            'data_extrato' => ['key' => 'DTPOSTED', 'type' => 'date'],
        ];
    }
}




cDeveloper\PhpOfxReader\OfxReader;
use Seu\NameSpace\CustomTemplate;

$url = 'https://seu-dominio.com/arquivo.ofx';
$ofxReader = new OfxReader($url, CustomTemplate::class);
$transactions = $ofxReader->getTransactions();