In app purchases in Microsoft Store

I seem to be chasing my tail following links while trying to figure out how to implement IAP from a cocos2d-x 3.17.2 app (not using Cocos Creator) from the Microsoft Store. The Microsoft store only supports Windows 10, which is fine with me. 3.17.2 only builds Win32 apps, which is also fine with me. And Microsoft provides a way to package a Win32 app as an MSIX package from Visual Studio 2017 for use in their store here. But the only current documentation I can find for implementing IAP from the Microsoft Store seems to require that it be a UWP app, here, which is not the same as a Win32 app. A user named ImagnGames on this discussion board has shown a somewhat kludgy way to re-introduce Win10 projects into Cocos2d-x, but I’m not sure if that will get me any closer to being able to build a UWP app, or if that’s really required for IAP. So if anyone else has gone down this rat hole, I would appreciate any wisdom you could impart!

Check if these help at all:

https://github.com/microsoft/DesktopBridgeToUWP-Samples/tree/master/Samples/StoreSample

C++ code here too:
https://github.com/Microsoft/Windows-universal-samples/tree/win10-1507/Samples/Store

You may need to write a C++/CLI library to handle this, which you can link to your own app.

1 Like

Given the communication in this topic, I think a more straightforward way to get IAP working in the Microsoft Store could be to revert to using proj.win10 in Cocos2d-x v3.15.1. Has anyone else tried going this route?

I’m not sure what the project type has to do with getting IAP working, so regardless of Win32 or Win10 app types, in the end you still need to interface with the code required to process the IAP. In all likelihood you would still need to use C++/CLI.

Getting IAP working in the Microsoft Store for a desktop application is not simple. Here’s what I’ve learned. For starters, you need a good understanding of the C++ syntax for: lambda functions, templates, and C++/CX (the successor to C++/CLI which is now obsolete). Much of the Microsoft documentation features sample code written in C#, so it’s important to download Microsoft’s “Store” samples from github, (as recommended by R101 earlier in this discussion) so you can find the equivalent C++/CX code. To use cocos2d-x in win32 mode requires using the Microsoft Desktop Bridge, which I was unable to get working by following Microsoft’s online documentation. Using cocos2d-x in win10 mode is more straightforward, but since the latest versions of cocos2d-x have dropped the proj.win10 directory, you need to either use cocos2d-x v3.15.1(the last version to support proj.win10), or try to follow roots’s suggestions for getting proj.win10 working in cocos2d-x v3.17. You will need to open and read dozens of web pages provided by Microsoft describing add-ons (their term for in-app purchases), and configuring your app’s properties in the latest version of Visual Studio (either 2017 or 2019 will work) and in the Microsoft Partner Dashboard. Be sure to set the the “Target Platform Version” and “Target Platform Min. Version” to 10.0.14393.0 in the project’s properties to avoid strange compiler errors. Rather than creating a separate library to communicate with the Microsoft Store, you can create and make calls from your program into a cpp source file included with your project, as long as you avoid symbol conflicts by not including any cocos2d-x #include’s in your cpp file that uses C++/CX to talk to the store.

1 Like

Hi @doffen,

  1. i just did a google search and came across this link, not sure if it will be of help to you.
    https://techcommunity.microsoft.com/t5/windows-dev-appconsult/enable-in-app-product-purchases-for-desktop-bridge-converted/ba-p/316901

  2. i am also curious to know what Windows platforms are you targeting for this feature?

  1. Over here, are you referring to packaging the Win32 app as a MSIX package?
    i have followed the link here, and managed to package in latest cocos2d-x v4 project. But i don’t think it can target ARM platform, just x86.
    If you happen to be targeting Surface Pro, i think may still be supported

@Darren, your techcommunity link seems to have some useful info I hadn’t seen before. I’m basically targeting Windows desktop for now, and I have no problem using the older version (v3.15.1) of cocos2d-x. I’m not sure why my win32 MSIX package didn’t work, since I tried to use the same Microsoft documentation as you did – glad you found a way to get it working for you.

@doffen, just wondering which part did it not work for you with win32 package?
One problem i ran into was that the resources and dlls were not copied to the package and the exe couldn’t run.
i managed to find a way of copying them with reference from this link. Just thought i’ll post it here in case anyone else run into this same issue.