Skip to content

Commit

Permalink
docs(txs): update hooks section
Browse files Browse the repository at this point in the history
  • Loading branch information
021-projects committed Apr 19, 2024
1 parent dac1e31 commit d08fb76
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions docs/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@ To get a transaction creator, use the `tx` function:
$creator = tx(100, 'USD');
```

### Handling Errors
### Hooks
If you are performing an operation during which an unexpected exception might occur and you need to secure the means, put them in `before` or `after` hooks:
```php
// This code will roll back the transaction.
$creator->after(function () {
throw new \Exception('Error');
$creator->before(function (
// Just add the necessary parameters to the function signature
// and the container will automatically resolve them.
\O21\LaravelWallet\Contracts\TransactionCreator $creator,
\O21\LaravelWallet\Contracts\Transaction $tx,
) {
// Code that will be executed before the transaction is created.
});

$creator->after(function (
\O21\LaravelWallet\Contracts\TransactionCreator $creator,
\O21\LaravelWallet\Contracts\Transaction $tx,
) {
// Code that will be executed after the transaction is created.
// throw new \Exception('Do rollback');
});
```

Expand Down

0 comments on commit d08fb76

Please sign in to comment.