AlexDisler / cordova-plugin-inapppurchase

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

item added you already own this item #34

Open justintseng opened 8 years ago

justintseng commented 8 years ago

When i pay for a product in google play by use a redeem code at last step it show a dialogue:item added then i click the button OK it show a dialogue:you already own this item failed to purchase

can you help me?

Your code / steps to reproduce

inAppPurchase
      .buy('xxxx')
      .then(function (data) {
        console.log(data);
        donePaid('xxxx',good_price);
        // ...then mark it as consumed:
        return inAppPurchase.consume(data.productType, data.receipt, data.signature);
      })
      .then(function () {
        console.log('product was successfully consumed!');
      })
      .catch(function (err) {
        console.log(err);
        if(device.platform == 'iOS'){
            var errorText = err.errorMessage;
        }else{
            var errorText = err.message;
        }
        myApp.addNotification({
           title:' ( ´・◡・`)',
           message: errorText,
        });
      });

Console output

user cancled

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

managed in google play

Version of cordova

6,2.0

Version of iOS/Android

android 5.1.1

Dalimil commented 7 years ago

I'm having the exact same issue. The item is purchased but the success callback is never received... Does anyone know if this is specific to the 'redeem code' payment method?

webster76 commented 7 years ago

Same problem here. Success callback is never called. Will test it with another payment method now.

Update: This does not seem to be a plugin-related error. See this article in the google play help forum for more information. The issue is the same, but it seems to be a native app where the problem occurs.

Update 2: Using another payment method (e.g. paypal) works as expected, no errors here.

Update 3: After paying the product one time with a payment method that is not promo code, the promo code also seems to work fine. (???) Can anyone reproduce this?

Update 4: It is not required to purchase the product with another payment method. The important step is to ADD this payment method to your account. After doing this, i was able to "pay" with the code without problems.

PrithiviRajG commented 7 years ago

@webster76 I am also facing this issue only for redeem code. even though the product is purchased at the back end with promo code, I am getting error message like "you already own this item" and it goes to catch block.

Following link also discuss the same issue but I am not able to fine any solution

https://productforums.google.com/forum/#!topic/play/khtOt2SSlf4;context-place=forum/play

webster76 commented 7 years ago

I found a possible workaround. It's not very elegant but it works, the only thing we can not influence are the falsy pop ups from the play store. BUT, if the user confirms these messages, the promise is rejected with error code -5 (cancelled). So in the .catch callback we have to check the error code and then immediately try to restore recently purchased product. In the response callback, we can find the product the customer purchased recently and do whatever has to be done. Long story short:

inAppPurchase.buy(productId)
    .then(function (response) {
        // never called in our case
    })
    .catch(function (err) {
        // cancelled, perhaps our strange error?
        if (err.code == -5)
        {
            // try to find recently purchased productId
            inAppPurchase.restorePurchases()
                .then(function (purchases) {
                    // find productId in purchases
                    // do your stuff
                })
        }

    });
PrithiviRajG commented 7 years ago

@webster76 Thank you. But Google will throw the dialogue box you already own this item before we can handle the response.

webster76 commented 7 years ago

@PrithiviRajG That's right, but the purchase is done nonetheless. Have you tried to add a payment method to your google account? You do not really need it, but in my case, the error did not occur anymore after adding a payment method (e.g. paypal) to my account. btw: I created a google support ticket with a description of the problem and will report if there are any updates on this problem.

webster76 commented 7 years ago

This is the reply to my ticket from the google support:

[...] Please note, if you do not have any payment methods defined in your in your payment methods, our system will not be able to properly test your in-app purchase. The error message you're receiving is due to the fact that payment methods must be defined in order to test your in-app subscriptions.

You may want to consider some of the following information regarding your in-app tests:

You can review the following resources for more information about upgrading your app to use the In-app Billing Version 3 API: https://support.google.com/googleplay/android-developer/answer/6090268 http://developer.android.com/google/play/billing/api.html

Long story short: it's a bug and will not be fixed, or am I missing something? That's not very satisfactory.