RevenueCat / purchases-capacitor

Capacitor in-app purchases and subscriptions made easy.
MIT License
151 stars 14 forks source link

Unable to serialize plugin response as JSON #33

Closed maxbarry closed 1 year ago

maxbarry commented 1 year ago

Thanks for the great plugin!

I frequently get the below errors logged in XCode on Mac when running on an iOS device - the plugin call seems to succeed, and I'm not sure how serious it is.

Possibly it occurs when the plugin returns undefined?

[Capacitor Plugin Error] - CapacitorPurchases - addListener - Unable to serialize plugin response as JSON.Ensure that all data passed to success callback from module method is JSON serializable!
[Capacitor Plugin Error] - CapacitorPurchases - logIn - Unable to serialize plugin response as JSON.Ensure that all data passed to success callback from module method is JSON serializable!
[Capacitor Plugin Error] - CapacitorPurchases - logOut - Unable to serialize plugin response as JSON.Ensure that all data passed to success callback from module method is JSON serializable!

From calls like this:

  await CapacitorPurchases.setup({
      apiKey: REVENUECAT_PUBLIC_API_KEY,
  })

  CapacitorPurchases.addListener("purchasesUpdate", ({ purchases, purchaserInfo }) => {
      console.log("Got updated purchaserInfo!", purchaserInfo)
  })

Incidentally, the plugin says I should supply appUserID to setup(), but the docs say it's optional.

[Purchases] - DEBUG: ℹ️ Configuring SDK using RevenueCat's UserDefaults suite.
[Purchases] - WARN: ⚠️ The appUserID is empty. This method should only be called with non-empty values.
[Purchases] - DEBUG: 👤 Identifying App User ID
[Purchases] - DEBUG: ℹ️ Debug logging enabled
[Purchases] - DEBUG: ℹ️ SDK Version - 4.16.0

─ @capacitor/app@4.1.1 ├─ @capacitor/cli@4.6.1 │ ├─ @ionic/cli-framework-output@^2.2.5 │ ├─ @ionic/utils-fs@^3.1.6 │ ├─ @ionic/utils-subprocess@^2.1.11 │ ├─ @ionic/utils-terminal@^2.3.3 │ ├─ commander@^9.3.0 │ ├─ debug@^4.3.4 │ ├─ env-paths@^2.2.0 │ ├─ kleur@^4.1.4 │ ├─ native-run@^1.6.0 │ ├─ open@^8.4.0 │ ├─ plist@^3.0.5 │ ├─ prompts@^2.4.2 │ ├─ rimraf@^3.0.2 │ ├─ semver@^7.3.7 │ ├─ semver@7.3.8 │ │ └─ lru-cache@^6.0.0 │ ├─ tar@^6.1.11 │ ├─ tslib@^2.4.0 │ └─ xml2js@^0.4.23 ├─ @capacitor/core@4.6.1 │ └─ tslib@^2.1.0 ├─ @capacitor/haptics@4.1.0 ├─ @capacitor/ios@4.6.1 ├─ @capacitor/keyboard@4.1.0 ├─ @capacitor/share@4.1.0 ├─ @capacitor/status-bar@4.1.1 ├─ @capgo/capacitor-purchases@1.3.42

riderx commented 1 year ago

Hello, thanks for the report ! i check your issue with serialization, i think i found a fix for it ! for the empty value i'm not sure in the SDK doc it say it's optional, i will look better

riderx commented 1 year ago

Ok i manage to fix the warning too, let me know if that fix all your issues

maxbarry commented 1 year ago

The warning about missing appUserID is gone, thank you.

I think the serialization warning is gone on logIn and logOut but I still see it on addListener:

2023-01-12 12:51:57.075405+1100 App[17542:1051242] [Purchases] - DEBUG: ℹ️ Sending latest CustomerInfo to delegate.
2023-01-12 12:51:57.075501+1100 App[17542:1051242] [Purchases] - DEBUG: 😻 CustomerInfo updated from network.
[Capacitor Plugin Error] - CapacitorPurchases - addListener - Unable to serialize plugin response as JSON.Ensure that all data passed to success callback from module method is JSON serializable!
⚡️  TO JS {}
2023-01-12 12:51:57.076425+1100 App[17542:1051242] [Purchases] - DEBUG: 😻 CustomerInfo updated from network.
2023-01-12 12:51:57.076491+1100 App[17542:1051242] [Purchases] - DEBUG: ℹ️ GetCustomerInfoOperation: Finished

├─ @capgo/capacitor-purchases@2.0.2

riderx commented 1 year ago

Thank you so much for the feedback you made me realize I could now use the official hybrid implementation and remove all my custom code, what I did in the plugin v2.

If you can upgrade and give it a try :)

maxbarry commented 1 year ago

Yes!! Success! No more warning about JSON serialization, and now I actually get a response object from addListener() when the user's purchase info changes, rather than undefined. Thank you so much!

└─ @capgo/capacitor-purchases@2.0.15

riderx commented 1 year ago

perfect 😍 

Maker of Capgo https://capgo.app/ Capacitor Live updates Podcast host at SOLOS https://solos.ventures/ Maker of Captime https://captime.app Crossfit timer app Mobile app Builder at Forgr https://forgr.ee/ 

On January 13, 2023, Martin DONADIEU @.***> wrote:

Yes!! Success! No more warning about JSON serialization, and now I actually get a response object from addListener() when the user's purchase info changes, rather than undefined. Thank you so much!

└─ @@.***

— Reply to this email directly, view it on GitHub https://github.com/Cap- go/capacitor-purchases/issues/33#issuecomment-1381212995, or unsubscribe https://github.com/notifications/unsubscribe- auth/AA7FGL3MRNSAAYS6RSHOGNLWSCYZTANCNFSM6AAAAAATWF4CNU. You are receiving this because you commented.Message ID: <Cap- @.***>