Example #1
0
        /// <summary>
        /// This Async service For Get the Player's Info.
        /// </summary>
        /// <exception cref="GameballException">Thrown if the request fails..</exception>
        public async Task <PlayerInfo> GetPlayerInfoAsync(string playerUniqueId, GameballLang Language = 0)
        {
            if (Language != 0)
            {
                Client.DefaultRequestHeaders.Add("lang", GameballUtils.ToValidLang(Language));
            }
            PlayerInfoRequest Info = new PlayerInfoRequest()
            {
                PlayerUniqueId = playerUniqueId,
                Hash           = GameballUtils.GetSHA1(playerUniqueId, TransactionKey)
            };

            Info.Validate();
            var response = await this.Client.PostAsync(ApiBase + GameballConstants.PlayerInfo, new StringContent(Info.Serialize(), Encoding.UTF8, "application/json"));

            //Removes Overhead of lang header if not necessary in next calls.
            Client.DefaultRequestHeaders.Remove("lang");

            if (!response.IsSuccessStatusCode)
            {
                throw (BuildGameballException(response));
            }
            else
            {
                return(JsonConvert.DeserializeObject <PlayerInfo>(await response.Content.ReadAsStringAsync()));
            }
        }
Example #2
0
        /// <summary>
        /// This Async service For Creating a Discount Coupon.
        /// </summary>
        /// <exception cref="GameballException">Thrown if the request fails..</exception>
        public async Task <CreateCouponResponse> CreateDiscountCouponAsync(CreateCouponRequest coupon)
        {
            coupon.Validate();
            coupon.TransactionTime = DateTime.UtcNow;
            string hash = GameballUtils.GetSHA1(coupon.PlayerUniqueId, TransactionKey);

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

            if (!response.IsSuccessStatusCode)
            {
                throw (BuildGameballException(response));
            }
            else
            {
                return(JsonConvert.DeserializeObject <CreateCouponResponse>(await response.Content.ReadAsStringAsync()));
            }
        }
Example #3
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()));
            }
        }
Example #4
0
        /// <summary>
        /// This service For Reversing a Transaction.
        /// </summary>
        /// <exception cref="GameballException">Thrown if the request fails..</exception>
        public TransactionResponse ReverseTransaction(ReverseTransactionRequest reverse)
        {
            reverse.Validate();
            reverse.TransactionTime = DateTime.UtcNow;
            string hash = GameballUtils.GetSHA1(reverse.PlayerUniqueId, TransactionKey, GameballUtils.ToUtcTime(reverse.TransactionTime), GameballUtils.ToValidAmount(reverse.Amount));

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

            if (!response.IsSuccessStatusCode)
            {
                throw (BuildGameballException(response));
            }
            else
            {
                return(JsonConvert.DeserializeObject <TransactionResponse>(response.Content.ReadAsStringAsync().Result));
            }
        }
Example #5
0
        /// <summary>
        /// This Async service For Redeem Points Based on the Amount send and the Client Transaction Config.
        /// </summary>
        /// <exception cref="GameballException">Thrown if the request fails..</exception>
        public async Task <TransactionResponse> RedeemPointsAsync(RedeemPointsRequest redeem)
        {
            redeem.Validate();
            redeem.TransactionTime = DateTime.UtcNow;
            string hash = GameballUtils.GetSHA1(redeem.PlayerUniqueId, TransactionKey, GameballUtils.ToUtcTime(redeem.TransactionTime));

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

            if (!response.IsSuccessStatusCode)
            {
                throw (BuildGameballException(response));
            }
            else
            {
                return(JsonConvert.DeserializeObject <TransactionResponse>(await response.Content.ReadAsStringAsync()));
            }
        }
Example #6
0
        /// <summary>
        /// This Async service For Get Player Balances.
        /// </summary>
        /// <exception cref="GameballException">Thrown if the request fails..</exception>
        public async Task <PlayerBalance> GetPlayerBalanceAsync(string playerUniqueId)
        {
            PlayerBalanceRequest Balance = new PlayerBalanceRequest()
            {
                PlayerUniqueId = playerUniqueId,
                Hash           = GameballUtils.GetSHA1(playerUniqueId, TransactionKey)
            };

            Balance.Validate();
            var response = await this.Client.PostAsync(ApiBase + GameballConstants.Balance, new StringContent(Balance.Serialize(), Encoding.UTF8, "application/json"));

            if (!response.IsSuccessStatusCode)
            {
                throw (BuildGameballException(response));
            }
            else
            {
                return(JsonConvert.DeserializeObject <PlayerBalance>(await response.Content.ReadAsStringAsync()));
            }
        }
Example #7
0
        /// <summary>
        /// This async service For Validate Discount Coupon.
        /// </summary>
        /// <exception cref="GameballException">Thrown if the request fails..</exception>
        public async Task <ValidateCouponResponse> ValidateDiscountCouponAsync(string playerUniqueId, string code)
        {
            ValidateCouponRequest Coupon = new ValidateCouponRequest()
            {
                PlayerUniqueId  = playerUniqueId,
                Hash            = GameballUtils.GetSHA1(playerUniqueId, TransactionKey),
                TransactionTime = DateTime.UtcNow,
                Code            = code
            };

            Coupon.Validate();
            var response = await this.Client.PostAsync(ApiBase + GameballConstants.ValidateDiscount, new StringContent(Coupon.Serialize(), Encoding.UTF8, "application/json"));

            if (!response.IsSuccessStatusCode)
            {
                throw (BuildGameballException(response));
            }
            else
            {
                return(JsonConvert.DeserializeObject <ValidateCouponResponse>(await response.Content.ReadAsStringAsync()));
            }
        }
Example #8
0
        /// <summary>
        /// This service For Redeem Discount Coupon.
        /// </summary>
        /// <exception cref="GameballException">Thrown if the request fails..</exception>
        public bool RedeemDiscountCoupon(string playerUniqueId, string code)
        {
            RedeemCouponRequest Coupon = new RedeemCouponRequest()
            {
                PlayerUniqueId  = playerUniqueId,
                Hash            = GameballUtils.GetSHA1(playerUniqueId, TransactionKey),
                TransactionTime = DateTime.UtcNow,
                Code            = code
            };

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

            if (!response.IsSuccessStatusCode)
            {
                throw (BuildGameballException(response));
            }
            else
            {
                return(response.IsSuccessStatusCode);
            }
        }