AlexDisler / cordova-plugin-inapppurchase

A lightweight cordova plugin for in app purchases on iOS/Android
316 stars 192 forks source link

Subscription doesn't work in Android #256

Open scrabionau77 opened 5 years ago

scrabionau77 commented 5 years ago

Hi to all! I've a problem with subscription on Android (i did not test Apple) my code: inAppPurchase.subscribe(productId) .then(function (data) { console.log('OK'); }) .catch(function (err) { console.log( 'Error:' + JSON.stringify(err) ); });

The then function is never invoked. Only the catch is invoked In console i get only "Error:{}", no error message appears!

i've 2 active subscriptions in my Google Play (not simple consumable/non-consumable products!) i've added manifest.json in www root with the right key

Note: The method inAppPurchase.getProducts works fine!

I successfully used this code in another app about a year ago. has something changed?

I'm using cordova 8.1.2 and cordova android 7.1.4. Plugin version: 1.1.0 Thanks in advance

scrabionau77 commented 5 years ago

Up! Can someone help me?

netse-ai commented 5 years ago

@scrabionau77 Can you post the full code? I have a different issue, what you are trying to do works for me. What I have an issue with is restorePurchases(). I can subscribe fine, with REAL subscriptions, not only test ones. The problem is I can't seem to restore the purchases... I just get "Error retrieving purchase details"...

firebiird commented 5 years ago

I have the exact same issue as this - After successful subscription I get the catch invoked and {} as the output.

This is my code :

async upgrade() {

        const x = this;

        const loadingModal = await this.loadingService.create();

        loadingModal.present();

        this.iap.getProducts(['premium'])
            .then(function (products) {
                x.iap
                    .subscribe('premium')
                    .then(async (data) => {

                        x.loadingService.dismiss();

                        if (this.platform.is('android')) {
                            console.log('This is android subscription data: ');
                            console.log(JSON.stringify(data));

                            const resp = await x.http.post(LifefyleHttpClient.SUBSCRIBE_ANDROID_URL, data);

                            resp.subscribe(() => {
                                SessionManagerService.setUserPlanType('Premium');
                                x.dismiss();
                            }, error1 => {
                                x.notificationService.pushAlert('Error', error1.error.message);
                            });

                        }

                        if (this.platform.is('ios')) {
                            const resp = await x.http.post(LifefyleHttpClient.SUBSCRIBE_IOS_URL, data);

                            resp.subscribe(() => {
                                SessionManagerService.setUserPlanType('Premium');
                                x.dismiss();
                            }, error1 => {
                                x.notificationService.pushAlert('Error', error1.error.message);
                            });
                        }

                    })
                    .catch((err) => {

                        x.loadingService.dismiss();
                        console.log('There was an error subscribing: ');
                        console.log(JSON.stringify(err));

                        if (err.errorMessage !== undefined) {
                            x.notificationService.pushAlert('Error', 'Something went wrong while trying to process your request. please try again later (' + err.errorMessage + ')');
                        }
                    });
            })
            .catch(function (err) {

                x.loadingService.dismiss();
                console.log('There was an error getting the products: ');
                console.log(err);
                x.notificationService.pushAlert('Error', 'Something went wrong while trying to process your request. please try again later (' + err + ')');
            });

    }

My Info is as follows:

Ionic:

   Ionic CLI                     : 5.0.2 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.4.2
   @angular-devkit/build-angular : 0.13.1
   @angular-devkit/schematics    : 7.1.4
   @angular/cli                  : 7.1.4
   @ionic/angular-toolkit        : 1.2.3

Cordova:

   Cordova CLI       : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms : android 8.0.0, browser 5.0.4, ios 4.5.5
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.2, (and 14 other plugins)

Utility:

   cordova-res : not installed
   native-run  : not installed

System:

   Android SDK Tools : 26.1.1 (/Users/leewilliams/Library/Android/sdk)
   ios-deploy        : 1.9.2
   ios-sim           : 5.1.0
   NodeJS            : v11.9.0 (/usr/local/bin/node)
   npm               : 6.9.0
   OS                : macOS Mojave
   Xcode             : Xcode 10.2.1 Build version 10E1001