src/ApprienUnitySDK/Assets/Apprien/Scripts/Apprien.cs
/// <summary>
/// <para>
/// Fetch Apprien variant IAP id for the given product.
/// NOTE: Only use this overload for fetching single products, if required by game/store logic. 
/// Use the other overload when fetching multiple products, to save on request volume.
/// </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="product">Apprien.Product instance. After the request completes, will contain the Apprien IAP id variant.</param>
/// <param name="callback">Callback that is called when the request finishes. Takes string argument, containing the resolved IAP id.</param>
/// <returns>Returns an IEnumerator that can be forwarded manually or passed to StartCoroutine.</returns>
Fetch Apprien variant IAP id for the given product.
NOTE: Only use this overload for fetching single products, if required by game/store logic.
Use the other overload when fetching multiple products, to save on request volume.
>
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 Apprien variant IAP id for the given product . NOTE : Only use this overload for fetching single products if required by game / store logic . Use the other overload when fetching multiple products to save on request volume . > 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 FetchApprienPrice(ApprienProduct product, Action callback = null)
        {
            var requestSendTimestamp = DateTime.Now;
            var url = string.Format(ApprienUtility.REST_GET_PRICE_URL, StoreIdentifier, GamePackageName, product.BaseIAPId);
            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)
                    {
                        var apprienVariantIAPid = request.downloadHandler.text;
                        product.ApprienVariantIAPId = apprienVariantIAPid;
                    }
                    else
                    {
                        SendError((int) request.responseCode, "Error occured while fetching Apprien prices");
                        Debug.Log("Apprien request error: " + request.responseCode + ". " + request.downloadHandler.text);
                    }
                }
                if (callback != null)
                {
                    callback();
                }
            }
        }
public IEnumerator FetchApprienPrice ( ApprienProduct product , Action callback = null ) { var requestSendTimestamp = DateTime . Now ; var url = string . Format ( ApprienUtility . REST_GET_PRICE_URL , StoreIdentifier , GamePackageName , product . BaseIAPId ) ; 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 ) { var apprienVariantIAPid = request . downloadHandler . text ; product . ApprienVariantIAPId = apprienVariantIAPid ; } else { SendError ( ( int ) request . responseCode , " " ) ; Debug . Log ( " " + request . responseCode + " " + request . downloadHandler . text ) ; } } if ( callback != null ) { callback ( ) ; } } }
Fetch Apprien variant IAP id for the given product.
Fetch Apprien variant IAP id for the given product .
// Timeout the request and return false // Specify that the request is still in progress // send apprien api info about the error // send apprien api info about the error // Apprien IAP id variant fetched, apply it to the given product and // 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 .
product
ApprienProduct
Apprien.Product instance. After the request completes, will contain the Apprien IAP id variant.
Apprien . Product instance . After the request completes will contain the Apprien IAP id variant .
callback
Action
Callback that is called when the request finishes. Takes string argument, containing the resolved IAP id.
Callback that is called when the request finishes . Takes string argument containing the resolved IAP id .