/// <summary> /// Check if the product is already activated on MEGA license server /// </summary> /// <param name="productId">Product identifier</param> private static async Task CheckLicenseAsync(string productId) { try { if (string.IsNullOrEmpty(productId)) { return; } #if DEBUG var receipt = await CurrentAppSimulator.GetProductReceiptAsync(productId); #else var receipt = await CurrentApp.GetProductReceiptAsync(productId); #endif if (string.IsNullOrEmpty(receipt)) { return; } LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Checking product license..."); LogService.Log(MLogLevel.LOG_LEVEL_DEBUG, "License info: " + receipt); if (!CheckReceiptIdStatus(receipt)) { await ActivateMegaLicenseAsync(receipt); } } catch (Exception e) { // If an error occurs, ignore. App will try again on restart LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Error (re-)checking licenses", e); } }
public static void GetProductReceipt(string productId, Action <CallbackResponse <string> > OnProductReceiptAcquired) { Utils.RunOnWindowsUIThread(async() => { String receipt = String.Empty; // exceptions raised on the UI thread will be delivered on the UI thread.. so catch exception that is happening on // the UI thread, and marshal it back to the Unity app thread. try { if (_isLicenseSimulationOn) { receipt = await CurrentAppSimulator.GetProductReceiptAsync(productId); } else { receipt = await CurrentApp.GetProductReceiptAsync(productId); } } catch (Exception ex) { Utils.RunOnUnityAppThread(() => { if (OnProductReceiptAcquired != null) { OnProductReceiptAcquired(new CallbackResponse <string> { Result = null, Exception = ex, Status = CallbackStatus.Failure }); } }); return; } Utils.RunOnUnityAppThread(() => { if (OnProductReceiptAcquired != null) { OnProductReceiptAcquired(new CallbackResponse <string> { Result = receipt, Exception = null, Status = CallbackStatus.Success }); } }); }); }
public IAsyncOperation <string> RequestProductReceiptAsync(string productId) { return(CurrentAppSimulator.GetProductReceiptAsync(productId)); }
public static async Task <string> GetProductReceiptAsync(bool isTestingMode, String productId) { return(isTestingMode ? await CurrentAppSimulator.GetProductReceiptAsync(productId) : await CurrentApp.GetProductReceiptAsync(productId)); }