public IEnumerator CreditUserWallet(string @namespace, string userId, string accessToken, string currencyCode, CreditUserWalletRequest creditUserWalletRequest, ResultCallback <WalletInfo> callback) { 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(accessToken, nameof(accessToken) + " cannot be null"); Assert.IsNotNull(currencyCode, nameof(currencyCode) + " cannot be null"); Assert.IsNotNull(creditUserWalletRequest, nameof(creditUserWalletRequest) + " cannot be null"); var request = HttpRequestBuilder .CreatePut(this.baseUrl + "/admin/namespaces/{namespace}/users/{userId}/wallets/{currencyCode}/credit") .WithPathParam("namespace", @namespace) .WithPathParam("userId", userId) .WithPathParam("currencyCode", currencyCode) .WithBearerAuth(accessToken) .WithContentType(MediaType.ApplicationJson) .Accepts(MediaType.ApplicationJson) .WithBody(creditUserWalletRequest.ToUtf8Json()) .GetResult(); IHttpResponse response = null; yield return(this.httpWorker.SendRequest(request, rsp => response = rsp)); var result = response.TryParseJson <WalletInfo>(); callback.Try(result); }
/// <summary> /// Credit a user wallet by currency code, if the wallet does not exist, it will create a new wallet. /// </summary> /// <param name="userId">UserId of a user</param> /// <param name="currencyCode">The currency code</param> /// <param name="creditUserWalletRequest">The request to credit a user wallet</param> /// <param name="callback">Returns Wallet info via callback when completed</param> public void CreditUserWallet(string userId, string currencyCode, CreditUserWalletRequest creditUserWalletRequest, ResultCallback <WalletInfo> callback) { Report.GetFunctionLog(this.GetType().Name); if (!this.session.IsValid()) { callback.TryError(ErrorCode.IsNotLoggedIn); return; } this.coroutineRunner.Run( this.api.CreditUserWallet( this.namespace_, userId, this.session.AuthorizationToken, currencyCode, creditUserWalletRequest, callback)); }
public IEnumerator CreditUserWallet_Success() { ServerEcommerce serverEcommerce = AccelByteServerPlugin.GetEcommerce(); CreditUserWalletRequest creditUserWalletRequest = new CreditUserWalletRequest { amount = 1000, source = CreditUserWalletSource.PURCHASE, reason = "Unity GameServer Ecommerce CreditUserWallet test." }; int expectedBalance = walletBalance + creditUserWalletRequest.amount; Result <WalletInfo> walletInfo = null; serverEcommerce.CreditUserWallet(TestVariables.userId, TestVariables.currencyCode, creditUserWalletRequest, result => { walletInfo = result; }); while (walletInfo == null) { Thread.Sleep(100); yield return(null); } TestHelper.Assert.IsTrue(!walletInfo.IsError, "Credit user wallet failed."); TestHelper.Assert.IsTrue(walletInfo.Value.balance == expectedBalance, "Balance is not increased."); }