Skip to content

Commit

Permalink
add transaction completed event
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Jan 7, 2024
1 parent 242ac84 commit b48bc2b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Events/TransactionCompleted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Cone\Bazar\Events;

use Cone\Bazar\Models\Transaction;
use Illuminate\Foundation\Events\Dispatchable;

class TransactionCompleted
{
use Dispatchable;

/**
* The transaction instance.
*/
public Transaction $transaction;

/**
* Create a new event instance.
*/
public function __construct(Transaction $transaction)
{
$this->transaction = $transaction;
}
}
3 changes: 3 additions & 0 deletions src/Models/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Cone\Bazar\Models;

use Cone\Bazar\Database\Factories\TransactionFactory;
use Cone\Bazar\Events\TransactionCompleted;
use Cone\Bazar\Interfaces\Models\Transaction as Contract;
use Cone\Bazar\Support\Facades\Gateway;
use Cone\Root\Traits\InteractsWithProxy;
Expand Down Expand Up @@ -153,6 +154,8 @@ public function markAsCompleted(?DateTimeInterface $date = null): void

if ($this->pending() || $this->completed_at->notEqualTo($date)) {
$this->setAttribute('completed_at', $date)->save();

TransactionCompleted::dispatch($this);
}
}

Expand Down

0 comments on commit b48bc2b

Please sign in to comment.