/// <summary> /// Purchases the product with given id. /// You need to specify whether your 'id' is store-specific or generic. /// </summary> public static void PurchaseProduct(IAP.OnPurchasedHandler callback, string id, bool isStoreSpecific) { onPurchaseComplete = callback; if (IsInitialized) { Product product = ( isStoreSpecific ? storeController.products.WithStoreSpecificID(id) : storeController.products.WithID(id) ); if (product == null) { DoOnIAPComplete(null, new IAPFail(IAPFail.Reason.ProductNotFound)); return; } if (!product.availableToPurchase) { DoOnIAPComplete(null, new IAPFail(IAPFail.Reason.ProductNotAvailable)); return; } storeController.InitiatePurchase(product); } else { DoOnIAPComplete(null, new IAPFail(IAPFail.Reason.NotInitialized)); } }
/// <summary> /// Do the callback for delegate: IAP.OnPurchasedHandler /// </summary> private static void DoOnIAPComplete(IAPSuccess success, IAPFail fail) { if (onPurchaseComplete != null) { onPurchaseComplete(success, fail); } onPurchaseComplete = null; }