Skip to content

Commit

Permalink
fix(transactions): update received field when amount changed in updat…
Browse files Browse the repository at this point in the history
…ing event*
  • Loading branch information
021-projects committed Feb 20, 2024
1 parent be309d8 commit 536077e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/Observers/TransactionObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public function created(Transaction $tx): void
public function updating(Transaction $tx): void
{
$this->callProcessorMethodIfExist($tx, 'updating');

if ($tx->isDirty('amount')) {
/** @var \O21\LaravelWallet\Transaction\Preparer $preparer */
$preparer = app(TransactionPreparer::class);
$preparer->prepare($tx);
}
}

public function updated(Transaction $tx): void
Expand All @@ -41,12 +47,6 @@ public function updated(Transaction $tx): void
event(new TransactionStatusChanged($tx, $originalStatus));
}

if ($tx->wasChanged('amount')) {
/** @var \O21\LaravelWallet\Transaction\Preparer $preparer */
$preparer = app(TransactionPreparer::class);
$preparer->prepare($tx);
}

event(new TransactionUpdated($tx));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public function test_received_changed_when_amount_changed(): void

$this->assertEquals(
40,
$tx->received
$tx->fresh()->received
);
}
}

0 comments on commit 536077e

Please sign in to comment.