Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Iamarslansaleem opened this issue Jul 8, 2023 · 4 comments

Comments

@Iamarslansaleem
Copy link

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
Copy link
Author

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

@v-trishyn
Copy link

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
Copy link
Owner

j3k0 commented Jul 13, 2023

@Iamarslansaleem Have you solved this?

@uKioops
Copy link

uKioops commented Jul 19, 2023

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)
    });


  } 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants