Home Game Development in app buy – unity IAP scripting not initialized on android

in app buy – unity IAP scripting not initialized on android

0
in app buy – unity IAP scripting not initialized on android

[ad_1]

I’m attempting so as to add a In App Purchase in unity for android however once I push the button that launch the code I get this error: PurchaseProductID FAIL. Not initialized.

There is not any extra error on logcat console. I’ve a closed take a look at printed on play console and set on IAP unity service.

the method get the InitializePurchasing methodology however not the OnInitialized or OnInitializedFailed strategies.

right here is my code:

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing UnityEngine.Purchasing;
utilizing System;

public class IAPScript : MonoBehaviour, IStoreListener
{
public static IAPScript occasion;
non-public static IStoreController m_StoreController;         
non-public static IExtensionProvider m_StoreExtensionProvider; 


///  HERE THE STRINGS. NO CAPS

public static string buy50lifes = "50lifes";

void Start()
{
    // If we have not arrange the Unity Purchasing reference
    if (m_StoreController == null)
    {
        // Begin to configure our connection to Purchasing
        InitializePurchasing();
    }
}

non-public void Awake()
{
if (occasion == null)
{
  occasion = this;
}
else
{
  Destroy(this);
}
}

public void InitializePurchasing() 
{
    // If we now have already linked to Purchasing ...
    if (IsInitialized())
    {
        // ... we're achieved right here.
        return;
    }

    

    // Create a builder, first passing in a set of Unity supplied shops.
    var builder = ConfigurationBuilder.Instance(CustomaryPurchasingModule.Instance());

    // Add a product to promote / restore by means of its identifier, associating the final identifier
    // with its store-specific identifiers.
    builder.AddProduct(buy50lifes, ProductKind.Consumable);     /// PUT PRODUCTS HERE ««««««««««««««««
    // Continue including the non-consumable product.
    //builder.AddProduct(, ProductKind.NonConsumable);

    // Kick off the rest of the set-up with an asynchrounous name, passing the configuration 
    // and this class' occasion. Expect a response both in OnInitialized or OnInitializeFailed.
    UnityPurchasing.Initialize(this, builder);
}


public bool IsInitialized()
{
    // Only say we're initialized if each the Purchasing references are set.
    return m_StoreController != null && m_StoreExtensionProvider != null;
}


public void PurchaseConsumable() ///CREATE VOID FOR BUYING PRODUCTS««««««««««««««««
{
    PurchaseProductID(buy50lifes);
}

public String GetProducePriceFromStore(string id)
{
    if(m_StoreController!=null&& m_StoreController.merchandise!=null)
        return m_StoreController.merchandise.WithID(id).metadata.localizedPriceString;
    else 
        return "";
}


void PurchaseProductID(string productId)
{
    // If Purchasing has been initialized ...
    if (IsInitialized())
    {
        // ... lookup the Product reference with the final product identifier and the Purchasing 
        // system's merchandise assortment.
        Product product = m_StoreController.merchandise.WithID(productId);

        // If the lookup discovered a product for this system's retailer and that product is able to be bought ... 
        if (product != null && product.availableToPurchase)
        {
            Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
            // ... purchase the product. Expect a response both by Course ofPurchase or OnPurchaseFailed 
            // asynchronously.
            m_StoreController.InitiatePurchase(product);
        }
        // Otherwise ...
        else
        {
            // ... report the product look-up failure scenario  
            Debug.Log("PurchaseProductID: FAIL. Not buying product, both shouldn't be discovered or shouldn't be obtainable for buy");
        }
    }
    // Otherwise ...
    else
    {
        // ... report the very fact Purchasing has not succeeded initializing but. Consider ready longer or 
        // retrying initiailization.
        Debug.Log("PurchaseProductID FAIL. Not initialized.");
    }
}


// Restore purchases beforehand made by this buyer. Some platforms robotically restore purchases, like Google. 
// Apple presently requires specific buy restoration for IAP, conditionally displaying a password immediate.
public void RestorePurchases()
{
    // If Purchasing has not but been arrange ...
    if (!IsInitialized())
    {
        // ... report the scenario and cease restoring. Consider both ready longer, or retrying initialization.
        Debug.Log("RestorePurchases FAIL. Not initialized.");
        return;
    }

    // If we're operating on an Apple system ... 
    if (Application.platform == RuntimePlatform.IPhonePlayer || 
        Application.platform == RuntimePlatform.OSXPlayer)
    {
        // ... start restoring purchases
        Debug.Log("RestorePurchases began ...");

        // Fetch the Apple store-specific subsystem.
        var apple = m_StoreExtensionProvider.GetExtension<IAppleExtensions>();
        // Begin the asynchronous technique of restoring purchases. Expect a affirmation response in 
        // the Action<bool> under, and Course ofPurchase if there are beforehand bought merchandise to revive.
        apple.RestoreTransactions((outcome) => {
            // The first part of restoration. If no extra responses are acquired on Course ofPurchase then 
            // no purchases can be found to be restored.
            Debug.Log("RestorePurchases persevering with: " + outcome + ". If no additional messages, no purchases obtainable to revive.");
        });
    }
    // Otherwise ...
    else
    {
        // We are usually not operating on an Apple system. No work is critical to revive purchases.
        Debug.Log("RestorePurchases FAIL. Not supported on this platform. Current = " + Application.platform);
    }
}


//  
// --- IStoreListener
//

public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
    // Purchasing has succeeded initializing. Collect our Purchasing references.
    Debug.Log("OnInitialized: PASS");

    // Overall Purchasing system, configured with merchandise for this software.
    m_StoreController = controller;
    // Store particular subsystem, for accessing device-specific retailer options.
    m_StoreExtensionProvider = extensions;
}


public void OnInitializeFailed(InitializationFailureReason error)
{
    // Purchasing set-up has not succeeded. Check error for cause. Consider sharing this cause with the consumer.
    Debug.Log("OnInitializeFailed InitializationFailureReason:" + error);
}


public PurchaseProcessingResult Course ofPurchase(PurchaseEventArgs args) 
{
// A consumable product has been bought by this consumer.
if (String.Equals(args.boughtProduct.definition.id, buy50lifes, StringComparability.Ordinal))                                 ///PRODUCTS««««««««««««««««
{
    Debug.Log(string.Format("Course ofPurchase: PASS. Product: '{0}'", args.boughtProduct.definition.id));


}
else
{
    Debug.Log(string.Format("Course ofPurchase: FAIL. Unrecognized product: '{0}'", args.boughtProduct.definition.id));
}

    // Return a flag indicating whether or not this product has utterly been acquired, or if the appliance wants 
    // to be reminded of this buy at subsequent app launch. Use PurchaseProcessingResult.Pending when nonetheless 
    // saving bought merchandise to the cloud, and when that save is delayed. 
    return PurchaseProcessingResult.Complete;
}


public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
{
    // A product buy try didn't succeed. Check failureReason for extra element. Consider sharing 
    // this cause with the consumer to information their troubleshooting actions.
    Debug.Log(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason));
}
}

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here