Page MenuHomePhorge

D5157.1775456614.diff
No OneTemporary

Authored By
Unknown
Size
20 KB
Referenced Files
None
Subscribers
None

D5157.1775456614.diff

diff --git a/src/app/Console/Commands/JobExecuteCommand.php b/src/app/Console/Commands/JobExecuteCommand.php
--- a/src/app/Console/Commands/JobExecuteCommand.php
+++ b/src/app/Console/Commands/JobExecuteCommand.php
@@ -32,9 +32,7 @@
$job = str_replace('/', '\\', $job);
- if (preg_match('/^(WalletCheck|WalletCharge)$/', $job)) {
- $object = $this->getWallet($object);
- } elseif (preg_match('/^(User|Domain|Group|Resource|SharedFolder).[a-zA-Z]+$/', $job, $m)) {
+ if (preg_match('/^(User|Domain|Group|Resource|SharedFolder|Wallet).[a-zA-Z]+$/', $job, $m)) {
$object = $this->{'get' . $m[1]}($object);
} else {
$this->error("Invalid or unsupported job name.");
diff --git a/src/app/Console/Commands/Wallet/ChargeCommand.php b/src/app/Console/Commands/Wallet/ChargeCommand.php
--- a/src/app/Console/Commands/Wallet/ChargeCommand.php
+++ b/src/app/Console/Commands/Wallet/ChargeCommand.php
@@ -68,9 +68,9 @@
} else {
if ($this->option('topup')) {
$this->info("Dispatching wallet charge for {$wallet->id}");
- \App\Jobs\WalletCharge::dispatch($wallet->id);
+ \App\Jobs\Wallet\ChargeJob::dispatch($wallet->id);
} else {
- \App\Jobs\WalletCheck::dispatch($wallet->id);
+ \App\Jobs\Wallet\CheckJob::dispatch($wallet->id);
}
}
}
diff --git a/src/app/Http/Controllers/API/V4/PaymentsController.php b/src/app/Http/Controllers/API/V4/PaymentsController.php
--- a/src/app/Http/Controllers/API/V4/PaymentsController.php
+++ b/src/app/Http/Controllers/API/V4/PaymentsController.php
@@ -132,7 +132,7 @@
// Trigger auto-payment if the balance is below the threshold
if ($wallet->balance < round($request->balance * 100)) {
- \App\Jobs\WalletCharge::dispatch($wallet->id);
+ \App\Jobs\Wallet\ChargeJob::dispatch($wallet->id);
}
$result = self::walletMandate($wallet);
diff --git a/src/app/Jobs/WalletCharge.php b/src/app/Jobs/Wallet/ChargeJob.php
rename from src/app/Jobs/WalletCharge.php
rename to src/app/Jobs/Wallet/ChargeJob.php
--- a/src/app/Jobs/WalletCharge.php
+++ b/src/app/Jobs/Wallet/ChargeJob.php
@@ -1,10 +1,11 @@
<?php
-namespace App\Jobs;
+namespace App\Jobs\Wallet;
+use App\Jobs\CommonJob;
use App\Wallet;
-class WalletCharge extends CommonJob
+class ChargeJob extends CommonJob
{
/** @var int How many times retry the job if it fails. */
public $tries = 5;
diff --git a/src/app/Jobs/WalletCheck.php b/src/app/Jobs/Wallet/CheckJob.php
rename from src/app/Jobs/WalletCheck.php
rename to src/app/Jobs/Wallet/CheckJob.php
--- a/src/app/Jobs/WalletCheck.php
+++ b/src/app/Jobs/Wallet/CheckJob.php
@@ -1,11 +1,12 @@
<?php
-namespace App\Jobs;
+namespace App\Jobs\Wallet;
+use App\Jobs\CommonJob;
use App\Wallet;
use Carbon\Carbon;
-class WalletCheck extends CommonJob
+class CheckJob extends CommonJob
{
public const THRESHOLD_DEGRADE = 'degrade';
public const THRESHOLD_DEGRADE_REMINDER = 'degrade-reminder';
@@ -224,10 +225,10 @@
* Get the date-time for an action threshold. Calculated using
* the date when a wallet balance turned negative.
*
- * @param \App\Wallet $wallet A wallet
- * @param string $type Action type (one of self::THRESHOLD_*)
+ * @param Wallet $wallet A wallet
+ * @param string $type Action type (one of self::THRESHOLD_*)
*
- * @return \Carbon\Carbon The threshold date-time object
+ * @return Carbon The threshold date-time object
*/
public static function threshold(Wallet $wallet, string $type): ?Carbon
{
diff --git a/src/app/Mail/NegativeBalanceDegraded.php b/src/app/Mail/NegativeBalanceDegraded.php
--- a/src/app/Mail/NegativeBalanceDegraded.php
+++ b/src/app/Mail/NegativeBalanceDegraded.php
@@ -2,7 +2,6 @@
namespace App\Mail;
-use App\Jobs\WalletCheck;
use App\Tenant;
use App\User;
use App\Utils;
@@ -10,15 +9,15 @@
class NegativeBalanceDegraded extends Mailable
{
- /** @var \App\Wallet A wallet with a negative balance */
+ /** @var Wallet A wallet with a negative balance */
protected $wallet;
/**
* Create a new message instance.
*
- * @param \App\Wallet $wallet A wallet
- * @param \App\User $user A wallet controller to whom the email is being sent
+ * @param Wallet $wallet A wallet
+ * @param User $user A wallet controller to whom the email is being sent
*
* @return void
*/
diff --git a/src/app/Mail/NegativeBalanceReminderDegrade.php b/src/app/Mail/NegativeBalanceReminderDegrade.php
--- a/src/app/Mail/NegativeBalanceReminderDegrade.php
+++ b/src/app/Mail/NegativeBalanceReminderDegrade.php
@@ -2,7 +2,7 @@
namespace App\Mail;
-use App\Jobs\WalletCheck;
+use App\Jobs\Wallet\CheckJob;
use App\Tenant;
use App\User;
use App\Utils;
@@ -37,7 +37,7 @@
{
$appName = Tenant::getConfig($this->user->tenant_id, 'app.name');
$supportUrl = Tenant::getConfig($this->user->tenant_id, 'app.support_url');
- $threshold = WalletCheck::threshold($this->wallet, WalletCheck::THRESHOLD_DEGRADE);
+ $threshold = CheckJob::threshold($this->wallet, CheckJob::THRESHOLD_DEGRADE);
$vars = [
'date' => $threshold->toDateString(),
diff --git a/src/app/Providers/Payment/Stripe.php b/src/app/Providers/Payment/Stripe.php
--- a/src/app/Providers/Payment/Stripe.php
+++ b/src/app/Providers/Payment/Stripe.php
@@ -79,7 +79,7 @@
];
// Note: Stripe does not allow to set amount for 'setup' operation
- // We'll dispatch WalletCharge job when we receive a webhook request
+ // We'll dispatch Wallet\ChargeJob when we receive a webhook request
$session = StripeAPI\Checkout\Session::create($request);
@@ -375,7 +375,7 @@
// Top-up the wallet if balance is below the threshold
if ($payment->wallet->balance < $threshold && $payment->status != Payment::STATUS_PAID) {
- \App\Jobs\WalletCharge::dispatch($payment->wallet->id);
+ \App\Jobs\Wallet\ChargeJob::dispatch($payment->wallet->id);
}
}
diff --git a/src/tests/Feature/Console/Wallet/ChargeTest.php b/src/tests/Feature/Console/Wallet/ChargeTest.php
--- a/src/tests/Feature/Console/Wallet/ChargeTest.php
+++ b/src/tests/Feature/Console/Wallet/ChargeTest.php
@@ -50,8 +50,8 @@
$this->artisan('wallet:charge ' . $wallet->id)
->assertExitCode(0);
- Queue::assertPushed(\App\Jobs\WalletCheck::class, 1);
- Queue::assertPushed(\App\Jobs\WalletCheck::class, function ($job) use ($wallet) {
+ Queue::assertPushed(\App\Jobs\Wallet\CheckJob::class, 1);
+ Queue::assertPushed(\App\Jobs\Wallet\CheckJob::class, function ($job) use ($wallet) {
$job_wallet_id = TestCase::getObjectProperty($job, 'walletId');
return $job_wallet_id === $wallet->id;
});
@@ -76,12 +76,12 @@
$this->artisan('wallet:charge')->assertExitCode(0);
- Queue::assertPushed(\App\Jobs\WalletCheck::class, $count);
- Queue::assertPushed(\App\Jobs\WalletCheck::class, function ($job) use ($wallet1) {
+ Queue::assertPushed(\App\Jobs\Wallet\CheckJob::class, $count);
+ Queue::assertPushed(\App\Jobs\Wallet\CheckJob::class, function ($job) use ($wallet1) {
$job_wallet_id = TestCase::getObjectProperty($job, 'walletId');
return $job_wallet_id === $wallet1->id;
});
- Queue::assertPushed(\App\Jobs\WalletCheck::class, function ($job) use ($wallet2) {
+ Queue::assertPushed(\App\Jobs\Wallet\CheckJob::class, function ($job) use ($wallet2) {
$job_wallet_id = TestCase::getObjectProperty($job, 'walletId');
return $job_wallet_id === $wallet2->id;
});
diff --git a/src/tests/Feature/Controller/PaymentsMollieEuroTest.php b/src/tests/Feature/Controller/PaymentsMollieEuroTest.php
--- a/src/tests/Feature/Controller/PaymentsMollieEuroTest.php
+++ b/src/tests/Feature/Controller/PaymentsMollieEuroTest.php
@@ -205,7 +205,7 @@
$this->assertEquals(30.10, $wallet->getSetting('mandate_amount'));
$this->assertEquals(10, $wallet->getSetting('mandate_balance'));
- Bus::assertDispatchedTimes(\App\Jobs\WalletCharge::class, 0);
+ Bus::assertDispatchedTimes(\App\Jobs\Wallet\ChargeJob::class, 0);
// Test updating a disabled mandate (invalid input)
$wallet->setSetting('mandate_disabled', 1);
@@ -235,8 +235,8 @@
$this->assertSame($mandate_id, $json['id']);
$this->assertFalse($json['isDisabled']);
- Bus::assertDispatchedTimes(\App\Jobs\WalletCharge::class, 1);
- Bus::assertDispatched(\App\Jobs\WalletCharge::class, function ($job) use ($wallet) {
+ Bus::assertDispatchedTimes(\App\Jobs\Wallet\ChargeJob::class, 1);
+ Bus::assertDispatched(\App\Jobs\Wallet\ChargeJob::class, function ($job) use ($wallet) {
$job_wallet_id = $this->getObjectProperty($job, 'walletId');
return $job_wallet_id === $wallet->id;
});
diff --git a/src/tests/Feature/Controller/PaymentsMollieTest.php b/src/tests/Feature/Controller/PaymentsMollieTest.php
--- a/src/tests/Feature/Controller/PaymentsMollieTest.php
+++ b/src/tests/Feature/Controller/PaymentsMollieTest.php
@@ -239,7 +239,7 @@
$this->assertEquals(30.10, $wallet->getSetting('mandate_amount'));
$this->assertEquals(10, $wallet->getSetting('mandate_balance'));
- Bus::assertDispatchedTimes(\App\Jobs\WalletCharge::class, 0);
+ Bus::assertDispatchedTimes(\App\Jobs\Wallet\ChargeJob::class, 0);
// Test updating a disabled mandate (invalid input)
$wallet->setSetting('mandate_disabled', 1);
@@ -269,8 +269,8 @@
$this->assertSame($mandate_id, $json['id']);
$this->assertFalse($json['isDisabled']);
- Bus::assertDispatchedTimes(\App\Jobs\WalletCharge::class, 1);
- Bus::assertDispatched(\App\Jobs\WalletCharge::class, function ($job) use ($wallet) {
+ Bus::assertDispatchedTimes(\App\Jobs\Wallet\ChargeJob::class, 1);
+ Bus::assertDispatched(\App\Jobs\Wallet\ChargeJob::class, function ($job) use ($wallet) {
$job_wallet_id = $this->getObjectProperty($job, 'walletId');
return $job_wallet_id === $wallet->id;
});
diff --git a/src/tests/Feature/Controller/PaymentsStripeTest.php b/src/tests/Feature/Controller/PaymentsStripeTest.php
--- a/src/tests/Feature/Controller/PaymentsStripeTest.php
+++ b/src/tests/Feature/Controller/PaymentsStripeTest.php
@@ -283,8 +283,8 @@
$this->assertSame('AAA', $json['id']);
$this->assertFalse($json['isDisabled']);
- Bus::assertDispatchedTimes(\App\Jobs\WalletCharge::class, 1);
- Bus::assertDispatched(\App\Jobs\WalletCharge::class, function ($job) use ($wallet) {
+ Bus::assertDispatchedTimes(\App\Jobs\Wallet\ChargeJob::class, 1);
+ Bus::assertDispatched(\App\Jobs\Wallet\ChargeJob::class, function ($job) use ($wallet) {
$job_wallet_id = $this->getObjectProperty($job, 'walletId');
return $job_wallet_id === $wallet->id;
});
@@ -515,9 +515,9 @@
$this->assertSame(Payment::STATUS_PAID, $payment->status);
$this->assertSame($payment->id, $wallet->fresh()->getSetting('stripe_mandate_id'));
- // Expect a WalletCharge job if the balance is negative
- Bus::assertDispatchedTimes(\App\Jobs\WalletCharge::class, 1);
- Bus::assertDispatched(\App\Jobs\WalletCharge::class, function ($job) use ($wallet) {
+ // Expect a wallet charge job if the balance is negative
+ Bus::assertDispatchedTimes(\App\Jobs\Wallet\ChargeJob::class, 1);
+ Bus::assertDispatched(\App\Jobs\Wallet\ChargeJob::class, function ($job) use ($wallet) {
$job_wallet_id = TestCase::getObjectProperty($job, 'walletId');
return $job_wallet_id === $wallet->id;
});
diff --git a/src/tests/Feature/Controller/Reseller/PaymentsMollieTest.php b/src/tests/Feature/Controller/Reseller/PaymentsMollieTest.php
--- a/src/tests/Feature/Controller/Reseller/PaymentsMollieTest.php
+++ b/src/tests/Feature/Controller/Reseller/PaymentsMollieTest.php
@@ -141,7 +141,7 @@
$this->assertEquals(30.10, $wallet->getSetting('mandate_amount'));
$this->assertEquals(10, $wallet->getSetting('mandate_balance'));
- Bus::assertDispatchedTimes(\App\Jobs\WalletCharge::class, 0);
+ Bus::assertDispatchedTimes(\App\Jobs\Wallet\ChargeJob::class, 0);
// Delete mandate
$response = $this->actingAs($reseller)->delete("api/v4/payments/mandate");
diff --git a/src/tests/Feature/Jobs/WalletCheckTest.php b/src/tests/Feature/Jobs/Wallet/CheckTest.php
rename from src/tests/Feature/Jobs/WalletCheckTest.php
rename to src/tests/Feature/Jobs/Wallet/CheckTest.php
--- a/src/tests/Feature/Jobs/WalletCheckTest.php
+++ b/src/tests/Feature/Jobs/Wallet/CheckTest.php
@@ -1,8 +1,8 @@
<?php
-namespace Tests\Feature\Jobs;
+namespace Tests\Feature\Jobs\Wallet;
-use App\Jobs\WalletCheck;
+use App\Jobs\Wallet\CheckJob;
use App\User;
use App\Wallet;
use Carbon\Carbon;
@@ -10,7 +10,7 @@
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
-class WalletCheckTest extends TestCase
+class CheckTest extends TestCase
{
/**
* {@inheritDoc}
@@ -41,8 +41,8 @@
// Test that the job is dispatched to the proper queue
Queue::fake();
$user = $this->getTestUser('jack@kolab.org');
- WalletCheck::dispatch($user->wallets()->first()->id);
- Queue::assertPushedOn(\App\Enums\Queue::Background->value, WalletCheck::class);
+ CheckJob::dispatch($user->wallets()->first()->id);
+ Queue::assertPushedOn(\App\Enums\Queue::Background->value, CheckJob::class);
}
/**
@@ -58,7 +58,7 @@
$wallet->balance = 0;
$wallet->save();
- $job = new WalletCheck($wallet->id);
+ $job = new CheckJob($wallet->id);
$job->handle();
// Ensure the job ends up on the correct queue
@@ -70,7 +70,7 @@
$wallet->balance = -100;
$wallet->save();
- $job = new WalletCheck($wallet->id);
+ $job = new CheckJob($wallet->id);
$job->handle();
Mail::assertNothingSent();
@@ -79,7 +79,7 @@
$wallet->setSetting('balance_negative_since', $now->subHours(2)->toDateTimeString());
$wallet->setSetting('balance_warning_initial', null);
- $job = new WalletCheck($wallet->id);
+ $job = new CheckJob($wallet->id);
$job->handle();
// Assert the mail was sent to the user's email, but not to his external email
@@ -90,7 +90,7 @@
// Run the job again to make sure the notification is not sent again
Mail::fake();
- $job = new WalletCheck($wallet->id);
+ $job = new CheckJob($wallet->id);
$job->handle();
Mail::assertNothingSent();
@@ -100,7 +100,7 @@
$wallet->setSetting('balance_negative_since', null);
$wallet->setSetting('balance_warning_initial', null);
- $job = new WalletCheck($wallet->id);
+ $job = new CheckJob($wallet->id);
$job->handle();
// Assert the mail was sent to the user's email, but not to his external email
@@ -119,7 +119,7 @@
$wallet->owner->suspend();
$wallet->setSetting('balance_warning_initial', null);
- $job = new WalletCheck($wallet->id);
+ $job = new CheckJob($wallet->id);
$job->handle();
Mail::assertNothingSent();
@@ -138,7 +138,7 @@
$wallet->save();
$this->backdateEntitlements($wallet->entitlements, Carbon::now()->subWeeks(5));
- $job = new WalletCheck($wallet->id);
+ $job = new CheckJob($wallet->id);
$job->handle();
$wallet->refresh();
@@ -162,7 +162,7 @@
// Balance turned negative 7+1 days ago, expect mail sent
$wallet->setSetting('balance_negative_since', $now->subDays(7 + 1)->toDateTimeString());
- $job = new WalletCheck($wallet->id);
+ $job = new CheckJob($wallet->id);
$job->handle();
// Assert the mail was sent to the user's email and to his external email
@@ -173,7 +173,7 @@
// Run the job again to make sure the notification is not sent again
Mail::fake();
- $job = new WalletCheck($wallet->id);
+ $job = new CheckJob($wallet->id);
$job->handle();
Mail::assertNothingSent();
@@ -183,7 +183,7 @@
$wallet->owner->suspend();
$wallet->setSetting('balance_warning_reminder', null);
- $job = new WalletCheck($wallet->id);
+ $job = new CheckJob($wallet->id);
$job->handle();
Mail::assertNothingSent();
@@ -207,7 +207,7 @@
$days = 7 + 7 + 1;
$wallet->setSetting('balance_negative_since', $now->subDays($days)->toDateTimeString());
- $job = new WalletCheck($wallet->id);
+ $job = new CheckJob($wallet->id);
$job->handle();
// Assert the mail was sent to the user's email, and his external email
@@ -224,7 +224,7 @@
$wallet->owner->suspend();
$wallet->owner->undegrade();
- $job = new WalletCheck($wallet->id);
+ $job = new CheckJob($wallet->id);
$job->handle();
Mail::assertNothingSent();
@@ -248,32 +248,32 @@
// Test degraded_last_reminder not set
$wallet->setSetting('degraded_last_reminder', null);
- $job = new WalletCheck($wallet->id);
+ $job = new CheckJob($wallet->id);
$res = $job->handle();
Mail::assertNothingSent();
$_last = Wallet::find($wallet->id)->getSetting('degraded_last_reminder');
$this->assertSame(Carbon::now()->toDateTimeString(), $_last);
- $this->assertSame(WalletCheck::THRESHOLD_DEGRADE_REMINDER, $res);
+ $this->assertSame(CheckJob::THRESHOLD_DEGRADE_REMINDER, $res);
// Test degraded_last_reminder set, but 14 days didn't pass yet
$last = $now->copy()->subDays(10);
$wallet->setSetting('degraded_last_reminder', $last->toDateTimeString());
- $job = new WalletCheck($wallet->id);
+ $job = new CheckJob($wallet->id);
$res = $job->handle();
Mail::assertNothingSent();
$_last = $wallet->fresh()->getSetting('degraded_last_reminder');
- $this->assertSame(WalletCheck::THRESHOLD_DEGRADE_REMINDER, $res);
+ $this->assertSame(CheckJob::THRESHOLD_DEGRADE_REMINDER, $res);
$this->assertSame($last->toDateTimeString(), $_last);
// Test degraded_last_reminder set, and 14 days passed
$wallet->setSetting('degraded_last_reminder', $now->copy()->subDays(14)->setSeconds(0));
- $job = new WalletCheck($wallet->id);
+ $job = new CheckJob($wallet->id);
$res = $job->handle();
// Assert the mail was sent to the user's email, and his external email
@@ -284,7 +284,7 @@
$_last = $wallet->fresh()->getSetting('degraded_last_reminder');
$this->assertSame(Carbon::now()->toDateTimeString(), $_last);
- $this->assertSame(WalletCheck::THRESHOLD_DEGRADE_REMINDER, $res);
+ $this->assertSame(CheckJob::THRESHOLD_DEGRADE_REMINDER, $res);
// Test suspended user - no mail sent
Mail::fake();
@@ -292,7 +292,7 @@
$wallet->owner->undegrade();
$wallet->setSetting('degraded_last_reminder', null);
- $job = new WalletCheck($wallet->id);
+ $job = new CheckJob($wallet->id);
$job->handle();
Mail::assertNothingSent();
diff --git a/src/tests/Unit/Mail/NegativeBalanceDegradedTest.php b/src/tests/Unit/Mail/NegativeBalanceDegradedTest.php
--- a/src/tests/Unit/Mail/NegativeBalanceDegradedTest.php
+++ b/src/tests/Unit/Mail/NegativeBalanceDegradedTest.php
@@ -2,7 +2,6 @@
namespace Tests\Unit\Mail;
-use App\Jobs\WalletCheck;
use App\Mail\NegativeBalanceDegraded;
use App\User;
use App\Wallet;
diff --git a/src/tests/Unit/Mail/NegativeBalanceReminderDegradeTest.php b/src/tests/Unit/Mail/NegativeBalanceReminderDegradeTest.php
--- a/src/tests/Unit/Mail/NegativeBalanceReminderDegradeTest.php
+++ b/src/tests/Unit/Mail/NegativeBalanceReminderDegradeTest.php
@@ -2,7 +2,7 @@
namespace Tests\Unit\Mail;
-use App\Jobs\WalletCheck;
+use App\Jobs\Wallet\CheckJob;
use App\Mail\NegativeBalanceReminderDegrade;
use App\User;
use App\Wallet;
@@ -21,7 +21,7 @@
$wallet->balance = -100;
$wallet->save();
- $threshold = WalletCheck::threshold($wallet, WalletCheck::THRESHOLD_DEGRADE);
+ $threshold = CheckJob::threshold($wallet, CheckJob::THRESHOLD_DEGRADE);
\config([
'app.support_url' => 'https://kolab.org/support',

File Metadata

Mime Type
text/plain
Expires
Mon, Apr 6, 6:23 AM (13 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18826226
Default Alt Text
D5157.1775456614.diff (20 KB)

Event Timeline