AlexDisler / cordova-plugin-inapppurchase

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

Restore Purchases returns empty array #79

Open patrickhofer opened 7 years ago

patrickhofer commented 7 years ago

The variable data always returns an empty array. With this code the inapp purchases are always restored. This should not be the case.

Can someone give me an example how I should implement inapp purchases with this plugin and ionic?


 var productIds = ["com.domain.app"]; // I have the correct ID here

$scope.restore = function (productId) {
    $ionicLoading.show({ template: spinner + 'Restoring Purchases...' });
    inAppPurchase
      .restorePurchases(productId)
      .then(function (data) {
          // data = []
          $ionicLoading.hide();
          localStorage.setItem('sold', 'true');
          save("isUnlocked", true);
          $state.go("12")
      })
      .catch(function (err) {
        $ionicLoading.hide();
        console.log(err);
        $ionicPopup.alert({
          title: 'Something went wrong',
          template: 'Check your console log for the error details'
        });
      });
  };
<div ng-hide="unlocked_s == 'true' || unlocked_e == 'true'" ng-hide="errorinapp === 'yes'" ng-repeat="product in products" ng-click="restore(product.productId)">
<img src="img/restore.png"  class="li" alt=""><h4 style="padding-top: 0.7vh">
Ripristina gli acquisti In-App <img src="img/arrow_map.png" alt="" style="vertical-align: middle" height="24px">
</h4>
</div>
caleb87 commented 7 years ago

Probably cause you're doing that on iOS, in which case you should use getReceipt(). The docs say you must call restorePurchases first, then getReceipt, although my code works fine just using getReceipt().

For Android you must use restorePurchases.

jasonatt commented 7 years ago

I am also getting this issue... Not sure its because I am on an alpha version but I am getting an empy array on Android... Purchases work fine and also .getProducts. Just checking that we can actually test restore purchases on android without publishing right?

Please include:

Your code / steps to reproduce

var productId = 'com.myapp.ads' inAppPurchase .restorePurchases(productId) .then(function (purchases) { console.log(purchases); / [{ transactionId: ... productId: ... state: ... date: ... }] / })

Console output

[find: function] length: 0 proto: Array[0]

Type of product you are working with consumable/non-consumable/subscription

non-consumable

Version of cordova

6.5

Version of iOS/Android

Android 6.0

jersobh commented 7 years ago

:( I'm only depending on this to release my app..

jasonatt commented 7 years ago

Same here buddy... @AlexDisler is it possible to have clarification on this issue? I tried purchasing not as a tester as well and data still returns blank. I also checked if I have the items in the orders list and there are so not sure what's the issue at this point as I tried looking at this issue outside the plugin because it could be an api issue but since not much users are complaining about it makes me wonder if my theory is right...

iwok commented 7 years ago

Same problem here, purchase works but restore returning an empty array. On iOS everything is working fine.

jersobh commented 7 years ago

Guys, I don't have a phone to test, but if you could get a logcat (adb) it would be something.

caleb87 commented 7 years ago

Been awhile since I messed with IAPs; forgive me if I'm wrong.

Google Play Store only provides Managed Products and Subscriptions. When a Managed Product is consumed, it's totally gone on Android. It will never show in Restore Purchases even with other IAP libraries. You can store the IAP data on your own server, and use the Play Store API to get information on it. Many games like Clash of Clans won't restore your purchase data either, so it's important customers link their account to Facebook/User System.

It sounds like you are consuming the product, even if unintentionally. I'd verify your code to ensure it's not consuming it. If it's not consumed, restore purchase will return so long as the authorization is correct.

Consumption is intended to work like: 1) Purchase 2) Send to your server to verify it and store it 3) Respond to the app as "successful verify", so it can then consume it. Now it's gone. If the user lost connection right as they did the purchase, it would never get consumed.

jersobh commented 7 years ago

Okay, but what about subscriptions? It should at least return the purchase code for verification. But data comes [ ]

caleb87 commented 7 years ago

Subscriptions will always return. Were you able to complete a subscription, but cannot restore it?

If it's not, I'd question if your purchase is actually completing. Are you getting a transaction number?

jersobh commented 7 years ago

The only thing that comes as response is "[ ]" on a subscription. A blank array.

caleb87 commented 7 years ago

jersobh, you get a blank array on restorePurchases, but do you get the blank array for the purchase itself?

If the purchase is a blank array, the permissions on the Play Store in-app-purchase are probably configured wrong. For example, the IAP is not live.

If the purchase returns, and the restore purchase is blank, then this is strange. As I said, confirm that the purchase transaction is actually returning a transaction ID. Do you have a full object for this that you can paste? Can exclude app details.

jasonatt commented 7 years ago

@caleb87 the purchase returns, and the restore purchase is blank for me too. I have tested this over and over with actual paid and testing ids and I saw this issue in various other comments as ref above.

I do get a full array on purchase but on restore I get []. My code is the same as @jersobh with the difference that I use Managed Purchases. I fail to believe that I have to host this from my side as the user has the purchase data on their account which stays in the history and this is what the array should return.

Something is wrong with the restore call unless you have it working and can share some code?

olaferlandsen commented 7 years ago

for me is a empty array and i trying with android and ios :(

raiyanihiren commented 5 years ago

Hello, If you consume product then its never display in restore product. So you have to use just buy method, not use consume method, caused consumable product is always purchased new its never display in restore purchase. If you want to use one product for life time then that product known as non-consumable product and its will also display in restore purchase list.

Thanks