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

Most upvoted comments

I think we need to contact apple for this and this looks really terrible that there is a different test case which is not reproducible in sandbox environment. 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.

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 transaction when 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 SKPaymentTransactionStateDeferred or SKPaymentTransactionStateFailed we are not suppose to finishTransaction.

Since in many cases the SKPaymentTransactionStateFailed result is followed by a SKPaymentTransactionStatePurchased as 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.

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.