react-native-iap: iOS in-app purchase failure when payment method added live when there is not payment method already present
Version of react-native-iap
react-native-iap": "^2.3.17
Platforms you faced the error (IOS or Android or both?)
iOS
Expected behavior
Payment should go through only when finishTransaction is being called
Actual behavior
The amount is being detected after a payment method like credit card is added.
But the RNIap.buyProductWithoutFinishTransaction(sku) method reached.
Tested environment (Emulator? Real Device?)
Real Device - iPhone 6s
Steps to reproduce the behavior
- Check to ensure the Apple account in the device the payments method is set to none or some invalid payment details
- Make the in-app purchase through the app
- User is taken to the Account settings page to add a valid payment method
- Payment method is charged but the transaction receipt is not received in the below mentioned code
ComponentDidMount(){
await RNIap.initConnection();
await RNIap.consumeAllItems();
const prod = await RNIap.getProducts(product);
}
async componentWillUnmount() {
RNIap.endConnection()
}
buyProduct(sku){
await RNIap.clearTransaction();
RNIap.buyProductWithoutFinishTransaction(sku)
.then(purchase => {
// not reached
if(calltoserverisSuccess){
RNIap.finishTransaction();
}
})
.catch(error => {
// code enters catch case if ever
}}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 27 (21 by maintainers)
Commits related to this issue
- Add additional event listener to handle success purchase after failure. Make workaround for #307. Resolve #307 for now. — committed to dooboolab-community/react-native-iap by hyochan 6 years ago
- Implement support of handling dropped success purchase. This is similar feature from react-native-iap(https://github.com/dooboolab/react-native-iap/issues/307). Similar issue in current repo #54. — committed to dooboolab-community/flutter_inapp_purchase by hyochan 5 years ago
I think we need to contact
applefor this and this looks really terrible that there is a different test case which is not reproducible insandboxenvironment. For those who want to understand the problem, I’ve recorded the screen and you can see the clip here. @anandwahed Could you also contact apple for this? Because I know they aren’t that supportive so it is better for more people to have contact with them. Let’s gather up to solve this issue.@JJMoon
Today we received answer from Apple. There may be callback returned again after
failure. We are working on workaround solution in #348 but I am afraid this could be very nasty.I’ve tested this in a live purchase and seems to be working. However, keep in mind that you should only add listener when there was a failure or it may be duplicated with a successful result.
@anandwahed I guess it’s right way to
finish transactionwhen it’s failed. Please look up this thread. https://stackoverflow.com/questions/11008636/inapp-purchase-skpaymentqueue-finish-transaction-doesnt-work When it fails, there will be no receipt, so you don’t apply the purchase product. And the finishing transaction doesn’t always mean ‘purchasing’. Meanwhile, I will investigate thread 6431.@dooboolab and @JJMoon also i think i found the issue when going through our iOS code. In the updatedTransactions method when we receive a failure message in the
SKPaymentTransactionStateDeferredorSKPaymentTransactionStateFailedwe are not suppose tofinishTransaction.Since in many cases the
SKPaymentTransactionStateFailedresult is followed by aSKPaymentTransactionStatePurchasedas mentioned in the above thread 6431. I am not sure about the Objective-C code so kindly check and confirm if we do clear the transaction on failure.@dooboolab @JJMoon have a look at this one https://forums.developer.apple.com/thread/6431 https://forums.developer.apple.com/thread/64489
I understand this error happens when the user is in logged out state, or no credit card info. If the methods work fine, the cause of this error lies somewhere else. We need to prepare this action, which leaves the app, viewDidDisappear etc. In sandbox mode, this symptom happens somewhat different way. When I make a new sandbox account, and the first purchasing doesn’t work. At the second time, the device is logged in state, and works fine. I don’t have a clue for this error.