Question

Experiencing a TCP timeout when calling purchasePackage method (Ionic / Capacitor)

  • 7 February 2024
  • 4 replies
  • 54 views

Badge

Hello,

I’m building an Ionic mobile app with the Capacitor plugin and testing payments for IOS and Android in sandbox mode. I have the Google Play store payment working properly in sandbox mode but with IOS I am having an issue with the purchasePackage method.

I am receiving offerings and packages properly, using the IOS key, but when I pass in a package into the purchasePackage method, a TCP timeout occurs. I assume this is because it is reaching out to an API and waiting for a response that it isn’t getting. How can we get past this or is this a known issue with developing with Ionic Capacitor and IOS payment subscriptions? I want to test this in a production environment but that would need Apple’s approval with broken authentication. Any guidance or input would be greatly appreciated 

Steps taken to debug: 

  1. Make sure IOS and Android keys are working properly
  2. Purposely passing broken data into purchasePackage to see what it returns
  3. Console logging and follow the trail of data until it reaches it to make sure data is intact upon method call 
  4. Testing with a physical Apple device with a sandbox user that is two factor authenticated
  5. Something to note is the restorePurchase function IS working within IOS and the sandbox user can be validated and go through the app fine
     

This is the first method that gets called when clicking the Purchase button the user clicks:

This leads to our next method purchaseSubscription where the timeout happens. 

Method where purchasePackage is being called: 

async purchaseSubscription(){
try {
console.log('CHECK IF PACKAGES IS NULL::::', this.packages[0])
const purchase = await Purchases.purchasePackage({aPackage: this.packages[0]}).catch(e => console.log('PURCHASE SUBSCRIPTION ERROR::',e));
console.log('WHAT PURCHASE HOLDS:::', JSON.stringify(purchase))
} catch (e) {
console.log(e)
return null
}
},

Debug console showing the TCP timeout after the purchasePackage method is being called:


 


4 replies

Userlevel 5
Badge +9

Hey @yonatan-leulseged-d01133,

It’s tough to which API request is timing out. I have some recommendations to help narrow it down:

  1. Are you able to access api.revenuecat.com and app.revenuecat.com from the device’s web browser?
  2. Are you able to hook up a JS console to the device to see the request logs? This guide is a little outdated but should help: https://developer.apple.com/library/archive/documentation/AppleApplications/Conceptual/Safari_Developer_Guide/GettingStarted/GettingStarted.html
  3. Are you able to run the app from Xcode to view the debug logs?
  4. And finally to eliminate issues with Apple’s API, can you try using StoreKitTest? This will mock Apple’s servers on your local computer but still make API requests to RevenueCat. 

Hey @sharif , I work on Yonatan’s team and can answer a few of these points:

  1. The devices we’re testing on are connected to the internet and are having no issues reaching the sites in the web browser
  2. We’ll definitely try this out, see if maybe we can get this going to see where the issues may be
  3. The devices were plugged into a Mac and these are screenshots from XCode’s debug logs. We’ve already tried our code on all of the different Log Level options in the SDK.
  4. I tried this method as well, but it seemed like your docs for this are a bit outdated with the latest UI version of XCode and I had trouble following along. Also, like I mentioned we were testing on real devices and the guide for StoreTestKits seemed like they were only necessary for running on emulators.

I appreciate the response, this aspect (specifically testing on the App Store) has been giving us trouble for a while and we’re not sure where to go from here. I’m fairly confident this is related to Apple’s API rather than RevenueCat’s, like Yonatan mentioned we didn’t seem to have any issues fetching the offerings or on the Play Store, and this is the point in the code’s execution that triggers the Play Store payment method (which seems to work perfectly fine), so I would assume this would be related to a timeout when RevenueCat is reaching out to the App Store API.

I’ve seen previous mentions that the App Store can take upwards of 15-30 seconds for payment requests to process, and we typically are getting this error within 6-8 seconds. Is there a way to maybe extend the request timeout length so that it doesn’t give up before it gets a response? At this point we’re pretty out of ideas on this, it seems like we have everything configured properly and the error we’re getting isn’t listed in any of RevenueCat’s error handling documentation.

Update: I hooked up the JS Console to the device on my Mac using Safari, and found a new error that was being thrown: DataCloneError: the object could not be cloned. After a quick google search, I was able to fix the error by declaring a new constant 

const clonedPackage = JSON.parse(JSON.stringify(package))

and the payment method succeeded! Figured I’d share in case anybody else was dealing with a similar issue.

Userlevel 5
Badge +9

I’m glad to hear it worked! We’ll get that guide updated. For your and future readers’ information, StoreKitTest can be used in the simulator as well as a real device. The catch is that on simulator, StoreKitTest is the only option you have to test purchases, while on device you can use StoreKitTest and Apple’s classic sandbox environment.

Reply