Skip to content

Commit

Permalink
use correct paid_for_type on payment #396
Browse files Browse the repository at this point in the history
- seed meter tokens table for demo company
- use appropriate paid_for_type as expected on the frontend
  • Loading branch information
beesaferoot committed Dec 8, 2024
1 parent 67cfe1f commit 0058b0f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/backend/app/Console/Commands/DemoDataCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand Down Expand Up @@ -47,6 +48,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,
Expand Down Expand Up @@ -265,6 +267,22 @@ private function generateTransaction(): void {
$token->save();
$transactionData->token = $token;

// generate meter_token
$meterTokenData = [
'meter_id' => $randomMeter->id,
'token' => Str::random(30),
'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',
Expand Down
4 changes: 2 additions & 2 deletions src/backend/app/Listeners/PaymentListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ public function onPaymentSuccess(
$this->applianceRatePaymentHistoryService->assign();
break;
case $paidFor instanceof Asset:
$paymentHistory->paid_for_type = Asset::class;
$paymentHistory->paid_for_type = 'appliance';
$paymentHistory->paid_for_id = $paidFor->id;
break;
case $paidFor instanceof Token:
$paymentHistory->paid_for_type = Token::class;
$paymentHistory->paid_for_type = 'token';
$paymentHistory->paid_for_id = $paidFor->id;
break;
}
Expand Down

0 comments on commit 0058b0f

Please sign in to comment.