react-native-purchases
                                
                                 react-native-purchases copied to clipboard
                                
                                    react-native-purchases copied to clipboard
                            
                            
                            
                        purchasePackage Successful When Nothing Purchased
- [x] I have updated Purchases SDK to the latest version
- [x] I have read the Contribution Guidelines
- [x] I have searched the Community
- [x] I have read docs.revenuecat.com
- [x] I have searched for existing Github issues
Describe the bug
I've noticed behavior with Purchases.purchasePackage that if a user already has a plan and say clicks on another plan through the app to upgrade, it will not open the native in-app purchase payments box and simply return the existing purchasePackage.
Hi @enchorb! Thanks for reporting. A couple of questions so we can try to figure out what's going on:
- What SDK version are you using?
- Is this on iOS or Android?
- Could you share a code snippet for how you're calling purchasePackage?
Also, note that for Android, when upgrading you need to pass in the UpgradeInfo. Docs on it here
Hi,
Using the latest version (4.6.0), platform is iOS (haven't tested on Android), and the code snippet is below:
<Button
          w={'80%'}
          maxW={500}
          isDisabled={isEmpty(plan) || anotherPlatform}
          isLoadingText={`${t(TRANSLATE('text.subscribing'))}...`}
          onPress={async () => {
            const purchase =
              Platform.OS === 'android' && !!activePlans[0]?.productIdentifier
                ? await 
                    Purchases.purchasePackage(plan, {
                      oldSKU: activePlans[0].productIdentifier,
                      prorationMode: PRORATION_MODE.IMMEDIATE_WITH_TIME_PRORATION
                    }
                  )
                : await Purchases.purchasePackage(plan);
            // On Purchase Success
            if (!isEmpty(purchase)) {
              await Purchases.syncPurchases();
              const info = await Purchases.getPurchaserInfo();
              if (!isEmpty(info)) onPurchaseStateChanged(info);
              displaySnackbar('purchase/succeeded');
              return navigateBack(navigation);
            }
          }}
@enchorb Thanks for getting back to me!
🤔 Could you share the logs for the app? They should bring us more information about what's going on. A couple of things that I noticed on your code in the meantime:
- there's no need to call syncPurchasesafter the purchase has been made, the purchase will already be synced whenpurchasePackagefinishes.
- the return value of purchasePackageis:
MakePurchaseResult = { productIdentifier: string; purchaserInfo: PurchaserInfo; };
So it includes the purchaserInfo already, no need to call getPurchaserInfo afterwards.
- purchasePackagecan throw, perhaps an error is being thrown and isn't getting handled?
Hi,
I changed my code based on those changes. However after further testing this is also occurring even when the user doesn't have any existing subscription, compare the response when the purchasePackage is successful but nothing was actually purchased vs when something actually was
False Positive
 {
  "firstSeenMillis": 1657049132000,
  "requestDate": "2022-07-05T21:35:35Z",
  "entitlements": {
    "all": { HIDDEN },
    "active": {}
  },
  "latestExpirationDateMillis": 1657053256000,
  "originalPurchaseDate": "2013-08-01T07:00:00Z",
  "nonSubscriptionTransactions": [],
  "managementURL": null,
  "latestExpirationDate": "2022-07-05T20:34:16Z",
  "originalPurchaseDateMillis": 1375340400000,
  "requestDateMillis": 1657056935000,
  "activeSubscriptions": [],
  "originalApplicationVersion": "1.0",
  "originalAppUserId": "b317c421-aeec-42d2-bcb1-c4d207853929",
  "firstSeen": "2022-07-05T19:25:32Z"
}
Actual
{
  "firstSeenMillis": 1657049132000,
  "requestDate": "2022-07-05T21:38:13Z",
  "entitlements": {
    "all": { HIDDEN },
    "active": {
      "test_v0": {
        "latestPurchaseDate": "2022-07-05T21:38:05Z",
        "latestPurchaseDateMillis": 1657057085000,
        "isSandbox": true,
        "originalPurchaseDate": "2022-07-01T03:36:43Z",
        "expirationDate": "2022-07-05T21:43:05Z",
        "expirationDateMillis": 1657057385000,
        "billingIssueDetectedAt": null,
        "unsubscribeDetectedAtMillis": null,
        "identifier": "test_v0",
        "periodType": "NORMAL",
        "unsubscribeDetectedAt": null,
        "store": "APP_STORE",
        "isActive": true,
        "willRenew": true,
        "ownershipType": "PURCHASED",
        "originalPurchaseDateMillis": 1656646603000,
        "productIdentifier": "test_v0_monthly",
        "billingIssueDetectedAtMillis": null
      }
    }
  },
  "latestExpirationDateMillis": 1657057385000,
  "originalPurchaseDate": "2013-08-01T07:00:00Z",
  "nonSubscriptionTransactions": [],
  "managementURL": "https://apps.apple.com/account/subscriptions",
  "latestExpirationDate": "2022-07-05T21:43:05Z",
  "originalPurchaseDateMillis": 1375340400000,
  "requestDateMillis": 1657057093000,
  "activeSubscriptions": [
    "test_v0_monthly"
  ],
  "originalApplicationVersion": "1.0",
  "originalAppUserId": "b317c421-aeec-42d2-bcb1-c4d207853929",
  "firstSeen": "2022-07-05T19:25:32Z"
}
🤔 Any chance that your app is keeping a cached purchaserInfo somewhere? I've been digging around the code and I can't see any path that would lead to this otherwise.
If not, could you share the debug logs? They might help us understand what's happening.
@enchorb were to able to make any progress here? I've been trying to reproduce without any luck. Does it consistently reproduce for you? Which iOS version are you running?
This issue has been automatically marked as stale due to inactivity. It will be closed if no further activity occurs. Please reach out if you have additional information to help us investigate further!
This happened to me on iOS.
It turns out that my sandbox account wasn't the one that I registered in App Store Connect. Once I signed out of the current sandbox account and into the Sandbox Tester account I had registered in App Store Connect, then everything worked as expected again.
Hope this helps.