Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- [Webhooks Events]()
- [Verify webhook signature manually](#Verify-webhook-signature)
- [Validate webhook signature manually](#validate-webhook-signature)
- [Commands](#commands)
- [Testing and test cards](#Testing-and-test-cards)

## Introduction
Expand Down Expand Up @@ -565,6 +566,16 @@ class YouCanPayWebhooksController extends Controller
}
```

### Commands

If you need to clean the pending transactions, there's a command

```shell
php artisan youcanpay:clean-pending-transactions
```

You can add it to the scheduler that can run the command every single time, so the clean will be automatic and depend on the `tolerance` value that is defined in the `youcanpay` config file.

## Testing and test cards

| **CARD** | **CVV** | **DATE** | **BEHAVIOUR** |
Expand Down Expand Up @@ -604,7 +615,3 @@ The MIT License (MIT). Please see [License File](LICENSE.md) for more informatio
## Laravel Package Boilerplate

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

```

```
11 changes: 10 additions & 1 deletion config/youcanpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@

"success_redirect_uri" => env("SUCCCESS_REDIRECT_URI"),

"fail_redirect_uri" => env("FAIL_REDIRECT_URI")
"fail_redirect_uri" => env("FAIL_REDIRECT_URI"),

/*
* The tolerance value at which to look to the old pending transactions,
* and remove them from the database.
* By default it's set to 48 hours
*/
"transaction" => [
"tolerance" => env('TRANSACTION_TOLERANCE', 60 * 60 * 48),
]

];
15 changes: 15 additions & 0 deletions database/factories/TransactionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,19 @@ public function definition()
'payload'=> []
];
}


/**
* Indicate that the transaction is pending.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function pending()
{
return $this->state(function (array $attributes) {
return [
'status' => YouCanPayStatus::pending(),
];
});
}
}
43 changes: 43 additions & 0 deletions src/Console/CleanPendingTransactionCommand.php
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();
}
}
}
3 changes: 0 additions & 3 deletions src/Facades/LaravelYouCanPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use Illuminate\Support\Facades\Facade;

/**
* @see \Devinweb\LaravelYouCanPay\Skeleton\SkeletonClass
*/
class LaravelYouCanPay extends Facade
{
/**
Expand Down
21 changes: 0 additions & 21 deletions src/Facades/LaravelYoucanPay.php

This file was deleted.

Loading