Laravel package for managing electrical meter recharges

v1.0.0 2025-06-15 13:14 UTC

This package is auto-updated.

Last update: 2025-06-15 14:08:07 UTC


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

  1. Add the package to your composer.json:
{
    "require": {
        "recharge-meter/service": "*"
    }
}
  1. Publish the configuration:
php artisan vendor:publish --tag=recharge-config
  1. Run the migrations:
php artisan migrate
  1. 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

  1. 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);
  1. Clear Credit Token
$result = Recharge::getClearCreditToken('22000169833', 1);
  1. Clear Tamper Sign Token
$result = Recharge::getClearTamperSignToken('22000169833', 1);
  1. Get Contract Info
$result = Recharge::getContractInfo('22000169833', 1);
  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'
]);
  1. Update Meter
$result = Recharge::updateMeter([
    'MeterCode' => '22000169833',
    'MeterType' => 1,
    'CustomerName' => 'John Doe Updated',
    'Address' => '456 New St',
    'PhoneNumber' => '0987654321'
]);

Use Type Management

  1. List Use Types
$useTypes = UseType::getList();
  1. Add Use Type
$result = UseType::add(
    useTypeId: 'RES',
    useTypeName: 'Residential',
    meterType: 1,
    price: 100.00,
    vat: 18.00
);
  1. Update Use Type
$result = UseType::update(
    useTypeId: 'RES',
    price: 120.00,
    vat: 20.00
);
  1. 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