Skip to content

Conversation

@codegen-sh
Copy link
Contributor

@codegen-sh codegen-sh bot commented Oct 29, 2025

Summary

This PR fixes the Braintree currency line item handling by removing the cart service dependency and adding support to include line extended data.

Changes

  • Removed the cart service dependency
  • Added support to include line extended data
  • Fixed additional card details validation

Related Commits

  • fix: removed the cart service dependency (43d95a7)
  • fix: added support to include line extended data (2da89c9)
  • fix: additional card details (d57b9ce)

Created by @govind Diwakar via Codegen


💻 View my workAbout Codegen
⛔ Remove Codegen from PR🚫 Ban action checks

Summary by CodeRabbit

  • Chores

    • Bumped Braintree payment plugin version to 0.0.16
  • Improvements

    • Support for using an order or default currency when creating transactions
    • Improved error construction and handling for payment operations
  • Documentation

    • Added and documented a new optional defaultCurrencyCode configuration for the Braintree provider

@coderabbitai
Copy link

coderabbitai bot commented Oct 29, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Bumps plugin version to 0.0.16; refactors the Braintree provider to remove cartService, use an optional context order_currency_code (falling back to provider defaultCurrencyCode or "USD") for currency in transaction construction; exposes/adjusts some public types and documents defaultCurrencyCode.

Changes

Cohort / File(s) Summary
Package versioning
plugins/braintree-payment/package.json
Version bumped from 0.0.15 to 0.0.16.
Core provider refactor
plugins/braintree-payment/src/providers/payment-braintree/src/core/braintree-base.ts
Removed cartService and its initialization; added order_currency_code?: string to ExtendedPaymentProviderContext; resolve currencyCode from context.order_currency_code with fallback to options.defaultCurrencyCode or "USD"; replaced cart-based currency usages in line-item and transaction construction; updated error handling calls to use buildBraintreeError.
Public types / imports
plugins/braintree-payment/src/providers/payment-braintree/src/core/braintree-import.ts, plugins/braintree-payment/src/providers/payment-braintree/src/index.ts, plugins/braintree-payment/src/providers/payment-braintree/src/services/braintree-import.ts
Adjusted import ordering and expanded exported/public type surface (added account-holder and webhook/logger types in imports).
Types & configuration
plugins/braintree-payment/src/providers/payment-braintree/src/types/index.ts, plugins/braintree-payment/src/providers/payment-braintree/README.md, plugins/braintree-payment/README.md
Added optional defaultCurrencyCode?: string to BraintreeOptions; documented defaultCurrencyCode in provider README and root README (example "USD").
Tests (imports order)
plugins/braintree-payment/src/providers/payment-braintree/src/core/__tests__/*
Minor reordering of imports in test files; no behavioral changes.
Utility formatting
plugins/braintree-payment/src/utils/format-amount.ts
Minor docblock/whitespace formatting changes only.

Sequence Diagram(s)

sequenceDiagram
  participant Client as Caller
  participant Provider as BraintreeBase
  participant Context as ProviderContext
  participant Logger as Logger

  rect rgb(245,250,240)
    Note over Client,Provider: Build transaction request using resolved currency
  end

  Client->>Provider: getTransactionCreateRequestBody(context, items)
  Provider->>Context: read order_currency_code
  alt order_currency_code present
    Context-->>Provider: return order_currency_code
  else
    Provider-->>Provider: use options.defaultCurrencyCode or "USD"
  end
  Provider->>Provider: construct line items and unitOfMeasure with resolved currencyCode
  Provider-->>Client: return transaction request body
  alt error
    Provider->>Logger: log error with context
    Provider-->>Client: throw buildBraintreeError(error, operation, Logger, context)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay attention to all removed cartService references to ensure no residual cart-dependent logic remains.
  • Verify currency resolution order: context.order_currency_codeoptions.defaultCurrencyCode"USD".
  • Review changes to exported/imported types in braintree-import.ts and index.ts for public API impact.
  • Confirm README/type docs match the implemented defaultCurrencyCode behavior.

Possibly related PRs

Suggested reviewers

  • dwene
  • antony-lambdacurry

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 "Fix Braintree Currency Line Item" directly references a core change in the pull request—improving how the Braintree payment provider handles currency for line items. The changes include removing the cart service dependency and replacing it with direct currency code handling derived from context and configuration, which is the essence of fixing currency line item handling. The title is specific, mentions the target component (Braintree), and clearly identifies the problem area (currency line item), making it clear to reviewers what the PR addresses. While the title doesn't capture all details such as the error handling helper or cart service removal, the instructions explicitly note that covering every detail is not required.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between fb96fe3 and 0a7364b.

📒 Files selected for processing (7)
  • plugins/braintree-payment/src/providers/payment-braintree/src/core/__tests__/braintree-base.spec.ts (1 hunks)
  • plugins/braintree-payment/src/providers/payment-braintree/src/core/__tests__/braintree-import.spec.ts (1 hunks)
  • plugins/braintree-payment/src/providers/payment-braintree/src/core/braintree-base.ts (8 hunks)
  • plugins/braintree-payment/src/providers/payment-braintree/src/core/braintree-import.ts (4 hunks)
  • plugins/braintree-payment/src/providers/payment-braintree/src/index.ts (1 hunks)
  • plugins/braintree-payment/src/providers/payment-braintree/src/services/braintree-import.ts (1 hunks)
  • plugins/braintree-payment/src/utils/format-amount.ts (2 hunks)

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

@SGFGOV SGFGOV requested a review from dwene October 29, 2025 06:22
@SGFGOV SGFGOV marked this pull request as ready for review October 29, 2025 06:23
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
plugins/braintree-payment/src/providers/payment-braintree/src/core/braintree-base.ts (1)

445-446: Remove unused cart variable.

This variable is declared but never assigned or used. It appears to be leftover from the cart service removal refactor.

Apply this diff:

-      let cart: CartDTO | undefined;
-      
     const lineItems = context.items
🧹 Nitpick comments (2)
plugins/braintree-payment/src/providers/payment-braintree/src/core/braintree-base.ts (2)

113-120: Remove or utilize the unused context parameter.

The context parameter is declared but never used within the function body. If it's intended for future logging enhancements, consider adding a comment explaining this; otherwise, remove it to reduce confusion.

Apply this diff if the parameter should be removed:

-export const buildBraintreeError = (error: unknown, operation: string, logger: Logger, context?: Record<string, unknown>): MedusaError => {
+export const buildBraintreeError = (error: unknown, operation: string, logger: Logger): MedusaError => {

Then update call sites at lines 633, 636, 655, 792, 868, and 891 to remove the context argument.


464-464: Remove unnecessary type cast and optional chaining.

The as string type cast and optional chaining operator ?. are unnecessary since currencyCode is already guaranteed to be a string (with the 'USD' fallback on line 456).

Apply this diff:

-          unitOfMeasure: (currencyCode as string)?.toUpperCase().substring(0, 12), // Max 12 characters
+          unitOfMeasure: currencyCode.toUpperCase().substring(0, 12), // Max 12 characters
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f80de76 and 43d95a7.

📒 Files selected for processing (2)
  • plugins/braintree-payment/package.json (1 hunks)
  • plugins/braintree-payment/src/providers/payment-braintree/src/core/braintree-base.ts (3 hunks)
🔇 Additional comments (2)
plugins/braintree-payment/package.json (1)

3-3: LGTM! Version bump aligns with the refactoring scope.

The version increment from 0.0.15 to 0.0.16 appropriately reflects the changes in this PR, which include removing the cart service dependency and adding new context fields.

plugins/braintree-payment/src/providers/payment-braintree/src/core/braintree-base.ts (1)

65-65: LGTM! Appropriate addition to support cart-independent currency handling.

The new optional order_currency_code field enables currency derivation without depending on the cart service, which aligns with the PR objectives.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
plugins/braintree-payment/src/providers/payment-braintree/README.md (1)

21-21: Fix typo in documentation.

"merchnat" should be "merchant".

Apply this diff:

-BRAINTREE_MERCHANT_ID=<Your merchnat Id>
+BRAINTREE_MERCHANT_ID=<Your merchant Id>
🧹 Nitpick comments (1)
plugins/braintree-payment/src/providers/payment-braintree/README.md (1)

60-60: Consider expanding the documentation.

The documentation could be more detailed to help users understand when and how defaultCurrencyCode is used, such as explaining it's used as a fallback when currency information is not provided in the payment context.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 43d95a7 and ee71cd6.

📒 Files selected for processing (3)
  • plugins/braintree-payment/src/providers/payment-braintree/README.md (2 hunks)
  • plugins/braintree-payment/src/providers/payment-braintree/src/core/braintree-base.ts (4 hunks)
  • plugins/braintree-payment/src/providers/payment-braintree/src/types/index.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugins/braintree-payment/src/providers/payment-braintree/src/core/braintree-base.ts
🔇 Additional comments (1)
plugins/braintree-payment/src/providers/payment-braintree/src/types/index.ts (1)

4-4: LGTM!

The addition of the optional defaultCurrencyCode property is correctly typed and aligns with the documentation changes in the README.

@lcmohsen lcmohsen merged commit 9c136ed into main Oct 30, 2025
@lcmohsen lcmohsen deleted the fix-braintree-currency-line-item branch October 30, 2025 10:00
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.

3 participants