diff --git a/src/backend/app/Console/Commands/DemoDataCreator.php b/src/backend/app/Console/Commands/DemoDataCreator.php index d90c74bd2..d29744e64 100644 --- a/src/backend/app/Console/Commands/DemoDataCreator.php +++ b/src/backend/app/Console/Commands/DemoDataCreator.php @@ -2,9 +2,11 @@ namespace App\Console\Commands; +use App\Helpers\TokenGenerator; use App\Models\MainSettings; use App\Models\MaintenanceUsers; use App\Models\Meter\Meter; +use App\Models\Meter\MeterToken; use App\Models\Person\Person; use App\Models\Token; use App\Models\Transaction\AgentTransaction; @@ -47,6 +49,7 @@ public function __construct( private AirtelTransaction $airtelTransaction, private Meter $meter, private Token $token, + private MeterToken $meterToken, private CalinTransaction $calinTransaction, private MainSettings $mainSettings, private TicketCategory $ticketCategory, @@ -254,7 +257,7 @@ private function generateTransaction(): void { // generate random token if ($transactionData->transaction->amount > 0) { $tokenData = [ - 'token' => Str::random(30), + 'token' => TokenGenerator::generate(), 'load' => round( $transactionData->transaction->amount / $randomMeter['tariff']['price'], @@ -266,6 +269,22 @@ private function generateTransaction(): void { $token->save(); $transactionData->token = $token; + // generate meter_token + $meterTokenData = [ + 'meter_id' => $randomMeter->id, + 'token' => TokenGenerator::generate(), + 'energy' => round( + $transactionData->transaction->amount / + $randomMeter['tariff']['price'], + 2 + ), + 'transaction_id' => $transaction->id, + ]; + $meterToken = $this->meterToken->newQuery()->make(['meter_id' => $meterTokenData['meter_id'], + 'token' => $meterTokenData['token'], '' => $meterTokenData['energy'], + 'transaction_id' => $meterTokenData['transaction_id']]); + $meterToken->save(); + // payment event event( 'payment.successful', diff --git a/src/backend/app/Helpers/TokenGenerator.php b/src/backend/app/Helpers/TokenGenerator.php new file mode 100644 index 000000000..73037d18f --- /dev/null +++ b/src/backend/app/Helpers/TokenGenerator.php @@ -0,0 +1,19 @@ + - - Token {{ token.paid_for.token }} + + Token ({{ formatToken(token.paid_for.token) }}) {{ token.paid_for_type }} -