Skip to content

Enhance payment processing, add performance profiling, and improve code quality#100

Merged
rsmoke merged 10 commits intomainfrom
staging
Apr 6, 2026
Merged

Enhance payment processing, add performance profiling, and improve code quality#100
rsmoke merged 10 commits intomainfrom
staging

Conversation

@rsmoke
Copy link
Copy Markdown
Member

@rsmoke rsmoke commented Apr 6, 2026

This pull request introduces a robust system for recording and auditing payment gateway callbacks, including a new PaymentGatewayCallback model and associated admin interface, as well as a refactor of the payment receipt logic to improve reliability and traceability. It also adds database-level enforcement of uniqueness for payment transaction IDs, and includes some dependency and code quality improvements.

Payment Gateway Callback Tracking and Admin Interface:

  • Introduced a new PaymentGatewayCallback model and database table to record all payment gateway callback attempts, including their status, payload, and associations to Payment and User. This provides a full audit trail of gateway interactions. [1] [2]
  • Added an ActiveAdmin resource for PaymentGatewayCallback, allowing admins to view, filter, and inspect callback records, and linked these callbacks to the payment admin view for easy cross-reference. [1] [2]

Payment Handling Refactor and Hardening:

  • Refactored the PaymentsController#payment_receipt action to delegate all gateway receipt processing to a new service object, Payments::GatewayReceiptRecorder, which handles user resolution, duplicate detection, error handling, and callback recording in a consistent and testable way. [1] [2] [3] [4] [5] [6] [7]
  • Added stricter validation for payment callback parameters and improved user/account matching logic to prevent fraudulent or malformed requests. [1] [2]

Database Integrity Improvements:

  • Added a unique index on payments.transaction_id to ensure transaction IDs are unique at the database level, preventing race conditions and duplicate payments. [1] [2]

Admin Dashboard and Query Optimizations:

  • Improved performance and correctness of admin dashboard queries for recent payments and applications, including eager loading and more efficient lookups. [1] [2] [3]

Development and Code Quality Enhancements:

  • Added stackprof for profiling (required by Sentry), and included rubocop and rubocop-rails for code linting in development and test environments. [1] [2]

These changes collectively improve the reliability, traceability, and maintainability of our payment processing and administration features.

rsmoke added 10 commits April 6, 2026 09:54
Included 'rubocop' and 'rubocop-rails' in the Gemfile to enhance code quality checks and maintainability. Updated Gemfile.lock to reflect the new dependencies and their versions.
Updated the PaymentsController to improve the payment receipt logic by utilizing a service object for recording gateway receipts. Adjusted the orderNumber generation to use the user's email and ID. Enhanced request specs to cover scenarios for duplicate and forbidden statuses, ensuring robust handling of payment callbacks. This refactor improves code maintainability and clarity in payment processing.
Added a new table for payment gateway callbacks with relevant fields and foreign keys to enhance payment processing capabilities. Updated the ActiveRecord schema version to reflect these changes, ensuring improved data integrity and functionality in handling payment events.
…associations

Introduced a new ActiveAdmin interface for managing PaymentGatewayCallback records, including filters and display options. Updated the Payment model to establish a relationship with PaymentGatewayCallback, allowing for better tracking of gateway callbacks. Enhanced ransackable associations and attributes for improved query capabilities. Updated the Payment admin view to display associated gateway callbacks, improving user experience in payment management.
…ecorder

Updated the Payments::GatewayReceiptRecorder service to improve duplicate transaction handling by introducing a dedicated method for duplicate results. Added tests to cover scenarios where uniqueness validation fails and when concurrent callbacks raise a RecordNotUnique error. Refactored the PaymentsController to ensure consistent handling of duplicate statuses in payment receipts, enhancing overall robustness in payment processing.
…ayments table

Modified the ActiveRecord schema to add a unique index on the transaction_id column in the payments table, enhancing data integrity by preventing duplicate transaction entries. Updated the schema version to reflect this change.
Included the 'stackprof' gem in the Gemfile to enable performance profiling when the profiles_sample_rate is set in the Sentry configuration. This addition supports better performance monitoring and analysis capabilities in the application.
Included the 'stackprof' gem in the Gemfile.lock to support performance profiling capabilities in the application, enhancing monitoring and analysis features.
…ance

Updated the ActiveAdmin dashboard to enhance the retrieval of recent applications and payments. Improved code readability by breaking down complex queries into more manageable parts, including the use of includes for eager loading. This refactor aims to optimize performance and maintainability of the dashboard's data presentation.
@rsmoke rsmoke merged commit a5ec9ea into main Apr 6, 2026
5 checks passed
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.

1 participant