Example #1
0
        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);
        }
 public static extern MLResult.Code MLPurchaseHistoryQueryGetPageResult(ulong historyHandle, ref MLPurchaseHistoryResult outPageResult);