fix gitlab tests
This commit is contained in:
@@ -5,8 +5,8 @@ namespace App\Services\Payments;
|
||||
use App\Models\Configuration;
|
||||
use App\Models\Enrollment;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PayPalPayment;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Student;
|
||||
use App\Models\User;
|
||||
use App\Services\EmailService;
|
||||
@@ -14,7 +14,9 @@ use Illuminate\Support\Facades\Log;
|
||||
|
||||
class PaypalPaymentSyncService
|
||||
{
|
||||
public function __construct(private EmailService $emailService) {}
|
||||
public function __construct(private EmailService $emailService)
|
||||
{
|
||||
}
|
||||
|
||||
public function sync(bool $dryRun = false, bool $reportOnly = false): array
|
||||
{
|
||||
@@ -34,16 +36,15 @@ class PaypalPaymentSyncService
|
||||
$failed = [];
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
if (! $reportOnly) {
|
||||
if (!$reportOnly) {
|
||||
$entry->sync_attempts = (int) $entry->sync_attempts + 1;
|
||||
$entry->save();
|
||||
}
|
||||
|
||||
$user = User::query()->where('school_id', $entry->parent_school_id)->first();
|
||||
if (! $user) {
|
||||
if (!$user) {
|
||||
$failed[] = (string) $entry->transaction_id;
|
||||
Log::error('PayPal sync: no user for parent_school_id', ['parent_school_id' => $entry->parent_school_id]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -53,12 +54,11 @@ class PaypalPaymentSyncService
|
||||
->latest('created_at')
|
||||
->first();
|
||||
|
||||
if (! $reportOnly && ! $dryRun) {
|
||||
if (!$reportOnly && !$dryRun) {
|
||||
if ($invoice) {
|
||||
$ok = $this->applyPayment($invoice, $entry->amount, (string) $entry->transaction_id, $schoolYear, $semester, $entry->created_at);
|
||||
if (! $ok) {
|
||||
if (!$ok) {
|
||||
$failed[] = (string) $entry->transaction_id;
|
||||
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
@@ -106,7 +106,7 @@ class PaypalPaymentSyncService
|
||||
$invoice->status = 'Paid';
|
||||
}
|
||||
|
||||
if (! $invoice->save()) {
|
||||
if (!$invoice->save()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ class PaypalPaymentSyncService
|
||||
private function updateEnrollmentStatusIfPaid(int $invoiceId, string $schoolYear): void
|
||||
{
|
||||
$invoice = Invoice::query()->find($invoiceId);
|
||||
if (! $invoice || (float) $invoice->balance > 0) {
|
||||
if (!$invoice || (float) $invoice->balance > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -155,16 +155,15 @@ class PaypalPaymentSyncService
|
||||
{
|
||||
if ($processed === 0 && empty($failed)) {
|
||||
Log::info("[{$mode}] No PayPal sync updates.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$subject = "[{$mode}] PayPal Sync Report - ".now()->format('Y-m-d H:i');
|
||||
$subject = "[{$mode}] PayPal Sync Report - " . now()->format('Y-m-d H:i');
|
||||
$body = "PayPal Sync Mode: {$mode}\n\n";
|
||||
$body .= "{$processed} PayPal payments processed.\n\n";
|
||||
|
||||
if (! empty($failed)) {
|
||||
$body .= count($failed)." failed transactions:\n".implode("\n", $failed);
|
||||
if (!empty($failed)) {
|
||||
$body .= count($failed) . " failed transactions:\n" . implode("\n", $failed);
|
||||
} else {
|
||||
$body .= "No failed transactions.\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user