private MLResult GetAllPurchaseHistoryInternal(Action <MLPurchaseHistoryQuery> callback) { ulong handle = MagicLeapNativeBindings.InvalidHandle; MLResult.Code historyResult = MLPurchaseNativeBindings.MLPurchaseHistoryQueryCreate(ref handle); MLResult result = MLResult.Create(historyResult); if (!result.IsOk || !MagicLeapNativeBindings.MLHandleIsValid(handle)) { MLPluginLog.ErrorFormat("MLPurchase.GetAllPurchaseHistoryInternal failed to create purchase history query. Reason: {0}", result); return(result); } historyResult = MLPurchaseNativeBindings.MLPurchaseHistoryQueryGetPage(handle, MaxPurchaseHistoryItems); result = MLResult.Create(historyResult); if (!result.IsOk) { MLPluginLog.ErrorFormat("MLPurchase.GetAllPurchaseHistoryInternal failed to submit purchase history query. Reason: {0}", result); DestroyPurchaseHistoryQuery(handle); } else { _pendingPurchaseHistoryQueries.Add(new PurchaseHistoryQueryInfo(handle, callback)); } return(result); }
private MLResult MakePurchaseInternal(string token, Action <MLPurchaseRequest> callback) { ulong handle = MagicLeapNativeBindings.InvalidHandle; MLResult.Code purchaseResult = MLPurchaseNativeBindings.MLPurchaseCreate(ref handle); MLResult result = MLResult.Create(purchaseResult); if (!result.IsOk || !MagicLeapNativeBindings.MLHandleIsValid(handle)) { MLPluginLog.ErrorFormat("MLPurchase.MakePurchaseInternal failed to create purchase request. Reason: {0}", result); return(result); } MLPluginLog.Debug("Purchasing: " + token); purchaseResult = MLPurchaseNativeBindings.MLPurchaseSubmit(handle, token); result = MLResult.Create(purchaseResult); if (!result.IsOk) { MLPluginLog.ErrorFormat("MLPurchase.MakePurchaseInternal failed to submit purchase request. Reason: {0}", result); DestroyPurchaseRequest(handle); } else { _pendingPurchaseRequests.Add(new PurchaseRequestInfo(handle, callback)); } return(result); }
private MLResult GetItemDetailsInternal(string[] itemIds, Action <MLPurchaseItemDetail> callback) { // Create handle ulong handle = MagicLeapNativeBindings.InvalidHandle; MLResult.Code detailsResult = MLPurchaseNativeBindings.MLPurchaseItemDetailsCreate(ref handle); MLResult result = MLResult.Create(detailsResult); if (!result.IsOk || !MagicLeapNativeBindings.MLHandleIsValid(handle)) { MLPluginLog.ErrorFormat("MLPurchase.GetItemDetailsInternal failed, unable to create item details query. Reason: {0}", result); return(result); } result = InitiateItemDetailsQuery(handle, itemIds); if (!result.IsOk) { MLPluginLog.ErrorFormat("MLPurchase.GetItemDetailsInternal failed to submit item details request. Reason: {0}", result); DestroyItemDetail(handle); } else { _pendingItemDetailQueries.Add(new ItemDetailQueryInfo(handle, callback)); } return(result); }
private void UpdatePurchaseHistoryQuery() { List <PurchaseHistoryQueryInfo> completedQueries = new List <PurchaseHistoryQueryInfo>(); for (int i = 0; i < _pendingPurchaseHistoryQueries.Count; ++i) { PurchaseHistoryQueryInfo info = _pendingPurchaseHistoryQueries[i]; MLPurchaseHistoryResult historyResult = MLPurchaseHistoryResult.Create(); info.Details.Result = MLPurchaseNativeBindings.MLPurchaseHistoryQueryGetPageResult(info.Handle, ref historyResult); if (info.Details.Result == MLResult.Code.Ok) { if (historyResult.status == MLCloudStatus.Done) { uint numPurchaseConfirmationsToAdd = Math.Min(historyResult.count, info.NumItemsLeft); for (int j = 0; j < numPurchaseConfirmationsToAdd; j++) { IntPtr offsetPtr = new IntPtr(historyResult.confirmations.ToInt64() + (Marshal.SizeOf(typeof(MLPurchaseConfirmation)) * j)); info.Details.PurchaseConfirmations.Add((MLPurchaseConfirmation)Marshal.PtrToStructure(offsetPtr, typeof(MLPurchaseConfirmation))); } info.NumItemsLeft -= numPurchaseConfirmationsToAdd; MLPluginLog.DebugFormat("purchase history query: hasNextPage {0}, fetchAll {1}, NumItemsLeft {2}", historyResult.hasNextPage ? "true" : "false", info.FetchAll ? "true" : "false", info.NumItemsLeft.ToString()); // TESTING if (historyResult.hasNextPage && (info.FetchAll || info.NumItemsLeft > 0)) { info.Details.Result = MLPurchaseNativeBindings.MLPurchaseHistoryQueryGetPage(info.Handle, Math.Min(info.NumItemsLeft, MaxPurchaseHistoryItems)); if (info.Details.Result != MLResult.Code.Ok) { MLPluginLog.ErrorFormat("MLPurchase.UpdatePurchaseHistoryQuery failed to query for succeeding purchase history pages. Reason: {0}", GetResultString(info.Details.Result)); completedQueries.Add(info); } } else { completedQueries.Add(info); } } } else { MLPluginLog.Debug("purchase history query get page result, result: " + info.Details.Result.ToString()); completedQueries.Add(info); } } PublishPurchaseHistories(completedQueries); }
private bool DestroyPurchaseHistoryQuery(ulong handle) { if (MagicLeapNativeBindings.MLHandleIsValid(handle)) { MLResult.Code result = MLPurchaseNativeBindings.MLPurchaseHistoryQueryDestroy(handle); if (result == MLResult.Code.Ok) { return(true); } MLPluginLog.ErrorFormat("MLPurchase.DestroyPurchaseHistoryQuery failed to free purchase history query handle. Reason: {0}", GetResultString(result)); return(false); } MLPluginLog.Error("MLPurchase.DestroyPurchaseHistoryQuery failed, handle is invalid."); return(false); }
/// <summary> /// Properly dispose the Item Detail Query handle /// </summary> /// <param name="handle">Item Detail Query handle to be destroyed</param> /// <returns>Retrun true on success, otherwise false</returns> private bool DestroyItemDetail(ulong handle) { if (MagicLeapNativeBindings.MLHandleIsValid(handle)) { MLResult.Code result = MLPurchaseNativeBindings.MLPurchaseItemDetailsDestroy(handle); if (result == MLResult.Code.Ok) { return(true); } MLPluginLog.ErrorFormat("MLPurchase.DestroyItemDetail failed, unable to free item details handle. Reason: {0}", GetResultString(result)); return(false); } MLPluginLog.ErrorFormat("MLPurchase.DestroyItemDetail failed, handle is invalid."); return(false); }
/// <summary> /// Begin query for the whole purchase history /// </summary> /// <param name="callback">Method to be called when the query is completed</param> /// <returns> /// MLResult.Result will be MLResult.Code.Ok if successful. /// /// MLResult.Result will be MLResult.Code.AllocFailed if the handle cannot be allocated. /// /// MLResult.Result will be MLResult.Code.UnspecifiedFailure if there is an unexpected failure. /// /// MLResult.Result will be MLResult.Code.InvalidParam if any input parameters are invalid. /// /// MLResult.Result will be MLResult.Code.PrivilegeDenied if there is an privilege error with the purchase details system call. /// /// MLResult.Result will be MLResult.Code.CloudSystemError if there is an issue with the cloud service, e.g. service is not available for any reason. /// </returns> public static MLResult GetAllPurchaseHistory(Action <MLPurchaseHistoryQuery> callback) { if (!IsStarted) { MLResult result = MLResult.Create(MLResult.Code.UnspecifiedFailure, "Please call MLPurchase.Start() first"); MLPluginLog.ErrorFormat("MLPurchase.GetAllPurchaseHistory failed to get entire purchase history. Reason: {0}", result); return(result); } if (callback == null) { MLResult result = MLResult.Create(MLResult.Code.InvalidParam, "Invalid MakePurchaseHistoryQuery params"); MLPluginLog.ErrorFormat("MLPurchase.GetAllPurchaseHistory failed to get entire purchase history. Reason: {0}", result); return(result); } return(Instance.GetAllPurchaseHistoryInternal(callback)); }
/// <summary> /// Initiates a purchase /// </summary> /// <param name="token">Token returned by MLPurchaseItemDetailsResult</param> /// <param name="callback">Method to be called when the purchase is completed</param> /// <returns> /// MLResult.Result will be MLResult.Code.Ok if successful. /// /// MLResult.Result will be MLResult.Code.AllocFailed if the handle cannot be allocated. /// /// MLResult.Result will be MLResult.Code.UnspecifiedFailure if there is an unexpected failure. /// /// MLResult.Result will be MLResult.Code.InvalidParam if any input parameters are invalid. /// /// MLResult.Result will be MLResult.Code.PrivilegeDenied if there is an privilege error with the purchase details system call. /// /// MLResult.Result will be MLResult.Code.CloudSystemError if there is an issue with the cloud service, e.g. service is not available for any reason. /// </returns> public static MLResult MakePurchase(string token, Action <MLPurchaseRequest> callback) { if (!IsStarted) { MLResult result = MLResult.Create(MLResult.Code.UnspecifiedFailure, "Please call MLPurchase.Start() first"); MLPluginLog.ErrorFormat("MLPurchase.MakePurchase failed to make a purchase. Reason: {0}", result); return(result); } if (callback == null) { MLResult result = MLResult.Create(MLResult.Code.InvalidParam, "Invalid callback parameter passed."); MLPluginLog.ErrorFormat("MLPurchase.MakePurchase failed to make a purchase. Reason: {0}", result); return(result); } return(Instance.MakePurchaseInternal(token, callback)); }
/// <summary> /// Request for the details for the given IAP ids /// </summary> /// <param name="itemIds">Array of IAP ids</param> /// <param name="callback">Method to be called when the query is completed</param> /// <returns> /// MLResult.Result will be MLResult.Code.Ok if successful. /// /// MLResult.Result will be MLResult.Code.AllocFailed if the handle cannot be allocated. /// /// MLResult.Result will be MLResult.Code.UnspecifiedFailure if there is an unexpected failure. /// /// MLResult.Result will be MLResult.Code.InvalidParam if any input parameters are invalid. /// /// MLResult.Result will be MLResult.Code.PrivilegeDenied if there is an privilege error with the purchase details system call. /// /// MLResult.Result will be MLResult.Code.CloudSystemError if there is an issue with the cloud service, e.g. service is not available for any reason. /// </returns> public static MLResult GetItemDetails(string[] itemIds, Action <MLPurchaseItemDetail> callback) { if (!IsStarted) { MLResult result = MLResult.Create(MLResult.Code.UnspecifiedFailure, "Please call MLPurchase.Start() first."); MLPluginLog.ErrorFormat("MLPurchase.GetItemDetails failed to get item details. Reason: {0}", result); return(result); } if (itemIds == null || itemIds.Length == 0 || callback == null) { MLResult result = MLResult.Create(MLResult.Code.InvalidParam, "Invalid GetItemDetails params."); MLPluginLog.Error(result); return(result); } return(Instance.GetItemDetailsInternal(itemIds, callback)); }
/// <summary> /// Create an initialized version of this struct. /// </summary> /// <returns>An initialized version of this struct.</returns> public static SettingsNative Create() { if (!defaultSettings.HasValue) { SettingsNative settings = new SettingsNative() { Version = 1u, SwayHistorySize = 0u, MaxDeltaAngle = 0.0f, ControlDampeningFactor = 0.0f, MaxSwayAngle = 0.0f, MaximumHeadposeRotationSpeed = 0.0f, MaximumHeadposeMovementSpeed = 0.0f, MaximumDepthDeltaForSway = 0.0f, MinimumDistance = 0.0f, MaximumDistance = 0.0f, MaximumSwayTimeSeconds = 0.0f, EndResolveTimeoutSeconds = 0.0f, }; try { MLResult.Code result = NativeBindings.MLMovementGetDefaultSettings(out settings); if (result != MLResult.Code.Ok) { MLPluginLog.ErrorFormat("MLMovement.NativeBindings.SettingsNative.Create failed to get default movement settings. Reason: {0}", result); } } catch (System.DllNotFoundException) { MLPluginLog.Error("MLMovement API is currently available only on device."); } catch (System.EntryPointNotFoundException) { MLPluginLog.Error("MLMovement API symbols not found"); } defaultSettings = settings; } return(defaultSettings.Value); }