Skip to content

fix: prevent None values in Razorpay amount conversion#2

Open
vishwajeet-13 wants to merge 4 commits into
mainfrom
fix/razorpay-null-amounts
Open

fix: prevent None values in Razorpay amount conversion#2
vishwajeet-13 wants to merge 4 commits into
mainfrom
fix/razorpay-null-amounts

Conversation

@vishwajeet-13

@vishwajeet-13 vishwajeet-13 commented Dec 26, 2025

Copy link
Copy Markdown
Collaborator

handled none values

Summary by CodeRabbit

  • Bug Fixes

    • Safely coerce fee, tax and base amounts before calculations to avoid None-related errors and improve payment amount accuracy.
  • Refactor

    • Improved readability and formatting across payment handling and status sync logic.
  • Chores

    • Added additional debug logging to surface payment entity details during processing; minor whitespace/formatting tidy-ups; CI updated to newer Python and Node versions.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 26, 2025

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Formatting and readability edits across multiple modules; numeric fields in set_payment_details are coerced with or 0 to avoid None-to-int conversions; labeled debug prints for the payment entity were added; CI workflow updated to Python 3.14 and Node 24. No public API signature or control-flow behavior changes.

Changes

Cohort / File(s) Summary
Order: numeric coercion, debug traces & formatting
razorpay_frappe/razorpay_integration/doctype/razorpay_order/razorpay_order.py
Reformatted status type annotation; set_payment_details reads fee, tax, and base_amount with payment_entity.get(..., 0) or 0 before int conversion; extra parentheses in sync_status for readability; added labeled debug prints (frappe.errprint("Payment Entity: ") and the entity).
Client-side formatting
razorpay_frappe/razorpay_integration/doctype/razorpay_order/razorpay_order.js
Minor punctuation/formatting change: add_web_link call now ends with ); on the same line.
Payment link: formatting
razorpay_frappe/razorpay_integration/doctype/razorpay_payment_link/razorpay_payment_link.py
Reflowed imports and a DF.Literal annotation across multiple lines; wrapped some call arguments—no logic changes.
Settings: whitespace
razorpay_frappe/razorpay_integration/doctype/razorpay_settings/razorpay_settings.py
Removed trailing blank lines after class declaration; no behavioral changes.
Webhook processor: whitespace
razorpay_frappe/webhook_processor.py
Removed an empty blank line between an except block and a following @property; no control-flow changes.
CI workflow: toolchain versions
.github/workflows/ci.yml
Updated CI to use python-version: '3.14' (was 3.11) and node-version: 24 (was 18); no other workflow logic changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰
Fees and taxes warmed with care, no None shall slip away,
Parentheses in order, debug signs to light the way,
CI hops to newer rails, small trims tidy the scene,
A rabbit cheers the neat little changes — bright and keen. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'prevent None values in Razorpay amount conversion' accurately reflects the main change in the PR, which adds null-safety handling (using get() with default values of 0) for fee, tax, and base_amount fields in the set_payment_details method.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/razorpay-null-amounts

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 24088c1 and c8b69e6.

📒 Files selected for processing (1)
  • razorpay_frappe/razorpay_integration/doctype/razorpay_order/razorpay_order.py
🧰 Additional context used
🪛 Ruff (0.14.10)
razorpay_frappe/razorpay_integration/doctype/razorpay_order/razorpay_order.py

44-44: Undefined name Pending

(F821)


44-44: Undefined name Failed

(F821)


44-44: Undefined name Paid

(F821)


44-44: Undefined name Refund

(F821)


44-44: Undefined name Progress

(F821)


44-44: Undefined name Refunded

(F821)

🔇 Additional comments (3)
razorpay_frappe/razorpay_integration/doctype/razorpay_order/razorpay_order.py (3)

43-45: Formatting improvement is good; static analysis warnings are false positives.

The multi-line format improves readability. The Ruff warnings about undefined names are false positives—these are string literals within a DF.Literal type annotation, not variable references.


182-184: LGTM! Readability improvement.

Breaking the complex conditional across multiple lines with explicit parentheses improves code clarity without changing the logic.


138-147: Defensive None handling is necessary and correctly implemented.

The .get(key, 0) or 0 pattern is essential here because convert_from_razorpay_money does not handle None inputs—it performs integer division and will crash if None is passed. The fee, tax, and base_amount fields from the Razorpay API may return None, making this defensive pattern a required safeguard.

