laratables/monta-partner-api
Composer 安装命令:
composer require laratables/monta-partner-api
包简介
Laravel SDK for the Monta Partner API — authentication, token caching, and a fluent HTTP client.
README 文档
README
A Laravel 11/12/13 SDK for the Monta Partner API. Handles OAuth token exchange, automatic caching & refresh, and exposes a clean fluent client for every HTTP verb.
Installation
composer require laratables/monta-partner-api
The service provider and Monta facade are auto-discovered via Laravel's
package discovery. No manual registration needed.
Publish the config (optional):
php artisan vendor:publish --tag=monta-config
Configuration
Add to your .env:
MONTA_CLIENT_ID=your-client-id MONTA_CLIENT_SECRET=your-client-secret # Optional — these are the defaults: MONTA_BASE_URL=https://api.monta.com MONTA_API_VERSION=v2024-01-18 MONTA_CACHE_STORE=default # any Laravel cache store MONTA_HTTP_TIMEOUT=30 MONTA_HTTP_CONNECT_TIMEOUT=10
Usage
Dependency Injection (recommended)
use Monta\PartnerApi\Contracts\MontaClientInterface; class ChargeController extends Controller { public function __construct(private MontaClientInterface $monta) {} public function index(): JsonResponse { $data = $this->monta->get('/charge-points', ['pageSize' => 25])->json(); return response()->json($data); } public function start(int $id): JsonResponse { $result = $this->monta->post("/charge-points/{$id}/start")->json(); return response()->json($result); } }
Facade
use Monta\PartnerApi\Facades\Monta; $chargePoints = Monta::get('/charge-points', ['pageSize' => 50])->json(); $charge = Monta::post('/charges', ['chargePointId' => 123])->json(); $updated = Monta::patch('/charge-points/456', ['name' => 'Bay 1'])->json(); Monta::delete('/webhooks/789');
Accessing any Monta API endpoint
The client works with any endpoint from the Monta API docs — just pass the path and any parameters:
// Charges $charges = $this->monta->get('/charges', ['pageSize' => 25, 'page' => 1])->json(); $charge = $this->monta->post('/charges', ['chargePointId' => 123])->json(); // Teams $teams = $this->monta->get('/teams')->json(); $team = $this->monta->get('/teams/456')->json(); // Webhooks $webhook = $this->monta->post('/webhooks', [ 'url' => 'https://yourapp.com/webhooks/monta', 'events' => ['charge.started', 'charge.stopped'], ])->json(); $this->monta->delete('/webhooks/789'); // Wallets $wallet = $this->monta->get('/wallets/123')->json(); // Any other endpoint — same pattern $this->monta->patch('/charge-points/456', ['name' => 'Bay 1']);
Working with responses
Every method returns a standard Laravel Illuminate\Http\Client\Response object:
$response = $this->monta->get('/charges'); $response->json(); // full decoded array $response->json('data'); // single key from the response $response->json('data.0.id'); // nested key using dot notation $response->collect('data'); // returns a Laravel Collection $response->status(); // HTTP status code e.g. 200 $response->successful(); // true if 2xx
Domain resource classes
Copy ChargePointsResource as a template for each API domain (Charges, Teams,
Wallets, Webhooks…):
use Monta\PartnerApi\Http\Resources\ChargePointsResource; // Register in a service provider: $this->app->bind(ChargePointsResource::class, fn($app) => new ChargePointsResource($app->make(MontaClientInterface::class)) ); // Use in a controller: public function __construct(private ChargePointsResource $chargePoints) {} public function index(): JsonResponse { return response()->json($this->chargePoints->list(['pageSize' => 50])); }
Error Handling
use Monta\PartnerApi\Exceptions\MontaApiException; use Monta\PartnerApi\Exceptions\MontaAuthenticationException; try { $result = $this->monta->post('/charges', $payload)->json(); } catch (MontaAuthenticationException $e) { // Bad credentials, or the API returned 401 // The cached token is automatically cleared; the next request will re-authenticate Log::critical('Monta auth failed', ['error' => $e->getMessage()]); } catch (MontaApiException $e) { // Any other non-2xx response Log::error('Monta API error', [ 'status' => $e->getStatusCode(), 'body' => $e->getResponse()->json(), ]); }
Token Caching
Access tokens are cached in the Laravel cache store defined by MONTA_CACHE_STORE.
They are proactively refreshed 30 seconds before expiry to avoid clock-skew issues.
A 401 response automatically evicts the cached token so the next call re-authenticates
transparently.
Testing
Running the test suite
composer test # or directly: ./vendor/bin/phpunit
Mocking in your application tests
Because everything is bound against MontaClientInterface, swapping in a mock
is straightforward:
use Monta\PartnerApi\Contracts\MontaClientInterface; // Using Laravel's built-in mock helper (Mockery under the hood): $this->mock(MontaClientInterface::class, function ($mock) { $mock->shouldReceive('get') ->with('/charge-points', \Mockery::any()) ->andReturn(new \Illuminate\Http\Client\Response( new \GuzzleHttp\Psr7\Response(200, [], json_encode(['data' => []])) )); }); // Or use Http::fake() to intercept at the HTTP layer: Http::fake([ 'https://api.monta.com/auth/token' => Http::response(['accessToken' => 'tok', 'expiresIn' => 3600]), 'https://api.monta.com/charge-points' => Http::response(['data' => []]), ]);
Package Structure
src/
├── Contracts/
│ └── MontaClientInterface.php Type-hint this in your code
├── Exceptions/
│ ├── MontaApiException.php Non-2xx API responses
│ └── MontaAuthenticationException.php Auth / token failures
├── Facades/
│ └── Monta.php Monta:: facade
├── Http/
│ ├── MontaClient.php Core client (auth + all verbs)
│ └── Resources/
│ └── ChargePointsResource.php Example domain resource — copy this pattern
├── Support/
│ └── MontaToken.php Token value object with expiry
└── MontaServiceProvider.php Auto-discovered service provider
config/
└── monta.php
tests/
├── TestCase.php Orchestra Testbench base
├── Unit/
│ ├── MontaTokenTest.php Token parsing & expiry logic
│ ├── ExceptionsTest.php Exception message / code derivation
│ ├── MontaClientAuthTest.php Token fetch, caching, refresh
│ ├── MontaClientHttpTest.php HTTP verbs, headers, error handling
│ └── ChargePointsResourceTest.php Resource method → client delegation
└── Feature/
├── AuthenticationFlowTest.php Full auth + API call flows
└── ServiceProviderTest.php DI bindings, singleton, facade, config
laratables/monta-partner-api 适用场景与选型建议
laratables/monta-partner-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「ev」 「Monta」 「Charging」 「Partner-API」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 laratables/monta-partner-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 laratables/monta-partner-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 laratables/monta-partner-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Monta Checkout Extension
A PHP Client for the Monta Portal
Alfabank REST API integration
Laravel Open Charge provides a fluent wrapper for the Open Charge Map POI API supporting Laravel 5.x, Lumen 5.x
This API Product provides the option to manage charging at all public Shell Recharge locations. The end points provides control to start, stop and get status of the charging session.
Laravel package for Accurate Online API integration.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-22