react-native-iap
react-native-iap copied to clipboard
Overall confusion with APIs and documentation
Description
This module used to be quite easy to use prior to version 11.x. I have been trying to migrate my app to 12.x and realised a lot of the technical decisions made for the Android update add a lot of friction and aren't properly documented. For example, why does the requestPurchase function now accepts both sku (for iOS) and skus (Android) ?
Adding to that, it doesn't seem like this is documented anywhere at all. Overall it seems like the APIs for both iOS and Android have deviated drastically from one another in the last updated and this was not even part of the list of breaking changes.
I'm by no means complaining or meaning to shame the wonderful work of the maintainers, but just think some changes have made into the public versions without updates to the docs or changelogs.
Expected Behavior
- API changes should have been listed in the Breaking Changes of 12.x
- The documentation doesn't mention the difference between
requestPurchaseon both platforms - The documentation doesn't mention the new
Productobject shapes since the May 2022 Play Store changes. Things likelocalizedPriceare simply not there anymore.
Hi thanks for submitting this. It got me rocking back and forth between Android and iOS thinking it was me. This is my workaround until this is straightened out:
requestPurchase(Platform.select({
ios: { sku, andDangerouslyFinishTransactionAutomaticallyIOS: false },
android: { skus: [sku] }
}))
To avoid creating another issue, I'll post another discrepancy between documentation and code here as well.
The documentation states that the property price is the localized price string, with only number (eg. 1.99). This is true in production on iOS. However, Android returns the localized price with the currency for both the price and localizedPrice properties (e.g., $1.99 instead of just 1.99).
This traces back to this code block on latest main and currently in the latest release (v12.10.8):
/** Added to maintain backwards compatibility */
export const singleProductAndroidMap = (
originalProd: ProductAndroid,
): ProductAndroid => {
const prod: ProductAndroid = {
...originalProd,
//legacy properties
price:
originalProd.oneTimePurchaseOfferDetails?.formattedPrice ??
originalProd.price,
localizedPrice:
originalProd.oneTimePurchaseOfferDetails?.formattedPrice ??
originalProd.price,
currency:
originalProd.oneTimePurchaseOfferDetails?.priceCurrencyCode ??
originalProd.currency,
};
return prod;
};