onepf / OpenIAB

Open In-App Billing for Google Play, SlideMe, Amazon Store, Nokia Store, Samsung Apps, Yandex.Store, Appland, Aptoide, AppMall and Fortumo.
http://onepf.org/openiab/
Apache License 2.0
474 stars 172 forks source link

Failed purchase error codes - Billing response codes instead of IAB Helper ? #460

Open aetiom opened 9 years ago

aetiom commented 9 years ago

Hello

It seems that error codes returned by purchaseFailedEvent, in unity plugin, is about IAB Helper error codes. How can i get "Billing response codes" instead of IAB Helper in unity?

IAB Helper error is not enough accurate for reach my goal. I would like to catch error like "ITEM_ALREADY_OWNED"

Regards,

RomanZhilich commented 9 years ago

I'm pretty sure you can get this error from IabResult:BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED = 7;

aetiom commented 9 years ago

I'm not sure that IAB result is directy accessible from purchaseFailedEvent in unity plugin. How can i access it?

Here my purchaseFaildeEvent function, that always retuns me an -1005 error code when item is already owned.

private void purchaseFailedEvent(int errorCode, string errorMessage) {

    // if sku has already been purchased (error code 7)
    if (errorCode == 7) {

        /* unconsumable SKU */

        if (_SKU_temp == SKU_NOADS) { SetNoAds(true, null); }
        else if (_SKU_temp == SKU_PREMIUM) { SetPremium (true, null); }

        /* consumable SKU */

        else if (consumable_skuNames.Contains(_SKU_temp)) {

            if (inventory.GetPurchase(_SKU_temp) != null) {
                OpenIAB.consumeProduct (inventory.GetPurchase(_SKU_temp));
                ShowMsg ("Consuming item");
            }

            else {
                ShowMsg ("Unable to find purchase entry. Retry later.");
            }

        }
    }

    else {
        ShowMsg ("Purchasing product error (" + errorCode + ")");
    }

    // clear vars
    _SKU_temp = null;

    Debug.LogError("purchaseFailedEvent: " + errorMessage);
}