Payment Dummy Data and Flow Documentation ========================================= ## Dummy Data Seed Command To populate the database with dummy payment methods (UPI, Cards, Gift Cards) for testing, run the following Artisan command: ```bash php artisan db:seed --class=DummyPaymentMethodSeeder ``` This will create dummy payment records for the first available customer (or create a new test customer if none exists). ## Dummy Data Created ### UPI List - Google Pay: test@ybl - PhonePe: 9999999999@ybl - Paytm: demo@paytm - Other: mangalore@upi ### Card List - Visa: XXXX XXXX XXXX 1111 - MasterCard: XXXX XXXX XXXX 4444 - RuPay: XXXX XXXX XXXX 2222 ### Gift Card List - GIFT100 - GIFT500 - MANGALORE250 --- ## Add Payment Method Flow 1. **User Interaction**: Customer clicks "Add UPI", "Add Card", or "Add Gift Card" on the payment page. 2. **Frontend Validation**: `public/common/js/customer/payment-methods.js` catches the form submission, performs client-side validation (e.g. 16 digits for card, correct expiry date, required fields), and sends an AJAX request using `window.apiRequest()` to `/api/customer/payment-methods`. 3. **Backend Validation**: `PaymentMethodController@store` validates the incoming payload using `validateMethod`. 4. **Data Masking & Security**: - For Cards: The system *only* receives the `card_last_four` digits and generic card info. The full card number and CVV are NEVER submitted to the backend or saved. A `dummy_token` is generated and saved securely in the `encrypted_data` JSON column to mock a real payment gateway tokenization. - For UPI/Gift Cards: The identifier is securely stored in the `encrypted_data` field. 5. **Persistence**: The validated and masked data is inserted into the `customer_payment_methods` table. 6. **UI Refresh**: The backend returns a success response. The frontend JS hides the modal, resets the form, shows a success toast/alert, and immediately calls `loadPaymentMethods()` to re-fetch and render the updated lists without requiring a page reload. --- ## Common Errors and Fixes 1. **Error: "type doesn't have a default value" (SQLSTATE 1364) / Data not saving** - *Fix*: The `fillMethod` was overwriting attributes by calling `$method->fill()` multiple times, clearing the `type` or failing to set `encrypted_data`. Ensure that `fillMethod` properly merges data or sets `encrypted_data` correctly without overwriting previous `$fill()` calls. (Fixed in latest code) 2. **Error: 401 Unauthorized during AJAX request** - *Fix*: The customer token in `localStorage` has expired or is invalid. The `apiRequest` utility handles this by redirecting to the login page. Ask the user to log in again. 3. **Error: Uncaught ReferenceError: msClearFieldErrors is not defined** - *Fix*: Ensure `public/common/js/api.js` is loaded before `payment-methods.js` as it contains all the necessary helper functions. 4. **Cards failing validation because of "expiry_year"** - *Fix*: The backend expects a 4-digit year. The frontend creates this by doing `"20" + yearVal` (e.g., "2026"). Ensure that the logic doesn't result in an invalid date. 5. **No connection could be made because the target machine actively refused it (MySQL Error)** - *Fix*: Your local MySQL database is not running. Start XAMPP/WAMP/Docker or the relevant MySQL service.