- Order Management: Create, update, delete, and view orders.
- Payment Processing: Multi-gateway support (Credit Card, PayPal, Stripe).
- Role-Based Access: Admin and Customer roles.
- JWT Authentication: Secure API access.
- SOLID Architecture: Repository and Service patterns for clean, testable code.
- Repository Pattern: Data access abstraction
- Service Layer: Business logic encapsulation
- Manager/Driver Pattern: Payment gateway extensibility [Facade, Factory, Strategy, Interface].
- Pipeline Pattern: Order filtering
- Strategy Pattern: Payment method selection
- Service Provider: Dynamic configuration loading
- Filtering Pipeline: Order Filtering (Pipelined)
-
Product Management (Admin/Operations)
- Admin creates products via
/api/products - Products are available for all users to view via
/api/products
- Admin creates products via
-
Order Creation (Customer)
- Customer creates order with
/api/orders - Order status:
pending(initial state) - Can reference products by
product_idor manually specify items
- Customer creates order with
-
Order Confirmation (Admin)
- Admin reviews and updates order status via
/api/orders/{id}/status - Status transitions:
pending→confirmed(enables payment)pending→cancelled(blocks payment)
- Admin reviews and updates order status via
-
Payment Processing (Customer)
- Customer lists available payment gateways via
/api/payment-gateways - Only gateways with configured credentials appear
- Default gateway is pre-selected (marked with
is_default: true) - Customer pays confirmed order via
/api/orders/{id}/pay - Multiple partial payments allowed until total equals order amount
- Overpayment prevention: Validation blocks payments exceeding order total
- Customer lists available payment gateways via
-
Payment Restrictions
- Confirmed orders: Can be paid
- Pending orders: Cannot be paid (must be confirmed first)
- Cancelled orders: Cannot be paid
- Fully paid orders: Additional payments blocked with validation message
- Gateways configured via database settings (
payment_gatewayskey) and the value that holds all payment gatways configs. SettingServiceProviderdynamically loads config at boot- Only gateways with credentials appear in customer gateway list
- Supports: Credit Card, PayPal, Stripe (extensible)
- Middleware Validation:
ValidatePaymentMethodmiddleware validates payment methods before processing
-
Clone & Install
git clone <repo> cd project composer install cp .env.example .env php artisan key:generate php artisan jwt:secret touch database/database.sqlite php artisan migrate:fresh --seed php artisan serve php artisan test
This creates:
- Admin:
admin@tocaan.com/password - Customer:
customer@tocaan.com/password - Dummy orders and payments.
- Admin:
- To add a new payment gateway to the system follow these steps for example ApplePay:
- Create the Driver Class: Create a new class
ApplePayDriver.phpinapp/PaymentGateways/Drivers/that implementsApp\Contracts\PaymentGatewayInterface. Implement theprocessmethod. - Add the Driver creation function: Add a driver creation method
createApplePayDriverinapp/PaymentGateways/PaymentManager.php: - Add to Enum: Add the new case to
app/Enums/PaymentMethod.php: - Configure Credentials (Runtime): Add the credentials to the
payment_gatewayssetting in the database (or via the Admin Settings API). This is stored as JSON. - The system will now dynamically load "Apple Pay", display it in the list of available gateways for customers, and process payments using your new driver, without writing any additional logic code.