How to implement Mac App Store in-app purchase and receipt verfication?

I’m trying to build a Mac desktop version of our iPad app, but I’m running into issues implementing in-app purchase and receipt verification. Is this possible with Unity and has anybody done it? To clarify, I’m not just trying to submit my app to the Mac App Store, but I need IAP and receipt verification.

I’ve built a plugin for Unity to handle the IAP and receipts (in Xcode), but because the app is not being built and run from Xcode, it does not appear to be entering sandbox mode. The only information on this that I can find in the docs is “Test During the Development Process”:

It suggest that the app should exit with code 173 when the receipt file isn’t found and that the sandbox receipt will automatically be downloaded. It should be in the app in “Contents/_MASReceipt/receipt”. I’m doing exactly this with my bundle using exit(173). The app exits, but no receipt is downloaded.

Since I’ve been unable to get my app to connect to the sandbox, I thought I’d try using a sample receipt, but the little instruction I’ve found doesn’t work. In any case, I think I need a real receipt to work with.

Also, in case anybody asks I have done the usual required steps for submitting the app to the Mac App Store, updating the Info.plist, icons and running codesign and productbuild.

TL;DR - How do you retrieve the app receipt for a Unity mac desktop app during development?

After quite a bit of work I’ve found a solution. For anyone else trying to do this, here are the general steps…

  1. Build a default Xcode Cocoa app and implement all your in-app purchase and receipt verification code. The app doesn’t need to do anything when run, just test that transactions and verification are working in sandbox mode.

  2. Build a bundle as a plugin for Unity with the same code from your test app. Add the bundle to Assets/Plugins with your binding code, then build the app (Mac OS X Intel Only).

  3. Open the package contents of the app and update the Info.plist, and other files as needed. Follow the usual steps for app store submission up to the codesign step.!

  4. Open the contents of your Xcode app build (from step 1) and copy the _MASReceipt folder over to the contents of your Unity build. This is necessary because insofar as I’ve seen, running the app built from Unity doesn’t trigger the sandbox mode and thus does not receive a receipt. As long as your Unity app has the right bundle ID and code signature, it validates the receipt correctly.

All of this is pretty time consuming, since you have to repeat steps 3 and 4 every time you do a new build. So it’s best to save this as the last development phase.

I also found this post… though since I implemented my own I haven’t tried it: