GrowSing
GrowSing

Reputation: 623

In app purchase, WinRT, C#

I am trying to implement IaPs into my application (WinRT platform), using C# and I can't find any good tutorials or even documentation (only docum. I have found is for Silverlight...).

I have created a beta app and one free IaP for it. I have tested it locally (using CurrentAppSimulator) and everything worked fine, but now in that beta (I found out that creating beta is only way how to test it with real CurrentApp instance) I can't even get my ListingInformation (it seems to be emply, or even null - can't say because I can't debug it).

I have this ini method:

    private async void ini()
        {
#if DEBUG
            StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("Data");
            StorageFile proxyFile = await proxyDataFolder.GetFileAsync("WindowsStoreProxy.xml");
            await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);

            listing = await CurrentAppSimulator.LoadListingInformationAsync();
#else
            listing = await CurrentApp.LoadListingInformationAsync();
#endif
        }

Listing is declared global. But then I call this and nothing show up (emply sb, emplty dialog).

private async void btnListAllProducts_Click_1(object sender, RoutedEventArgs e)
    {
        StringBuilder sb = new StringBuilder();

        foreach (var product in listing.ProductListings)
        {
            sb.AppendLine(string.Format("{0}, {1}, {2}",
              product.Key,
              product.Value.Name,
              product.Value.FormattedPrice));
        }

        var messageDialog = new MessageDialog(sb.ToString());
        await messageDialog.ShowAsync();
    }

In some older tutorials for Silverlight I found out that there was some appmanifest connection (copying some ID), but I can't find it, so I skip this step (maybe reason of my "bug"??).

Anyway I have few other question. As I was testing in CurrentAppSimulator, it never saved up, so after restarting of my app I was able to buy that item again. Do I have to save some licence information somewhere?

My buy method looks like this:

async private void btnBuySuperMap_Click_1(object sender, RoutedEventArgs e)
        {
            var newMapItem =
            listing.ProductListings.FirstOrDefault(p => p.Value.ProductId == "11111" && p.Value.ProductType == ProductType.Durable);

            string receipt;
            bool licInfo;
#if DEBUG
            licInfo = CurrentAppSimulator.LicenseInformation.ProductLicenses[newMapItem.Value.ProductId].IsActive;
#else
            licInfo = CurrentApp.LicenseInformation.ProductLicenses[newMapItem.Value.ProductId].IsActive;
#endif
            try
            {
                if (licInfo)
                {
                    var messageDialog = new MessageDialog("You already own this Map!");
                    await messageDialog.ShowAsync();
                }
                else
                {
#if DEBUG
                    receipt = await CurrentAppSimulator.RequestProductPurchaseAsync(newMapItem.Value.ProductId, true);
#else
                    receipt = await CurrentApp.RequestProductPurchaseAsync(newMapItem.Value.ProductId, true);
#endif
                    txtBoughtSW.Visibility = Visibility.Visible;
                    txtBoughtSW.Text = "You own the Super Map Now!";
                }
            }
            catch (Exception ex)
            {
                var messageDialog = new MessageDialog(ex.ToString());
                messageDialog.ShowAsync();
            }
        }

Last thing I would like to say, it is in first, simple, testing look. After this works Ill implement it better of course. :)

Thanks in advance for any advice!

PS: Do anyone knows about some good tutorial for this? If not, I might create my own for others (with some help).

EDIT: At this moment it's Windows (tablet) version (WinRT, Universal). WindowsPhone implementation is next (after successful implementation of this) (maybe shared class?? don't know).

Upvotes: 1

Views: 133

Answers (1)

GrowSing
GrowSing

Reputation: 623

It's done. I edited some information of that IaP item in Dev Center and now it's working. Tip: sometimes it doesn't work if you don't fill all (even optional) info like description etc., language description must be (probably) for all language your apps supports (even MS says that it's optionally as well)..

Upvotes: 1

Related Questions