public void ItUsesSandboxDuringInitiation() { Env.Set("STEAM_USE_MICROTRANSACTION_SANDBOX", true); var transaction = new SteamTransactionEntity { playerSteamId = 123456789L }; transaction.AddProduct <ExampleVirtualProduct>(); Http.Fake(Http.Response(new JsonObject { ["response"] = new JsonObject { ["result"] = "OK", ["params"] = new JsonObject { ["orderid"] = transaction.orderId, ["transid"] = "11122233" } } }, 200)); OnFacet <SteamPurchasingServerFacet> .CallSync( nameof(SteamPurchasingServerFacet.InitiateTransaction), transaction ); Http.AssertSent(request => request.Url == "http://api.steam.com/ISteamMicroTxnSandbox/InitTxn/v3/" ); }
public void ItUsesSandboxDuringFinalization() { Env.Set("STEAM_USE_MICROTRANSACTION_SANDBOX", true); var transaction = new SteamTransactionEntity { state = SteamTransactionEntity.InitiatedState }; transaction.Save(); Http.Fake(Http.Response(new JsonObject { ["response"] = new JsonObject { ["result"] = "OK", ["params"] = new JsonObject { ["orderid"] = transaction.orderId, ["transid"] = transaction.transactionId } } }, 200)); OnFacet <SteamPurchasingServerFacet> .CallSync <SteamTransactionEntity>( nameof(SteamPurchasingServerFacet.FinalizeTransaction), transaction.orderId, true ); Http.AssertSent(request => request.Url == "http://api.steam.com/ISteamMicroTxnSandbox/FinalizeTxn/v2/" ); }
public void ItRejectsLoginWithInvalidToken() { Env.Set("STEAM_API_URL", "https://partner.steam-api.com/"); Env.Set("STEAM_PUBLISHER_KEY", "some-publisher-key"); Env.Set("STEAM_APP_ID", "480"); Http.Fake(Http.Response(new JsonObject { ["response"] = new JsonObject { ["error"] = new JsonObject { ["errorcode"] = 3, ["errordesc"] = "Invalid parameter" } } })); Assert.Catch <AuthException>(() => { OnFacet <SteamLoginFacet> .CallSync( nameof(SteamLoginFacet.Login), "some-invalid-session-token" ); }, "Invalid session token."); Http.AssertSent(request => request.Url == "https://partner.steam-api.com/" + "ISteamUserAuth/AuthenticateUserTicket/v1/?" + "key=some-publisher-key&" + "appid=480&" + "ticket=some-invalid-session-token" ); }
public void ItLogsPlayerIn() { var player = new PlayerEntity { steamId = "123456789" }; player.Save(); Env.Set("STEAM_API_URL", "https://partner.steam-api.com/"); Env.Set("STEAM_PUBLISHER_KEY", "some-publisher-key"); Env.Set("STEAM_APP_ID", "480"); Http.Fake(Http.Response(new JsonObject { ["response"] = new JsonObject { ["params"] = new JsonObject { ["result"] = "OK", ["steamid"] = "123456789", ["ownersteamid"] = "123456789", ["vacbanned"] = false, ["publisherbanned"] = false } } })); OnFacet <SteamLoginFacet> .CallSync( nameof(SteamLoginFacet.Login), "valid-session-token" ); Http.AssertSent(request => request.Url == "https://partner.steam-api.com/" + "ISteamUserAuth/AuthenticateUserTicket/v1/?" + "key=some-publisher-key&" + "appid=480&" + "ticket=valid-session-token" ); Assert.IsTrue(Auth.Check()); Assert.AreEqual( player.EntityId, Auth.Id() ); }
public IEnumerator ClickingBuyInitiatesTransaction() { // setup scene var go = new GameObject(); var smm = go.AddComponent <SteamPurchasingClientMock>(); yield return(null); // setup authentication var playerEntity = new PlayerEntity(); playerEntity.Save(); ActingAs(playerEntity); Assert.IsNotNull(playerEntity.EntityId); // setup HTTP Http.Fake(Http.Response(new JsonObject { ["response"] = new JsonObject { ["result"] = "OK", ["params"] = new JsonObject { // this order id is not used and // it does not match the generated ["orderid"] = "938473", ["transid"] = "374839" } } }, 200)); // click the button smm.PlayerClickedBuy(); // assert request to initiate transaction has been sent Http.AssertSent(request => request.Url == "http://api.steam.com/ISteamMicroTxn/InitTxn/v3/" && request["key"] == "<steam-publisher-key>" && request["appid"] == "<steam-app-id>" && request["orderid"] != "0" && request["steamid"] == "123456789" && request["itemcount"] == "1" && request["language"] == "en" && request["currency"] == "USD" && request["itemid[0]"] == "1" && request["qty[0]"] == "3" && request["amount[0]"] == "1500" && request["description[0]"].AsString .Contains("An example product") ); // assert a transaction entity has been created var entities = DB.TakeAll <SteamTransactionEntity>().Get(); Assert.AreEqual(1, entities.Count); var entity = entities[0]; Assert.AreEqual(SteamTransactionEntity.InitiatedState, entity.state); Assert.AreEqual("USD", entity.currency); Assert.AreEqual("en", entity.language); Assert.AreNotEqual(0L, entity.orderId); Assert.AreEqual(374839L, entity.transactionId); Assert.AreEqual(123456789L, entity.playerSteamId); Assert.AreEqual(playerEntity.EntityId, entity.authenticatedPlayerId); Assert.AreEqual(1, entity.items.Count); Assert.AreEqual(1, entity.items[0].itemId); Assert.AreEqual(15_00, entity.items[0].totalAmountInCents); Assert.AreEqual(3, entity.items[0].quantity); StringAssert.Contains( "An example product", entity.items[0].description ); Assert.AreEqual( typeof(ExampleVirtualProduct).FullName, entity.items[0].productClass ); // now the Steamworks API will notify the game via a callback }
public IEnumerator SteamRejectsTransactionFinalization() { // setup scene var go = new GameObject(); var smm = go.AddComponent <SteamPurchasingClientMock>(); yield return(null); // setup database var transaction = new SteamTransactionEntity { state = SteamTransactionEntity.InitiatedState, playerSteamId = 123456789L, orderId = 111222333L, transactionId = 374839L, language = "en", currency = "USD", items = new List <SteamTransactionEntity.Item> { new SteamTransactionEntity.Item { itemId = 1, quantity = 3, totalAmountInCents = 15_00, description = "An example product, that a user can buy.", category = null, productClass = typeof(ExampleVirtualProduct).FullName } } }; transaction.Save(); Http.Fake(Http.Response(new JsonObject { ["response"] = new JsonObject { ["result"] = "Failure", ["params"] = new JsonObject { ["orderid"] = "111222333", ["transid"] = "374839" }, ["error"] = new JsonObject { ["errorcode"] = 100, ["errordesc"] = "Insufficient funds" } } }, 200)); // Steamworks fires the callback smm.SteamworksCallbackHandler( new MicroTxnAuthorizationResponse_t { m_ulOrderID = 111222333L, m_unAppID = 440, m_bAuthorized = 1 } ); Http.AssertSent(request => request.Url == "http://api.steam.com/ISteamMicroTxn/FinalizeTxn/v2/" && request["key"] == "<steam-publisher-key>" && request["appid"] == "<steam-app-id>" && request["orderid"] == "111222333" ); // transaction was updated accordingly transaction.Refresh(); Assert.AreEqual( SteamTransactionEntity.FinalizationErrorState, transaction.state ); Assert.AreEqual("100", transaction.errorCode); Assert.AreEqual("Insufficient funds", transaction.errorDescription); // client logs failure LogAssert.Expect( LogType.Error, new Regex( @"^The transaction failed because of:[\s\S]*" + @"Steam rejected transaction finalization\.[\s\S]*" + @"100[\s\S]*Insufficient funds[\s\S]*111222333", RegexOptions.Multiline ) ); }
public IEnumerator SteamRejectsTransactionInitiation() { // setup scene var go = new GameObject(); var smm = go.AddComponent <SteamPurchasingClientMock>(); yield return(null); // setup HTTP Http.Fake(Http.Response(new JsonObject { ["response"] = new JsonObject { ["result"] = "Failure", ["params"] = new JsonObject { // this order id is not used and // it does not match the generated ["orderid"] = "938473" }, ["error"] = new JsonObject { ["errorcode"] = 1001, ["errordesc"] = "Action not allowed" } } }, 200)); // click the button smm.PlayerClickedBuy(); // assert request to initiate transaction has been sent Http.AssertSent(request => request.Url == "http://api.steam.com/ISteamMicroTxn/InitTxn/v3/" && request["key"] == "<steam-publisher-key>" && request["appid"] == "<steam-app-id>" && request["orderid"] != "0" && request["steamid"] == "123456789" && request["itemcount"] == "1" && request["language"] == "en" && request["currency"] == "USD" && request["itemid[0]"] == "1" && request["qty[0]"] == "3" && request["amount[0]"] == "1500" && request["description[0]"].AsString .Contains("An example product") ); // assert a transaction entity has been created // with proper error state var entities = DB.TakeAll <SteamTransactionEntity>().Get(); Assert.AreEqual(1, entities.Count); var entity = entities[0]; Assert.AreEqual(SteamTransactionEntity.InitiationErrorState, entity.state); Assert.AreEqual("1001", entity.errorCode); Assert.AreEqual("Action not allowed", entity.errorDescription); Assert.AreNotEqual(0L, entity.orderId); // client logs failure LogAssert.Expect( LogType.Error, new Regex( @"^The transaction failed because of:[\s\S]*" + @"Steam rejected transaction initiation\.[\s\S]*" + @"1001[\s\S]*Action not allowed[\s\S]*" + entity.orderId, RegexOptions.Multiline ) ); }
public IEnumerator ReceivingPositiveUserResponseFinishesTransaction() { // setup scene var go = new GameObject(); var smm = go.AddComponent <SteamPurchasingClientMock>(); yield return(null); // setup database var transaction = new SteamTransactionEntity { state = SteamTransactionEntity.InitiatedState, playerSteamId = 123456789L, orderId = 111222333L, transactionId = 374839L, language = "en", currency = "USD", items = new List <SteamTransactionEntity.Item> { new SteamTransactionEntity.Item { itemId = 1, quantity = 3, totalAmountInCents = 15_00, description = "An example product, that a user can buy.", category = null, productClass = typeof(ExampleVirtualProduct).FullName } } }; transaction.Save(); // setup HTTP Http.Fake(Http.Response(new JsonObject { ["response"] = new JsonObject { ["result"] = "OK", ["params"] = new JsonObject { ["orderid"] = "111222333", ["transid"] = "374839" } } }, 200)); // Steamworks fires the callback smm.SteamworksCallbackHandler( new MicroTxnAuthorizationResponse_t { m_ulOrderID = 111222333L, m_unAppID = 440, m_bAuthorized = 1 } ); // steam received finalization request Http.AssertSent(request => request.Url == "http://api.steam.com/ISteamMicroTxn/FinalizeTxn/v2/" && request["key"] == "<steam-publisher-key>" && request["appid"] == "<steam-app-id>" && request["orderid"] == "111222333" ); // transaction was updated accordingly transaction.Refresh(); Assert.AreEqual( SteamTransactionEntity.CompletedState, transaction.state ); // products were given to the player LogAssert.Expect( LogType.Log, $"Giving item {nameof(ExampleVirtualProduct)} to the player..." ); // client logs success LogAssert.Expect( LogType.Log, new Regex( @"^The transaction has succeeded and the products have", RegexOptions.Multiline ) ); }