refactor(sender, order): enhance rate validation logic and introduce …#735
Conversation
…cancellation handling for indexed orders - Updated rate validation logic to use symmetric tolerance for market rate comparisons, improving accuracy in payment order processing. - Enhanced error messages to provide clearer feedback on rate validation failures. - Introduced a new function, handleCancellationForIndexedOrder, to streamline cancellation handling for existing payment orders, ensuring proper order management during validation failures. - Refactored existing cancellation calls to utilize the new function, improving code clarity and maintainability.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughUpdated rate validation to use symmetric absolute-tolerance checks across sender/order flows and introduced a cancellation helper that prefers updating existing indexed PaymentOrders; adjusted error responses and tightened cancellation error handling. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant SenderController as Sender Controller
participant OrderService as Order Service
participant ProviderPool as Provider/Rate Lookup
participant DB as Database
Client->>SenderController: InitiatePaymentOrder(request with providedRate)
SenderController->>ProviderPool: Fetch achievableRate for bucket
ProviderPool-->>SenderController: rateResult (achievableRate) or rateErr
alt rateErr
SenderController->>OrderService: handleCancellationForIndexedOrder(ctx, indexedOrder?, cancellationFields)
OrderService-->>DB: find indexed order / create cancellation row
OrderService-->>SenderController: cancellation result / error
SenderController-->>Client: return error (wrapped)
else have achievableRate
SenderController->>SenderController: compute tolerance = achievableRate * 0.001
SenderController->>SenderController: check abs(providedRate - achievableRate) <= tolerance
alt outside tolerance
SenderController->>OrderService: handleCancellationForIndexedOrder(...)
OrderService-->>DB: update/create cancellation
SenderController-->>Client: return "outside 0.1% tolerance of market rate" error
else within tolerance
SenderController->>OrderService: proceed with order creation/assignment
OrderService-->>DB: create/lock order
OrderService->>ProviderPool: assign provider / verify current or prev rate
OrderService-->>Client: success response
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ❌ 5❌ Failed checks (3 warnings, 2 inconclusive)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…ct direct NGN/NGN match - Modified test cases to use a rate of "1" for NGN/NGN direct matches, ensuring consistency with the updated validation logic. - Enhanced comments in the test setup to clarify the rationale behind rate normalization and bucket range calculations. - Improved clarity in test payloads to align with the new rate validation expectations.
…ogic - Updated test setup to reuse existing tokens, preventing duplicate entries and ensuring consistency in test execution. - Enhanced the CreateTestSenderProfile function to support token retrieval by ID and improved handling of network associations. - Adjusted the AddProviderOrderTokenToProvider function to streamline payout address assignment, enhancing clarity and maintainability.
…cancellation handling for indexed orders
Description
References
Testing
Checklist
mainBy submitting a PR, I agree to Paycrest's Contributor Code of Conduct and Contribution Guide.
Summary by CodeRabbit
Bug Fixes
Tests
Chores