recharge-meter / service
Laravel package for managing electrical meter recharges
v1.0.0
2025-06-15 13:14 UTC
Requires
- php: ^8.2
- guzzlehttp/guzzle: ^7.8
- laravel/framework: ^12.0
Requires (Dev)
- orchestra/testbench: ^8.0
- phpunit/phpunit: ^10.0
README
A Laravel package for managing electrical and water meter recharges using the STS Vend System API.
Features
- Meter recharge token generation
- Clear credit/tamper token management
- Contract information retrieval
- Meter registration and updates
- Use type management (tariffs and pricing)
- Comprehensive logging
- Simulation mode for testing
- Database tracking of all operations
Installation
- Add the package to your
composer.json
:
{ "require": { "recharge-meter/service": "*" } }
- Publish the configuration:
php artisan vendor:publish --tag=recharge-config
- Run the migrations:
php artisan migrate
- Configure your
.env
file:
RECHARGE_API_URL=http://120.26.4.119:9094 RECHARGE_SIMULATE=false RECHARGE_LOGGING_ENABLED=true RECHARGE_LOG_CHANNEL=daily RECHARGE_CONNECT_TIMEOUT=10 RECHARGE_REQUEST_TIMEOUT=30
Usage
Authentication
All operations require authentication:
use RechargeMeter\Facades\Recharge; use RechargeMeter\Facades\UseType; // Set credentials for meter operations Recharge::setCredentials('your-user-id', 'your-password'); // Set credentials for use type operations UseType::setCredentials('your-user-id', 'your-password');
Meter Operations
- Get Vending Token
// Amount-based vending (type 0) $result = Recharge::process('22000169833', 1, 5000, 0); // Quantity-based vending (type 1) $result = Recharge::process('22000169833', 1, 100, 1);
- Clear Credit Token
$result = Recharge::getClearCreditToken('22000169833', 1);
- Clear Tamper Sign Token
$result = Recharge::getClearTamperSignToken('22000169833', 1);
- Get Contract Info
$result = Recharge::getContractInfo('22000169833', 1);
- Register Meter
$result = Recharge::registerMeter([ 'MeterCode' => '22000169833', 'MeterType' => 1, // 1-Electric, 2-Water 'CustomerName' => 'John Doe', 'UseTypeId' => 'RES', 'Address' => '123 Main St', 'PhoneNumber' => '1234567890' ]);
- Update Meter
$result = Recharge::updateMeter([ 'MeterCode' => '22000169833', 'MeterType' => 1, 'CustomerName' => 'John Doe Updated', 'Address' => '456 New St', 'PhoneNumber' => '0987654321' ]);
Use Type Management
- List Use Types
$useTypes = UseType::getList();
- Add Use Type
$result = UseType::add( useTypeId: 'RES', useTypeName: 'Residential', meterType: 1, price: 100.00, vat: 18.00 );
- Update Use Type
$result = UseType::update( useTypeId: 'RES', price: 120.00, vat: 20.00 );
- Delete Use Type
$result = UseType::delete('RES');
Response Format
All operations return a standardized response:
[ 'success' => true|false, 'data' => [...] | null, 'error' => 'error message' | null, 'history_id' => 123 // For recharge operations ]
Testing
The package includes a simulation mode for testing. Enable it in your .env
:
RECHARGE_SIMULATE=true
Run the tests:
vendor/bin/phpunit
Error Handling
All operations include comprehensive error handling and logging. Errors are:
- Logged to the configured channel
- Stored in the database for recharge operations
- Returned in a standardized format
License
MIT