fernandocarletti/ofx
Composer 安装命令:
composer require fernandocarletti/ofx
包简介
Object-oriented PHP parser for Open Financial Exchange (OFX) files supporting OFX v1 (SGML) and v2 (XML)
README 文档
README
Disclaimer: This library was built entirely using OpenCode and Claude Opus 4.5.
A modern, object-oriented PHP parser for Open Financial Exchange (OFX) files. Supports both OFX v1 (SGML) and OFX v2 (XML) formats with human-friendly property names and full type safety.
Features
- Dual Format Support - Parses both OFX v1 (SGML) and v2 (XML) formats
- Complete OFX Coverage - Supports all major OFX domains: banking, credit cards, investments, bill pay, transfers, tax forms, and more
- Human-Friendly API - Property names like
transactionIdandaccountNumberinstead of cryptic OFX tags likeTRNUIDandACCTID - Modern PHP - Built for PHP 8.4+ using property hooks and strict typing
- Fully Typed - Complete type declarations for IDE autocompletion and static analysis
- Zero Dependencies - Only requires standard PHP extensions
Installation
composer require fernandocarletti/ofx
Quick Start
use Ofx\Parser; $parser = new Parser(); $ofx = $parser->parseFile('/path/to/statement.ofx'); // Access bank statement transactions $bankMessages = $ofx->bankMessagesResponseV1; $statement = $bankMessages->statementTransactionResponses[0]->statementResponse; foreach ($statement->transactionList->transactions as $transaction) { echo sprintf( "%s: %s %s\n", $transaction->datePosted->format('Y-m-d'), $transaction->name, $transaction->amount ); } // Check balances echo "Ledger Balance: " . $statement->ledgerBalance->amount . "\n"; echo "Available Balance: " . $statement->availableBalance->amount . "\n";
Usage Examples
Parsing Bank Statements
use Ofx\Parser; $parser = new Parser(); $ofx = $parser->parseFile('bank_statement.ofx'); $statement = $ofx->bankMessagesResponseV1 ->statementTransactionResponses[0] ->statementResponse; // Account information $account = $statement->bankAccount; echo "Routing: " . $account->routingNumber . "\n"; echo "Account: " . $account->accountId . "\n"; echo "Type: " . $account->accountType->value . "\n"; // CHECKING, SAVINGS, etc. // Transaction details foreach ($statement->transactionList->transactions as $txn) { echo sprintf( "[%s] %s - %s (%s)\n", $txn->type->value, // CREDIT, DEBIT, CHECK, etc. $txn->transactionId, $txn->name, $txn->amount ); if ($txn->isDebit()) { echo " This was a debit transaction\n"; } if ($txn->checkNumber !== null) { echo " Check #" . $txn->checkNumber . "\n"; } }
Parsing Credit Card Statements
$ofx = $parser->parseFile('credit_card.ofx'); $statement = $ofx->creditCardMessagesResponseV1 ->statementTransactionResponses[0] ->creditCardStatementResponse; // Credit card account echo "Card: " . $statement->creditCardAccount->accountId . "\n"; // Transactions foreach ($statement->transactionList->transactions as $txn) { echo $txn->datePosted->format('M d') . ": "; echo $txn->name . " " . $txn->amount . "\n"; } // Balances echo "Current Balance: " . $statement->ledgerBalance->amount . "\n"; echo "Available Credit: " . $statement->availableBalance->amount . "\n";
Parsing Investment Statements
$ofx = $parser->parseFile('investment.ofx'); $statement = $ofx->investmentMessagesResponseV1 ->statementTransactionResponses[0] ->investmentStatementResponse; // Investment account $account = $statement->investmentAccount; echo "Broker ID: " . $account->brokerId . "\n"; echo "Account: " . $account->accountId . "\n"; // Positions foreach ($statement->positionList->positions as $position) { echo sprintf( "%s: %s units @ %s\n", $position->securityId->uniqueId, $position->units, $position->unitPrice ); } // Investment transactions (buys, sells, dividends, etc.) $txnList = $statement->investmentTransactionList; foreach ($txnList->buyStock ?? [] as $buy) { echo "BUY: " . $buy->securityId->uniqueId . "\n"; }
Accessing Header Information
$ofx = $parser->parseFile('statement.ofx'); // Header is available after parsing $header = $parser->parsedHeader; echo "OFX Version: " . $header->version . "\n"; // 102, 160, 200, 220, etc. echo "Is v1 (SGML): " . ($header->isVersion1 ? 'Yes' : 'No') . "\n"; echo "Is v2 (XML): " . ($header->isVersion2 ? 'Yes' : 'No') . "\n"; echo "Encoding: " . $header->encoding . "\n"; // UTF-8, Windows-1252, etc.
Parsing from Different Sources
// From file path $ofx = $parser->parseFile('/path/to/file.ofx'); // From string content $content = file_get_contents('statement.ofx'); $ofx = $parser->parseString($content); // From stream resource $stream = fopen('statement.ofx', 'r'); $ofx = $parser->parseStream($stream); fclose($stream);
Checking Signon Status
$ofx = $parser->parseFile('statement.ofx'); $signon = $ofx->signonMessagesResponseV1->signonResponse; if ($signon->status->isSuccess()) { echo "Signed on successfully\n"; echo "Server date: " . $signon->serverDate->format('Y-m-d H:i:s') . "\n"; echo "Language: " . $signon->language->value . "\n"; if ($signon->financialInstitution !== null) { echo "FI: " . $signon->financialInstitution->organization . "\n"; } } else { echo "Signon failed: " . $signon->status->code . "\n"; echo "Message: " . $signon->status->message . "\n"; }
Supported OFX Domains
| Domain | Request | Response | Description |
|---|---|---|---|
| Signon | signonMessagesRequestV1 |
signonMessagesResponseV1 |
Authentication and session management |
| Signup | signupMessagesRequestV1 |
signupMessagesResponseV1 |
Account enrollment and information |
| Bank | bankMessagesRequestV1 |
bankMessagesResponseV1 |
Bank account statements and transactions |
| Credit Card | creditCardMessagesRequestV1 |
creditCardMessagesResponseV1 |
Credit card statements and transactions |
| Investment | investmentMessagesRequestV1 |
investmentMessagesResponseV1 |
Brokerage statements, positions, trades |
| Security List | securityListMessagesRequestV1 |
securityListMessagesResponseV1 |
Security (stock/fund/bond) information |
| Profile | profileMessagesRequestV1 |
profileMessagesResponseV1 |
Financial institution capabilities |
emailMessagesRequestV1 |
emailMessagesResponseV1 |
Secure messaging with FI | |
| Bill Pay | billPayMessagesRequestV1 |
billPayMessagesResponseV1 |
Bill payment and payee management |
| Interbank Transfer | interbankTransferMessagesRequestV1 |
interbankTransferMessagesResponseV1 |
Transfers between institutions |
| Wire Transfer | wireTransferMessagesRequestV1 |
wireTransferMessagesResponseV1 |
Wire transfer processing |
| Tax 1099 | tax1099MessagesRequestV1 |
tax1099MessagesResponseV1 |
Tax form 1099 variants (INT, DIV, B, R, etc.) |
Requirements
- PHP 8.4 or higher
- Extensions:
simplexml,libxml,bcmath,mbstring
Development
# Install dependencies composer install # Run tests composer test # Run static analysis composer analyse # Check code style composer cs-check # Fix code style composer cs-fix
License
This library is open-sourced software licensed under the MIT license.
fernandocarletti/ofx 适用场景与选型建议
fernandocarletti/ofx 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 01 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「parser」 「Banking」 「finance」 「ofx」 「financial」 「investment」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fernandocarletti/ofx 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fernandocarletti/ofx 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fernandocarletti/ofx 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
Sila PHP SDK for API Version 0.2
Creates an XML file for a Single Euro Payments Area (SEPA) Credit Transfer.
Simple OFX file parser
An MT940 bank statement parser for PHP
PHP SDK for Ledga.io - Programmatic double-entry ledgers for finance, gaming and multi-tenant SaaS
统计信息
- 总下载量: 24
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-27