Payment System Logic
Vehicle Availability Check
Critical Rule: Before creating ANY payment, the system checks vehicle availability for the order dates.
- If the vehicle is NOT available for the order dates → payment creation is forbidden
- If the vehicle is available → payment creation proceeds
- This check applies to ALL payment creation methods:
- Manual payments via
addPayment - Stripe payment links via
createPaymentLink - Stripe payment intents via
createPaymentIntent
- Manual payments via
Stripe Integration Logic
All Stripe payment methods go through addPayment resolver where availability is checked:
Payment Link Creation (createPaymentLink)
- Calls
addPaymentinternally withpayment_link_livemethod - Vehicle availability is checked in addPayment
- If available → creates payment record with
pendingstatus - Creates Stripe product and price
- Generates payment link
- Saves session ID to payment
Payment Intent Creation (createPaymentIntent)
- Calls
addPaymentinternally withstripe_livemethod - Vehicle availability is checked in addPayment
- If available → creates payment record with
pendingstatus - Retrieves or creates Stripe customer
- Creates Payment Intent in Stripe
- Saves session ID to payment
Order Status Automation
Rules:
- Before any payment creation: Vehicle availability MUST be checked via
checkAvailability - After successful Stripe payment: Order status changes to “Confirmed” via
updateOrderStatusAfterPaymentif passed availability check viacheckAvailability - After manual completed payment: Order status changes to “Confirmed” (if was “Requested”) if passed availability check via
checkAvailability - Google Calendar Integration: When order status changes to “Confirmed”,
updateCalendarEventXis called automatically to update the corresponding calendar event
Error Handling
System returns union type PaymentMutationPayload:
PaymentPayload- success with payment data and new order statusMutationError- error with code and description
Audit and Logging
All payment operations are logged with specific actions:
- Creation: “paymentsEdited”, “+amount”
- Deletion: “paymentsEdited”, “-amount”
- Order status change: “payment_confirmed” or “updated”
- Calendar update: automatic logging in calendar service
Logs contain information about user, time, and operation details.
Flow Summary
Manual Payment Flow
addPayment → Check Vehicle Availability → Create Payment (FQL) →Update Order Total → Change Order Status (if completed) →Update Google Calendar Event → Return SuccessStripe Payment Flow
createPaymentLink/Intent → addPayment → Check Vehicle Availability →Create Payment (pending) → Stripe Processing → Webhook →updateOrderStatusAfterPayment → Change Order Status →updateCalendarEventX → Send NotificationsKey Security Rules
- NO payment creation without vehicle availability check
- All Stripe payments go through addPayment validation
- Automatic order confirmation only after successful payment
- Calendar events always synchronized with order status
- Multiple availability checks: creation, webhook processing, status updates
- Google Calendar events are automatically updated when order status changes to “Confirmed”