darknautica/volta-php
Composer 安装命令:
composer require darknautica/volta-php
包简介
The official Laravel SDK for Volta — AI billing, handled.
README 文档
README
The official Laravel SDK for Volta — AI billing, handled.
Requirements
- PHP 8.2+
- Laravel 10, 11, or 12
Installation
composer require darknautica/volta-php
Publish the config:
php artisan vendor:publish --tag=volta-config
Add to your .env:
VOLTA_APP_KEY=your-app-key-here VOLTA_BASE_URL=https://volta.test
Quick Start
Three lines to add billing to any AI endpoint:
use DarkNautica\Volta\Facades\Volta; // Check before calling AI if (!Volta::hasAccess($user->id)) { return response()->json(['error' => 'Insufficient credits'], 402); } // Make your AI call here... // Deduct after success Volta::charge($user->id, 1);
Middleware
Protect entire routes automatically:
// Requires 1 credit (default) Route::post('/generate', [AIController::class, 'generate']) ->middleware('volta.gate'); // Requires 3 credits, specific model Route::post('/analyze', [AIController::class, 'analyze']) ->middleware('volta.gate:3,gpt-4');
The middleware resolves the user automatically:
$request->volta_user_idif set explicitly$request->user()->idif authenticated- Falls back to request IP for anonymous users
Blade Directives
{{-- Show balance --}} <span>@voltaBalance($user->id) credits remaining</span> {{-- Conditional content --}} @voltaHasAccess($user->id, 1) <button>Generate</button> @endvoltaHasAccess @voltaNoAccess($user->id, 1) <a href="/billing">Buy more credits</a> @endvoltaNoAccess {{-- Embed billing portal --}} <iframe src="@voltaPortalUrl($user->id)" width="100%" height="600"></iframe>
Available Methods
| Method | Description |
|---|---|
Volta::charge($userId, $credits, $model?) |
Deduct credits. Throws on failure. |
Volta::hasAccess($userId, $credits?) |
Check access. Always returns bool. |
Volta::balance($userId) |
Get credit balance. |
Volta::topUp($userId, $credits) |
Add credits to a user. |
Volta::usage($userId) |
Get usage history array. |
Volta::portalUrl($userId, $options?) |
Get signed billing portal URL. |
Testing Connection
php artisan volta:test
This will verify your API key, test connectivity, and display account info.
Error Handling
use DarkNautica\Volta\Exceptions\InsufficientCreditsException; use DarkNautica\Volta\Exceptions\RateLimitExceededException; try { Volta::charge($user->id, 1); } catch (InsufficientCreditsException $e) { return response()->json(['error' => 'Not enough credits'], 402); } catch (RateLimitExceededException $e) { return response()->json(['error' => 'Slow down', 'retry_after' => $e->retryAfter], 429); }
Fail Silently Mode
Set VOLTA_FAIL_SILENTLY=true in .env to prevent Volta errors from crashing your app. When enabled:
hasAccess()returnsfalsebalance()returns0charge()returnsfalse
This is useful for apps that should degrade gracefully if Volta is unreachable.
Configuration
| Env Variable | Default | Description |
|---|---|---|
VOLTA_APP_KEY |
(required) | Your Volta API key |
VOLTA_BASE_URL |
https://volta.test |
Volta API base URL |
VOLTA_TIMEOUT |
10 |
HTTP timeout in seconds |
VOLTA_FAIL_SILENTLY |
false |
Suppress exceptions, return safe defaults |
VOLTA_CACHE_TTL |
30 |
Balance cache duration in seconds (0 to disable) |
License
MIT
darknautica/volta-php 适用场景与选型建议
darknautica/volta-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sdk」 「stripe」 「laravel」 「billing」 「ai」 「credits」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 darknautica/volta-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 darknautica/volta-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 darknautica/volta-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Flexible payment integration for Laravel, lunarphp, supporting multiple payment providers.
Rich payment solutions for Laravel framework. Paypal, payex, authorize.net, be2bill, omnipay, recurring paymens, instant notifications and many more
Alfabank REST API integration
A simple Symfony bundle for Stripe API.
Configuration-driven, multi-gateway payment orchestration for Laravel. Drivers expose primitives; flows compose them.
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-09