[Android] purchaseUpdatedListener firing only once, not on every subscription transaction
See original GitHub issueVersion of react-native-iap
"react-native-iap": "4.5.4",
Version of react-native
"react-native": "0.61.4",
Platforms you faced the error (IOS or Android or both?)
Android, not tested on iOS
Expected behavior
purchaseUpdatedListener firing every time purchase is received
Actual behavior
purchaseUpdatedListener firing only once for first recipt, then nothing happens
Tested environment (Emulator? Real Device?)
Real device, run in dev env with test google account (subscription recurring every 5 minutes - email is incoming but receipt is not).
Simplified code I am using:
import React from 'react';
import { Text, View, TouchableOpacity, Alert } from 'react-native';
import RNIap, {
purchaseUpdatedListener,
purchaseErrorListener,
} from 'react-native-iap';
import { SpinnerOverlay } from '../components/SpinnerOverlay';
import { itemSkus } from '../config/in-app';
import { validateRecipt } from '../utils/validateRecipt';
import { logger } from '../utils/logger';
export class SubscriptionScreenInner extends React.Component {
purchaseUpdateSubscription = null;
purchaseErrorSubscription = null;
constructor(props) {
super(props);
this.state = {
products: [],
productsLoaded: false,
isProcessing: false
};
}
componentDidMount = async () => {
try {
if (itemSkus) {
await RNIap.initConnection();
await RNIap.flushFailedPurchasesCachedAsPendingAndroid();
const products = await RNIap.getSubscriptions(itemSkus);
this.setState({ products, productsLoaded: true });
this.purchaseUpdateSubscription = purchaseUpdatedListener(
async (purchase) => {
try {
const receipt = purchase.transactionReceipt;
if (receipt) {
const validate = await validateRecipt(purchase);
if (validate) {
await RNIap.finishTransaction(purchase, false);
this.props.fetchUserProfile();
this.resetScreenState();
Alert.alert('receipt validated', 'cool');
}
}
} catch (error) {
this.resetScreenState();
logger('Validate recipt error', error);
}
}
);
this.purchaseErrorSubscription = purchaseErrorListener((error) => {
this.resetScreenState();
logger('Purchase error during loading', error);
});
}
} catch (error) {
logger('Store prroducts error', error);
}
};
componentWillUnmount() {
if (this.purchaseUpdateSubscription) {
this.purchaseUpdateSubscription.remove();
}
if (this.purchaseErrorSubscription) {
this.purchaseErrorSubscription.remove();
}
RNIap.endConnection();
}
requestSubscription = async (sku) => {
this.setState({ isProcessing: true }, async () => {
await RNIap.requestSubscription(sku);
});
};
resetScreenState = () => {
this.setState({ isProcessing: false });
};
render() {
const { products, productsLoaded, isProcessing } = this.state;
if (!productsLoaded || isProcessing) {
return (
<View>
<SpinnerOverlay />
</View>
);
}
return (
<View>
<View>
<View>
<View>
<Text>Buy monthly subscription</Text>
</View>
<View>
<TouchableOpacity onPress={() => this.requestSubscription(products[0].productId)}>
<Text>Buy</Text>
</TouchableOpacity>
</View>
</View>
</View>
</View>
);
}
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:37 (10 by maintainers)
Top Results From Across the Web
React Native In-App Purchases (Android) - YouTube
In this video I am going to explain in detail how to implement in-app purchases for your Android app using the react-native-iap module....
Read more >react-native-iap - npm
This react-native module will help you access the In-app purchases capabilities of your phone on the Android , iOS platforms and the Amazon ......
Read more >dooboolab/react-native-iap (Raised $40.00) - Issuehunt
clearTransaction () throwing "Cannot finish a purchasing transaction" ... [Android] purchaseUpdatedListener firing only once, not on every subscription ...
Read more >Integrate the Android IAP API | In-App Purchasing
If the subscription is continuous and has never been canceled at any point, the app will only receive one receipt for that subscription/customer....
Read more >React Native: Subscriptions with In-App Purchases - Ross Bulat
From here, iOS will display some prompts for the user to confirm the transaction. If confirmed, the purchaseUpdatedListener event will fire, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Oh, I see. You are having a problem with the next subscription event. Let me test this out and come back.
Thanks for the reminder! I’ll test this out tomorrow.