bavix / laravel-wallet

It's easy to work with a virtual wallet
https://bavix.github.io/laravel-wallet/
MIT License
1.14k stars 230 forks source link

Help with swap package #872

Closed rez1dent3 closed 9 months ago

rez1dent3 commented 9 months ago

@rez1dent3 Im trying to do wallet exchange have followed this steps from this link Laravel Wallet Swap but it dosen't exchange the amount instead it just transfer the amount I entered. can you please help

Here is my code

    {
        $sender = User::findOrFail(12);
        $receiver = User::findOrFail(11);

        $s = $sender->getWallet($sender->tag);
        $r = $receiver->getWallet($receiver->tag);

        $s->exchange($r, 10);

        return $r->balance;
    }

"bavix/laravel-wallet-swap": "^6.0",

Originally posted by @Peektower in https://github.com/bavix/laravel-wallet/issues/863#issuecomment-1912154724

rez1dent3 commented 9 months ago

@Peektower hello. Let's continue here.

rez1dent3 commented 9 months ago
  1. I don't understand what tag is. Can you describe your architecture?
  2. The wallet must have the currency stamped on it. a) Multi-wallets: https://github.com/bavix/laravel-wallet/blob/febd97ba360bcde916ed3bd73961c75c743c88f7/tests/Units/Domain/ExchangeTest.php#L92-L98

b) default wallet (any wallet. also suitable for multi-wallets):

$wallet->meta['currency'] = 'USD';
$wallet->save();
rez1dent3 commented 9 months ago

@Peektower I deleted your message in the next issue. Let's discuss separately. You have different problems.

Peektower commented 9 months ago

I’m using the tag to identify the user’s wallet

I’m using this trait HasWallets

So I want to exchange the amount based on the currency using the wallet exchange method. But when I do, the exact amount is transferred without the conversion

On Fri, 26 Jan 2024 at 16:35, Maxim Babichev @.***> wrote:

  1. I don't understand what tag is. Can you describe your architecture?
  2. The wallet must have the currency stamped on it. a) Multi-wallets:

    https://github.com/bavix/laravel-wallet/blob/febd97ba360bcde916ed3bd73961c75c743c88f7/tests/Units/Domain/ExchangeTest.php#L92-L98

b) default wallet:

$wallet->meta['currency'] = 'USD';$wallet->save();

— Reply to this email directly, view it on GitHub https://github.com/bavix/laravel-wallet/issues/872#issuecomment-1912350947, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMJBIPOIBHOLVWS5F3BOXKDYQPLNZAVCNFSM6AAAAABCMM3GKCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJSGM2TAOJUG4 . You are receiving this because you were mentioned.Message ID: @.***>

rez1dent3 commented 9 months ago

You need to add the currency type to the meta and everything will start working.

rez1dent3 commented 9 months ago

@Peektower Did you succeed? If not, then write. I'll make some detailed example.

Peektower commented 9 months ago

Using the exchange does work for me, so I’m opting to use external currency conversion api

On Fri, 26 Jan 2024 at 17:15, Maxim Babichev @.***> wrote:

@Peektower https://github.com/Peektower Did you succeed? If not, then write. I'll make some detailed example.

— Reply to this email directly, view it on GitHub https://github.com/bavix/laravel-wallet/issues/872#issuecomment-1912405213, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMJBIPISWZ4UMEEKTHM446TYQPQEVAVCNFSM6AAAAABCMM3GKCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJSGQYDKMRRGM . You are receiving this because you were mentioned.Message ID: @.***>

rez1dent3 commented 9 months ago

@Peektower The laravel-wallet-swap package works on top of the https://github.com/florianv/laravel-swap package, so all package providers (api providers and more) are available to you.

https://github.com/florianv/laravel-swap?tab=readme-ov-file#services

Peektower commented 9 months ago

Hi again Maxim, this is my response when i fetch the transactions

{ "id": 2, "user": 1, "type": "withdraw", "amount": "-22", "meta": "For lunch" },

so the challenges here now is how can i know the sender or receiver of the transactions

On Fri, 26 Jan 2024 at 17:38, Maxim Babichev @.***> wrote:

@Peektower https://github.com/Peektower The laravel-wallet-swap package works on top of the https://github.com/florianv/laravel-swap package, so all package providers (api providers and more) are available to you.

https://github.com/florianv/laravel-swap?tab=readme-ov-file#services

— Reply to this email directly, view it on GitHub https://github.com/bavix/laravel-wallet/issues/872#issuecomment-1912433365, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMJBIPP2GKBUFKWIOZISTFLYQPSYLAVCNFSM6AAAAABCMM3GKCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJSGQZTGMZWGU . You are receiving this because you were mentioned.Message ID: @.***>

rez1dent3 commented 9 months ago

@Peektower Hello. The transaction does not have a sender, the transfer does.

Example: https://github.com/bavix/laravel-wallet/blob/addf96927d0f2d257db20fdbbf24767d365d6470/tests/Units/Domain/EagerLoadingTest.php#L61-L69

And from the wallet you can get the owner of the wallet.