Skip to main content

Overview

The Payment Modes module manages the different payment methods accepted by the supermarket. This system allows administrators to define, configure, and maintain various payment options available to customers.

PayMode Model

The PayMode model (Models/PayMode.cs:3-8) defines payment method information:
public class PayMode
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Observation { get; set; }
}

Properties

PropertyTypeDescriptionExamples
IdintUnique identifier1, 2, 3
NamestringPayment method name”Cash”, “Credit Card”, “Debit Card”
ObservationstringAdditional notes or configuration details”Visa and Mastercard only”, “Exact change required”
The Observation field provides flexibility to store method-specific rules, restrictions, or processing instructions.

CRUD Operations

1

View Payment Methods

List all configured payment modes in the system
2

Add New Method

Create new payment methods as they become available
3

Update Details

Modify payment method names or observations
4

Remove Method

Deactivate payment methods no longer accepted

Listing Payment Modes

The Index page (Pages/PayModes/Index.cshtml.cs:22-28) displays all payment methods:
public IList<PayMode> PayModes { get; set; } = default!;

public async Task OnGetAsync()
{
    if (_context.PayModes != null)
    {
        PayModes = await _context.PayModes.ToListAsync();
    }
}
All payment modes are loaded asynchronously and exposed through the PayModes property for display in the user interface.

Creating Payment Modes

public IActionResult OnGet()
{
    return Page();
}
Displays the payment mode creation form to the user.

Common Payment Methods

Cash

Traditional currency paymentObservation: “Exact change preferred”

Credit Card

Card-based deferred paymentObservation: “Visa, Mastercard, Amex accepted”

Debit Card

Direct bank account paymentObservation: “All major networks accepted”

Mobile Payment

Digital wallet transactionsObservation: “Apple Pay, Google Pay, Samsung Pay”

Gift Card

Store credit paymentObservation: “Store gift cards only”

Bank Transfer

Electronic fund transferObservation: “Requires verification”

Editing Payment Modes

The Edit page handles updates to existing payment methods:
[BindProperty]
public PayMode PayMode { get; set; } = default!;

public async Task<IActionResult> OnGetAsync(int? id)
{
    if (id == null || _context.PayModes == null)
    {
        return NotFound();
    }

    var payMode = await _context.PayModes.FirstOrDefaultAsync(m => m.Id == id);

    if (payMode == null)
    {
        return NotFound();
    }
    PayMode = payMode;
    return Page();
}

public async Task<IActionResult> OnPostAsync()
{
    if (!ModelState.IsValid)
    {
        return Page();
    }

    _context.Attach(PayMode).State = EntityState.Modified;

    try
    {
        await _context.SaveChangesAsync();
    }
    catch (DbUpdateConcurrencyException)
    {
        if (!PayModeExists(PayMode.Id))
        {
            return NotFound();
        }
        else
        {
            throw;
        }
    }

    return RedirectToPage("./Index");
}
Editing payment modes is useful when updating processing rules, accepted card networks, or fee structures.

Deleting Payment Modes

The Delete page provides confirmation before removing payment methods:
[BindProperty]
public PayMode PayMode { get; set; } = default!;

public async Task<IActionResult> OnGetAsync(int? id)
{
    if (id == null || _context.PayModes == null)
    {
        return NotFound();
    }

    var payMode = await _context.PayModes.FirstOrDefaultAsync(m => m.Id == id);

    if (payMode == null)
    {
        return NotFound();
    }
    else
    {
        PayMode = payMode;
    }
    return Page();
}

public async Task<IActionResult> OnPostAsync(int? id)
{
    if (id == null || _context.PayModes == null)
    {
        return NotFound();
    }

    var payMode = await _context.PayModes.FindAsync(id);

    if (payMode != null)
    {
        PayMode = payMode;
        _context.PayModes.Remove(payMode);
        await _context.SaveChangesAsync();
    }

    return RedirectToPage("./Index");
}
Deleting a payment mode that has been used in transactions may cause referential integrity issues. Consider implementing soft deletes or preventing deletion of payment modes with transaction history.

Authorization

All payment mode management operations require authentication:
[Authorize]
public class IndexModel : PageModel
{
    // Implementation
}
Only authenticated administrators can configure payment methods.

Database Context

Payment modes are managed through the SupermarketContext (Data/SupermarketContext.cs:16):
public DbSet<PayMode> PayModes { get; set; }

Page Structure

The payment mode management module follows the standard CRUD structure:
PageRoutePurpose
Index/Pages/PayModes/Index.cshtmlList all payment modes
Create/Pages/PayModes/Create.cshtmlAdd new payment method
Edit/Pages/PayModes/Edit.cshtmlUpdate payment method details
Delete/Pages/PayModes/Delete.cshtmlRemove payment method

Observation Field Usage

The Observation field provides flexibility for storing payment method details:
Example: “Accepts Visa, Mastercard, and American Express. Minimum purchase $5”Store information about which card networks are accepted and any minimum purchase requirements.
Example: “Instant verification” or “Requires 2-3 business days for bank transfer”Communicate expected processing times to cashiers and customers.
Example: “2.5% processing fee applied” or “No additional fees”Document any fees associated with the payment method.
Example: “Request ID verification for purchases over $100”Provide operational guidelines for staff processing payments.

Enhanced Validation

Consider adding validation to ensure data quality:
public class PayMode
{
    public int Id { get; set; }
    
    [Required]
    [StringLength(50)]
    public string Name { get; set; }
    
    [StringLength(500)]
    public string Observation { get; set; }
}

Integration Scenarios

Transaction Processing

Link payment modes to transaction records to track payment method usage

Reporting

Analyze which payment methods are most popular with customers

Payment Gateway

Map payment modes to external payment processor configurations

Fee Calculation

Calculate transaction fees based on payment method selection

Best Practices

1

Clear Naming

Use descriptive names that customers and staff easily understand
2

Complete Observations

Document all important details, restrictions, and requirements
3

Regular Updates

Keep payment method information current as policies change
4

Status Tracking

Consider adding an Active/Inactive flag instead of deleting methods

Common Queries

Active Payment Methods Only

// If implementing an IsActive field
var activePayModes = await _context.PayModes
    .Where(pm => pm.IsActive)
    .ToListAsync();

Most Used Payment Method

// If linked to transactions
var popularPayMode = await _context.Transactions
    .GroupBy(t => t.PayModeId)
    .Select(g => new { PayModeId = g.Key, Count = g.Count() })
    .OrderByDescending(x => x.Count)
    .FirstOrDefaultAsync();

Search by Name

var payMode = await _context.PayModes
    .FirstOrDefaultAsync(pm => pm.Name.Contains(searchTerm));

Future Enhancements

Consider implementing these features for a more robust payment system:
  • Payment Gateway Integration: Connect to third-party processors
  • Transaction Fees: Track fees associated with each payment type
  • Active Status: Enable/disable payment methods without deletion
  • Display Order: Control the order payment methods appear in POS
  • Icon Support: Add icons for visual payment method identification
  • Currency Support: Handle multi-currency payment methods
  • Validation Rules: Store payment-specific validation logic

Build docs developers (and LLMs) love