bavix / laravel-wallet

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

Returned error: Transaction failed. Message: Bavix\Wallet\Internal\Service\StorageService::get(): Argument #1 ($uuid) must be of type string, null given, called in C:\Users\BAMIDELE\Documents\DELASOFT\www\payvilla\vendor\bavix\laravel-wallet\src\Services\RegulatorService.php on line 52 #967

Closed delasoftcode closed 1 week ago

delasoftcode commented 2 weeks ago

Trying to listen to the TransactionCreatedEventInterface to send a notification gives me error:

TransactionCreatedListner

namespace App\Listeners;

use App\Models\User;
use App\Notifications\TransactionCreatedNotification;
use Bavix\Wallet\Models\Wallet;
use Bavix\Wallet\Internal\Events\TransactionCreatedEventInterface;
use Bavix\Wallet\Models\Transaction;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;

class TransactionCreatedListener
{
    protected $transaction;

    /**
     * Create the event listener.
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     */
    public function handle(TransactionCreatedEventInterface $event): void
    {
        Log::alert($event->getId());
        // retrieve transaction
        $this->transaction = Transaction::where('id', '=', $event->getId());

        // retrieve user id
        $user_id = $this->transaction->pluck('payable_id');

        // $user_id = implode($user_id->toArray());

        // retrieve user
        $user = User::find($user_id);

        // retrieve amount
        $amount = $this->transaction->pluck('amount');
        // $amount = implode($transaction->toArray());

        // retrieve balance
        $wallet_balance = Wallet::where('id', '=', $event->getWalletId())->pluck('balance');

        $data = ['balance' => $wallet_balance, 'type' => $event->getType, 'amount' => $amount, 'date' => $event->getCreatedAt()];

        // send notification
        $user->notify(new TransactionCreatedNotification($data));
    }
}

TransactionCreatedNotification

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
// use App\Listeners\TransactionCreatedListener;

class TransactionCreatedNotification extends Notification
{
    use Queueable;

    protected $data;

    /**
     * Create a new notification instance.
     */
    public function __construct($data)
    {
        $this->data = $data;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @return array<int, string>
     */
    public function via(object $notifiable): array
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     */
    public function toMail(object $notifiable): MailMessage
    {
        return (new MailMessage)
                    ->subject('Wallet '.ucfirst($this->data['type']))
                    ->line('transaction occur')
                    ->line('A wallet '.$this->data->type.' just occurred on your account.')
                    ->line('Type: '.$this->data['type'])
                    ->line('Balance: '.$this->data['balance'])
                    ->line('Time: '.$this->data['date'])
                    ->line('Thank you for using SelarPoint!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @return array<string, mixed>
     */
    public function toArray(object $notifiable): array
    {
        return [
            //
        ];
    }
}

AppServiceProvider

public function boot(): void
    {
        Event::listen(
            TransactionCreatedEventInterface::class,
            TransactionCreatedListener::class,
        );
    }

Server:

delasoftcode commented 2 weeks ago

Laravel version 11.0

rez1dent3 commented 2 weeks ago

@delasoftcode hello. Your wallet does not exist, because... it doesn't have a uuid. That's why you get the error.

This line tells me https://github.com/bavix/laravel-wallet/blob/83e3de51c9d9f629f478e7979dc5486a96389f41/src/Services/RegulatorService.php#L52

Please add the code you are running to get this error.

PS, I've edited the issue to add syntax highlighting.

github-actions[bot] commented 1 week ago

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