Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117978664
D4334.1775519097.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
D4334.1775519097.diff
View Options
diff --git a/src/app/Http/Controllers/API/V4/Admin/WalletsController.php b/src/app/Http/Controllers/API/V4/Admin/WalletsController.php
--- a/src/app/Http/Controllers/API/V4/Admin/WalletsController.php
+++ b/src/app/Http/Controllers/API/V4/Admin/WalletsController.php
@@ -79,7 +79,7 @@
return response()->json(['status' => 'error', 'errors' => $v->errors()], 422);
}
- $amount = (int) ($request->amount * 100);
+ $amount = (int) round($request->amount * 100);
$method = $amount > 0 ? 'award' : 'penalty';
DB::beginTransaction();
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
@@ -64,8 +64,8 @@
// Normally the auto-payment setup operation is 0, if the balance is below the threshold
// we'll top-up the wallet with the configured auto-payment amount
- if ($wallet->balance < intval($request->balance * 100)) {
- $mandate['amount'] = intval($request->amount * 100);
+ if ($wallet->balance < round($request->balance * 100)) {
+ $mandate['amount'] = (int) round($request->amount * 100);
self::addTax($wallet, $mandate);
}
@@ -131,7 +131,7 @@
]);
// Trigger auto-payment if the balance is below the threshold
- if ($wallet->balance < intval($request->balance * 100)) {
+ if ($wallet->balance < round($request->balance * 100)) {
\App\Jobs\WalletCharge::dispatch($wallet);
}
@@ -199,7 +199,7 @@
return $v->errors()->toArray();
}
- $amount = (int) ($request->amount * 100);
+ $amount = (int) round($request->amount * 100);
// Validate the minimum value
// It has to be at least minimum payment amount and must cover current debt,
@@ -279,7 +279,7 @@
return response()->json(['status' => 'error', 'errors' => $v->errors()], 422);
}
- $amount = (int) ($request->amount * 100);
+ $amount = (int) round($request->amount * 100);
// Validate the minimum value
if ($amount < Payment::MIN_AMOUNT) {
@@ -379,8 +379,8 @@
return false;
}
- $min_balance = (int) (floatval($settings['mandate_balance']) * 100);
- $amount = (int) (floatval($settings['mandate_amount']) * 100);
+ $min_balance = (int) round(floatval($settings['mandate_balance']) * 100);
+ $amount = (int) round(floatval($settings['mandate_amount']) * 100);
// The wallet balance is greater than the auto-payment threshold
if ($wallet->balance >= $min_balance) {
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
@@ -368,7 +368,7 @@
if ($status == Payment::STATUS_PAID) {
$payment->wallet->setSetting('stripe_mandate_id', $intent->id);
- $threshold = intval((float) $payment->wallet->getSetting('mandate_balance') * 100);
+ $threshold = (int) round((float) $payment->wallet->getSetting('mandate_balance') * 100);
// Call credit() so wallet/account state is updated
$this->creditPayment($payment, $intent);
diff --git a/src/tests/Feature/Controller/Admin/WalletsTest.php b/src/tests/Feature/Controller/Admin/WalletsTest.php
--- a/src/tests/Feature/Controller/Admin/WalletsTest.php
+++ b/src/tests/Feature/Controller/Admin/WalletsTest.php
@@ -103,7 +103,7 @@
$this->assertCount(2, $json['errors']);
// Admin user - a valid bonus
- $post = ['amount' => '50', 'description' => 'A bonus'];
+ $post = ['amount' => '17.40', 'description' => 'A bonus'];
$response = $this->actingAs($admin)->post("api/v4/wallets/{$wallet->id}/one-off", $post);
$response->assertStatus(200);
@@ -111,7 +111,7 @@
$this->assertSame('success', $json['status']);
$this->assertSame('The bonus has been added to the wallet successfully.', $json['message']);
- $this->assertSame($balance += 5000, $json['balance']);
+ $this->assertSame($balance += 1740, $json['balance']);
$this->assertSame($balance, $wallet->fresh()->balance);
$this->assertSame($reseller_balance, $reseller_wallet->fresh()->balance);
@@ -119,11 +119,11 @@
->where('type', Transaction::WALLET_AWARD)->first();
$this->assertSame($post['description'], $transaction->description);
- $this->assertSame(5000, $transaction->amount);
+ $this->assertSame(1740, $transaction->amount);
$this->assertSame($admin->email, $transaction->user_email);
// Admin user - a valid penalty
- $post = ['amount' => '-40', 'description' => 'A penalty'];
+ $post = ['amount' => '-17.40', 'description' => 'A penalty'];
$response = $this->actingAs($admin)->post("api/v4/wallets/{$wallet->id}/one-off", $post);
$response->assertStatus(200);
@@ -131,7 +131,7 @@
$this->assertSame('success', $json['status']);
$this->assertSame('The penalty has been added to the wallet successfully.', $json['message']);
- $this->assertSame($balance -= 4000, $json['balance']);
+ $this->assertSame($balance -= 1740, $json['balance']);
$this->assertSame($balance, $wallet->fresh()->balance);
$this->assertSame($reseller_balance, $reseller_wallet->fresh()->balance);
@@ -139,7 +139,7 @@
->where('type', Transaction::WALLET_PENALTY)->first();
$this->assertSame($post['description'], $transaction->description);
- $this->assertSame(-4000, $transaction->amount);
+ $this->assertSame(-1740, $transaction->amount);
$this->assertSame($admin->email, $transaction->user_email);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Apr 6, 11:44 PM (6 h, 42 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18816402
Default Alt Text
D4334.1775519097.diff (5 KB)
Attached To
Mode
D4334: Fix award/penalty rounding issue
Attached
Detach File
Event Timeline