// Callback from native code
        void IStore.LaunchPurchase_Done(string message)
        {
            // Extract promise and allow again
            Promise <PurchasedProduct> promise;

            lock (this) {
                promise = LastLaunchProductPromise;
                LastLaunchProductPromise = null;
            }

            if (promise == null)
            {
                Debug.LogWarning("Responding to LaunchPurchase without having promise set");
            }

            Bundle json = Bundle.FromJson(message);

            if (json.Has("error"))
            {
                promise.Reject(ParseError(json));
                return;
            }

            PurchasedProduct product = new PurchasedProduct(
                Common.ParseEnum <StoreType>(json["store"], StoreType.Appstore),
                json["productId"], json["internalProductId"], json["price"],
                json["currency"], json["receipt"], json["token"]);

            promise.Resolve(product);
        }
        Promise <Done> IStore.TerminatePurchase(PurchasedProduct product)
        {
            // Already in progress? Refuse immediately.
            lock (this) {
                if (LastTerminatePurchasePromise != null)
                {
                    return(Promise <Done> .Rejected(new CotcException(ErrorCode.AlreadyInProgress, "Terminating purchase")));
                }
                LastTerminatePurchasePromise = new Promise <Done>();
            }

            Bundle arg = Bundle.CreateObject();

            arg["token"]             = product.Token;
            arg["internalProductId"] = product.InternalProductId;

            // Will call back the CotcInappPurchaseGameObject
            CotcInappPurchase_terminatePurchase(arg.ToJson(), (this as IStore).TerminatePurchase_Done);
            return(LastTerminatePurchasePromise);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Extremely important call to be made in case success is returned from #LaunchPurchase and
 /// then validated to #CotcSdk.GamerStore.ValidateReceipt. Failure to do that may leave
 /// transactions in an open state and disrupt the purchase process (delivering several times
 /// the product, etc.).
 /// </summary>
 public Promise <Done> CloseTransaction(PurchasedProduct product)
 {
     return(Store.TerminatePurchase(product));
 }
Ejemplo n.º 4
0
    public void DoListProducts()
    {
        var inApp = FindObjectOfType<CotcInappPurchaseGameObject>();
        if (!RequireGamer()) return;

        var pp = new PurchasedProduct[1];
        var result = new ValidateReceiptResult[1];
        Gamer.Store.ListConfiguredProducts()
            .Then(products => {
                Debug.Log("Got BO products.");
                return inApp.FetchProductInfo(products);
            })
            .Then(enrichedProducts => {
                Debug.Log("Received enriched products");
                foreach (ProductInfo pi in enrichedProducts) {
                    Debug.Log(pi.ToJson());
                }

                // Purchase the first one
                return inApp.LaunchPurchase(Gamer, enrichedProducts[0]);
            })
            .Then(purchasedProduct => {
                Debug.Log("Purchase ok: " + purchasedProduct.ToString());
                pp[0] = purchasedProduct;
                return Gamer.Store.ValidateReceipt(purchasedProduct.StoreType, purchasedProduct.CotcProductId, purchasedProduct.PaidPrice, purchasedProduct.PaidCurrency, purchasedProduct.Receipt);
            })
            .Then(validationResult => {
                Debug.Log("Validated receipt");
                result[0] = validationResult;
                return inApp.CloseTransaction(pp[0]);
            })
            .Then(done => {
                Debug.Log("Purchase transaction completed successfully: " + result[0].ToString());
            })
            .Catch(ex => {
                Debug.LogError("Error during purchase: " + ex.ToString());
            });
    }
Ejemplo n.º 5
0
        Promise<Done> IStore.TerminatePurchase(PurchasedProduct product)
        {
            // Already in progress? Refuse immediately.
            lock (this) {
                if (LastTerminatePurchasePromise != null) {
                    return Promise<Done>.Rejected(new CotcException(ErrorCode.AlreadyInProgress, "Terminating purchase"));
                }
                LastTerminatePurchasePromise = new Promise<Done>();
            }

            Bundle arg = Bundle.CreateObject();
            arg["token"] = product.Token;
            arg["internalProductId"] = product.InternalProductId;

            // Will call back the CotcInappPurchaseGameObject
            CotcInappPurchase_terminatePurchase(arg.ToJson());
            return LastTerminatePurchasePromise;
        }
Ejemplo n.º 6
0
        // Callback from native code
        void IStore.LaunchPurchase_Done(string message)
        {
            // Extract promise and allow again
            Promise<PurchasedProduct> promise;
            lock (this) {
                promise = LastLaunchProductPromise;
                LastLaunchProductPromise = null;
            }

            if (promise == null) {
                Debug.LogWarning("Responding to LaunchPurchase without having promise set");
            }

            Bundle json = Bundle.FromJson(message);
            if (json.Has("error")) {
                promise.Reject(ParseError(json));
                return;
            }

            PurchasedProduct product = new PurchasedProduct(
                Common.ParseEnum<StoreType>(json["store"], StoreType.Appstore),
                json["productId"], json["internalProductId"], json["price"],
                json["currency"], json["receipt"], json["token"]);
            promise.Resolve(product);
        }
 /// <summary>
 /// Extremely important call to be made in case success is returned from #LaunchPurchase and
 /// then validated to #CotcSdk.GamerStore.ValidateReceipt. Failure to do that may leave
 /// transactions in an open state and disrupt the purchase process (delivering several times
 /// the product, etc.).
 /// </summary>
 public Promise<Done> CloseTransaction(PurchasedProduct product)
 {
     return Store.TerminatePurchase(product);
 }