Exemplo n.º 1
0
        /// <summary>
        /// Notifies the user that a Validate Google Iap request has failed.
        /// </summary>
        ///
        /// <param name="serverResponse">A container for information on the response from the server. Only
        /// failed responses can be passed into this method.</param>
        /// <param name="request"> The request that was sent to the server.</param>
        /// <param name="callback">The error callback.</param>
        private void NotifyValidateGoogleIapError(ServerResponse serverResponse, ValidateGoogleIapRequest request, Action <ValidateGoogleIapRequest, ValidateGoogleIapError> errorCallback)
        {
            ReleaseAssert.IsTrue(serverResponse.Result != HttpResult.Success || serverResponse.HttpResponseCode != SuccessHttpResponseCode, "Input server request must describe an error.");

            switch (serverResponse.Result)
            {
            case HttpResult.Success:
                m_logging.LogVerboseMessage("Validate Google Iap request failed with http response code: " + serverResponse.HttpResponseCode);
                break;

            case HttpResult.CouldNotConnect:
                m_logging.LogVerboseMessage("Validate Google Iap request failed becuase a connection could be established.");
                break;

            default:
                m_logging.LogVerboseMessage("Validate Google Iap request failed for an unknown reason.");
                throw new ArgumentException("Invalid value for server response result.");
            }

            ValidateGoogleIapError error = new ValidateGoogleIapError(serverResponse);

            m_taskScheduler.ScheduleMainThreadTask(() =>
            {
                errorCallback(request, error);
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Notifies the user that a Validate Google Iap request was successful.
        /// </summary>
        ///
        /// <param name="serverResponse">A container for information on the response from the server. Only
        /// successful responses can be passed into this method.</param>
        /// <param name="request"> The request that was sent to the server.</param>
        /// <param name="callback">The success callback.</param>
        private void NotifyValidateGoogleIapSuccess(ServerResponse serverResponse, ValidateGoogleIapRequest request, Action <ValidateGoogleIapRequest, ValidateGoogleIapResponse> successCallback)
        {
            ReleaseAssert.IsTrue(serverResponse.Result == HttpResult.Success && serverResponse.HttpResponseCode == SuccessHttpResponseCode, "Input server request must describe a success.");

            m_logging.LogVerboseMessage("ValidateGoogleIap request succeeded.");

            ValidateGoogleIapResponse outputResponse = new ValidateGoogleIapResponse(serverResponse.Body);

            m_taskScheduler.ScheduleMainThreadTask(() =>
            {
                successCallback(request, outputResponse);
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// Validate a Receipt from a successful purchase on a Google device.
        /// </summary>
        ///
        /// <param name="purchaseData">A JSON encoded string returned from a successful in app billing purchase. See the
        /// Google Documentation at
        /// 'http://developer.android.com/google/play/billing/billing_integrate.html#Purchase'
        /// on how to access this value from your app.</param>
        /// <param name="purchaseDataSignature">A signature of the PurchaseData returned from a successful in app billing
        /// purchase. See the Google Documentation at
        /// 'http://developer.android.com/google/play/billing/billing_integrate.html#Purchase'
        /// on how to access this value from your app.</param>
        /// <param name="successCallback">The delegate which is called if the request was successful.</param>
        /// <param name="errorCallback">The delegate which is called if the request was unsuccessful. Provides
        /// a container with information on what went wrong.</param>
        public void ValidateGoogleIap(string purchaseData, string purchaseDataSignature, Action <ValidateGoogleIapRequest, ValidateGoogleIapResponse> successCallback, Action <ValidateGoogleIapRequest, ValidateGoogleIapError> errorCallback)
        {
            m_logging.LogVerboseMessage("Sending Validate Google Iap request.");

            var connectAccessToken = m_dataStore.GetString("UserAccessToken");
            var request            = new ValidateGoogleIapRequest(purchaseData, purchaseDataSignature, connectAccessToken);

            m_serverRequestSystem.SendImmediateRequest(request, (IImmediateServerRequest sentRequest, ServerResponse serverResponse) =>
            {
                ReleaseAssert.IsTrue(request == sentRequest, "Received request is not the same as the one sent!");

                if (serverResponse.Result == HttpResult.Success && serverResponse.HttpResponseCode == SuccessHttpResponseCode)
                {
                    NotifyValidateGoogleIapSuccess(serverResponse, request, successCallback);
                }
                else
                {
                    NotifyValidateGoogleIapError(serverResponse, request, errorCallback);
                }
            });
        }