-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: process authorized transactions as job (#375)
- Loading branch information
Showing
11 changed files
with
140 additions
and
67 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 was deleted.
Oops, something went wrong.
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,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Enums\EuPlatescStatus; | ||
use App\Models\Donation; | ||
use App\Services\EuPlatescService; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldBeUnique; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class CaptureAuthorizedDonationJob implements ShouldQueue, ShouldBeUnique | ||
{ | ||
use Dispatchable; | ||
use InteractsWithQueue; | ||
use Queueable; | ||
use SerializesModels; | ||
|
||
public Donation $donation; | ||
|
||
public EuPlatescService $service; | ||
|
||
/** | ||
* The number of seconds after which the job's unique lock will be released. | ||
* | ||
* @var int | ||
*/ | ||
public $uniqueFor = 3600; | ||
|
||
/** | ||
* Get the unique ID for the job. | ||
*/ | ||
public function uniqueId(): int | ||
{ | ||
return $this->donation->id; | ||
} | ||
|
||
public function __construct(Donation $donation, EuPlatescService $service) | ||
{ | ||
$this->donation = $donation; | ||
$this->service = $service; | ||
} | ||
|
||
public function handle(): void | ||
{ | ||
if ($this->service->recipeTransaction($this->donation)) { | ||
$this->donation->update([ | ||
'status' => EuPlatescStatus::CHARGED, | ||
'status_updated_at' => now(), | ||
]); | ||
} | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Jobs; | ||
|
||
use App\Models\Donation; | ||
use App\Models\Organization; | ||
use App\Services\EuPlatescService; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Database\Query\Builder; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class ProcessAuthorizedTransactionsJob implements ShouldQueue | ||
{ | ||
use Dispatchable; | ||
use InteractsWithQueue; | ||
use Queueable; | ||
use SerializesModels; | ||
|
||
/** | ||
* Execute the job. | ||
*/ | ||
public function handle(): void | ||
{ | ||
Organization::query() | ||
->whereHasEuPlatesc() | ||
->withWhereHas('donations', function (Builder $query) { | ||
return $query | ||
->whereAuthorized() | ||
->whereNotNull('ep_id'); | ||
}) | ||
->get() | ||
->each(function (Organization $organization) { | ||
$service = new EuPlatescService($organization); | ||
|
||
$organization->donations | ||
->each(fn (Donation $donation) => CaptureAuthorizedDonationJob::dispatch($donation, $service)); | ||
}); | ||
} | ||
} |
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
Empty file.
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 @@ | ||
laravel |
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,9 @@ | ||
#!/command/with-contenv sh | ||
|
||
php /var/www/artisan queue:work \ | ||
--max-jobs $WORKER_MAX_JOBS \ | ||
--sleep $WORKER_SLEEP \ | ||
--rest $WORKER_REST \ | ||
--timeout $WORKER_TIMEOUT \ | ||
--tries $WORKER_TRIES \ | ||
--force |
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 @@ | ||
longrun |