Search Unity

[Solved] In-App purchase in Windows Store Apps? (8.1)

Discussion in 'Windows' started by KungFooMasta, Mar 10, 2015.

  1. KungFooMasta

    KungFooMasta

    Joined:
    May 27, 2014
    Posts:
    24
    Hi community,

    I was having problems getting In-App purchase working in my game on the Windows Store App (8.1) platform, but I think I got it working. Wanted to post my solution in case it helps anybody.

    Normally I try to make all the 'async' APIs run synchronously by using the "Task.Run(async () => { my function }).Wait()" code, however in WP8, the marketplace would not appear unless I ran it like this:

    Code (CSharp):
    1.  
    2.                 System.Windows.Deployment.Current.Dispatcher.BeginInvoke(
    3.                     async () =>
    4.                     {
    5.                         try
    6.                         {
    7.                             string receipt = await CurrentApp.RequestProductPurchaseAsync(productListing.ProductId, true);
    8.  
    All Windows examples have the purchasing done from the UI thread.. it seems like the dispatcher has to be used when trying to make a purchase, so I also imitated this in my WSA implementation.

    Code (CSharp):
    1.  
    2. #elif NETFX_CORE
    3.         Task.Run(
    4.             async () =>
    5.             {
    6.                 await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
    7.                     CoreDispatcherPriority.Normal,
    8.                     async () =>
    9.                     {
    10.                     PurchaseResults result = await CurrentApp.RequestProductPurchaseAsync(productID);
    11.                     switch(result.Status)
    12.                     {
    13.                     case ProductPurchaseStatus.Succeeded:
    14.                         await CurrentApp.ReportConsumableFulfillmentAsync(productID, result.TransactionId);
    15.                         OnPurchaseDismissed(productID);
    16.                         break;
    17.                     case ProductPurchaseStatus.NotFulfilled:
    18.                         InAppPurchaseManager.Instance.CheckUnfulfilledConsumables();
    19.                         await CurrentApp.ReportConsumableFulfillmentAsync(productID, result.TransactionId);
    20.                         OnPurchaseDismissed(productID);
    21.                         break;
    22.                     }
    23.                 });
    24.             }).Wait();
    25. #else
    26.  
    Now its trying to reach out to marketplace, but fails since my app isn't listed. But at least its getting the marketplace involved.. I think it will work after I update/re-list my game.
     
  2. maxgreen

    maxgreen

    Joined:
    Oct 13, 2012
    Posts:
    8