j3k0 / cordova-plugin-purchase

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

[Ionic v7 | Capacitor v5] This Plugin v13 is not working with Capacitor #1438

Closed Iamarslansaleem closed 9 months ago

Iamarslansaleem commented 1 year ago

Observed behavior

Include logs with store.verbosity = store.DEBUG

I can't provide the logs because It's not triggering it in Capacitor.

### Expected behavior

should work the same as version 13 working with Cordova.

### System Info

Output of project info.

Ionic:

Ionic CLI : 7.1.1 (/usr/local/lib/node_modules/@ionic/cli) Ionic Framework : @ionic/angular 7.1.2 @angular-devkit/build-angular : 16.1.4 @angular-devkit/schematics : 16.1.4 @angular/cli : 16.1.4 @ionic/angular-toolkit : 9.0.0

Capacitor:

Capacitor CLI : 5.1.1 @capacitor/android : 5.1.1 @capacitor/core : 5.1.1 @capacitor/ios : 5.1.1

Utility:

cordova-res : 0.15.4 native-run : 1.7.2

System:

NodeJS : v18.16.0 (/usr/local/bin/node) npm : 9.7.2 OS : macOS Unknown

NOTE: Plugin version 13 is not triggering or not even responding with Capacitor. But version 11 works with Capacitor. Looking for help using In-App Purchase v13 with Capacitor v5. thanks!

you can see my implementation in the screenshot: image

Iamarslansaleem commented 1 year ago

Hi @j3k0, can you please help me out here real quick?

v-trishyn commented 1 year ago

Nothing could be seen in the implementation. So are you certain that you have installed v13? Also maybe you need to remove @awesome-cordova-plugins/in-app-purchase-2 completely - v13 has been implemented in TS and has bundled js file, I'm not sure how @awesome-cordova-plugins/in-app-purchase-2 is working with this plugin, maybe it is intercepting current pure workflow. Have you seen a message within the console Create CdvPurchase...?

j3k0 commented 1 year ago

@Iamarslansaleem Have you solved this?

uKioops commented 1 year ago

I am using capacitor v5 (with Ionic v6, but prob the same for v7) for an iOS and Android app. It is working with plugin purchase v13 but the implementation needs a little modification, I found it here but it might help.

Clearly the old InAppPurcharse2 does not work, so it needs to be removed.

Import

import 'cordova-plugin-purchase'; import 'cordova-plugin-purchase/www/store.d';

Init :

this.plt.ready().then(() => {
      const store: CdvPurchase.Store = new window.CdvPurchase.Store(); 
});

I did a function to register everything and I call it when I need it. My code might not be perfect but it seems to work.

registerFunction() {
    const { store, ProductType, Platform, AppleAppStore } = CdvPurchase;
    // if you use iaptic server side validation
    const iaptic = new CdvPurchase.Iaptic({
      appName: "yourappname",
      apiKey: "yourapikey",
    });

    store.validator = iaptic.validator;
    store.verbosity = 4; //to debug
    store.register([
      {
        id: yourSubId,
        type: CdvPurchase.ProductType.PAID_SUBSCRIPTION,
        platform: Platform.APPLE_APPSTORE,

      },
      {
        id: yourSubId,
        type: CdvPurchase.ProductType.PAID_SUBSCRIPTION,

        platform: Platform.GOOGLE_PLAY,
      },

       {
      id: 'test-subscription',
      type: CdvPurchase.ProductType.PAID_SUBSCRIPTION,
      platform: Platform.TEST
       }

    ]);

      if (this.plt.is('ios')) {
        console.log('init apple');
        store.initialize([{ platform: Platform.APPLE_APPSTORE }]);
      } else if (this.plt.is('android')) {
        console.log('init google');
        store.initialize([{ platform: Platform.GOOGLE_PLAY }]);
      } else {
        console.log('not mobile');
        store.initialize([{platform: Platform.TEST}])
      }
    }

    store.when()
    .productUpdated(product => {
      console.log('Update product')
      console.log(product)

    })
    .approved(transaction => {
      console.log('transaction happening');

      const monitor = store.monitor(transaction, state => {
        console.log('new State: ' + state);
        if (state === 'finished') {
          console.log(transaction.state)
          monitor.stop();
        }
      })
      console.log('transaction verify trigger')
      console.log(transaction.verify)
      transaction.verify()
    })
    .verified(receipt => {
      console.log('receipt Verified')
      console.log(receipt)
      console.log('receipt native transaction log')
      console.log(receipt.nativeTransactions)
      receipt.finish()
    })
    .unverified(receipt => {
      console.log('unverified payload')
      console.log(receipt.payload);
      console.log('unverified receipt')
      console.log(receipt.receipt);
    })
    .receiptUpdated((receipt) => {
      console.log('Receipt Update')
      console.log(receipt)
    });

  }