src/ApprienUnitySDK/Assets/Apprien/Scripts/Apprien.cs
/// <summary>
/// <para>
/// Fetch all Apprien variant IAP ids with optimum prices.
/// </para>
/// <para>
/// Prices are located in the Apprien -generated IAP id variants. Typically
/// the actual prices are fetched from the Store (Google or Apple) by the
/// StoreManager by providing the IAP id (or in this case the variant).
/// </para>
/// </summary>
/// <param name="callback">Callback that is called when all product variant requests have completed.</param>
/// <returns>Returns an IEnumerator that can be forwarded manually or passed to StartCoroutine</returns>
Fetch all Apprien variant IAP ids with optimum prices.

Prices are located in the Apprien -generated IAP id variants. Typically
the actual prices are fetched from the Store (Google or Apple) by the
StoreManager by providing the IAP id (or in this case the variant).
Fetch all Apprien variant IAP ids with optimum prices . Prices are located in the Apprien - generated IAP id variants . Typically the actual prices are fetched from the Store ( Google or Apple ) by the StoreManager by providing the IAP id ( or in this case the variant ) .
public IEnumerator FetchApprienPrices(ApprienProduct[] apprienProducts, Action callback = null)
        {
            var requestSendTimestamp = DateTime.Now;
            var url = string.Format(ApprienUtility.REST_GET_ALL_PRICES_URL, StoreIdentifier, GamePackageName);
            using(var request = UnityWebRequest.Get(url))
            {
                request.SetRequestHeader("Authorization", "Bearer " + Token);
                request.SetRequestHeader("Session-Id", ApprienIdentifier);
                ApprienUtility.SendWebRequest(request);
                while (!request.isDone)
                {
                    if ((DateTime.Now - requestSendTimestamp).TotalSeconds > RequestTimeout)
                    {
                        if (callback != null)
                        {
                            callback();
                        }
                        yield break;
                    }
                    yield return null;
                }
                if (ApprienUtility.IsHttpError(request))
                {
                    SendError((int) request.responseCode, "Error occured while fetching Apprien prices: HTTP error: " + request.downloadHandler.text);
                }
                else if (ApprienUtility.IsNetworkError(request))
                {
                    SendError((int) request.responseCode, "Error occured while fetching Apprien prices: Network error");
                }
                else
                {
                    if (request.responseCode == 200)
                    {
                        try
                        {
                            var productLookup = new Dictionary<string, ApprienProduct>();
                            foreach (var product in apprienProducts)
                            {
                                productLookup[product.BaseIAPId] = product;
                            }
                            var json = request.downloadHandler.text;
                            var productList = JsonUtility.FromJson<ApprienProductList>(json);
                            foreach (var product in productList.products)
                            {
                                if (productLookup.ContainsKey(product.@base))
                                {
                                    productLookup[product.@base].ApprienVariantIAPId = product.variant;
                                }
                            }
                        }
                        catch { } 
                    }
                    else
                    {
                        SendError((int) request.responseCode, "Error occured while fetching Apprien prices. Error: " + request.downloadHandler.text);
                    }
                }
                if (callback != null)
                {
                    callback();
                }
            }
        }
public IEnumerator FetchApprienPrices ( ApprienProduct [ ] apprienProducts , Action callback = null ) { var requestSendTimestamp = DateTime . Now ; var url = string . Format ( ApprienUtility . REST_GET_ALL_PRICES_URL , StoreIdentifier , GamePackageName ) ; using ( var request = UnityWebRequest . Get ( url ) ) { request . SetRequestHeader ( " " , " " + Token ) ; request . SetRequestHeader ( " " , ApprienIdentifier ) ; ApprienUtility . SendWebRequest ( request ) ; while ( ! request . isDone ) { if ( ( DateTime . Now - requestSendTimestamp ) . TotalSeconds > RequestTimeout ) { if ( callback != null ) { callback ( ) ; } yield break ; } yield return null ; } if ( ApprienUtility . IsHttpError ( request ) ) { SendError ( ( int ) request . responseCode , " " + request . downloadHandler . text ) ; } else if ( ApprienUtility . IsNetworkError ( request ) ) { SendError ( ( int ) request . responseCode , " " ) ; } else { if ( request . responseCode == 200 ) { try { var productLookup = new Dictionary < string , ApprienProduct > ( ) ; foreach ( var product in apprienProducts ) { productLookup [ product . BaseIAPId ] = product ; } var json = request . downloadHandler . text ; var productList = JsonUtility . FromJson < ApprienProductList > ( json ) ; foreach ( var product in productList . products ) { if ( productLookup . ContainsKey ( product . @base ) ) { productLookup [ product . @base ] . ApprienVariantIAPId = product . variant ; } } } catch { } } else { SendError ( ( int ) request . responseCode , " " + request . downloadHandler . text ) ; } } if ( callback != null ) { callback ( ) ; } } }
Fetch all Apprien variant IAP ids with optimum prices.
Fetch all Apprien variant IAP ids with optimum prices .
// Timeout the request and return false // Specify that the request is still in progress // Parse the JSON data and update the variant IAP ids // Create lookup to update the products in more linear time // If the JSON cannot be parsed, products will be using default IAP ids // If Apprien returns a non-200 message code, return base IAP id price // Regardless of the outcome, execute the callback
Returns an IEnumerator that can be forwarded manually or passed to StartCoroutine
Returns an IEnumerator that can be forwarded manually or passed to StartCoroutine
apprienProducts
ApprienProduct[]
callback
Action
Callback that is called when all product variant requests have completed.
Callback that is called when all product variant requests have completed .