Skip to content

Total amount per transaction #416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
JoelVeloz opened this issue Dec 6, 2021 · 8 comments
Closed

Total amount per transaction #416

JoelVeloz opened this issue Dec 6, 2021 · 8 comments
Assignees
Labels
question Further information is requested Stale

Comments

@JoelVeloz
Copy link

Hello, I have been reviewing the package I really liked the truth and I would like to add on my own a 'total' attribute within the transactions to know the total amount of my wallet after having made that transaction, in order to know how much balance I had in a given transaction.
I'm not sure whether to add the attribute into the meta array or add a column, but I would like to know in which section I could modify this, without touching the vendor folder.

I have other questions, how can I get a list of transactions by wallet? I have dealt with '$wallet-> transactions' but it returns all transactions by user.

And one last question, when generating a transaction, the package already includes a function to verify that the aggregate balance is correct? That is, to verify that the 'balance' of a wallet is correct, I must compare it with the sum of the transactions of this wallet.

@rez1dent3 rez1dent3 self-assigned this Dec 6, 2021
@rez1dent3 rez1dent3 added the question Further information is requested label Dec 6, 2021
@rez1dent3
Copy link
Member

rez1dent3 commented Dec 6, 2021

Hello.

my own a 'total' attribute within the transactions to know

like this.

public function extract(TransactionDtoInterface $dto): array
{
$bankMethod = null;
if ($dto->getMeta() !== null) {
$bankMethod = $dto->getMeta()['bank_method'] ?? null;
}
return array_merge($this->transactionDtoTransformer->extract($dto), [
'bank_method' => $bankMethod,
]);
}

I have dealt with '$wallet-> transactions' but it returns all transactions by user.

So it happened historically, but now this "feature" bothers me a little. But I don't want to break the package's backward compatibility.

You can easily achieve the desired result by adding where.

$wallet->transactions()->where('wallet_id', $wallet->getKey())->...

And one last question, when generating a transaction, the package already includes a function to verify that the aggregate balance is correct?

Details are needed here, I did not understand your question.

@rez1dent3
Copy link
Member

I decided to try adding a new method walletTransactions that might replace the old one.

@JoelVeloz
Copy link
Author

Hello
I've been testing the package, and still haven't found a way to insert the full amount of money per transaction, without altering the vendor.
I would like to know if it is possible to add that in a future update since when executing the 'composer update' everything restarts.
I wanted to tell you that yesterday I ran 'composer update' and something curious happened, at the moment a transaction code block like this is used:

DB :: transaction (function () {
Auth :: user () -> withdrawFloat (100);
});

It stopped working, and erroneously, the transaction was generated but the amount of the wallet was not withdrawn. I tried the package's transactions function and everything worked correctly, but I still don't understand why my code block stopped working.

Another thing I wanted to know is how to verify that the sum of the amount of all transactions is equivalent to the total amount of a wallet, is there a package function for this? Or should I create it by eloquent. I need this for the reason that as I progress in my project, it is verified that no error occurs in the transactions.

@rez1dent3
Copy link
Member

The update takes place not only in the database, but also in the storage. There is no way to implement atomicity at the transaction level. Package operations are atomic and will not let you get shot in the foot if you work with the package correctly.

If you need to combine several operations into one transaction, then you need to upgrade the package to version 7.1 and work through the package functions. More details here: https://bavix.github.io/laravel-wallet/#/transaction

@rez1dent3
Copy link
Member

I have freed myself from my affairs and there is time to respond in more detail.

The fact is that the package never declared to work with laravel transactions and until version 7.1, when using your case, the data was not inserted / updated into the database, but was updated in the storage (see the section race condition). I described the problem in more detail here: #412

If you want to maintain data atomicity, then you need to work with the internal transaction interface. It is optimized to work with the package and does not violate the atomicity of the data between the database and the store.

This interface allowed us to get rid of unnecessary updates in the database, which gave a big performance boost for 7.x. More details can be found here: https://github.com/bavix/laravel-wallet-benchmark

Now the package does not make +100500 database updates for the wallet, but only updates the state. Upon completion of the transaction, writes to the database. If you wrap in your own transaction, then you need to repeat everything that the package does inside.

@JoelVeloz
Copy link
Author

Could you give more detail about how the transactions work? and how it is connected to the wallet. What do you mean by data atomicity? Could you show a diagram of the process of how a transaction is generated, please
I would like to study the package further. That would help me to solve certain needs that I have in my project.

Regarding the transfers, I will update the package to test the new features, thank you.

@rez1dent3
Copy link
Member

You'd better look at the pull request #412, it's all there. Atomicity is an indivisible operation. Either applied or rolled back.

@github-actions
Copy link

This issue is stale because it has been open 21 days with no activity.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

2 participants