Skip to content
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

fix!: Represent prices as decimal values #758

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jon-signal
Copy link

@jon-signal jon-signal commented Aug 11, 2023

Fixes

The Twilio API actually returns prices as strings, but the Java SDK represents them as double values. Generally, it's best to avoid floating-point representations of monetary values, and it appears that the API itself is designed with this in mind.

This pull request:

  1. Changes the JSON in unit tests for pricing-related response objects to represent prices as strings. On its own, this has no functional effect, but does mean that the test vectors align with the real return values from the API.
  2. Changes the internal representation of prices from double to BigDecimal. The existing getters are unchanged and return a double representation of the prices. I've added new getters (e.g. getBasePriceDecimal) that return the prices as lossless decimal values.

The second change should be backward-compatible for most users, but I believe this is still technically a breaking change because it changes the constructors of those objects. Still, with the 10-series SDK going out, this may be a good time to make the change.

Checklist

  • I acknowledge that all my contributions will be made under the project's license
  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the Contribution Guidelines and my PR follows them
  • I have titled the PR appropriately
  • I have updated my branch with the main branch
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation about the functionality in the appropriate .md file (n/a)
  • I have added inline documentation to the code I modified

@jon-signal jon-signal changed the title [Fix!] Represent prices as decimal values [fix!]: Represent prices as decimal values Aug 11, 2023
@jon-signal jon-signal changed the title [fix!]: Represent prices as decimal values fix!: Represent prices as decimal values Aug 11, 2023
@jon-signal jon-signal force-pushed the prices_as_big_decimal branch 2 times, most recently from 3285143 to 6c75609 Compare August 11, 2023 17: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.

None yet

1 participant