Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jacques/ofxparser
OFX File Parser
https://github.com/jacques/ofxparser
Last synced: about 1 month ago
JSON representation
OFX File Parser
- Host: GitHub
- URL: https://github.com/jacques/ofxparser
- Owner: jacques
- License: mit
- Created: 2021-03-02T15:03:44.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-10-07T18:46:56.000Z (about 2 years ago)
- Last Synced: 2024-10-14T13:21:46.488Z (about 1 month ago)
- Language: PHP
- Size: 184 KB
- Stars: 1
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
OFX Parser
=================[![Build Status](https://travis-ci.org/jacques/ofxparser.svg?branch=master)](https://travis-ci.org/jacques/ofxparser) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/jacques/ofxparser/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/jacques/ofxparser/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/jacques/ofxparser/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/jacques/ofxparser/?branch=master) [![Latest Stable Version](https://poser.pugx.org/jacques/ofxparser/v/stable)](https://packagist.org/packages/jacques/ofxparser) [![License](https://poser.pugx.org/jacques/ofxparser/license)](https://packagist.org/packages/jacques/ofxparser)
OFX Parser is a PHP library designed to parse an OFX file downloaded from a financial institution into simple PHP objects.
It supports multiple Bank Accounts, the required "Sign On" response, and recognises OFX timestamps.
## Installation
Simply require the package using [Composer](https://getcomposer.org/):
```bash
$ composer require jacques/ofxparser
```## Usage
You can access the nodes in your OFX file as follows:
```php
$ofxParser = new \OfxParser\Parser();
$ofx = $ofxParser->loadFromFile('/path/to/your/bankstatement.ofx');$bankAccount = reset($ofx->bankAccounts);
// Get the statement start and end dates
$startDate = $bankAccount->statement->startDate;
$endDate = $bankAccount->statement->endDate;// Get the statement transactions for the account
$transactions = $bankAccount->statement->transactions;
```Most common nodes are support. If you come across an inaccessible node in your OFX file, please submit a pull request!
## Investments Support
Investments look much different than bank / credit card transactions. This version supports a subset of the nodes in the OFX 2.0.3 spec, per the immediate needs of the author(s). You may want to reference the OFX documentation if you choose to implement this library. In particular, this does not currently process investment positions (INVPOSLIST) or referenced security definitions (SECINFO).
This is not a pure pass-through of fields, such as this implementation in python: [csingley/ofxtools](https://github.com/csingley/ofxtools). This package contains fields that have been "translated" on occasion to make it more friendly to those less-familiar with the investments OFX spec.
To load investments from a Quicken (QFX) file or a MS Money (OFX / XML) file:
```php
// You'll probably want to alias the namespace:
use OfxParser\Entities\Investment as InvEntities;// Load the OFX file
$ofxParser = new \OfxParser\Parsers\Investment();
$ofx = $ofxParser->loadFromFile('/path/to/your/investments_file.ofx');// Loop over investment accounts (named bankAccounts from base lib)
foreach ($ofx->bankAccounts as $accountData) {
// Loop over transactions
foreach ($accountData->statement->transactions as $ofxEntity) {
// Keep in mind... not all properties are inherited for all transaction types...// Maybe you'll want to do something based on the transaction properties:
$nodeName = $ofxEntity->nodeName;
if ($nodeName == 'BUYSTOCK') {
// @see OfxParser\Entities\Investment\Transaction...$amount = abs($ofxEntity->total);
$cusip = $ofxEntity->securityId;// ...
}// Maybe you'll want to do something based on the entity:
if ($ofxEntity instanceof InvEntities\Transaction\BuyStock) {
// ...
}}
}
```## Fork & Credits
This is a fork of [asgrim/ofxparser](https://github.com/asgrim/ofxparser) which was a fork of [grimfor/ofxparser](https://github.com/Grimfor/ofxparser) made to be framework independent.
The source repo was designed for Symfony 2 framework, so credit should be given where credit due!
Heavily refactored by [Oliver Lowe](https://github.com/loweoj) and loosely based on the ruby [ofx-parser by Andrew A. Smith](https://github.com/aasmith/ofx-parser).