Implementing in-app purchase in an Electron app for the Mac App Store
Asked Answered
H

2

11

I've looked around and it seems like several people are having this issue but no-one seems to have solved it:

Adding Apple in-app purchase to Electron HTML/JS app

https://github.com/electron/electron/issues/3745

https://discuss.atom.io/t/osx-in-app-purchases-in-electron/22885

Some people suggest using this Node to Objective-C bridge to do it:

https://github.com/TooTallNate/NodObjC

Other people suggest using this in-app library, but from what I can see, it only validates receipts:

https://github.com/voltrue2/in-app-purchase

Has anyone actually managed to implement in-app purchases in an Electron app for the Mac App Store?

How did you do it?

If no one has done it, is it simply impossible to do?

Hydrostatic answered 15/10, 2017 at 10:4 Comment(0)
C
5

Update

Finally, I added in-app purchase directly to Electron.

See https://electronjs.org/docs/tutorial/in-app-purchases


First solution

I have implemented this solution and it works in development (not yet tested in production).

  1. Create a MacOS application (InAppPurchase) with Xcode that performs the in-app purchase (see https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Introduction.html)
  2. Put the InAppPurchase.app somewhere in your Electron app folder
  3. Use require('electron').shell.openItem or require('child_process').spawn('./InAppPurchase.app/Contents/MacOS/InAppPurchase'); in your Electron app to start the in-app purchase.

This is definitely not a clean solution but it seems to work...

Second solution

I think that it can also be done with NodObjC. However, this lib is very heavy compared to the first solution.

Third solution

Adding in-app purchase directly to Electron.


I will keep you informed if I can release my Electron app on the Mac Apple Store with IAP or if I found another solution.

Cholula answered 19/10, 2017 at 14:40 Comment(11)
That looks like a great start. I've looked a bit at NodObjC, but find it really confusing. Generally I find the mix of Objective C and JS really confusing. Can you share your Xcode "app"? I don't fully understand what 'require('electron').shell.openItem' does. Can you explain a bit further what it does?Hydrostatic
Btw... if you can give me a working solution I can implement, I'll throw in an extra $50 on top of the 300 bounty points as an extra thanks. I think it's crazy there is no known solution to this issue and really want to find one.Hydrostatic
Ok thanks, I will try to add it directly to Electron then. I think this is the best solution.Cholula
Sounds good. Let me know how it goes. If you have some example code, don't hesitate with posting it. Then I'll probably see if I can do something with that as well.Hydrostatic
Did you figure anything out? Can you create an example Xcode app you can share (or just share the main code), that illustrates how the Xcode app would be? If you can, then I might be able to understand how that solution works and build things from that.Hydrostatic
Yes. I managed to integrate it directly with Electron. I still have to make some small modifications and then I will send you the code.Cholula
That sounds awesome... really looking forward to it. When do you think you'll be able to do that? I'm eager to get it integrated into my app.Hydrostatic
If all goes well, I think I'll finish it tomorrow evening.Cholula
Sounds good. The bounty will expire in 4 hours. I'll simply give it to you know... hope you come up with something. I'll transfer the beer money to you once I've seen the implementation. Keep up the good work :-).Hydrostatic
I have pushed the in-app purchase integration to my Electron fork github.com/AdrienFery/electron/tree/in-app-purchase. I still have some modifications to do in order to pull request but it should work.Cholula
Damn... I didn't know it would be that much work. I'll take a closer look at the implementation tomorrow and see if I can try it out. Can you create an example app (or just some dummy code) to show how it would be implemented? What's your PayPal email so I can send you the extra $50?! I know it's not a big reward, but it's just an extra thanks.Hydrostatic
S
0

In addition to user108828 i can suggest a couple more ideas to solve your problem:

  1. You can implement MAS receipt validation as a dynamic library in obj-C/C++/C using Xcode and then include it in your project via ToTallNate's node-ffi. For implementation you can use any of a large number of solutions that you can easely find on web.

  2. Another way to perform receipt verification is to create a self made node addon that includes openssl and objective-c runtime libraries. For this solution you may also need to include CoreFoundation and/or some other apple frameworks. As a result you will be able to implement your validation in pure C/C++ and incapsulate it in your node module.

The API design of your dylib/node addon is strictly up to you and should be kept in secret.

Good luck!

Schreibe answered 15/1, 2018 at 18:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.