简体   繁体   English

统一 IAP | 应用内购买 | 未知错误

[英]Unity IAP | In App Purchase | Unknown Error

I want to implement IAP in my android game.我想在我的 android 游戏中实现 IAP。

This is my code, it is from the official unity website:这是我的代码,来自Unity官方网站:

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.我正在使用消耗品pile_shadycoin。 In the picture you can see the id and that it's active (it's german)在图片中,您可以看到 id 并且它处于活动状态(它是德语)

Picture of Google Play 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:如果我构建我的项目并将其放在我的智能手机上并按下链接到 BuyConsumable() 的按钮,它会打开菜单并显示:

Fehler Der angeforderte Artikel kann nicht gekauft werden 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.我没有发布 alpha 或 beta 版本。

I pulled the APK directly to my phone.我把APK直接拉到我的手机上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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