Skip to content

fix: Change PaymentCurrencyAmount.value type from float to string#191

Open
dinstein wants to merge 2 commits intogoogle-agentic-commerce:mainfrom
dinstein:fix/payment-currency-amount-value-type
Open

fix: Change PaymentCurrencyAmount.value type from float to string#191
dinstein wants to merge 2 commits intogoogle-agentic-commerce:mainfrom
dinstein:fix/payment-currency-amount-value-type

Conversation

@dinstein
Copy link

Summary

The value field in PaymentCurrencyAmount is currently defined as a numeric type (float/float64/Double), which is inconsistent with the W3C Payment Request API spec where value is defined as a DOMString. This PR aligns the type definition with the W3C standard for cross-language consistency.

Changes

  • Change PaymentCurrencyAmount.value from numeric type to string across Python (floatstr), Go (float64string), and Kotlin (DoubleString)
  • Update all sample code to use string literal values (e.g., "2.00" instead of 2.00) and add float() / strconv.ParseFloat() conversions where arithmetic operations are needed

Files changed (8 files)

File Change
src/ap2/types/payment_request.py floatstr
samples/go/pkg/ap2/types/payment_request.go float64string
samples/android/.../data/ShoppingAgentTypes.kt DoubleString
samples/python/.../merchant_agent/tools.py String literals + float() for sum
samples/python/.../sub_agents/catalog_agent.py float() conversion for arithmetic
samples/go/.../merchant_agent/tools.go String literals + strconv conversions
samples/go/.../merchant_agent/storage.go strconv.FormatFloat for Price→Value
samples/android/.../agent/DpcHelper.kt Remove redundant .toString() calls

Test plan

  • Verify Python samples run correctly with string values
  • Verify Go samples compile and run correctly
  • Verify Android sample builds successfully

@dinstein dinstein requested a review from a team as a code owner March 22, 2026 10:22
@google-cla
Copy link

google-cla bot commented Mar 22, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an inconsistency between the current implementation and the W3C Payment Request API specification by changing the PaymentCurrencyAmount.value field to a string type. This ensures cross-language consistency and requires updates to sample code to handle arithmetic operations with string values.

Highlights

  • Type Change: The PaymentCurrencyAmount.value field was changed from a numeric type (float/float64/Double) to a string type across Python, Go, and Kotlin to align with the W3C Payment Request API spec.
  • Code Updates: Sample code was updated to use string literal values for monetary amounts (e.g., "2.00" instead of 2.00).
  • Arithmetic Operations: Explicit conversions to numeric types (float() in Python, strconv.ParseFloat() in Go) were added where arithmetic operations are performed on the value field.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dinstein dinstein force-pushed the fix/payment-currency-amount-value-type branch 2 times, most recently from 082a3c0 to 1499de5 Compare March 22, 2026 10:27
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly aligns the PaymentCurrencyAmount.value type with the W3C specification by changing it from a numeric type to a string across the Python, Go, and Kotlin codebases. The changes are consistent and well-executed. My feedback focuses on improving the robustness of the implementation by adding error handling for string-to-numeric conversions and ensuring consistent formatting for currency values, which is crucial when dealing with monetary data.

Comment on lines +242 to +243
v, _ := strconv.ParseFloat(item.Amount.Value, 64)
newTotal += v
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The error from strconv.ParseFloat is ignored. If an item's amount is not a valid number, it will be silently added as 0 to the total. This could lead to incorrect calculations. It's better to log this error for debugging purposes. For example:

v, err := strconv.ParseFloat(item.Amount.Value, 64)
if err != nil {
    fmt.Fprintf(os.Stderr, "could not parse item value '%s', treating as 0: %v\n", item.Amount.Value, err)
}
newTotal += v

"asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bda02913",
"payTo": "0xMerchantWalletAddress",
"maxAmountRequired": str(int(item.amount.value * 1000000))
"maxAmountRequired": str(int(float(item.amount.value) * 1000000))
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The float() conversion could raise a ValueError if item.amount.value is not a valid number string. This would crash the request. It's safer to wrap this in a try...except ValueError block to handle potential malformed data gracefully.

Comment on lines +124 to +126
payment_request.details.total.amount.value = str(sum(
float(item.amount.value) for item in payment_request.details.display_items
))
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This block can be improved for robustness and formatting.

  1. Error Handling: The float() conversion will raise a ValueError if a value is not a valid number, which will crash the tool.
  2. Currency Formatting: str(sum(...)) doesn't guarantee two decimal places for the currency value (e.g., str(1.5) is '1.5').

Consider refactoring this to handle errors and format the output correctly. You may need to import logging.

total = 0
for item in payment_request.details.display_items:
    try:
        total += float(item.amount.value)
    except (ValueError, TypeError):
        logging.warning(f'Invalid value for item amount, skipping: {item.amount.value}')
payment_request.details.total.amount.value = f'{total:.2f}'

@dinstein dinstein force-pushed the fix/payment-currency-amount-value-type branch from 1499de5 to d0646f1 Compare March 22, 2026 10:29
Per the W3C Payment Request API specification, the `value` field in
PaymentCurrencyAmount is defined as a DOMString, not a number type.
This change aligns the implementation across Python, Go, and Kotlin
with the W3C standard for cross-language consistency.

Updated type definitions:
- Python: float -> str
- Go: float64 -> string
- Kotlin: Double -> String

Updated all sample code to use string values and handle
float conversions where arithmetic is needed.
@dinstein dinstein force-pushed the fix/payment-currency-amount-value-type branch from d0646f1 to 21c348d Compare March 22, 2026 10:31
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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