Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

UWP Store Win32:

 

Code sample to query the app in the Windows Store and purchase the first addon

 

The app runs in the Windows Store and is designed as Win32 app. Therefore, the store data is retrieved using the Windows.Store.Services.

 

The following is C # code

 

 

The app in the store is designed in such a way that the app is generally free and after an internal test phase the extensions are only possible against the purchase of the full version and the app can continue to operate in reduced mode.

 

C # Code for retrieving and managing app data data in the Windows Store

      #region Windows-Store

        //------------------< region: Windows-Store >------------------

        private StoreContext _Store_context = null;

        private StoreAppLicense appLicense = null;

        private String _Store_SkuStoreId = null;

        private StoreLicense _Store_addOnLicense_0 = null;

 

        private bool _Store_IsPaid = false;

        private bool _Store_IsTestperiod = true;

        private DateTime _Store_DateStart_TestPeriod = Convert.ToDateTime(null);

        private int _Store_Testrange_in_Days = 30;

 

        private async void init_Store()

        {

            //-------------< init_Store()-------------

            //< get variables >

            await check_Store_IsPaid();

            if (_Store_IsPaid == false)

            {

                await check_init_Store_Testperiod();

            }

            //</ get variables >

 

            //< set Controls >

            if (_Store_IsPaid == true )

            {

                btnStore.Visibility = Visibility.Collapsed;

            }

            else

            {

                if (_Store_IsTestperiod==true  )

                {

                    //*IsTestperiod: everything works

                }

                else

                {

                    //< Testperiod is over >

                    btnStore.Visibility = Visibility.Visible;

                    btnOptions.IsEnabled = false;

                    btnControllers.IsEnabled = false;

                    //</ Testperiod is over >

                }

            }

            //</ set Controls >

 

 

            //-------------</ init_Store()-------------

        }

 

        public async Task<bool> check_init_Store_Testperiod()

        {

            //-------------< check_init_Store_Testperiod()-------------

            //----< get Start_Testperiod >----

            try

            {              

                //< Get Setting >

                var varDateStart_TestPeriod = ApplicationData.Current.LocalSettings.Values["DateStart_TestPeriod"];

                //</ Get Setting >

 

                if (varDateStart_TestPeriod is null)

                {

                    //< init testperiod >

                    _Store_DateStart_TestPeriod = DateTime.Now;

                    //< Save Setting >

                    ApplicationData.Current.LocalSettings.Values["DateStart_TestPeriod"] = _Store_DateStart_TestPeriod.ToString();

                    //</ Save Setting >

                    //</ init testperiod >

                }

                else

                {

                    //< convert setting >

                    _Store_DateStart_TestPeriod = Convert.ToDateTime(varDateStart_TestPeriod);

                    //</ convert setting >

                }

            }

            catch (Exception ex)

            {

                //< error >

                MessageDialog dialog = new MessageDialog( ex.Message , "Information: Check Store TestPeriod");

                await dialog.ShowAsync();

                return false;

                //</ error >

            }

            //----</ get Start_Testperiod >----

 

            //----< check in TestPeriod >----

            if(_Store_DateStart_TestPeriod.AddDays(_Store_Testrange_in_Days)>DateTime.Now )

            { _Store_IsTestperiod  = true; }

            else

            { _Store_IsTestperiod = false ; }

            //----</ check in TestPeriod >----

 

            //< output >

            return _Store_IsTestperiod;

            //</ output >

 

            //-------------</ check_init_Store_Testperiod()-------------

        }

 

        public async Task<bool> check_Store_IsPaid()

        {

            //-------------< check_Store_IsPaid()-------------

            //< check ok >

            if(_Store_IsPaid ==true)

            {

                return true;

            }

            //</ check ok >

 

            //----< get Setting: Store_IsPaid >----

            try

            {

                //< Get Setting >

                var varStore_IsPaid = ApplicationData.Current.LocalSettings.Values["Store_IsPaid"];

                //</ Get Setting >

 

                if (varStore_IsPaid is null)

                {

                    //< init testperiod >

                    _Store_IsPaid = false;

                    //< Save Setting >

                    ApplicationData.Current.LocalSettings.Values["Store_IsPaid"] = _Store_IsPaid ;

                    //</ Save Setting >

                    //</ init testperiod >

                }

                else

                {

                    //< convert setting >

                    _Store_IsPaid = Convert.ToBoolean(varStore_IsPaid);

                    //</ convert setting >

                }

            }

            catch (Exception ex)

            {

                //< error >

                MessageDialog dialog = new MessageDialog(ex.Message, "Information: Check Store Addon is Paid");

                await dialog.ShowAsync();

                return false;

                //</ error >

            }

            //----</ get Setting: Store_IsPaid >----

 

 

 

            //< output >

            return _Store_IsPaid;

            //</ output >

 

            //-------------</ check_Store_IsPaid()-------------

        }

 

        public async Task<bool> get_Store_IsPaid()

        {

            //-------------< get_Store_LicenseInfo()-------------

            if (_Store_context == null)

            {

                _Store_context = StoreContext.GetDefault();  //UWP App

            }

           

            //< get Store Data >

            appLicense = await _Store_context.GetAppLicenseAsync();

            //</ get Store Data >

 

           

            if (appLicense == null)

            {

                return false;

            }

            else

            {

                //--< show License Infos >--

                _Store_SkuStoreId= appLicense.SkuStoreId;

                if (appLicense.AddOnLicenses.Count>0)

                {

                    foreach (KeyValuePair<string, StoreLicense> item in appLicense.AddOnLicenses)

                    {

                        _Store_addOnLicense_0 = item.Value;

                       

                        //--< check first AddOn >--

                        if(_Store_addOnLicense_0.IsActive==true)

                        {

                            _Store_IsPaid = true;

                            return true;                           

                        }

                        break;

                        //--</ check first AddOn >--

                    }

                }

                //* nothing found is false

                return false ;

                //--</ show License Infos >--

            }

 

           

            //-------------</ get_Store_LicenseInfo()-------------

        }

 

        public async Task<bool> get_Store_AddOn_License_0()

        {

            //-------------< get_Store_AddOn_License_0()-------------

            if (_Store_context == null)

            {

                _Store_context = StoreContext.GetDefault();  //UWP App

               

            }

 

            //< get Store Data >

            appLicense = await _Store_context.GetAppLicenseAsync();

            //</ get Store Data >

 

 

            if (appLicense == null)

            {

                return false;

            }

            else

            {

                //--< show License Infos >--

                if (appLicense.AddOnLicenses.Count > 0)

                {

                    foreach (KeyValuePair<string, StoreLicense> item in appLicense.AddOnLicenses)

                    {

                        _Store_addOnLicense_0 = item.Value;

                        return true;

                        //--</ check first AddOn >--

                    }

                }

                //* nothing found is false

                return false;

                //--</ show License Infos >--

            }

 

 

            //-------------</ get_Store_AddOn_License_0()-------------

        }

        #endregion /Windows-Store

 

 

