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

Purchases.purchasePackage hangs in the try block or goes directly into the finally block without resolving/rejecting the promise

Open bilal1031 opened this issue 1 year ago • 7 comments

Describe the bug I encountered an issue with the subscription process. Initially, I purchased a subscription and subsequently canceled it. After a few minutes, I attempted to repurchase the subscription, having confirmed through the webhook that the CANCELLATION event had been triggered. The Apple subscription process proceeded as expected, and I received an alert indicating that the purchase was successful. However, the function call Purchases.purchasePackage, which is expected to either resolve or reject the promise, appears to hang instead.

When a finally block is included, the execution proceeds to that block, but the expected resolution or rejection of the promise does not occur. Additionally, if I comment out the finally block, the line log('json', purchaseResponse)) is never executed, indicating that the function is stalling at this point.

This behavior suggests that something is preventing the function from properly resolving or rejecting the promise after the purchase process.

  1. Environment
    1. Platform: iOS
    2. SDK version: "react-native-purchases": "^8.1.0"
    3. OS version: 15.8.3
    4. Xcode/Android Studio version: Using expo dev-build
    5. React Native version: 0.74.5
    6. SDK installation (CocoaPods + version or manual):Using expo dev-build
    7. How widespread is the issue. Percentage of devices affected. Currently testing on my own device before launching into production
  2. Debug logs that reproduce the issue
  3. Steps to reproduce, with a description of expected vs. actual behavior
  4. Other information (e.g. stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc.)

Additional context

const onPressSubscribe = async () => {
    try {

       log('notify', 'Product ID: ' + product_id)
        setLoading(true)

        const offer = offerings.find(
          (item) => item.product.identifier == product_id
        )
        const { customerInfo } = await Purchases.logIn(user_id)

        // after this function call it goes to finally block when I deal with apple subscription process
        const purchaseResponse = await Purchases.purchasePackage(offer)

        log('json', purchaseResponse)
        log('success', 'Subscription Purchased Successfully')
       
       // perform stuff to update user data
   
        setLoading(false)
      
    } catch (ex) {

        console.log('Error', e.message)
        setLoading(false)

    } finally {

        // Here I am trying to see if the customer info is updated but it return a json showing that
        // there is no subscription purchased
        console.log('Finally')
        const customerInfo = await Purchases.getCustomerInfo()
        console.log('customerInfo', customerInfo)
        setLoading(false)
    }
  }

bilal1031 avatar Sep 04 '24 09:09 bilal1031

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

RCGitBot avatar Sep 04 '24 09:09 RCGitBot

Same here

crico avatar Sep 05 '24 06:09 crico

@bilal1031 Do you get the logs from right before purchasePackage but not the ones after? Is it possible that offer is null or undefined, causing an exception at purchasePackage? And also, are you able to get the debug logs when you run that code?

mshmoustafa avatar Sep 06 '24 17:09 mshmoustafa

@bilal1031 Do you get the logs from right before purchasePackage but not the ones after? Is it possible that offer is null or undefined, causing an exception at purchasePackage? And also, are you able to get the debug logs when you run that code?

In my case, when I execute Purchases.purchasePackage, the native iOS payment system opens, and the whole process finishes with 'Ok', but it doesn't return control back to my app. Instead, the native iOS payment system reappears. On Android, it works perfectly. I'm using the same versions of the libraries as @bilal1031

crico avatar Sep 07 '24 09:09 crico

@bilal1031 Do you get the logs from right before purchasePackage but not the ones after? Is it possible that offer is null or undefined, causing an exception at purchasePackage? And also, are you able to get the debug logs when you run that code?

Yes, I get the logs from right before purchasePackage but not the ones after. I also reviewed the code and confirmed that the offer variable is never null or undefined, as the function throws an error in those cases. I also tested by passing a hardcoded package as a parameter. Additionally, the scenario described by @crico, is the exact behavior occurring on iOS and it aligns with what I'm experiencing. I am not able to get the debug logs as I am using the expo development-build on a physical device.

