-
Notifications
You must be signed in to change notification settings - Fork 2
The discount value for paypal must be positive number #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
The discount value for paypal must be positive number #4
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughChanged PayPal order presenter to serialize a nil-safe, non-negative discount using Changes
Sequence Diagram(s)No sequence diagram necessary for this change. Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
spec/presenters/spree_paypal_checkout/order_presenter_spec.rb (1)
56-63: Good edge case coverage, but clarify the third test name.The tests appropriately cover zero and default value scenarios. However, the third test (line 61) is named "should be zero when discount is nil" but doesn't actually test a nil promo_total—it tests the default value. Consider renaming for clarity:
- it "should be zero when discount is nil" do + it "should be zero when promo_total has default value" do expect(subject.to_json['body'].purchase_units[0].amount.breakdown.discount.value).to eq("0.0") endNote: The varying string formats ("100", "0", "0.0") reflect how Ruby's
.to_shandles different numeric types and is expected behavior.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
app/presenters/spree_paypal_checkout/order_presenter.rb(1 hunks)spec/presenters/spree_paypal_checkout/order_presenter_spec.rb(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
spec/presenters/spree_paypal_checkout/order_presenter_spec.rb (1)
app/presenters/spree_paypal_checkout/order_presenter.rb (1)
to_json(15-59)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Cursor Bugbot
🔇 Additional comments (3)
spec/presenters/spree_paypal_checkout/order_presenter_spec.rb (2)
40-40: Minor test improvement, unrelated to discount fix.The change from
eq("")tobe_nil.or eq("")makes the test more flexible when handling nil names. While this is a reasonable improvement, it appears unrelated to the discount fix that is the focus of this PR.
51-54: Excellent test coverage for the core fix.This test correctly validates that negative promo_total values are converted to positive discount values, which is the primary requirement from PayPal's API documentation.
app/presenters/spree_paypal_checkout/order_presenter.rb (1)
39-39: Add explanatory comment and guard against nil promo_totalReplace
value: order.promo_total.abs.to_swith
# PayPal requires discount.value to be non-negative value: order.promo_total&.abs.to_s || '0'Ensure
order.promo_totalcan never be nil (or defaults to zero).
|
|
||
| it "should be zero when discount is nil" do | ||
| expect(subject.to_json['body'].purchase_units[0].amount.breakdown.discount.value).to eq("0.0") | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see the document from Paypal https://developer.paypal.com/docs/api/orders/v2/#definition-amount_breakdown
Summary by CodeRabbit
Bug Fixes
Tests