Skip to content

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

Stripe Integration Logic

All Stripe payment methods go through addPayment resolver where availability is checked:

  1. Calls addPayment internally with payment_link_live method
  2. Vehicle availability is checked in addPayment
  3. If available → creates payment record with pending status
  4. Creates Stripe product and price
  5. Generates payment link
  6. Saves session ID to payment

Payment Intent Creation (createPaymentIntent)

  1. Calls addPayment internally with stripe_live method
  2. Vehicle availability is checked in addPayment
  3. If available → creates payment record with pending status
  4. Retrieves or creates Stripe customer
  5. Creates Payment Intent in Stripe
  6. Saves session ID to payment

Order Status Automation

Rules:

  1. Before any payment creation: Vehicle availability MUST be checked via checkAvailability
  2. After successful Stripe payment: Order status changes to “Confirmed” via updateOrderStatusAfterPayment if passed availability check via checkAvailability
  3. After manual completed payment: Order status changes to “Confirmed” (if was “Requested”) if passed availability check via checkAvailability
  4. Google Calendar Integration: When order status changes to “Confirmed”, updateCalendarEventX is called automatically to update the corresponding calendar event

Error Handling

System returns union type PaymentMutationPayload:

  • PaymentPayload - success with payment data and new order status
  • MutationError - 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 Success

Stripe Payment Flow

createPaymentLink/Intent → addPayment → Check Vehicle Availability →
Create Payment (pending) → Stripe Processing → Webhook →
updateOrderStatusAfterPayment → Change Order Status →
updateCalendarEventX → Send Notifications

Key Security Rules

  1. NO payment creation without vehicle availability check
  2. All Stripe payments go through addPayment validation
  3. Automatic order confirmation only after successful payment
  4. Calendar events always synchronized with order status
  5. Multiple availability checks: creation, webhook processing, status updates
  6. Google Calendar events are automatically updated when order status changes to “Confirmed”