react-native-iap icon indicating copy to clipboard operation
react-native-iap copied to clipboard

What is the right way to test?

Open timraybould opened this issue 7 years ago • 1 comments

Umbrella question: what is the proper way to test in app purchases before release? I'm not sure if my implementation is working or not. Specific questions in bold below.

Environment

  • React Naive 0.57.8
  • react-native-iap 2.4.0-beta6
  • Simulator: various devices
  • Physical device: iPhone XS

Stripped down code

async componentDidMount() {
    await RNIap.initConnection()
    const products = await RNIap.getSubscriptions(items)
    this.setState({ products })
    console.log(products)
}

componentWillUnmount() {
    RNIap.endConnection()
}

async handlePurchase() {
    const purchase = await RNIap.buySubscription('my_product_id')
    await RNIap.finishTransaction()
    user.collection('purchases').add({receipt: purchase.transactionReceipt})
    user.update({premiumMember: true})
}

async restorePurchases() {
    const purchases = await RNIap.getAvailablePurchases()
    for (const purchase of purchases) {
        if (purchase.productId === 'my_product_id') {
            user.update({premiumMember: true})
            Alert.alert("restored!")
        } else {
            Alert.alert("Nope")
        }
    }
}

What Happens

  • My subscription product successfully logs to console.
  • When I tap the button to trigger "handlePurchase()" in simulator I get an error "Error: Cannot Connect to iTunes Store." 1) Is this expected behavior or is it possible to login to a Sandbox account in simulator?
  • On my device, I followed these steps, then tapped "Purchase" and it showed me the correct price and asked for my username / pw to make the purchase. I think it asked a second time as well, then the dialog was simply dismissed (seemed like it worked??). My attempts to write the purchase receipt to the database were not successful. 2) Is this expected in test mode or should there be an actual receipt?
  • 3) Is there any way to login to Sandbox user account (or another way) to determine if purchase was in fact successful?
  • The result of my signing in via the IAP flow in my app was that my Sandbox account was now nicely populated at the bottom of iTunes & App Store settings screen on my device.
  • The restore purchase button does bring up "Sign into iTunes" in simulator, however tells me that my Apple ID / pw is incorrect. Tapping the restore purchases button on device does nothing at all. 4) Is this expected behavior or should we be able to test restore on either simulator or device?

Thanks!

timraybould avatar Jan 16 '19 20:01 timraybould

I have gotten it to work. The dialogues on the phone now confirm that the purchase was successful, and the database writes went through. (Suggestion for the docs: explain / show what success looks like)

I'm not sure which variable changed things, but, when it worked here are the 3 things that were different from the attempt above:

  1. Instead of my personal iPhone, I used an old iPhone 7 that's not signed into any iCloud account.
  2. Instead of going through TestFlight, I built the app directly to the device from Xcode.
  3. I setup a new Sandbox user in App Store Connect (though, I have been doing this each new test anyway).

timraybould avatar Jan 16 '19 21:01 timraybould