adaptyteam / AdaptySDK-React-Native

React Native SDK for growing in-app subscriptions
https://docs.adapty.io/docs/quickstart
MIT License
122 stars 12 forks source link

Calling adapty.identify(id) inserts last purchase record #108

Open Ahmed-Aljasim opened 6 months ago

Ahmed-Aljasim commented 6 months ago

Description

I have been testing and doing a lot of purchases before I got to this point.

The product I created is of type consumable both on Adapty console and App Store (not sure if it should match or not, and cannot know how it is different from lifetime type which is not an option in App Store but that is a different question..).

I am testing on internal distribution build using two sandbox test accounts. I cleared purchase history from both accounts in App Store.

I also deleted all previous profiles: DELETE https://api.adapty.io/api/v1/sdk/profiles/{id}/delete

And confirmed profiles are deleted from Adapty event feed page and from the API: GET https://api.adapty.io/api/v1/sdk/profiles/{id}/

Response body:

{
    "errors": [
        {
            "detail": "User profile not found.",
            "status": "404",
            "source": {
                "pointer": "/data"
            },
            "code": "not_found"
        }
    ]
}

So now we should have two virgin testAccount1 and testAccount2 and no profiles stored in Adapty. I will be using: testAccount1 with customerUserId1 testAccount2 with customerUserId2

Starting with testAccount1: Calling adapty.identify(customerUserId1) in my app creates new profile with no purchase record. Then, I make a purchase and I could see a new record for that purchase as expected.

Now, I close the app and go to iOS Settings > App Store > Sandbox Accounts and sign into testAccount2 account. Reopen the app and then call adapty.identify(customerUserId2) which creates new profile but with a purchase record! There should be no purchase record.

Here is customerUserId1 and customerUserId2 profiles comparison:

{
    "data": {
        "app_id": "..", // same
        "profile_id": "..", // different
        "customer_user_id": "..", // different
        "total_revenue_usd": 0.0, // same
        "segment_hash": "..", // same
        "paid_access_levels": null, // same
        "subscriptions": null, // same
        "non_subscriptions": {
            "productName": [ // same
                {
                    "purchase_id": "..", // different
                    "purchased_at": "..", // same
                    "vendor_product_id": "..", // same
                    "vendor_transaction_id": "..", // same
                    "vendor_original_transaction_id": "..", // same
                    "store": "app_store", // same
                    "is_one_time": true, // same
                    "is_consumable": true, // same
                    "is_sandbox": true, // same
                    "is_refund": false // same
                }
            ]
        },
        "custom_attributes": {}, // same
        "promotional_offer_eligibility": false, // same
        "introductory_offer_eligibility": true // same
    }
}

paywall.js:

useMemo(() => {
    (async () => {
      try {
         await adapty.logout();
         await adapty.identify({id});
      } catch (err) {
          console.log("err:", err);
      }
  })();
}, []);

app.js:

useEffect(() => {
    (async () => {
      try {
          await adapty.activate(PublicSDKkey);
      } catch (err) {
          console.log("err:", err);
      }
  })();
}, []);

I am using Expo 50 SDK managed workflow with EAS service. I am testing this on iPhone 13 mini iOS 17.3.

Version

v2.7.0

What platforms are you seeing the problem on?

iOS

System info

System:
  OS: Windows 10 10.0.19045
  CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  Memory: 5.77 GB / 15.88 GB
Binaries:
  Node:
    version: 20.10.0
    path: C:\Program Files\nodejs\node.EXE
  Yarn:
    version: 1.22.17
    path: ~\AppData\Roaming\npm\yarn.CMD
  npm:
    version: 10.2.3
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK: Not Found
IDEs:
  Android Studio: Not Found
  Visual Studio: Not Found
Languages:
  Java: Not Found
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.73.4
    wanted: 0.73.4
  react-native-windows: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found