FIFO explained

FIFO stands for First-In-First-Out - the oldest credits are consumed first. This principle is fundamental to the flexible payment system.

The basic principle

Analogy: Milk in the fridge

Imagine your fridge:

  • You buy milk on Monday (best before Friday)
  • On Wednesday you buy new milk (best before next Wednesday)
  • Which do you drink first? The one from Monday!

That's how FIFO works with credits.

With credits

Timeline:
─────────────────────────────────────────────────→

Jan 1  Purchase: 10 credits (valid until Apr 1)   [█████]
Jan 15 Purchase: 20 credits (valid until Apr 15)  [██████████]

Booking on Jan 20 (8 credits):
→ Deducted from the oldest credits (purchase from Jan 1)
→ 2 credits from Jan 1 remaining
→ 20 credits from Jan 15 untouched

Why FIFO?

Advantages

  1. Minimizes expiry: Credits expiring soon are used first
  2. Fair treatment: Older purchases are billed first
  3. Transparency: Clear, traceable logic
  4. Automatic: No manual intervention required

The alternative would be...

LIFO (Last-In-First-Out): Newest credits first

  • Problem: Old credits expire unused
  • Unfair for customers

Manual: Customer chooses themselves

  • Problem: Complicated, error-prone
  • Confuses customers

FIFO in practice

Example 1: Simple case

Account balance:
┌─────────────────────────────────────────────────┐
│ Purchase Jan 1  │ 10 credits │ valid until Apr 1 │
└─────────────────────────────────────────────────┘

Booking: Yoga class for 10 credits

Result:
┌─────────────────────────────────────────────────┐
│ Purchase Jan 1  │ 0 credits  │ used up           │
└─────────────────────────────────────────────────┘

Example 2: Multiple packages

Account balance:
┌─────────────────────────────────────────────────┐
│ Purchase Jan 1  │ 5 credits  │ valid until Apr 1 │
│ Purchase Jan 15 │ 20 credits │ valid until Apr 15│
│ Purchase Feb 1  │ 10 credits │ valid until May 1 │
└─────────────────────────────────────────────────┘

Booking: Workshop for 12 credits

FIFO logic:
1. 5 credits from Purchase Jan 1 (now 0 remaining)
2. 7 credits from Purchase Jan 15 (now 13 remaining)
3. Purchase Feb 1 untouched

Result:
┌─────────────────────────────────────────────────┐
│ Purchase Jan 1  │ 0 credits  │ used up           │
│ Purchase Jan 15 │ 13 credits │ valid until Apr 15│
│ Purchase Feb 1  │ 10 credits │ valid until May 1 │
└─────────────────────────────────────────────────┘

Example 3: With cancellation

Starting position after booking:
┌─────────────────────────────────────────────────┐
│ Purchase Jan 15 │ 13 credits │ valid until Apr 15│
│ Purchase Feb 1  │ 10 credits │ valid until May 1 │
└─────────────────────────────────────────────────┘

Customer cancels the 12-credit booking

Refund:
- 12 credits are "returned"
- New entry with original expiry dates

Result:
┌─────────────────────────────────────────────────┐
│ Refund          │ 5 credits  │ valid until Apr 1 │
│ Refund          │ 7 credits  │ valid until Apr 15│
│ Purchase Jan 15 │ 13 credits │ valid until Apr 15│
│ Purchase Feb 1  │ 10 credits │ valid until May 1 │
└─────────────────────────────────────────────────┘

FIFO with cancellations

How does the refund work?

Upon cancellation:

  1. Credits are refunded
  2. Original expiry date is preserved
  3. Credits are sorted by expiry date
  4. FIFO applies again on the next booking

Important

  • Cancelled credits do not expire later
  • The original expiry date applies
  • Prevents an "expiry reset" via cancel and re-book

FIFO display for customers

In the wallet

Customers see their credits grouped:

My Credits
─────────────────────────────────────
5 Credits     │ expires Apr 1
20 Credits    │ expires Apr 15
10 Credits    │ expires May 1
─────────────────────────────────────
Total: 35 credits

At booking

Booking: Pilates for 8 credits

Credits to be used:
- 5 credits (expiring Apr 1)
- 3 credits (expiring Apr 15)

Remaining after booking: 27 credits

Special cases

Same expiry dates

When multiple packages expire on the same day:

  • The older purchase is used first
  • Based on purchase timestamp

Unlimited credits

Credits without an expiry date:

  • Are used last
  • Credits with an expiry date have priority

Trainer-bound credits

  • Are only used for matching classes
  • FIFO applies within trainer credits
  • Regular credits are not affected

FAQ about FIFO

Can I disable FIFO?

No, FIFO is built into the system. It is the fairest and most transparent method.

Can I "reserve" certain credits?

No, credits are always consumed according to FIFO. Manual selection is not possible.

What if only part of a package is needed?

Credits are combined across packages. If Package A only has 3 credits and you need 5, 3 are taken from A and 2 from the next package.

Are expired credits refunded upon cancellation?

No. If the credits would already have been expired at the time of cancellation, there is no refund.


Technical details

Data model

Each credit entry has:

  • amount: Number of credits
  • remaining: Remaining credits
  • purchased_at: Time of purchase
  • expires_at: Expiry date
  • user_id: Associated customer

FIFO query

SELECT * FROM credits
WHERE user_id = $userId
  AND remaining > 0
  AND (expires_at IS NULL OR expires_at > NOW())
ORDER BY expires_at ASC NULLS LAST, purchased_at ASC

Summary

AspectFIFO behavior
ConsumptionOldest credits first
SortingBy expiry date, then purchase date
CancellationOriginal expiry date is preserved
Unlimited creditsUsed last
DeactivationNot possible (by design)

Next steps

Fragen oder Feedback?

Wir helfen dir gerne weiter. Kontaktiere unser Support-Team.