Comment thread razorpay_frappe/razorpay_integration/doctype/razorpay_order/razorpay_order.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 (2)
razorpay_frappe/razorpay_integration/doctype/razorpay_order/razorpay_order.py (2)

132-133: Consider removing or using conditional logging.

These debug print statements will output to the error log on every payment detail fetch. If these are temporary debug traces, consider removing them before merging. If logging is needed for production, use conditional logging based on a debug flag or proper log levels.

🔎 Alternative: Conditional debug logging
-	frappe.errprint("Payment Entity: ")
-	frappe.errprint(payment_entity)
+	if frappe.conf.get("developer_mode"):
+		frappe.log("Payment Entity: " + str(payment_entity))

136-136: Optional: Remove extra blank line.

This extra blank line appears to be a leftover from the duplicate debug print removal mentioned in the previous review.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a1d9a88 and 39da222.

📒 Files selected for processing (1)
  • razorpay_frappe/razorpay_integration/doctype/razorpay_order/razorpay_order.py
🧰 Additional context used
🧬 Code graph analysis (1)
razorpay_frappe/razorpay_integration/doctype/razorpay_order/razorpay_order.py (1)
razorpay_frappe/utils.py (1)
  • convert_from_razorpay_money (48-49)
🪛 Ruff (0.14.10)
razorpay_frappe/razorpay_integration/doctype/razorpay_order/razorpay_order.py

44-44: Undefined name Pending

(F821)


44-44: Undefined name Failed

(F821)


44-44: Undefined name Paid

(F821)


44-44: Undefined name Refund

(F821)


44-44: Undefined name Progress

(F821)


44-44: Undefined name Refunded

(F821)

🔇 Additional comments (4)
razorpay_frappe/razorpay_integration/doctype/razorpay_order/razorpay_order.py (4)

43-45: LGTM: Formatting improvement.

The multi-line formatting of the status literal improves readability without changing functionality.

Note: The Ruff errors flagging "Pending", "Failed", etc. as undefined names are false positives—these are string literals within a DF.Literal type annotation, not variable references.


144-146: LGTM: Consistent None-guard for base_amount.

The same defensive pattern is correctly applied to base_amount, consistent with the fee and tax fields above.


181-183: LGTM: Improved readability.

The extra parentheses make the operator precedence clearer without changing the logic.


137-142: Good defensive pattern for handling None/missing values.

The .get("fee", 0) or 0 and .get("tax", 0) or 0 guards correctly prevent None from reaching convert_from_razorpay_money, which expects an int. The pattern handles both missing keys and explicit None values appropriately.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 39da222 and b1adae0.

📒 Files selected for processing (1)
  • .github/workflows/ci.yml
🧰 Additional context used
🪛 actionlint (1.7.9)
.github/workflows/ci.yml

57-57: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

⏰ 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: Server
🔇 Additional comments (2)
.github/workflows/ci.yml (2)

59-59: Node.js 24 (Krypton) is available and stable as of December 2025. It was released on May 6, 2025, and entered Active LTS status on October 28, 2025, with end-of-life planned for April 30, 2028. Using Node.js 24 in the CI pipeline is appropriate and will not cause failures due to version unavailability.

Likely an incorrect or invalid review comment.


54-54: No action required. Python 3.14 was released on October 7, 2025, and is fully supported by actions/setup-python and GitHub-hosted runners as of December 2025. The specified version will work correctly in the CI pipeline.

Likely an incorrect or invalid review comment.

Comment thread .github/workflows/ci.yml
Comment on lines 57 to 60
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 24
check-latest: true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Update actions/setup-node to v4.

The actions/setup-node@v3 action version is outdated. According to the static analysis tool, the runner is too old to run on GitHub Actions.

🔎 Proposed fix
       - name: Setup Node
-        uses: actions/setup-node@v3
+        uses: actions/setup-node@v4
         with:
           node-version: 24
           check-latest: true

Based on static analysis hints.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 24
check-latest: true
uses: actions/setup-node@v4
with:
node-version: 24
check-latest: true
🧰 Tools
🪛 actionlint (1.7.9)

57-57: the runner of "actions/setup-node@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🤖 Prompt for AI Agents
.github/workflows/ci.yml around lines 57 to 60: the workflow uses
actions/setup-node@v3 which is outdated; update the action reference to
actions/setup-node@v4 by replacing the uses line accordingly (keep the existing
with: keys like node-version: 24 and check-latest: true intact) so the runner
uses the current setup-node major version.

@Rl0007

Rl0007 commented Jun 10, 2026

Copy link
Copy Markdown

@vishwajeet-13 is it still relevant?

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