Skip to content

Conversation

@gustaavik
Copy link
Member

This pull request introduces significant updates to the payment provider system, checkout process, and development environment setup. Key changes include the implementation of a centralized PaymentProviderRepository system, enhancements to the checkout use case for better handling of discounts and shipping options, and adjustments to the development environment to support PostgreSQL and SQLite configurations. Additionally, new helper methods and dependencies have been added to improve functionality and maintainability.

Payment Provider System Enhancements:

  • Centralized Repository Implementation: Introduced a PaymentProviderRepository system to manage payment providers and their configurations, replacing the webhook repository approach. This includes CRUD operations, webhook management, and dynamic provider discovery. (docs/PAYMENT_PROVIDER_SYSTEM.md)
  • Domain Layer Updates: Added enums for PaymentProviderType and PaymentMethod to prevent circular imports and improve type safety. (internal/domain/common/payment_types.go) [1] [2]

Checkout Process Improvements:

  • Discount Handling: Enhanced the checkout recovery and order creation logic to use helper methods for managing applied discounts, ensuring consistency and reducing redundancy. (internal/application/usecase/checkout_recovery_usecase.go, internal/application/usecase/checkout_usecase.go) [1] [2]
  • Shipping Address Validation: Refactored shipping address validation to use dedicated getter methods for improved clarity and maintainability. (internal/application/usecase/checkout_usecase.go) [1] [2]
  • Currency Mismatch Handling: Added logic to prevent mixing currencies within a single checkout, with support for changing the checkout currency if no items are present. (internal/application/usecase/checkout_usecase.go)

Development Environment Updates:

  • PostgreSQL Support: Replaced SQLite setup with PostgreSQL for local development, including a new db-start command to initialize the database. (Makefile)
  • SQLite Configuration: Adjusted the run target to support SQLite for specific use cases. (Makefile)

Additional Changes:

  • New Helper Method: Added GetOrderByExternalID to the OrderUseCase for retrieving orders based on external references, such as MobilePay webhook events. (internal/application/usecase/order_usecase.go)
  • Dependency Updates: Updated go.mod to include new dependencies like github.com/stretchr/testify and github.com/zenfulcode/vipps-mobilepay-sdk. (go.mod)

These changes collectively enhance the scalability, maintainability, and functionality of the application while adhering to clean architecture principles.

gustaavik added 29 commits June 30, 2025 14:28
…-related migrations

- Deleted migrations for currency support, order customer details, product active status, default currency, cart tables, and checkout tables.
- Removed constraints and indexes related to legacy cart and checkout functionality.
- Cleaned up migrations for ensuring product variants and added unique constraints for shipping methods and categories.
- Updated migrations for adding currency and payment status to orders, including necessary indexes and data updates.
- Improved product deletion logic by removing unnecessary triggers and relying on application-level enforcement.
- Added a mock logger implementation to facilitate logging in tests.
- Created mock repositories for PaymentProvider, PaymentTransaction, Order, and Product to simulate database interactions.
- Developed a mock payment provider service to handle payment provider operations in tests.
- Implemented comprehensive test cases for each mock service to ensure expected behavior and error handling.
…ntities

- Implement tests for PaymentProvider including validation, methods, and constants.
- Add tests for PaymentTransaction covering creation, validation, metadata, and status updates.
- Create tests for Product and ProductVariant with focus on creation, validation, and variant management.
- Introduce tests for User entity covering creation, password management, and role validation.
- Ensure comprehensive coverage for all new functionalities and edge cases.
…orders, and discounts

- Implemented user seeding with role assignment and existence check.
- Added category seeding with hierarchical relationships.
- Enhanced product seeding to include variants and category mapping.
- Introduced order seeding with user and product variant associations.
- Added discount seeding with various types and constraints.
- Implemented shipping methods and zones seeding.
- Enhanced payment transaction seeding for completed orders.
- Improved checkout seeding with session management and item tracking.
- Updated clearData function to use DELETE for SQLite compatibility.
…, currencies, shipping, and users

- Implemented CategoryDTO for category representation.
- Created CheckoutDTO and related structures for checkout sessions.
- Added OrderDTO and OrderItemDTO for order management.
- Introduced ProductDTO and VariantDTO for product details.
- Developed DiscountDTO and AppliedDiscountDTO for discount handling.
- Established CurrencyDTO for currency representation.
- Created Shipping-related DTOs including ShippingMethodDetailDTO, ShippingZoneDTO, and ShippingRateDTO.
- Implemented UserDTO for user management.
- Generated TypeScript contracts for API interactions.
- Updated import paths for DTOs in various entity files to use the new location under internal/domain/dto.
- Removed old DTO files from internal/interfaces/api/contracts/dto as they have been migrated to internal/domain/dto.
- Added new DTO definitions for Category, Checkout, Common, Currency, Discount, Order, Product, Shipping, and User in the internal/domain/dto directory.
- Updated related contract files to reference the new DTOs.
- Cleaned up the readme and removed the todo file.
…scounts

- Updated Checkout and Order entities to store shipping and billing addresses as JSON.
- Introduced helper methods for setting and getting addresses and discounts in JSON format.
- Modified checkout and order processing logic to utilize new JSON methods for address and discount handling.
- Adjusted related use cases and repositories to accommodate changes in address storage.
- Enhanced webhook handling to allow requests without an Origin header.
- Separated webhook routes from main API routes for better organization and security.
… update PaymentTransaction to use it for metadata
…ustomer details, and add item DTO conversion
@gustaavik gustaavik merged commit 4e52100 into migrations-cleanup2 Jul 1, 2025
@gustaavik gustaavik deleted the migration-cleanup-payment-providers branch July 1, 2025 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants