| | 1 | == Use-case 0006 - Process a Payment |
| | 2 | |
| | 3 | '''Initiating actor:''' Pet Owner |
| | 4 | |
| | 5 | '''Other actors:''' None |
| | 6 | |
| | 7 | '''Description:''' |
| | 8 | The owner must pay for a confirmed booking. The system finds unpaid bookings for that user, and the owner submits their payment method. The system records the financial transaction and links it securely to the booking. |
| | 9 | |
| | 10 | '''Scenario:''' |
| | 11 | 1. Pet Owner navigates to their "Pending Payments" dashboard. |
| | 12 | 2. System fetches confirmed bookings that do not have a matching payment record yet using a LEFT JOIN: |
| | 13 | {{{ |
| | 14 | #!sql |
| | 15 | SELECT b.booking_id, b.address, b.date_from |
| | 16 | FROM bookings b |
| | 17 | LEFT JOIN payments p ON b.booking_id = p.booking_id |
| | 18 | WHERE b.owner_id = (SELECT user_id FROM users WHERE username = 'owner_bojan') |
| | 19 | AND b.status = 'CONFIRMED' |
| | 20 | AND p.payment_id IS NULL; |
| | 21 | }}} |
| | 22 | 3. Owner selects a booking, chooses 'CREDIT_CARD', and submits the payment. |
| | 23 | 4. System securely records the payment in the database, satisfying the 1:1 relationship rule: |
| | 24 | {{{ |
| | 25 | #!sql |
| | 26 | INSERT INTO payments (amount, payment_type, booking_id) |
| | 27 | VALUES ( |
| | 28 | 1500, |
| | 29 | 'CREDIT_CARD', |
| | 30 | (SELECT booking_id FROM bookings WHERE address = 'ul. Partizanska br. 10' LIMIT 1) |
| | 31 | ); |
| | 32 | }}} |