AlexDisler / cordova-plugin-inapppurchase

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

Data aways come blank #140

Open jersobh opened 7 years ago

jersobh commented 7 years ago

Please, I've seen many people talking about many different ways to implement this. I'm only using for android, so as I saw many doing, I don't need the getRecipt method, right?

This is my code: `checkSubscription () { var self = this inAppPurchase.getProducts(self.productIds) .then(function (products) { self.products = products; }) .catch(function (err) { console.log(err); });

  inAppPurchase.restorePurchases()
  .then(function (data) {
    for(var i = 0; i <= data.length; i++)
    if(data[i]["state"] == 0){
      self.subscription = true
    }
    else {
      Dialog.create({
        title: 'Assinatura',
        message: 'Você deve ser assinante para utilizar o app',
        buttons: [
          'Cancelar',
          {
            label: 'Assinar',
            handler () {
              self.subscribe()
            }
          }
        ]
      })
    }
  })
  .catch(function (err) {
    Dialog.create({
      title: 'Oops',
      message: 'Erro: '+ err,
      buttons: [
        'Ok'
      ]
    })
  });

},`

1st: I only have one product (the subscription). Do I need to use "getProducts"? 2nd: data[i]["state"] was data[i].state before. But it comes blank.

The app in published as alpha, the key is on the manifest.json (the purchase function WORKS). Please, I just need to check if the user is a subscriber.

jersobh commented 7 years ago

Current code: inAppPurchase.restorePurchases() .then(function (purchases) { if (purchases.length > 0){ for (let purchase of purchases) { if(purchase.productId == 'assinatura' && purchase.state == 0){ console.log('assinante') self.subscription = true } else { Dialog.create({ title: 'Assinatura', message: 'Sua assinatura não pode ser verificada', buttons: [ 'Cancelar', { label: 'Assinar', handler () { self.subscribe() } } ] }) } } }

jasonatt commented 7 years ago

Same here. Mentioned in #79