0

我有此代码用于我的应用内购买

string receipt = await Store.CurrentApp.RequestProductPurchaseAsync(pID, false);

文档指出,即使以下情况,此方法也会返回成功值:

there's no network connection available
the user cancels out of the dialog
the user's authentication fails

You should treat a success result as indicating the async process completed without      
errors. To ensure that the transaction itself was successful, check the   
LicenseInformation element in the returned receipt. 

在我解锁购买功能之前,有没有一种快速的方法来验证特定项目的收据是否实际成功?目前,如果没有错误,该功能将始终解锁,因为收据未经过验证。

我的代码:

    private async void inAppPurchase(string key)
    {

        if (!Store.CurrentApp.LicenseInformation.ProductLicenses[key].IsActive)
        {
            try
            {
                // The customer doesn't own this feature, so 
                // show the purchase dialog.
                MockIAPLib.ListingInformation li = await Store.CurrentApp.LoadListingInformationAsync();
                string pID = li.ProductListings[key].ProductId;

                //purchase successful
                string receipt = await Store.CurrentApp.RequestProductPurchaseAsync(pID, false);

                //Check the receipt for 

                switch (key)
                {
                    case "IsAdsVisibleSetting":
                        settings.IsAdsVisibleSetting = false;
                        break;
                    case "style_2":
                        fontFolder[key] = true;
                        settings.AllowedFontSetting = fontFolder;
                        break;
                    case "backgrounds_2":
                        backgroundGroups[key] = true;                          
                        settings.AllowedBackgroundGroupsSetting = backgroundGroups;
                        break;
                    case "backgrounds_3":
                        backgroundGroups[key] = true;
                        settings.AllowedBackgroundGroupsSetting = backgroundGroups;
                        break;
                }

                RenderStoreItems();
            }
            catch (Exception)
            {
                MessageBox.Show("Sorry, the in-app purchase was not completed because an error occurred.", "Purchasing Error", MessageBoxButton.OK);
            }
        }
    }
4

1 回答 1

0

购买方法调用后,请确保在完整填写货物之前检查许可证是否有效。如果是消耗品,则调用 ReportProductFulfillment() 方法。

CurrentApp.LicenseInformation.ProductLicenses[key].IsActive

顺便说一句,在您的代码中 includeReceipt 值设置为 false - 将始终保持“收据”为空。

于 2013-04-25T21:54:18.457 回答