RevenueCat / react-native-purchases

React Native in-app purchases and subscriptions made easy. Support for iOS and Android.
https://www.revenuecat.com
MIT License
691 stars 77 forks source link

Network Connection Lost Error During Subscription Renewal on Apple TV #1017

Open anyarik opened 1 week ago

anyarik commented 1 week ago

Describe the bug When I try on Apple TV to renew the subscription in the sandbox, I encounter a network error indicating "The network connection was lost". This issue only occurs when Apple requests for account password. If you attempt to renew the subscription immediately after the error, the subscription will go through successfully (provided that the Apple ID password input window was not displayed).

During the very first payment (with the payment history cleared for the account) in the sandbox, the subscription process goes through successfully.

The bug occurs in the following code block used for subscription:

const handleBuySubscription = async (product) => {
  try {
    setLoading(true);
    const { customerInfo } = await Purchases.purchasePackage(product);
    if (typeof customerInfo.entitlements.active[subscriptionSkus] !== "undefined") {
      setIsOwned(true);
      setCurentActiveSubscription(customerInfo.entitlements.active[subscriptionSkus]);
    }
    setLoading(false);
  } catch (error) {
    Alert.alert(i18n.t('subscriptionProcessingError'), error.message, [
      { text: i18n.t('close'), style: 'cancel' },
    ]);
    console.log('Subscription processing error:', error)
  } 
  finally {
    setLoading(false);
  }
};
  1. Environment

    1. Platform: tvOS
    2. SDK version:7.27.3
    3. OS version:17.5.1
    4. Xcode/Android Studio version:15.1
    5. React Native version:npm:react-native-tvos@0.73.6-1
    6. SDK installation (CocoaPods + version or manual):
    7. How widespread is the issue. Percentage of devices affected.
  2. Debug logs that reproduce the issue <SKPaymentQueue: 0x30084f520>: Payment completed with error: Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={NSErrorFailingURLStringKey=https://sandbox.itunes.apple.com/WebObjects/MZFinance.woa/wa/com.apple.jingle.app.finance.DirectAction/accountSummary?hardwareModel=AppleTV14%2C1&os=tvOS&applicationUsername=140&offerName=com.flixsnip.month&clientCorrelationKey=65D27514-1F0B-4BFE-9291-30037036C918&guid=00008110-00061CA01A81401E&quantity=1&hardwareFamily=AppleTV&xToken=BgIAAAEBFAACmgUAAAAAZmlURXSwn1RkOylNAtH2ljr0x%2Bi8fVHD&vid=65EC9846-23E6-4A9E-A7F6-FE3063789BBB&osBuildNumber=21L580&osVersion=17.5.1&bvrs=4&generateBuyParams=true&bid=com.flixsnip.flixsnip&receipt-data=… DEBUG: ℹ️ StoreKit1Wrapper (0x0000000302e9edc0) updatedTransaction: com.flixsnip.month (The network connection was lost.) 2 ERROR: 😿‼️ A network error has occurred. The network connection was lost. INFO: 💰 Finishing transaction 'CB9DF6BD-3598-4FF8-84A6-A1F5D4E04233' for product 'com.flixsnip.month' ERROR: 💰 Product purchase for 'com.flixsnip.month' failed with error: Error Domain=RevenueCat.ErrorCode Code=10 "A network error has occurred. The network connection was lost." UserInfo={readable_error_code=NETWORK_ERROR, source_file=RevenueCat/PurchasesOrchestrator.swift:802, sourcefunction=handleFailedTransaction(:), NSLocalizedDescription=A network error has occurred. The network connection was lost., NSUnderlyingError=0x3044d8ea0 {Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={NSLocalizedDescription=The network connection was lost., NSUnderlyingError=0x3044c1fe0 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={_kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-4, NSErrorPeerAddressKey={length = 16, bytes = 0x100201bb1124cafe0000000000000000}}}}}} DEBUG: ℹ️ StoreKit1Wrapper (0x0000000302e9edc0) removedTransaction: com.flixsnip.month (The network connection was lost.) ["NSUnderlyingError": Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={_kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-4, NSErrorPeerAddressKey={length = 16, bytes = 0x100201bb1124cafe0000000000000000}}, "NSLocalizedDescription": The network connection was lost.] 2 'Subscription processing error:', [Error: A network error has occurred. The network connection was lost.]

  3. Steps to reproduce, with a description of expected vs. actual behavior

Expected behavior The app should allow users to renew their subscription without any network errors.

Actual behavior The app throws a network error when users try to renew their subscription after cancellation.

  1. Other information (e.g. stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc.) Attaching a video demonstrating the error occurrence.

https://github.com/RevenueCat/react-native-purchases/assets/5025252/cbee40a0-6cab-41b2-a0dd-55af4242cf4a

Additional context

RCGitBot commented 1 week ago

👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!

rglanz-rc commented 1 week ago

Hi @anyarik, I'll have our SDK team look into this. In the meantime, can you confirm this happens with a fresh test user? Sometimes older test users with lots of transactions on their receipt can cause this network behavior in sandbox.