# Payment System Architecture

The payment system is built on a flexible gateway architecture:

**Card & Installment Logic:**

* Cards filtered based on business rules and basket state
* Installment plans calculated dynamically based on amount
* Support for multi-currency cards
* Bank and card type associations
* BIN number validation for card identification

**Stored Card Flow:**

* Phone number verification required before card storage
* OTP sent via SMS gateway
* Card tokenization through payment gateway
* Token stored with masked card number
* POS-specific card storage (each gateway has separate tokens)

**Gateway Integration:**

* Multiple payment gateway support (Garanti, Akbank, etc.)
* Each POS has dedicated gateway configuration
* Saved card gateways mapped to credit card gateways
* Secure token-based card storage

**Caching Strategy:**

* Phone numbers cached during OTP flow
* Credit card data temporarily cached during save process
* Cache keys include user identifier for security
