Esempio n. 1
0
    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
                         ));
    }
Esempio n. 2
0
    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
                         ));
    }
Esempio n. 3
0
    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."); }
                         ));
    }