"react-native-iap": "4.5.4",
"react-native": "0.61.4",
Android, not tested on iOS
purchaseUpdatedListener firing every time purchase is received
purchaseUpdatedListener firing only once for first recipt, then nothing happens
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>
);
}
}
I upgraded React Native to 0.63.2 but it haven't helped.
After bumping react-native-iap to 4.6.3 no change.
I have exactly the same issue, used to be on 4.4.9, bumped to 4.6.3 and still occurs
Were you able to fix it or did you figure out a workaround?
Unfortunately I don't have solution for this.
This is very strange. Are you saying that you attempt to purchase again after the first purchase, the purchaseUpdatedListener
is not firing? I've tested this earlier and it should keep firing until you kill the listener.
Oh, I see. You are having a problem with the next subscription event. Let me test this out and come back.
We are facing the same issue, I was using 4.4.9 and tried to downgrade and upgrade to latest 5.1.1 but result is still same. Only getting event first time.
any solution to this?
As a temporary solution I save first receipt from subscription event and validate it on each application initialization - it works, but I tested it only for Android.
Hi, @hyochan
Any idea when this will be resolved?
thanks
Thanks for the reminder! I'll test this out tomorrow.
@hyochan
I know you are still working on the issue, just wanted to know about the next patch date for this issue as our entire team is waiting for this one.
Thank you
@Kalesberg I will definitely try out this week and share updates. However, this library is used by many others and the implementation on purchaseUpdatedListner
hasn't been changed since then. I might have to make a reproducible example firstly. I'll try this week.
Related for iOS
in #1160
@hyochan
Appreciate it!!
@Kalesberg Could you kindly verify that android.test.purchased
also fires multiple times?
@hyochan will do that!
@hyochan
Our product is only for subscription base, so android.test.purchased
cannot best testified.
So I tried to use your demo app in this library and added test.sub1
but I was not able to get any product with it
@Kalesberg Could you put android logcat where it triggers purchaseUpdatedListener
?
Please tell me what's coming in billingResult
and purchases
.
@hyochan , hope it helps
really looking forward to this patch release
I am trying to look into this now. By the way can you give me better file format? rtf
file is hard to open in my env which is chromeos
. You may also send me an email ([email protected]) if you think it has privacy issue.
@Kalesberg You may also check this one out. https://stackoverflow.com/questions/56744971/google-play-billing-library-developer-error-code-5-if-i-want-to-consume-or-ackno
@hyochan
Does this mean there is nothing wrong with this plugin?
the iOS version works fine but just the android phones are problematic
We are just finding out the problem. However, following the logcat you've provided, it looks like to me that the acknowledgePurchase
which is finishTransaction
didn't work properly since the purchase was on the air. I've shared the stackoverflow which also talks about the similar situation.
@hyochan
the problem persists even in test subscription mode which should always succeed
@hyochan , any updates on the plugin?
Most helpful comment
Oh, I see. You are having a problem with the next subscription event. Let me test this out and come back.