简体   繁体   中英

Unity IAP | In App Purchase | Unknown Error

I want to implement IAP in my android game.

This is my code, it is from the official unity website:

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Purchasing;
using UnityEngine.UI;

public class Purchaser : MonoBehaviour, IStoreListener {
private static IStoreController m_StoreController;          // The Unity Purchasing system.
private static IExtensionProvider m_StoreExtensionProvider; // The store-specific Purchasing subsystems.

public Text text;

public static string kProductIDConsumable = "pile_shadycoin";

void Start() {
    if (m_StoreController == null) {
        InitializePurchasing();
    }
}

public void InitializePurchasing() {
    if (IsInitialized()) {
        return;
    }

    var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());

    builder.AddProduct(kProductIDConsumable, ProductType.Consumable);

    UnityPurchasing.Initialize(this, builder);
}


private bool IsInitialized() {
    return m_StoreController != null && m_StoreExtensionProvider != null;
}


public void BuyConsumable() {
    BuyProductID(kProductIDConsumable);
}

void BuyProductID(string productId) {
    if (IsInitialized()) {
        Product product = m_StoreController.products.WithID(productId);

        if (product != null && product.availableToPurchase) {
            text.text = "Purchasing product asychronously: '{0}'";
            m_StoreController.InitiatePurchase(product);
        } else {
            text.text = "BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase";
        }
    } else {
        text.text = "BuyProductID FAIL. Not initialized.";
    }
}

public void OnInitialized(IStoreController controller, IExtensionProvider extensions) {
    text.text = "OnInitialized: PASS";

    m_StoreController = controller;

    m_StoreExtensionProvider = extensions;
}


public void OnInitializeFailed(InitializationFailureReason error) {
    text.text = "OnInitializeFailed InitializationFailureReason:" + error;
}


public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args) {
    if (String.Equals(args.purchasedProduct.definition.id, kProductIDConsumable, StringComparison.Ordinal)) {
        text.text = "ProcessPurchase: PASS. Product: '{0}'";


    } else {
        text.text = "ProcessPurchase: FAIL. Unrecognized product: '{0}'";
    }
    return PurchaseProcessingResult.Complete;
}


public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason) {
    text.text = failureReason + "";
}
}

I am using the consumable item pile_shadycoin. In the picture you can see the id and that it's active (it's german)

Picture of Google Play

If I build my project and put it on my smartphone and press the button, which is linked to BuyConsumable() it opens the menu and says:

Fehler Der angeforderte Artikel kann nicht gekauft werden

In English:

Error The requested item cannot be purchased

I found my error. I didn't released the build on alpha or beta.

I pulled the APK directly to my phone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM