// // --- IAppcoinsStoreListener // public void OnInitialized(AppcoinsStoreController controller) { onInitializeSuccess.Invoke(); // Purchasing has succeeded initializing. Collect our Purchasing references. SetStatus("OnInitialized: PASS"); // Overall Purchasing system, configured with products for this application. m_StoreController = controller; if (_pendingPurchaseSkuID != null && !_pendingPurchaseSkuID.Equals("")) { SetStatus("OnInitialized: PASS! Resuming pending purchase of: " + _pendingPurchaseSkuID); BuyProductID(_pendingPurchaseSkuID); _pendingPurchaseSkuID = ""; } }
public void BuyProductID(string productId) { if (Application.isEditor) { AppcoinsProduct product = new AppcoinsProduct(); product.skuID = productId; ProcessPurchase(product); } else { //Fire event //Remove APPC from the price string string priceStr = _appcoinsPurchasing.GetAPPCPriceStringForSKU(productId).Replace(" APPC", ""); FireBuyIntentEvent(productId, priceStr); //Check if wallet is installed if (!_appcoinsPurchasing.HasWalletInstalled()) { SetStatus("BuyProductID: FAIL. Not purchasing product, no wallet app found on device!"); _appcoinsPurchasing.PromptWalletInstall(); _pendingPurchaseSkuID = productId; m_StoreController = null; //To force reinitialization return; } // If Purchasing has been initialized ... if (IsInitialized()) { // ... look up the Product reference with the general product identifier and the Purchasing // system's products collection. AppcoinsProduct product = m_StoreController.products.WithID(productId); //If the look up found a product for this device's store and that product is ready to be sold ... if (product != null) { if (product.productType == AppcoinsProductType.NonConsumable && OwnsProduct(productId)) { OnPurchaseFailed(product, AppcoinsPurchaseFailureReason.DuplicateTransaction); SetStatus("BuyProductID: FAIL. Not purchasing product, non-consumable is already owned!"); return; } SetStatus(string.Format("Purchasing product asychronously: '{0}'", product.skuID)); // ... buy the product. Expect a response either through ProcessPurchase or OnPurchaseFailed // asynchronously. /* TODO: for security, generate your payload here for verification. See the comments on * verifyDeveloperPayload() for more info. Since this is a SAMPLE, we just use * an empty string, but on a production app you should carefully generate this. * TODO: On this payload the developer's wallet address must be added, or the purchase does NOT work. */ string payload = ""; m_StoreController.InitiatePurchase(product, payload); } // Otherwise ... else { // ... report the product look-up failure situation SetStatus("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase"); } } // Otherwise ... else { // ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or // retrying initiailization. SetStatus("BuyProductID FAIL. Not initialized. Trying to initialize now"); InitializePurchasing(); } } }