diff --git a/app/Http/Controllers/Care/BillController.php b/app/Http/Controllers/Care/BillController.php index 0defcc5..2938f45 100644 --- a/app/Http/Controllers/Care/BillController.php +++ b/app/Http/Controllers/Care/BillController.php @@ -226,15 +226,20 @@ class BillController extends Controller $manualMethods = array_keys(collect(config('care.payment_methods', []))->except(['gateway'])->all()); + $validated = $request->validate([ + 'amount' => ['required', 'numeric', 'min:0.01'], + 'method' => ['required', 'string', 'in:'.implode(',', $manualMethods)], + 'reference' => ['nullable', 'string', 'max:100'], + 'notes' => ['nullable', 'string', 'max:500'], + ]); + + $validated['amount_minor'] = max(1, (int) round(((float) $validated['amount']) * 100)); + unset($validated['amount']); + $this->bills->recordPayment( $bill, $this->ownerRef($request), - $request->validate([ - 'amount_minor' => ['required', 'integer', 'min:1'], - 'method' => ['required', 'string', 'in:'.implode(',', $manualMethods)], - 'reference' => ['nullable', 'string', 'max:100'], - 'notes' => ['nullable', 'string', 'max:500'], - ]), + $validated, $this->ownerRef($request), ); @@ -247,10 +252,12 @@ class BillController extends Controller $this->authorizeBill($request, $bill); $validated = $request->validate([ - 'amount_minor' => ['nullable', 'integer', 'min:1'], + 'amount' => ['nullable', 'numeric', 'min:0.01'], ]); - $amount = (int) ($validated['amount_minor'] ?? $bill->balance_minor); + $amount = isset($validated['amount']) + ? max(1, (int) round(((float) $validated['amount']) * 100)) + : (int) $bill->balance_minor; try { $result = $this->bills->startGatewayPayment( diff --git a/resources/views/care/bills/show.blade.php b/resources/views/care/bills/show.blade.php index b42fdcf..197e552 100644 --- a/resources/views/care/bills/show.blade.php +++ b/resources/views/care/bills/show.blade.php @@ -78,11 +78,18 @@ @endif @if ($canPay && $bill->balance_minor > 0 && $bill->status !== \App\Models\Bill::STATUS_VOID) + @php + $balanceMajor = number_format($bill->balance_minor / 100, 2, '.', ''); + $currency = config('care.billing.currency'); + @endphp

Record payment

@csrf - + @@ -101,7 +108,10 @@ @if ($gatewayConfigured) @csrf - +
@else diff --git a/tests/Feature/CareBillTest.php b/tests/Feature/CareBillTest.php index 09368d0..b2ade28 100644 --- a/tests/Feature/CareBillTest.php +++ b/tests/Feature/CareBillTest.php @@ -125,7 +125,7 @@ class CareBillTest extends TestCase $this->actingAs($this->user) ->post(route('care.bills.payments.store', $bill), [ - 'amount_minor' => 3000, + 'amount' => 30.00, 'method' => 'cash', ]) ->assertRedirect(); @@ -136,7 +136,7 @@ class CareBillTest extends TestCase $this->actingAs($this->user) ->post(route('care.bills.payments.store', $bill), [ - 'amount_minor' => $bill->balance_minor, + 'amount' => $bill->balance_minor / 100, 'method' => 'momo', 'reference' => 'MOMO-123', ]) @@ -209,10 +209,15 @@ class CareBillTest extends TestCase ->assertSee('Pay') ->assertSee('Actions'); + $balanceMajor = number_format($bill->balance_minor / 100, 2, '.', ''); + $this->actingAs($this->user) ->get(route('care.bills.show', $bill)) ->assertOk() - ->assertSee('Record payment'); + ->assertSee('Record payment') + ->assertSee('name="amount"', false) + ->assertSee('value="'.$balanceMajor.'"', false) + ->assertDontSee('value="'.$bill->balance_minor.'"', false); } public function test_call_next_empty_booth_explains_walk_up_invoices(): void diff --git a/tests/Feature/CarePaymentGatewayTest.php b/tests/Feature/CarePaymentGatewayTest.php index bd51858..5625807 100644 --- a/tests/Feature/CarePaymentGatewayTest.php +++ b/tests/Feature/CarePaymentGatewayTest.php @@ -175,7 +175,7 @@ class CarePaymentGatewayTest extends TestCase $this->actingAs($this->user) ->post(route('care.bills.payments.gateway', $this->bill), [ - 'amount_minor' => $balance, + 'amount' => $balance / 100, ]) ->assertRedirect('https://checkout.paystack.com/care-test'); @@ -224,7 +224,7 @@ class CarePaymentGatewayTest extends TestCase $this->actingAs($this->user) ->post(route('care.bills.payments.gateway', $this->bill), [ - 'amount_minor' => 5000, + 'amount' => 50.00, ]) ->assertRedirect('https://checkout.flutterwave.com/v3/hosted/pay/test'); @@ -258,7 +258,7 @@ class CarePaymentGatewayTest extends TestCase $this->actingAs($this->user) ->post(route('care.bills.payments.gateway', $this->bill), [ - 'amount_minor' => 2500, + 'amount' => 25.00, ]) ->assertRedirect('https://pay.hubtel.com/checkout/test');