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

Adding introductoryPriceAsAmountAndroid #1277

Merged
merged 3 commits into from
Mar 20, 2021
Merged
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
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