bavix / laravel-wallet

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

Bavix\Wallet\Exceptions\UnconfirmedInvalid Confirmation has already been reset #971

Closed momostafa closed 1 month ago

momostafa commented 1 month ago

Describe your task When I try to delete a transaction that is not confirmed i get below error

Bavix\Wallet\Exceptions\UnconfirmedInvalid Confirmation has already been reset

To Reproduce Steps to reproduce the behavior: I am using Filament v3.2.92 for rendering tables

  1. Go to transactions table list view
  2. Click on on delete record
  3. the page displays error Bavix\Wallet\Exceptions\UnconfirmedInvalid Confirmation has already been reset
  4. If edit the record and change it from unconfirmed to confirmed only then i am able to delete the record

Trace Error I don't have it...

Expected behavior I expect to be able to delete transactions record either confirmed or unconfirmed

Server:

my extended transaction model

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Models\User;
use Bavix\Wallet\Traits\CanConfirm;
use Kevupton\LaravelCoinpayments\Models\Transaction as CoinpaymentsTransaction;
use Kevupton\LaravelCoinpayments\Coinpayments;

class Transaction extends \Bavix\Wallet\Models\Transaction
{
    use HasFactory;
    use CanConfirm;

    //use WatchableTrait;

    protected $fillable = [
        'payable_type',
        'payable_id',
        'wallet_id',
        'uuid',
        'type',
        'amount',
        'confirmed',
        'meta',
        'created_at',
        'updated_at',
    ];

    protected $casts = [
        'wallet_id' => 'int',
        'confirmed' => 'bool',
        'meta' => 'array',
    ];

    public function owner(): BelongsTo
    {
        return $this->belongsTo(User::class, 'id', 'payable_id');
    }

    public function wallet(): BelongsTo
    {
        return $this->belongsTo(Wallet::class);

    }

    public function onModelSaved(): void
    {
        optional($this->wallet)->refreshBalance();
    }

    public static function refreshTransactionStatus($TxnId, $all = false)
    {

        $private_key = env('COINPAYMENTS_PRIVATE_KEY');
        $public_key = env('COINPAYMENTS_PUBLIC_KEY');
        $merchant_id = env('COINPAYMENTS_MERCHANT_ID');
        $ipn_secret = env('COINPAYMENTS_IPN_SECRET');
        $ipn_url = env('COINPAYMENTS_IPN_URL');

        $transaction = new Coinpayments($private_key,
            $public_key,
            $merchant_id,
            $ipn_secret,
            $ipn_url,'json');

        $txn_id = $transaction->getTransactionInfo($TxnId, $all);

        $status = $txn_id->getResponse()['result']['status'];
        $status_text = $txn_id->getResponse()['result']['status_text'];
        $error = $txn_id->getResponse()['error'];
       // dd($error);
        if($error == 'ok') {

        CoinpaymentsTransaction::where('txn_id', $TxnId)->update(['status' => $status, 'status_text' => $status_text]);

        $updated = 'Status:'. ' ' . $status_text;
        return $updated;
       } else {
        return $error;
       }

    }

}

Thanks for your help and support

rez1dent3 commented 1 month ago

Yes, this is god related to adding soft delete. I'll fix it today or tomorrow.

momostafa commented 1 month ago

Thank you for your quick response

rez1dent3 commented 1 month ago

@momostafa FYI. Tag 11.1.0

Thanks for your feedback

momostafa commented 1 month ago

Thanks a lot I will update