-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add command to clean pending transactions.
- Loading branch information
Showing
9 changed files
with
135 additions
and
404 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
namespace Devinweb\LaravelYouCanPay\Console; | ||
|
||
use Devinweb\LaravelYouCanPay\Enums\YouCanPayStatus; | ||
use Devinweb\LaravelYouCanPay\Models\Transaction; | ||
use Illuminate\Console\Command; | ||
use Carbon\Carbon; | ||
|
||
class CleanPendingTransactionCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'youcanpay:clean-pending-transactions'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Clean all pending transactions based on the tolerance value get it from the youcanpay config file.'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
$tolerance = config('youcanpay.transaction.tolerance'); | ||
|
||
$transactions = Transaction::whereStatus(YouCanPayStatus::pending()) | ||
->where('created_at', '<=', Carbon::now()) | ||
->where('created_at', '>=', Carbon::now()->subSeconds($tolerance ?? 60*60*24)) | ||
->get(); | ||
|
||
foreach ($transactions as $transaction) { | ||
$transaction->delete(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.