andmarruda/billing-module
Composer 安装命令:
composer require andmarruda/billing-module
包简介
Billing module with one-time payments, recurring billing and NFSe integration
README 文档
README
Billing module for Laravel with ports and adapters architecture.
Installation
composer require andmarruda/billing-module
Laravel package auto-discovery loads Andmarruda\BillingModule\BillingModuleServiceProvider.
Layers
UseCases/: application workflows.Ports/: repository and service contracts.Infrastructure/: adapter implementations.Http/: controllers, requests, resources and routes.Events/,Listeners/,Console/Commands/: async workflows and cron entry points.
Implemented Scope
- One-time payments.
- Recurring billing managed by module cron flows (not Stripe subscriptions product).
- Stripe webhook processing with signature validation and idempotent event storage.
- NFSe integration adapter (FocusNFe package integration point).
- Reconciliation and retry commands.
- Optional coin credit flow for MVPs (ledger + user balance) on
PaymentSucceeded.
Routes
POST /billing/payments/one-timePOST /billing/subscriptions/recurringPOST /billing/subscriptions/{id}/cancelGET /billing/invoices/{id}POST /billing/webhooks/stripeGET /billing/subscriptions/currentwhenbilling.stores.enabled = truePOST /billing/webhooks/google-playwhenbilling.stores.enabled = truePOST /billing/webhooks/app-storewhenbilling.stores.enabled = true
Commands
billing:renew-subscriptionsbilling:retry-failed-paymentsbilling:sync-nfsebilling:reconcilebilling:expire-store-subscriptions
Scheduling is configured by Config/billing.php under crons.
Coins (MVP)
- Enable with
billing.coins.enabled = true. - Configure monthly coin recharge by plan with
billing.coins.monthly_plan_credits. - You can also credit coins in one-time payments by passing
metadata.coins. - Credits are idempotent per payment (
coin_ledger_entries.payment_idis unique).
Route Middleware
- Configure API middleware via
billing.route_middleware(string or array). - Configure webhook middleware independently via
billing.webhook_middleware. - Example:
billing.route_middleware = ['auth:sanctum']billing.webhook_middleware = ['throttle:60,1']
NFSe Async Emission
InvoiceIssuedtriggersIssueNfseForInvoice, which is queueable (ShouldQueue).- Queue processing strategy stays in the host app (driver/workers/supervision).
Stripe Webhook Security
- Signature validation supports timestamp tolerance through:
billing.stripe.webhook_tolerance_seconds(default300).
Store-Driven Subscriptions
- Enable mobile store flows with
billing.stores.enabled = true. - Configure product mapping in
billing.stores.google_play.product_mapandbilling.stores.app_store.product_map. - Bind concrete implementations for:
Andmarruda\BillingModule\Ports\Services\GooglePlayWebhookVerifierInterfaceAndmarruda\BillingModule\Ports\Services\AppStoreNotificationVerifierInterface
- Default verifier implementations are null adapters and intentionally do not accept webhooks.
Observability Events
Andmarruda\BillingModule\Events\NfseIssueFailed- Dispatched when NFSe issuance returns error, misses
external_id, or provider call throws.
- Dispatched when NFSe issuance returns error, misses
Andmarruda\BillingModule\Events\WebhookProcessingFailed- Dispatched when webhook event persistence fails for a non-duplicate reason.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-08