The first addon product (full version) can be purchased via a shop button

       private async  void btnStore_Click(object sender, RoutedEventArgs e)

        {

            if (_Store_addOnLicense_0==null)

            {

                //--< get Addon >--

                bool result_AddOn_0=await get_Store_AddOn_License_0();

                if (result_AddOn_0==false )

                {

                    //< no addon >

                    msgBox("no Addon found for this app", "MS Windows Store");

                    return;

                    //</ no addon >

                }

                //--</ get Addon >--

            }

 

 

            //----< Buy Addon >----

            StorePurchaseResult store_Result = await _Store_context.RequestPurchaseAsync(_Store_addOnLicense_0.SkuStoreId);

            if (store_Result.ExtendedError != null)

            {               

                msgBox (store_Result.ExtendedError.Message , "Error on Store");

                return;

            }

 

            switch (store_Result.Status)

            {

                case StorePurchaseStatus.AlreadyPurchased:

                    msgBox("OK: You already bought this AddOn.", "Addon is purchased.");

                    break;

                case StorePurchaseStatus.Succeeded:

                    msgBox("OK: Thank You. You bought the FullVersion", "Addon is purchased.");

                    break;

                case StorePurchaseStatus.NotPurchased:

                    msgBox("Error Reason: it may have been canceled.", "Product is NOT purchased");

                    break;

                case StorePurchaseStatus.NetworkError:

                    msgBox("Error Reason: network error.", "Product is NOT purchased");

                    break;

                case StorePurchaseStatus.ServerError:

                    msgBox("Error Reason: server error.", "Product is NOT purchased");

                    break;

                default:

                    msgBox("Error: unknown error.", "Product is purchased");

                    break;

            }

            //----</ Buy Addon >----

 

        }

 

 

 

 

 

 

 

 

Win32:

Initalize the store under Win32 apps in UWP

[ComImport]

[Guid("3E68D4BD-7135-4D10-8018-9FB6D9F33FA1")]

[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]

public interface IInitializeWithWindow

{

   void Initialize(IntPtr hwnd);

}

 

Including the UWP functions for Windows 32 applications

using System.Runtime.InteropServices;

 

Solution

Https://docs.microsoft.com/en-us/windows/uwp/monetize/in-app-purchases-and-trials#testing "]

 

User zero Windows.System.User

Mobile
»
UWP Store Win32: Get License Data of App from Store

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de