src/ApprienUnitySDK/Assets/Apprien/Scripts/Apprien.cs
/// <summary>
/// <para>
/// Posts the receipt to Apprien for calculating new prices.
/// </para>
/// <para>
/// Passes messages OnApprienPostReceiptSuccess or OnApprienPostReceiptFailed to the given MonoBehaviour.
/// </para>
/// </summary>
/// <param name="unityComponent">MonoBehaviour, typically 'this'.</param>
/// <param name="receiptJson"></param>
/// <returns>Returns an IEnumerator that can be forwarded manually or passed to StartCoroutine.</returns>
Posts the receipt to Apprien for calculating new prices.


Posts the receipt to Apprien for calculating new prices .
public IEnumerator PostReceipt(MonoBehaviour unityComponent, string receiptJson)
        {
            var formData = new List<IMultipartFormSection>();
            formData.Add(new MultipartFormDataSection("deal=receipt", receiptJson));
            var url = String.Format(ApprienUtility.REST_POST_RECEIPT_URL, StoreIdentifier, GamePackageName);
            using(var request = UnityWebRequest.Post(url, formData))
            {
                request.SetRequestHeader("Authorization", "Bearer " + Token);
                yield return ApprienUtility.SendWebRequest(request);
                if (ApprienUtility.IsHttpError(request))
                {
                    SendError((int) request.responseCode, "Error occured while posting receipt. HTTP error: " + request.downloadHandler.text);
                    unityComponent.SendMessage("OnApprienPostReceiptFailed", request.responseCode + ": " + request.error, SendMessageOptions.DontRequireReceiver);
                }
                else if (ApprienUtility.IsNetworkError(request))
                {
                    SendError((int) request.responseCode, "Error occured while posting receipt. Network error");
                    unityComponent.SendMessage("OnApprienPostReceiptFailed", request.responseCode + ": " + request.error, SendMessageOptions.DontRequireReceiver);
                }
                else
                {
                    unityComponent.SendMessage("OnApprienPostReceiptSuccess", request.downloadHandler.text, SendMessageOptions.DontRequireReceiver);
                }
            }
        }
public IEnumerator PostReceipt ( MonoBehaviour unityComponent , string receiptJson ) { var formData = new List < IMultipartFormSection > ( ) ; formData . Add ( new MultipartFormDataSection ( " " , receiptJson ) ) ; var url = String . Format ( ApprienUtility . REST_POST_RECEIPT_URL , StoreIdentifier , GamePackageName ) ; using ( var request = UnityWebRequest . Post ( url , formData ) ) { request . SetRequestHeader ( " " , " " + Token ) ; yield return ApprienUtility . SendWebRequest ( request ) ; if ( ApprienUtility . IsHttpError ( request ) ) { SendError ( ( int ) request . responseCode , " " + request . downloadHandler . text ) ; unityComponent . SendMessage ( " " , request . responseCode + " " + request . error , SendMessageOptions . DontRequireReceiver ) ; } else if ( ApprienUtility . IsNetworkError ( request ) ) { SendError ( ( int ) request . responseCode , " " ) ; unityComponent . SendMessage ( " " , request . responseCode + " " + request . error , SendMessageOptions . DontRequireReceiver ) ; } else { unityComponent . SendMessage ( " " , request . downloadHandler . text , SendMessageOptions . DontRequireReceiver ) ; } } }
Posts the receipt to Apprien for calculating new prices.
Posts the receipt to Apprien for calculating new prices .
Returns an IEnumerator that can be forwarded manually or passed to StartCoroutine.
Returns an IEnumerator that can be forwarded manually or passed to StartCoroutine .
unityComponent
MonoBehaviour
MonoBehaviour, typically 'this'.
MonoBehaviour typically ' this ' .
receiptJson
string
None