简体   繁体   中英

How to implement in-app purchases in a Windows Store App

I was wondering how exactly in-app purchases are implemented in Windows Store Apps (meaning not Windows Phone), simply because I've looked online and at Microsoft's tutorials and I have found nothing that seems to avail me.

I used Unity to develop my game and then exported a Windows Store 8.1 file. Specifically, I have an event implemented in my Unity code that is linked to a method in the MainPage.xaml.cs file accessible in Visual Studio (I am running Express 2013 for Windows). The actual method is being executed, but when I request a product purchase in the method like so, I get an error:

    // This is assigned to the event that is called in Unity whenever the "Get Points" button is pressed.
    private async void PurchasePoints(object arg)
    {
        // Find the GameManager GameObject.
        UnityEngine.GameObject gameManager = UnityEngine.GameObject.FindGameObjectWithTag("GameManager");

        // Get the script attached to it.
        GameManager gameManagerScript = gameManager.GetComponent<GameManager>();

        // Get the license information for this app.
        Windows.ApplicationModel.Store.LicenseInformation licenseInformation = Windows.ApplicationModel.Store.CurrentAppSimulator.LicenseInformation;

        if (licenseInformation.ProductLicenses["SectorDefense_Points_250"].IsActive)
        {
            await Windows.ApplicationModel.Store.CurrentAppSimulator.RequestProductPurchaseAsync("SectorDefense_Points_250");

            gameManagerScript.playerScore += 250;
        }
    }

I'm just generally confused as to how one is supposed to implement that sort of functionality.

I've made sure to look into the WindowsStoreProxy.xml file and customize everything within it to suit the app's needs, although I've never really worked with XML before.

Any help is much appreciated!

Thanks in advance.

No need of hard coding, here is the easiest way to implement in-app purchase for any application. Visit this link and download the plugin for free. Microsoft Store Plugin- https://prime31.com/plugins

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM