Closed HilalLko closed 2 years ago
@hilal-hipster Hello. An interesting case, I see that an incorrect query is being built in the database from your log. I will try to reproduce the problem. Thank you. Tomorrow I will unsubscribe on the result, it will not work quickly to check.
@hilal-hipster Hello. An interesting case, I see that an incorrect query is being built in the database from your log. I will try to reproduce the problem. Thank you. Tomorrow I will unsubscribe on the result, it will not work quickly to check.
Sure, @rez1dent3
Furthermore, while changing the cache & lock driver from 'array' to 'Redis' am seeing a difference between balances. Balance in original is "11.50" but after changing cache & lock driver from array to Redis, the balance is getting changed to "5.00" Old cache & lock drivers
'cache' => [
'driver' => array,
],
'lock' => [
'driver' => 'array',
'seconds' => 1,
],
New & updated one
'cache' => [
'driver' => redis,
],
'lock' => [
'driver' => 'redis',
'seconds' => 1,
],
Sorry, for asking this here instead of creating a new one.
@hilal-hipster Hello. An interesting case, I see that an incorrect query is being built in the database from your log. I will try to reproduce the problem. Thank you. Tomorrow I will unsubscribe on the result, it will not work quickly to check.
Just to let you know am using custom "TransactionDtoTransformer", in order to handle credit lifespan (validity/expiry), which contains
declare(strict_types=1);
namespace App\Bavix\Wallet\Transform;
use Bavix\Wallet\Internal\Dto\TransactionDtoInterface;
use Bavix\Wallet\Internal\Transform\TransactionDtoTransformer;
use Bavix\Wallet\Internal\Transform\TransactionDtoTransformerInterface;
use Carbon\Carbon;
final class CustomTransactionDtoTransformer implements TransactionDtoTransformerInterface
{
public function __construct(
private TransactionDtoTransformer $transactionDtoTransformer
) {
}
public function extract(TransactionDtoInterface $dto): array
{
if ($dto->getMeta() !== null && isset($dto->getMeta()['expire_on'])) {
return array_merge($this->transactionDtoTransformer->extract($dto), [
'expiring_at' => $dto->getMeta()['expire_on'],
'amount_used' => 0,
]);
}
return $this->transactionDtoTransformer->extract($dto);
}
}
Old cache & lock drivers
Most likely, you have already switched to redis before and then changed to array. And now we decided to switch back to redis. In this case, you need to completely reset the redis cache, as it is not relevant to you.
Array cache is not recommended for use, because does not protect against race conditions.
Just to let you know am using custom "TransactionDtoTransformer", in order to handle credit lifespan (validity/expiry), which contains
Now the problem is clear to me. Yes, the problem is not in the package, but in the custom assembler class. You need to add parameters not by condition, but always. Those put down the default-value.
I don't know your data and I'm assuming it's null there. This is what your assembler class should look like.
return array_merge($this->transactionDtoTransformer->extract($dto), [
'expiring_at' => $dto->getMeta()['expire_on'] ?? null,
'amount_used' => 0,
]);
@hilal-hipster FYI
By the way, after changing the cache, you can recalculate the balance using the bavix/laravel-wallet-warmup package.
composer req bavix/laravel-wallet-warmup
artisan wallet:warm-up
The package consists of a single console command that runs through all wallets and applies refreshBalance.
Old cache & lock drivers
Most likely, you have already switched to redis before and then changed to array. And now we decided to switch back to redis. In this case, you need to completely reset the redis cache, as it is not relevant to you.
Array cache is not recommended for use, because does not protect against race conditions.
Just to let you know am using custom "TransactionDtoTransformer", in order to handle credit lifespan (validity/expiry), which contains
Now the problem is clear to me. Yes, the problem is not in the package, but in the custom assembler class. You need to add parameters not by condition, but always. Those put down the default-value.
I don't know your data and I'm assuming it's null there. This is what your assembler class should look like.
return array_merge($this->transactionDtoTransformer->extract($dto), [ 'expiring_at' => $dto->getMeta()['expire_on'] ?? null, 'amount_used' => 0, ]);
@hilal-hipster FYI
But @rez1dent3 here am isset($dto->getMeta()['expire_on'])
am already checking existence of the key which contains expiration datetime
Old cache & lock drivers
Most likely, you have already switched to redis before and then changed to array. And now we decided to switch back to redis. In this case, you need to completely reset the redis cache, as it is not relevant to you.
Array cache is not recommended for use, because does not protect against race conditions.
Just to let you know am using custom "TransactionDtoTransformer", in order to handle credit lifespan (validity/expiry), which contains
Now the problem is clear to me. Yes, the problem is not in the package, but in the custom assembler class. You need to add parameters not by condition, but always. Those put down the default-value.
I don't know your data and I'm assuming it's null there. This is what your assembler class should look like.
return array_merge($this->transactionDtoTransformer->extract($dto), [ 'expiring_at' => $dto->getMeta()['expire_on'] ?? null, 'amount_used' => 0, ]);
@hilal-hipster FYI
if ($dto->getMeta() !== null && isset($dto->getMeta()['expire_on'])) {
return array_merge($this->transactionDtoTransformer->extract($dto), [
'expiring_at' => $dto->getMeta()['expire_on'],
'amount_used' => 0,
]);
}
With this inside custom "TransactionDtoTransformer" everything like withdrawal, deposit, and purchase works as expected but now am facing this weird thing as I need to add the same "expiring_at" for a refund too.
@hilal-hipster My code also has this check ??
. Because of your assembler class, an incorrect query is being built in the database:
-- first query
(amount
-1150.00, confirmed
1, created_at
2022-11-07 06:00:41, meta
{"title":"Order from B2C-pickup::CO0057","description":"Purchase of Order #CO0057"}, payable_id
369, payable_type
App\Models\Order, type
withdraw, updated_at
2022-11-07 06:00:41, uuid
413b7a9d-1abe-49a6-baa1-35a34093bd05, wallet_id
874),
-- second query
(amount
1150.00, confirmed
0, created_at
1, meta
2022-11-07 06:00:41, 2023-11-07 06:00:41, payable_id
{"title":"Order from B2C-pickup::CO0057","description":"Purchase of Order #CO0057"}, payable_type
1037, type
App\Models\User, updated_at
deposit, uuid
2022-11-07 06:00:41, wallet_id
bc76ac59-400b-44c5-b6ab-a4368075517d, 470)
If you look carefully, you will see that the values ​​fly to the database are not correct. In the first case, we have fewer parameters than in the second.
With this inside custom "TransactionDtoTransformer" everything like withdrawal, deposit, and purchase works as expected but now am facing this weird thing as I need to add the same "expiring_at" for a refund too.
Inside the database, the field will still be filled in some way (default value, for example). You need to put this value in your assembler class and everything will work for you.
Well @rez1dent3 second query here was the result of another check
-- second query (amount1150.00, confirmed0, created_at1, meta2022-11-07 06:00:41, 2023-11-07 06:00:41, payable_id{"title":"Order from B2C-pickup::CO0057","description":"Purchase of Order #CO0057"}, payable_type1037, typeApp\Models\User, updated_atdeposit, uuid2022-11-07 06:00:41, wallet_idbc76ac59-400b-44c5-b6ab-a4368075517d, 470)
which was like this
if ($dto->getMeta() !== null && (isset($dto->getMeta()['title']) && str_contains($dto->getMeta()['title'],'Order from'))) { if ($dto->getPayableType() == 'App\Models\User') { return array_merge($this->transactionDtoTransformer->extract($dto), [ 'expiring_at' => Carbon::now()->addYear(), 'amount_used' => 0, ]); } }
actually was trying to add "expiring_at" for refund transactions also.
One way or another, but the problem is clearly not on the side of the package. You need to solve the problem in your domain/application layer.
With this inside custom "TransactionDtoTransformer" everything like withdrawal, deposit, and purchase works as expected but now am facing this weird thing as I need to add the same "expiring_at" for a refund too.
Inside the database, the field will still be filled in some way (default value, for example). You need to put this value in your assembler class and everything will work for you.
@rez1dent3 assembler class Transaction Assembler,
'transaction' => TransactionDtoAssembler::class,
need to override ?
One way or another, but the problem is clearly not on the side of the package. You need to solve the problem in your domain/application layer.
Understood boss 😎
need to override ?
All right.
'assemblers' => [
...
'transaction' => TransactionDtoAssembler::class,
....
I wrote about the Assembler class, but I meant Transformer. Those, you need to return always up-to-date data for the table inside the Transformer class, without IF. You should put down the default values if the data did not come.
@hilal-hipster FYI^
@rez1dent3 Will not go for any big change as of now, i.e, changing TransactionDtoAssembler as of now. Instead, I will change my logic inside "TransactionDtoTransformer" now will use
return array_merge($this->transactionDtoTransformer->extract($dto), [
'expiring_at' => $dto->getMeta()['expire_on'] ?? Carbon::now()->addYear(),
'amount_used' => 0,
]);
In short, will add "expiring_at" & "amount_used" every time. As expiration of transaction will always be managed for transaction type "deposit" 😃
By the way, after changing the cache, you can recalculate the balance using the bavix/laravel-wallet-warmup package.
composer req bavix/laravel-wallet-warmup artisan wallet:warm-up
The package consists of a single console command that runs through all wallets and applies refreshBalance.
This works awesome, Thanks @rez1dent3
Describe the bug Whenever am trying to refund an order (Purchase) am getting the error below:
Am using below to refund a purchase.
Furthermore, a transfer is also giving the same error, i.e, "1136 Column count doesn't match value count at row 2", Transfer logic is stated below
Trace Error
Server: