Skip to content

Commit

Permalink
Adding introductoryPriceAsAmountAndroid (#1277)
Browse files Browse the repository at this point in the history
* feat: adding introductoryPriceAsAmountAndroid

* chore: safe conversion of types for intro price amount

* doc: introductoryPriceAsAmountAndroid
  • Loading branch information
Kelvne Pechim authored Mar 20, 2021
1 parent b001c40 commit b322906
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ Property | iOS | And | Comment
`title` | ✓ | ✓ | Returns the title Android and localizedTitle on iOS.
`description` | ✓ | ✓ | Returns the localized description on Android and iOS.
`introductoryPrice` | ✓ | ✓ | Formatted introductory price of a subscription, including its currency sign, such as €3.99.<br>The price doesn't include tax.
`introductoryPriceAsAmountAndroid` | | ✓ | Localized introductory price string, with only number (eg. `0.99`).
`introductoryPriceAsAmountIOS` | ✓ | | Localized introductory price string, with only number (eg. `0.99`).
`introductoryPricePaymentModeIOS` | ✓ | | The payment mode for this product discount.
`introductoryPriceNumberOfPeriods` | ✓ | | An integer that indicates the number of periods the product discount is available.
Expand Down
4 changes: 4 additions & 0 deletions android/src/main/java/com/dooboolab/RNIap/RNIapModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,15 @@ public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> s
for (SkuDetails skuDetails : skuDetailsList) {
WritableMap item = Arguments.createMap();
item.putString("productId", skuDetails.getSku());
long introductoryPriceMicros = skuDetails.getIntroductoryPriceAmountMicros();
long priceAmountMicros = skuDetails.getPriceAmountMicros();
// Use valueOf instead of constructors.
// See: https://www.javaworld.com/article/2073176/caution--double-to-bigdecimal-in-java.html
BigDecimal priceAmount = BigDecimal.valueOf(priceAmountMicros);
BigDecimal introductoryPriceAmount = BigDecimal.valueOf(introductoryPriceMicros);
BigDecimal microUnitsDivisor = BigDecimal.valueOf(1000000);
String price = priceAmount.divide(microUnitsDivisor).toString();
String introductoryPriceAsAmountAndroid = introductoryPriceAmount.divide(microUnitsDivisor).toString();
item.putString("price", price);
item.putString("currency", skuDetails.getPriceCurrencyCode());
item.putString("type", skuDetails.getType());
Expand All @@ -317,6 +320,7 @@ public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> s
item.putString("freeTrialPeriodAndroid", skuDetails.getFreeTrialPeriod());
item.putString("introductoryPriceCyclesAndroid", String.valueOf(skuDetails.getIntroductoryPriceCycles()));
item.putString("introductoryPricePeriodAndroid", skuDetails.getIntroductoryPricePeriod());
item.putString("introductoryPriceAsAmountAndroid", introductoryPriceAsAmountAndroid);
item.putString("iconUrl", skuDetails.getIconUrl());
item.putString("originalJson", skuDetails.getOriginalJson());
BigDecimal originalPriceAmountMicros = BigDecimal.valueOf(skuDetails.getOriginalPriceAmountMicros());
Expand Down

0 comments on commit b322906

Please sign in to comment.