Skip to content

fix!: Represent prices as decimal values - #758

Open
jon-signal wants to merge 3 commits into
twilio:mainfrom
jon-signal:prices_as_big_decimal
Open

jon-signal wants to merge 3 commits into
twilio:mainfrom
jon-signal:prices_as_big_decimal

Conversation

@jon-signal

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

Copy link
Copy Markdown

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 force-pushed the prices_as_big_decimal branch from 415acda to ba6e519 Compare August 11, 2023 16:48
@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
@jon-signal
jon-signal force-pushed the prices_as_big_decimal branch from 6c75609 to e267de8 Compare August 11, 2023 17:02
@jon-signal

Copy link
Copy Markdown
Author

Friends, I recognize this may not be a top priority, but is there anything I can do to help move this along to some kind of conclusion?

@jon-signal

Copy link
Copy Markdown
Author

Hello! I wanted to check in again: is there anything I can do to help this move forward?

@jon-signal

Copy link
Copy Markdown
Author

At the risk of being a nuisance, is there anything we can do to move this to a conclusion? I am happy to take "no" for an answer if that's the decision, but would love to understand next steps in any case!

This branch has not been deployed

No deployments
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