public IEnumerator Purchase() { var purchaseId = "dummy purchase Id"; var productId = "100_gold_coins"; var purchaseDone = false; var purchaseSucceeded = false; var failedReason = string.Empty; yield return(router.PurchaseAsync( purchaseId, productId, pId => { purchaseDone = true; purchaseSucceeded = true; }, (pId, err, code, reason) => { purchaseDone = true; failedReason = reason; } )); yield return(WaitUntil(() => purchaseDone, () => { throw new TimeoutException("failed to purchase async."); })); True(purchaseSucceeded, "purchase failed. reason:" + failedReason); }
public IEnumerator ChangePurhcaseSuceededRequest() { var dateTimeStr = DateTime.Now.ToLongDateString(); Func <string, string> onTicletRequestFunc = givenProductId => { var data = new SampleTicletJsonData(givenProductId, dateTimeStr); var jsonStr = JsonUtility.ToJson(data); return(jsonStr); }; router = new PurchaseRouter( iEnum => { runner.StartCoroutine(iEnum); }, productData => { // dummy response. return(new ProductInfo[] { new ProductInfo("100_gold_coins", "100_gold_coins_iOS", true, "one hundled of coins."), new ProductInfo("1000_gold_coins", "1000_gold_coins_iOS", true, "one ton of coins.") }); }, onTicletRequestFunc,// ここがリクエストに乗っかるので、ticketDataの値でassertを書けばいい。 ticketData => { True(ticketData.Contains(dateTimeStr)); return(ticketData); }, () => { }, (err, code, reason) => { }, backgroundPurchasedProductId => { }, null, DummyResponsehandlingDelegate ); yield return(WaitUntil(() => router.IsPurchaseReady(), () => { throw new TimeoutException("failed to ready."); })); var purchaseId = "dummy purchase Id"; var productId = "100_gold_coins"; var cor = router.PurchaseAsync( purchaseId, productId, pId => { // do nothing. }, (pId, err, code, reason) => { // do nothing. } ); while (cor.MoveNext()) { yield return(null); } }
[MTest] public void Purchase() { var purchaseId = "dummy purchase Id"; var productId = "100_gold_coins"; var purchaseDone = false; var purchaseSucceeded = false; var failedReason = string.Empty; RunEnumeratorOnMainThread( router.PurchaseAsync( purchaseId, productId, pId => { purchaseDone = true; purchaseSucceeded = true; }, (pId, err, reason, autoyaStatus) => { purchaseDone = true; failedReason = reason; } ) ); WaitUntil(() => purchaseDone, 10, "failed to purchase async."); Assert(purchaseSucceeded, "purchase failed. reason:" + failedReason); }
public IEnumerator RetryPurchaseThenFailThenComplete() { /* * ・storeのリブートに際して失敗したtransactionが復活するかどうか * が実機に依存するため、このテストはiOS/Androidの実機上でしか動作しない。 */ #if UNITY_EDITOR var a = true; if (a) { yield break; } #elif UNITY_IOS || UNITY_ANDROID // pass. #else yield break; #endif forceFailResponse = false; router = new PurchaseRouter( iEnum => { runner.StartCoroutine(iEnum); }, productData => { // dummy response. return(new ProductInfo[] { new ProductInfo("100_gold_coins", "100_gold_coins_iOS", true, "one hundled of coins."), new ProductInfo("1000_gold_coins", "1000_gold_coins_iOS", true, "one ton of coins.") }); }, givenProductId => givenProductId, ticketData => Guid.NewGuid().ToString(), () => { }, (err, code, reason) => { }, backgroundPurchasedProductId => { }, null, DummyResponsehandlingDelegate ); var storeId = router.StoreId(); yield return(WaitUntil(() => router.IsPurchaseReady(), () => { throw new TimeoutException("failed to ready."); })); var purchaseId = "dummy purchase Id"; var productId = "100_gold_coins"; var purchaseDone = false; var cor = router.PurchaseAsync( purchaseId, productId, pId => { // never success. Fail(); }, (pId, err, code, reason) => { purchaseDone = true; } ); while (cor.MoveNext()) { yield return(null); } yield return(WaitUntil( () => { var state = router.State(); if (state == PurchaseRouter.RouterState.Purchasing) { // httpが強制的に失敗するようにする。 forceFailResponse = true; } return purchaseDone; }, () => { throw new TimeoutException("timeout."); }, 15 )); forceFailResponse = false; var rebooted = false; var completed = false; router = new PurchaseRouter( iEnum => { runner.StartCoroutine(iEnum); }, productData => { // dummy response. return(new ProductInfo[] { new ProductInfo("100_gold_coins", "100_gold_coins_iOS", true, "one hundled of coins."), new ProductInfo("1000_gold_coins", "1000_gold_coins_iOS", true, "one ton of coins.") }); }, givenProductId => givenProductId, ticketData => Guid.NewGuid().ToString(), () => { rebooted = true; }, (err, code, reason) => { Fail("failed to boot store func. err:" + err + " reason:" + reason); }, backgroundPurchasedProductId => { completed = true; }, null, DummyResponsehandlingDelegate ); // store is renewed. not same id. AreNotEqual(storeId, router.StoreId()); yield return(WaitUntil( () => rebooted && completed, () => { throw new TimeoutException("timeout."); }, 10 )); }
public IEnumerator RetryPurchaseThenFinallySuccess() { forceFailResponse = false; // routerをhandling付きで生成すればいい。 router = new PurchaseRouter( iEnum => { runner.StartCoroutine(iEnum); }, productData => { // dummy response. return(new ProductInfo[] { new ProductInfo("100_gold_coins", "100_gold_coins_iOS", true, "one hundled of coins."), new ProductInfo("1000_gold_coins", "1000_gold_coins_iOS", true, "one ton of coins.") }); }, givenProductId => givenProductId, ticketData => ticketData, () => { }, (err, code, reason) => { }, backgroundPurchasedProductId => { }, null, DummyResponsehandlingDelegate ); yield return(WaitUntil(() => router.IsPurchaseReady(), () => { throw new TimeoutException("failed to ready."); })); var purchaseId = "dummy purchase Id"; var productId = "100_gold_coins"; var purchaseDone = false; var cor = router.PurchaseAsync( purchaseId, productId, pId => { purchaseDone = true; }, (pId, err, code, reason) => { // never fail. } ); while (cor.MoveNext()) { yield return(null); } yield return(WaitUntil( () => { var state = router.State(); if (state == PurchaseRouter.RouterState.Purchasing) { // httpが強制的に失敗するようにする。 forceFailResponse = true; } // リトライにN-1回失敗したあとに成功するようにフラグを変更する。 if (forceFailCount == PurchaseSettings.PURCHASED_MAX_RETRY_COUNT - 1) { forceFailResponse = false; } return purchaseDone; }, () => { throw new TimeoutException("timeout."); }, 10 )); }
public IEnumerator RetryPurchaseThenFail() { forceFailResponse = false; // routerをhandling付きで生成すればいい。 router = new PurchaseRouter( iEnum => { runner.StartCoroutine(iEnum); }, productData => { // dummy response. return(new ProductInfo[] { new ProductInfo("100_gold_coins", "100_gold_coins_iOS", true, "one hundled of coins."), new ProductInfo("1000_gold_coins", "1000_gold_coins_iOS", true, "one ton of coins.") }); }, givenProductId => givenProductId, ticketData => ticketData, () => { }, (err, code, reason) => { }, backgroundPurchasedProductId => { }, null, DummyResponsehandlingDelegate ); yield return(WaitUntil(() => router.IsPurchaseReady(), () => { throw new TimeoutException("failed to ready."); })); var purchaseId = "dummy purchase Id"; var productId = "100_gold_coins"; var purchaseDone = false; var cor = router.PurchaseAsync( purchaseId, productId, pId => { // never success. }, (pId, err, code, reason) => { purchaseDone = true; } ); while (cor.MoveNext()) { yield return(null); } yield return(WaitUntil( () => { var state = router.State(); if (state == PurchaseRouter.RouterState.Purchasing) { // httpが強制的に失敗するようにする。 forceFailResponse = true; } return purchaseDone; }, () => { throw new TimeoutException("timeout."); }, 15 )); True(router.State() == PurchaseRouter.RouterState.RetryFailed); /* * ・storeのリブートに際して失敗したtransactionが復活するかどうか * が実機に依存するため、このテストはiOS/Androidの実機上でしか動作しない。 */ #if UNITY_EDITOR var a = true; if (a) { yield break; } #elif UNITY_IOS || UNITY_ANDROID // pass. #else yield break; #endif // done, but transaction is remaining. var completed = false; // reload router will finish remaining transaction. router = new PurchaseRouter( iEnum => { runner.StartCoroutine(iEnum); }, productData => { // dummy response. return(new ProductInfo[] { new ProductInfo("100_gold_coins", "100_gold_coins_iOS", true, "one hundled of coins."), new ProductInfo("1000_gold_coins", "1000_gold_coins_iOS", true, "one ton of coins.") }); }, givenProductId => givenProductId, ticketData => ticketData, () => { }, (err, code, reason) => { }, backgroundPurchasedProductId => { completed = true; } ); yield return(WaitUntil( () => completed, () => { throw new TimeoutException("failed to complete remaining transaction."); } )); }
public IEnumerator ChangePurhcaseSucceededRequest() { var dateTimeStr = DateTime.Now.Ticks.ToString(); Func <string, byte[]> onTicketRequestFunc = givenProductId => { var data = new SampleTicketJsonData(givenProductId, dateTimeStr); var jsonStr = JsonUtility.ToJson(data); return(Encoding.UTF8.GetBytes(jsonStr)); }; router = new PurchaseRouter( iEnum => runner.StartCoroutine(iEnum), () => PurchaseRouter.RequestProductInfosAs.Binary, productData => { // dummy response. return(new ProductInfo[] { new ProductInfo("100_gold_coins", "100_gold_coins_iOS", true, "one hundled of coins."), new ProductInfo("1000_gold_coins", "1000_gold_coins_iOS", true, "one ton of coins.") }); }, onTicketRequestFunc,// ここがリクエストに乗っかるので、ticketDataの値でassertを書けばいい。 ticketData => { Assert.True(ticketData is byte[], "not byte[], but ticketData:" + ticketData); var ticketDataStr = Encoding.UTF8.GetString((byte[])ticketData); True(ticketDataStr.Contains(dateTimeStr)); return(ticketDataStr); }, () => { }, (err, code, reason) => { }, ticketAndReceipt => Encoding.UTF8.GetBytes(JsonUtility.ToJson(ticketAndReceipt)), ticketAndReceipt => Encoding.UTF8.GetBytes(JsonUtility.ToJson(ticketAndReceipt)), failData => Encoding.UTF8.GetBytes(JsonUtility.ToJson(failData)), (backgroundPurchasedProductId, data) => { }, null, DummyResponsehandlingDelegate ); yield return(WaitUntil( () => router.IsPurchaseReady(), () => { throw new TimeoutException("failed to ready."); } )); var purchaseId = "dummy purchase Id"; var productId = "100_gold_coins"; var done = false; var cor = router.PurchaseAsync( purchaseId, productId, pId => { done = true; }, (pId, err, code, reason) => { // do nothing. } ); while (done) { yield return(null); } }