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 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); }