Пример #1
0
        /// <summary>
        /// This Async service is used by Clients to send Purchase Rewards (could have a discount)
        /// and Events to Gameball based on Events triggered by the Players Actions on the Client's Interface.
        /// </summary>
        /// <exception cref="GameballException">Thrown if the request fails..</exception>
        public async Task <ActionResponse> SendActionAsync(ActionRequest action)
        {
            action.Validate();
            action.PointsTransaction.TransactionTime = DateTime.UtcNow;
            string hash = GameballUtils.GetSHA1(action.PlayerUniqueId, TransactionKey, GameballUtils.ToUtcTime(action.PointsTransaction.TransactionTime), GameballUtils.ToValidAmount(action.PointsTransaction.RewardAmount));

            action.PointsTransaction.Hash = hash;
            var response = await this.Client.PostAsync(ApiBase + GameballConstants.Action, new StringContent(action.Serialize(), Encoding.UTF8, "application/json"));

            if (!response.IsSuccessStatusCode)
            {
                throw (BuildGameballException(response));
            }
            else
            {
                return(JsonConvert.DeserializeObject <ActionResponse>(await response.Content.ReadAsStringAsync()));
            }
        }
Пример #2
0
        /// <summary>
        /// This service For Reward Points Based on the Amount send and the Client Transaction Config.
        /// </summary>
        /// <exception cref="GameballException">Thrown if the request fails..</exception>
        public TransactionResponse RewardPoints(RewardPointsRequest reward)
        {
            reward.Validate();
            reward.TransactionTime = DateTime.UtcNow;
            string Hash = GameballUtils.GetSHA1(reward.PlayerUniqueId, TransactionKey, GameballUtils.ToUtcTime(reward.TransactionTime), GameballUtils.ToValidAmount(reward.Amount));

            reward.Hash = Hash;

            var response = this.Client.PostAsync(ApiBase + GameballConstants.Reward, new StringContent(reward.Serialize(), Encoding.UTF8, "application/json")).Result;

            if (!response.IsSuccessStatusCode)
            {
                throw (BuildGameballException(response));
            }
            else
            {
                return(JsonConvert.DeserializeObject <TransactionResponse>(response.Content.ReadAsStringAsync().Result));
            }
        }