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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 43 additions & 4 deletions src/main/java/com/twilio/type/InboundCallPrice.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.twilio.converter.Promoter;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.Objects;

/**
Expand Down Expand Up @@ -41,8 +42,8 @@ public static Type forValue(final String value) {
}
}

private final double basePrice;
private final double currentPrice;
private final BigDecimal basePrice;
private final BigDecimal currentPrice;
private final Type type;

/**
Expand All @@ -53,19 +54,57 @@ public static Type forValue(final String value) {
* @param type type of phone number
*/
@JsonCreator
public InboundCallPrice(@JsonProperty("base_price") final double basePrice,
@JsonProperty("current_price") final double currentPrice,
public InboundCallPrice(@JsonProperty("base_price") final BigDecimal basePrice,
@JsonProperty("current_price") final BigDecimal currentPrice,
@JsonProperty("number_type") final Type type) {
this.basePrice = basePrice;
this.currentPrice = currentPrice;
this.type = type;
}

/**
* Returns the retail price per minute to receive a call to this phone number type. The value returned by this
* method is represented as a {@code double}, which may result in loss of precision.
*
* @return the retail price per minute to receive a call to this phone number type
*
* @deprecated please use {{@link #getBasePriceDecimal()}} instead for a lossless representation of the price
*/
@Deprecated
public double getBasePrice() {
return basePrice.doubleValue();
}

/**
* Returns the retail price per minute to receive a call to this phone number type.
*
* @return the retail price per minute to receive a call to this phone number type
*/
public BigDecimal getBasePriceDecimal() {
return basePrice;
}

/**
* Returns the current price per minute (which accounts for any volume or custom price discounts) to receive a call
* to this phone number type. The value returned by this method is represented as a {@code double}, which may result
* in loss of precision.
*
* @return the current price per minute to receive a call to this phone number type
*
* @deprecated please use {{@link #getCurrentPriceDecimal()} instead for a lossless representation of the price
*/
@Deprecated
public double getCurrentPrice() {
return currentPrice.doubleValue();
}

/**
* Returns the current price per minute (which accounts for any volume or custom price discounts) to receive a call
* to this phone number type.
*
* @return the current price per minute to receive a call to this phone number type
*/
public BigDecimal getCurrentPriceDecimal() {
return currentPrice;
}

Expand Down
45 changes: 41 additions & 4 deletions src/main/java/com/twilio/type/InboundSmsPrice.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.twilio.converter.Promoter;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.Objects;

/**
Expand Down Expand Up @@ -42,8 +43,8 @@ public static Type forValue(final String value) {
}
}

private final double basePrice;
private final double currentPrice;
private final BigDecimal basePrice;
private final BigDecimal currentPrice;
private final Type type;

/**
Expand All @@ -54,19 +55,55 @@ public static Type forValue(final String value) {
* @param type type of phone number
*/
@JsonCreator
public InboundSmsPrice(@JsonProperty("base_price") final double basePrice,
@JsonProperty("current_price") final double currentPrice,
public InboundSmsPrice(@JsonProperty("base_price") final BigDecimal basePrice,
@JsonProperty("current_price") final BigDecimal currentPrice,
@JsonProperty("number_type") final Type type) {
this.basePrice = basePrice;
this.currentPrice = currentPrice;
this.type = type;
}

/**
* Returns the retail price to receive a message. The value returned by this method is represented as a
* {@code double}, which may result in loss of precision.
*
* @return the retail price to receive a message
*
* @deprecated please use {{@link #getBasePriceDecimal()}} instead for a lossless representation of the price
*/
@Deprecated
public double getBasePrice() {
return basePrice.doubleValue();
}

/**
* Returns the retail price to receive a message.
*
* @return the retail price to receive a message
*/
public BigDecimal getBasePriceDecimal() {
return basePrice;
}

/**
* Returns the current price (which accounts for any volume or custom price discounts) to receive a message. The
* value returned by this method is represented as a {@code double}, which may result in loss of precision.
*
* @return the current price to receive a message
*
* @deprecated please use {{@link #getCurrentPriceDecimal()} instead for a lossless representation of the price
*/
@Deprecated
public double getCurrentPrice() {
return currentPrice.doubleValue();
}

/**
* Returns the current price (which accounts for any volume or custom price discounts) to receive a message.
*
* @return the current price to receive a message
*/
public BigDecimal getCurrentPriceDecimal() {
return currentPrice;
}

Expand Down
47 changes: 43 additions & 4 deletions src/main/java/com/twilio/type/OutboundCallPrice.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,65 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.Objects;

@JsonIgnoreProperties(ignoreUnknown = true)
@ToString
public class OutboundCallPrice {
private final double basePrice;
private final double currentPrice;
private final BigDecimal basePrice;
private final BigDecimal currentPrice;

@JsonCreator
public OutboundCallPrice(@JsonProperty("base_price") final double basePrice,
@JsonProperty("current_price") final double currentPrice) {
public OutboundCallPrice(@JsonProperty("base_price") final BigDecimal basePrice,
@JsonProperty("current_price") final BigDecimal currentPrice) {
this.basePrice = basePrice;
this.currentPrice = currentPrice;
}

/**
* Returns the retail price per minute to make a call from this phone number type. The value returned by this
* method is represented as a {@code double}, which may result in loss of precision.
*
* @return the retail price per minute to make a call from this phone number type
*
* @deprecated please use {{@link #getBasePriceDecimal()}} instead for a lossless representation of the price
*/
@Deprecated
public double getBasePrice() {
return basePrice.doubleValue();
}

/**
* Returns the retail price per minute to make a call from this phone number type.
*
* @return the retail price per minute to make a call from this phone number type
*/
public BigDecimal getBasePriceDecimal() {
return basePrice;
}

/**
* Returns the current price per minute (which accounts for any volume or custom price discounts) to make a call
* from this phone number type. The value returned by this method is represented as a {@code double}, which may
* result in loss of precision.
*
* @return the current price per minute to make a call from this phone number type
*
* @deprecated please use {{@link #getCurrentPriceDecimal()} instead for a lossless representation of the price
*/
@Deprecated
public double getCurrentPrice() {
return currentPrice.doubleValue();
}

/**
* Returns the current price per minute (which accounts for any volume or custom price discounts) to make a call
* from this phone number type.
*
* @return the current price per minute to make a call from this phone number type
*/
public BigDecimal getCurrentPriceDecimal() {
return currentPrice;
}

Expand Down
47 changes: 43 additions & 4 deletions src/main/java/com/twilio/type/OutboundPrefixPrice.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

Expand All @@ -22,8 +23,8 @@ public class OutboundPrefixPrice {

private final List<String> prefixes;
private final String friendlyName;
private final double basePrice;
private final double currentPrice;
private final BigDecimal basePrice;
private final BigDecimal currentPrice;

/**
* Initialize an OutboundPrefixPrice.
Expand All @@ -36,8 +37,8 @@ public class OutboundPrefixPrice {
@JsonCreator
public OutboundPrefixPrice(@JsonProperty("prefixes") final List<String> prefixes,
@JsonProperty("friendly_name") final String friendlyName,
@JsonProperty("base_price") final double basePrice,
@JsonProperty("current_price") final double currentPrice) {
@JsonProperty("base_price") final BigDecimal basePrice,
@JsonProperty("current_price") final BigDecimal currentPrice) {
this.prefixes = prefixes;
this.friendlyName = friendlyName;
this.basePrice = basePrice;
Expand All @@ -52,11 +53,49 @@ public String getFriendlyName() {
return friendlyName;
}

/**
* Returns the retail price per minute to make a call to numbers matching this prefix list. The value returned by
* this method is represented as a {@code double}, which may result in loss of precision.
*
* @return the retail price per minute to make a call to numbers matching this prefix list
*
* @deprecated please use {{@link #getBasePriceDecimal()}} instead for a lossless representation of the price
*/
@Deprecated
public double getBasePrice() {
return basePrice.doubleValue();
}

/**
* Returns the retail price per minute to make a call to numbers matching this prefix list.
*
* @return the retail price per minute to make a call to numbers matching this prefix list
*/
public BigDecimal getBasePriceDecimal() {
return basePrice;
}

/**
* Returns the current price per minute (which accounts for any volume or custom price discounts) to make a call to
* numbers matching this prefix list. The value returned by this method is represented as a {@code double}, which
* may result in loss of precision.
*
* @return the current price per minute to make a call to numbers matching this prefix list
*
* @deprecated please use {{@link #getCurrentPriceDecimal()} instead for a lossless representation of the price
*/
@Deprecated
public double getCurrentPrice() {
return currentPrice.doubleValue();
}

/**
* Returns the current price per minute (which accounts for any volume or custom price discounts) to make a call to
* numbers matching this prefix list.
*
* @return the current price per minute to make a call to numbers matching this prefix list
*/
public BigDecimal getCurrentPriceDecimal() {
return currentPrice;
}

Expand Down
38 changes: 32 additions & 6 deletions src/main/java/com/twilio/type/PhoneNumberPrice.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.twilio.converter.Promoter;
import lombok.ToString;

import java.math.BigDecimal;
import java.util.Objects;

/**
Expand Down Expand Up @@ -56,8 +57,8 @@ public static Type forValue(final String value) {
}
}

private final double basePrice;
private final double currentPrice;
private final BigDecimal basePrice;
private final BigDecimal currentPrice;
private final Type type;

/**
Expand All @@ -68,29 +69,54 @@ public static Type forValue(final String value) {
* @param type type of phone number
*/
@JsonCreator
public PhoneNumberPrice(@JsonProperty("base_price") final double basePrice,
@JsonProperty("current_price") final double currentPrice,
public PhoneNumberPrice(@JsonProperty("base_price") final BigDecimal basePrice,
@JsonProperty("current_price") final BigDecimal currentPrice,
@JsonProperty("number_type") final Type type) {
this.basePrice = basePrice;
this.currentPrice = currentPrice;
this.type = type;
}

/**
* Returns the base price of the phone number.
* Returns the base price of the phone number. The value returned by this method is represented as a {@code double},
* which may result in loss of precision.
*
* @return the base price of the phone number
*
* @deprecated please use {{@link #getBasePriceDecimal()} instead for a lossless representation of the price
*/
@Deprecated
public double getBasePrice() {
return basePrice.doubleValue();
}

/**
* Returns the base price of the phone number.
*
* @return the base price of the phone number
*/
public BigDecimal getBasePriceDecimal() {
return basePrice;
}

/**
* Returns the current price of the phone number.
* Returns the current price of the phone number. The value returned by this method is represented as a
* {@code double}, which may result in loss of precision.
*
* @return the current price of the phone number
*
* @deprecated please use {{@link #getCurrentPriceDecimal()} instead for a lossless representation of the price
*/
@Deprecated
public double getCurrentPrice() {
return currentPrice.doubleValue();
}

/**
* Returns the current price of the phone number.
*
* @return the current price of the phone number
*/ public BigDecimal getCurrentPriceDecimal() {
return currentPrice;
}

Expand Down
Loading