feat: update session payment logic to ensure accurate payable amounts and reflect consumables in cost breakdown
- Adjusted the calculation of payable amounts in PaymentStep to align with server logic, ensuring overpayments are handled correctly. - Enhanced DetailsStep to include consumables in the itemized cost breakdown, ensuring consistency with patient share calculations. - Updated tests for SessionPaymentPage to validate new behavior regarding overpayments and consumable listings. - Modified PatientController to register SessionPayment correctly when settling sessions via wallet, preventing double charges. - Refactored WalletService to remove outdated methods and ensure wallet transactions reflect the correct amounts after discounts. - Improved accessibility in SearchableSelect component by adding aria labels and ensuring proper role attributes for screen readers. - Updated styles to ensure minimum touch targets meet WCAG guidelines for mobile usability.
This commit is contained in:
@@ -85,6 +85,56 @@ class PatientWalletSessionSettleTest extends ApiTestCase
|
||||
self::assertSame(100_000, $wallet['data']['balance_rials']);
|
||||
}
|
||||
|
||||
/**
|
||||
* رگرسیون: تسویهٔ کیف پول باید SessionPayment ثبت کند تا مراجعه واقعاً is_paid شود.
|
||||
* پیشتر فقط موجودی کسر میشد و مراجعه پرداختنشده میماند، پس PATCH دوم دوباره
|
||||
* از کیف پول کم میکرد (کسر مضاعف از پول واقعی بیمار).
|
||||
*/
|
||||
public function testSettlingTwiceDoesNotChargeWalletAgain(): void
|
||||
{
|
||||
[$owner, $record, $patient] = $this->recordFor();
|
||||
$this->em->persist(new WalletTransaction($patient, 1_000_000, 'credit', 1_000_000));
|
||||
$this->em->flush();
|
||||
|
||||
$session = $this->sessionFor($record, 400_000);
|
||||
$url = '/api/v1/session/' . $session->getUuid();
|
||||
|
||||
$this->authJson('PATCH', $url, $owner, ['payment_method' => 'wallet']);
|
||||
self::assertSame(200, $this->responseCode());
|
||||
|
||||
// تسویهٔ دوباره روی همان مراجعه نباید چیزی کسر کند.
|
||||
$res = $this->authJson('PATCH', $url, $owner, ['payment_method' => 'wallet']);
|
||||
self::assertSame(200, $this->responseCode());
|
||||
self::assertTrue($res['data']['is_paid']);
|
||||
|
||||
$wallet = $this->authJson('GET', '/api/v1/patient/' . $record->getUuid() . '/wallet', $owner);
|
||||
self::assertSame(600_000, $wallet['data']['balance_rials']);
|
||||
}
|
||||
|
||||
/**
|
||||
* رگرسیون: مبلغِ کسرشده باید مانده (پس از تخفیف) باشد نه قیمتِ نهاییِ خام.
|
||||
*/
|
||||
public function testWalletSettleChargesPayableAfterDiscount(): void
|
||||
{
|
||||
[$owner, $record, $patient] = $this->recordFor();
|
||||
$this->em->persist(new WalletTransaction($patient, 1_000_000, 'credit', 1_000_000));
|
||||
$this->em->flush();
|
||||
|
||||
$session = $this->sessionFor($record, 400_000);
|
||||
$session->setDiscount('fixed', 100_000, 100_000);
|
||||
$this->em->flush();
|
||||
|
||||
$res = $this->authJson('PATCH', '/api/v1/session/' . $session->getUuid(), $owner, [
|
||||
'payment_method' => 'wallet',
|
||||
]);
|
||||
self::assertSame(200, $this->responseCode());
|
||||
self::assertTrue($res['data']['is_paid']);
|
||||
|
||||
// ۴۰۰٬۰۰۰ − ۱۰۰٬۰۰۰ تخفیف = ۳۰۰٬۰۰۰ کسر شود، نه ۴۰۰٬۰۰۰.
|
||||
$wallet = $this->authJson('GET', '/api/v1/patient/' . $record->getUuid() . '/wallet', $owner);
|
||||
self::assertSame(700_000, $wallet['data']['balance_rials']);
|
||||
}
|
||||
|
||||
public function testSettleSessionWithCashDoesNotTouchWallet(): void
|
||||
{
|
||||
[$owner, $record, $patient] = $this->recordFor();
|
||||
|
||||
Reference in New Issue
Block a user