whilesmart/eloquent-payments
Composer 安装命令:
composer require whilesmart/eloquent-payments
包简介
Polymorphic payment records for Laravel: gateway-agnostic audit trail attachable to invoices, expenses, subscriptions, or any payable.
README 文档
README
Polymorphic, gateway-agnostic payment records for Laravel. Attaches to invoices, expenses, subscriptions, orders, or any payable model.
Why
whilesmart/eloquent-invoices tracks payment state as scalars on the invoice row (amount_paid_cents, paid_at). That is a good summary view but there is no audit trail: no per-event log, no gateway reference, no multi-installment history, no refund chain, no failed-attempt record.
This package is that audit trail. Invoices, expenses, or anything else payable gets a payments() relationship; each Payment row is a single event.
Install
composer require whilesmart/eloquent-payments
php artisan migrate
Attach the HasPayments trait to any payable:
use Whilesmart\Payments\Contracts\Payable; use Whilesmart\Payments\Traits\HasPayments; class Invoice extends Model implements Payable { use HasPayments; }
Data model
Every Payment row captures:
payable(morph) -- what's being paid for.owner(nullable morph) -- who initiated / owns the payment, typically the workspace.amount_cents,currency.status--pending | authorized | succeeded | failed | refunded | partially_refunded | cancelled.direction--inbound(collection) /outbound(payout, refund).gateway,gateway_reference-- provider + its ID. Unique pair.method-- free-form string (card,mobile_money,bank_transfer, ...). SeePaymentMethodenum for canonical values.- Audit timestamps --
authorized_at,succeeded_at,failed_at,refunded_at. failure_reason-- text.parent_payment_id-- for refunds, points to the original payment.metadata-- JSON.
Reflecting onto the payable
The HasPayments trait includes recordPayment() which creates a Payment AND, when payments.auto_reflect_on_payable is on (default), syncs the payable's own summary fields:
$invoice->recordPayment([ 'amount_cents' => 50000, 'currency' => 'USD', 'status' => 'succeeded', 'method' => 'card', 'gateway' => 'stripe', 'gateway_reference' => 'ch_123...', 'succeeded_at' => now(), ]); // Effect: // invoice.amount_paid_cents += 50000 (or rather, set to sum of succeeded payments) // invoice.paid_at = now() if cumulative >= total_cents
If the payable has no amount_paid_cents column, reflection is silently skipped -- the package never errors out of ignorance of your schema.
Routes
Registers an apiResource at the configured prefix:
GET /api/payments
POST /api/payments
GET /api/payments/{payment}
PUT /api/payments/{payment}
DELETE /api/payments/{payment}
Index filters: payable_type, payable_id, owner_type, owner_id, status, direction, gateway, per_page.
Config
php artisan vendor:publish --tag=payments-config:
return [ 'register_routes' => env('PAYMENTS_REGISTER_ROUTES', true), 'route_prefix' => env('PAYMENTS_ROUTE_PREFIX', 'api'), 'route_middleware' => ['api', 'auth:sanctum'], 'table' => env('PAYMENTS_TABLE', 'payments'), 'auto_reflect_on_payable' => env('PAYMENTS_AUTO_REFLECT', true), ];
Siblings
whilesmart/eloquent-invoices-- invoices (money in). ImplementPayable, attachHasPayments.whilesmart/eloquent-expenses-- expenses (money out). Same pattern; thePaymentdirection flips tooutbound.whilesmart/eloquent-subscriptions(future) -- recurring billing.
whilesmart/eloquent-payments 适用场景与选型建议
whilesmart/eloquent-payments 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 100 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 whilesmart/eloquent-payments 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 whilesmart/eloquent-payments 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 100
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 41
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-24