/// <summary> /// Redeem Campaign Code to Receive In Game Item. /// </summary> /// <param name="code">The campaign code to redeem.</param> /// <param name="region">Region of the item. If not set, the region from the access token will be used.</param> /// <param name="language">Display language.null If not set, the language from the access token will be used.</param> /// <param name="callback">Returns a Result that contains EntitlementInfo via callback when completed</param> public void RedeemCode(string code, string region, string language, ResultCallback <FulfillmentResult> callback) { Report.GetFunctionLog(this.GetType().Name); Assert.IsNotNull(code, "Can't redeem code! code parameter is null!"); if (!this.session.IsValid()) { callback.TryError(ErrorCode.IsNotLoggedIn); return; } FulFillCodeRequest fulFillCodeRequest = new FulFillCodeRequest { code = code, region = region, language = language }; this.coroutineRunner.Run( this.api.RedeemCode( this.@namespace, this.session.UserId, this.session.AuthorizationToken, fulFillCodeRequest, callback)); }
public IEnumerator RedeemCode(string @namespace, string userId, string accessToken, FulFillCodeRequest fulFillCodeRequest, ResultCallback <FulfillmentResult> callback) { Report.GetFunctionLog(this.GetType().Name); Assert.IsNotNull(@namespace, nameof(@namespace) + " cannot be null"); Assert.IsNotNull(userId, nameof(userId) + " cannot be null"); Assert.IsNotNull(accessToken, nameof(accessToken) + " cannot be null"); Assert.IsNotNull(fulFillCodeRequest, nameof(fulFillCodeRequest) + " cannot be null"); var request = HttpRequestBuilder .CreatePost(this.baseUrl + "/public/namespaces/{namespace}/users/{userId}/fulfillment/code") .WithPathParam("namespace", @namespace) .WithPathParam("userId", userId) .WithBearerAuth(accessToken) .WithContentType(MediaType.ApplicationJson) .WithBody(fulFillCodeRequest.ToUtf8Json()) .Accepts(MediaType.ApplicationJson) .GetResult(); IHttpResponse response = null; yield return(this.httpClient.SendRequest(request, rsp => response = rsp)); var result = response.TryParseJson <FulfillmentResult>(); callback.Try(result); }