j3k0 / cordova-plugin-purchase

In-App Purchase for Cordova on iOS, Android and Windows
https://purchase.cordova.fovea.cc
1.3k stars 537 forks source link

Issue implement plugin replacement for IAP on Ionic Capacitor mobile app. #1604

Open dukec2020 opened 9 hours ago

dukec2020 commented 9 hours ago

Hi @j3k0 ,

I have an Ionic capacitor app that works with IAP, but due to an upgrade issue so, IAP doesn't work anymore. So I'm replacing IAP with this package and having this issue. Could you help me resolve it, in case need personal support I'm willing to send you an email

Observed behavior

Here is the implemented code.

app.component.ts

import 'cordova-plugin-purchase';
import "cordova-plugin-purchase/www/store.d"
...
constructor(){
...
 this.platform.ready().then(() => {
      this.iap = CdvPurchase.store
      this.iap.verbosity =  CdvPurchase.LogLevel.DEBUG
      this.iap.initialize([
        CdvPurchase.Platform.GOOGLE_PLAY,
        CdvPurchase.Platform.APPLE_APPSTORE,
      ]).then((value: CdvPurchase.IError[]): void => {
        alert('error initilization');
        // alert(JSON.stringify(value));
        console.log(value);
      });
...
}

Debug output on XCode

Loading network plugin
[CdvPurchase.AppleAppStore.objc] Initialized.
⚡️  Loading app at capacitor://localhost...
Reachable via WiFi
 - <AppMeasurement>[I-ACS025026] Deferring to Firebase for event data collection
To Native Cordova ->  Device getDeviceInfo Device1773120281 ⚡️  [log] - onscript loading complete
["options": []]
To Native Cordova ->  File requestAllPaths File1773120282 ["options": []]
⚡️  [log] - Create CdvPurchase...
⚡️  WebView loaded
⚡️  To Native ->  App addListener 109411414
⚡️  [error] - ERROR {"name":"NullInjectorError","ngTempTokenPath":null,"ngTokenPath":["Store","Store","Store"]}
⚡️  [log] - {"name":"NullInjectorError","ngTempTokenPath":null,"ngTokenPath":["Store","Store","Store"]}
⚡️  [log] - Create CdvPurchase...

And app screen blank on device

Expected behavior

No error output

System Info


   Ionic CLI                     : 7.2.0 (/Users/user/.nvm/versions/node/v16.20.2/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.6.11
   @angular-devkit/build-angular : 13.3.1
   @angular-devkit/schematics    : 13.1.4
   @angular/cli                  : 13.1.4
   @ionic/angular-toolkit        : 6.1.0

Capacitor:

   Capacitor CLI      : 3.9.0
   @capacitor/android : 5.0.5
   @capacitor/core    : 5.0.5
   @capacitor/ios     : 5.0.5

Cordova:

   Cordova CLI       : not installed
   Cordova Platforms : not available
   Cordova Plugins   : not available

Utility:

   cordova-res                          : not installed globally
   native-run (update available: 2.0.1) : 1.5.0

System:

   NodeJS : v16.20.2 (/Users/user/.nvm/versions/node/v16.20.2/bin/node)
   npm    : 8.19.4
   OS     : macOS Unknown
   Xcode  : Xcode 15.4 Build version 15F31d
j3k0 commented 8 hours ago

It's not clear what that error is. Is "platform.ready" triggered? From basic googling it looks like this NullInjectorError might be unrelated? (Store is a angular class too right?)

You are also not registering products and events handlers.

Feel free to reach out by email (cf https://github.com/j3k0)

dukec2020 commented 6 hours ago

Yes, I'm putting an initialized store on the platform.ready function (source code above) The source code in Angular