/// <summary>
        /// Initialises a new instance of the request with the given description.
        /// </summary>
        ///
        /// <param name="desc">The description.</param>
        /// <param name="connectAccessToken">A valid session ConnectAccessToken obtained through one of the login endpoints.</param>
        /// <param name="serverUrl">The server url for this call.</param>
        public ValidateAmazonIapRequest(ValidateAmazonIapRequestDesc desc, string connectAccessToken, string serverUrl)
        {
            ReleaseAssert.IsNotNull(desc, "A description object cannot be null.");

            ReleaseAssert.IsNotNull(desc.ReceiptId, "ReceiptId cannot be null.");
            ReleaseAssert.IsNotNull(desc.UserId, "UserId cannot be null.");

            ReleaseAssert.IsNotNull(connectAccessToken, "Connect Access Token cannot be null.");

            ReceiptId          = desc.ReceiptId;
            UserId             = desc.UserId;
            LocalCost          = desc.LocalCost;
            LocalCurrency      = desc.LocalCurrency;
            ConnectAccessToken = connectAccessToken;

            Url = serverUrl + "/1.0/iap/validate/amazon";
            HttpRequestMethod = HttpRequestMethod.Post;
        }
Beispiel #2
0
        /// <summary>
        /// Validate a Receipt from a successful purchase on an Amazon device. If the option
        /// to automatically record IAPs is enabled both <code>LocalCost</code> and
        /// <code>LocalCurrency</code> are regarded as required.
        /// </summary>
        ///
        /// <param name="desc">The request description.</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 ValidateAmazonIap(ValidateAmazonIapRequestDesc desc, Action <ValidateAmazonIapRequest, ValidateAmazonIapResponse> successCallback, Action <ValidateAmazonIapRequest, ValidateAmazonIapError> errorCallback)
        {
            m_logging.LogVerboseMessage("Sending Validate Amazon Iap request.");

            var serverUrl          = m_dataStore.GetString("ConnectUrl");
            var connectAccessToken = m_dataStore.GetString("UserAccessToken");
            var request            = new ValidateAmazonIapRequest(desc, connectAccessToken, serverUrl);

            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)
                {
                    NotifyValidateAmazonIapSuccess(serverResponse, request, successCallback);
                }
                else
                {
                    NotifyValidateAmazonIapError(serverResponse, request, errorCallback);
                }
            });
        }