bilal1031 avatar Sep 07 '24 13:09 bilal1031

any news?

crico avatar Sep 17 '24 07:09 crico

Uhm, is anyone at RevenueCat aware that this issue is a real blocker for adoption? In our case, most of the time, the native purchase UI does not even appear. The call to purchasePackage just hangs. No UI appears, no promise rejection, nothing.

yolpsoftware avatar Oct 17 '24 22:10 yolpsoftware

Hi, I have raised this with the team and we will be looking into fixing this.

HaleyRevcat avatar Dec 12 '24 16:12 HaleyRevcat

Uhm, is anyone at RevenueCat aware that this issue is a real blocker for adoption? In our case, most of the time, the native purchase UI does not even appear. The call to purchasePackage just hangs. No UI appears, no promise rejection, nothing.

bro have you got the solution if yes tell me how you solved it i am facing same issue right now

jeneesh01 avatar Dec 28 '24 09:12 jeneesh01

Describe the bug I encountered an issue with the subscription process. Initially, I purchased a subscription and subsequently canceled it. After a few minutes, I attempted to repurchase the subscription, having confirmed through the webhook that the CANCELLATION event had been triggered. The Apple subscription process proceeded as expected, and I received an alert indicating that the purchase was successful. However, the function call Purchases.purchasePackage, which is expected to either resolve or reject the promise, appears to hang instead.

When a finally block is included, the execution proceeds to that block, but the expected resolution or rejection of the promise does not occur. Additionally, if I comment out the finally block, the line log('json', purchaseResponse)) is never executed, indicating that the function is stalling at this point.

This behavior suggests that something is preventing the function from properly resolving or rejecting the promise after the purchase process.

  1. Environment

    1. Platform: iOS
    2. SDK version: "react-native-purchases": "^8.1.0"
    3. OS version: 15.8.3
    4. Xcode/Android Studio version: Using expo dev-build
    5. React Native version: 0.74.5
    6. SDK installation (CocoaPods + version or manual):Using expo dev-build
    7. How widespread is the issue. Percentage of devices affected. Currently testing on my own device before launching into production
  2. Debug logs that reproduce the issue

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

  4. Other information (e.g. stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc.)

Additional context

const onPressSubscribe = async () => {
    try {

       log('notify', 'Product ID: ' + product_id)
        setLoading(true)

        const offer = offerings.find(
          (item) => item.product.identifier == product_id
        )
        const { customerInfo } = await Purchases.logIn(user_id)

        // after this function call it goes to finally block when I deal with apple subscription process
        const purchaseResponse = await Purchases.purchasePackage(offer)

        log('json', purchaseResponse)
        log('success', 'Subscription Purchased Successfully')
       
       // perform stuff to update user data
   
        setLoading(false)
      
    } catch (ex) {

        console.log('Error', e.message)
        setLoading(false)

    } finally {

        // Here I am trying to see if the customer info is updated but it return a json showing that
        // there is no subscription purchased
        console.log('Finally')
        const customerInfo = await Purchases.getCustomerInfo()
        console.log('customerInfo', customerInfo)
        setLoading(false)
    }
  }

if you got the solution tell me how you solved it as i am facing same issue as yours

jeneesh01 avatar Dec 28 '24 09:12 jeneesh01

Hi @jeneesh01 apologies for the delay here. We were auditing our tickets and found this issue was never resolved. For this issue with purchasePackage, can you confirm what you are passing to this method? You should be passing a PurchasesPackage to this: https://github.com/RevenueCat/react-native-purchases/blob/29a99f7b4606f160be6c8ec2c730c8b3f5fe6ba7/src/purchases.ts#L549C2-L584C4

HaleyRevcat avatar Mar 17 '25 19:03 HaleyRevcat

Hi @HaleyRevcat. Thank you for reaching out. I don’t remember the solution at the moment, but I was able to figure it out before, so you can close the issue.

bilal1031 avatar Mar 17 '25 23:03 bilal1031