-
Notifications
You must be signed in to change notification settings - Fork 15.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add in-app purchase for MacOS #11292
Conversation
Looking forward to seeing this in production... a much needed feature for Electron! |
Can anyone merge this or tell me what needs to be done before it can be merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AdrienFery it looks like our CI is failing because of incorrectly formatted code. You can run npm run lint
locally to identify the formatting issues.
filenames.gypi
Outdated
'atom/browser/in_app_purchase.h', | ||
'atom/browser/in_app_purchase_mac.mm', | ||
'atom/browser/in_app_purchase_observer.h', | ||
'atom/browser/in_app_purchase_observer_mac.mm', | ||
'atom/browser/atom_browser_main_parts.cc', | ||
'atom/browser/atom_browser_main_parts.h', | ||
'atom/browser/atom_browser_main_parts_mac.mm', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feature will never be used on any platform other than macOS,
can you please put all of its files under a OS check at the bottom of the file?
You will need to create a new section ['OS=="mac"', {
right under the ['OS=="win"', {
.
UPD Files with "_mac" suffix are already fine, they won't used on any other platform,
but I guess we need to filter the other files too.
lib/browser/api/in-app-purchase.js
Outdated
} | ||
|
||
if (typeof quantity !== 'number') { | ||
quantity = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lib/browser/api/in-app-purchase.js
Outdated
} | ||
|
||
if (typeof callback !== 'function') { | ||
callback = function() {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please handle absence of a callback on the native side.
It doesn't make much sense to create and call an empty function.
lib/browser/api/in-app-purchase.js
Outdated
return binding.getReceiptURL(); | ||
}, | ||
|
||
purchaseProduct: function(productID, quantity, callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to allow this method to be called in forms
purchaseProduct(someId, 2)
and purchaseProduct(someId, function() {})
,
you will have to check the type of the second argument to decide if it is quantity
or callback
.
You can do it like this:
if (typeof quantity == 'function') {
quantity = 1
callback = quantity
}
@@ -8,6 +8,7 @@ module.exports = [ | |||
{name: 'dialog', file: 'dialog'}, | |||
{name: 'globalShortcut', file: 'global-shortcut'}, | |||
{name: 'ipcMain', file: 'ipc-main'}, | |||
{name: 'inAppPurchase', file: 'in-app-purchase'}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It also should be available on macOS only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should I do to restrict this to macOS only ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, there's not existing way to do it. I guess I or somebody else can add it after this PR is merged.
Let's skip it for now.
It means that it will be broken soon. |
@alexeykuzmin Any idea how to implement automatic tests ? I don't think that it is possible to interact with the Apple Store Dialog to sign in and to confirm the purchase. |
@zcbenz @deepak1556 any ideas how this feature can be tested? |
The built on jenkins failed. I don't understand why. I just tested to built on my Mac and it works. |
@AdrienFery Electron uses the macOS 10.10 SDK to build (see https://electronjs.org/docs/development/build-instructions-osx#macos-sdk) which is why the build failed in CI. This code change needs to be compatible with the macOS 10.10 SDK. |
3148f22
to
5f1c76c
Compare
Currently we don't have a way to test things that require code sign, we are simply relying on users to test them, for example the Handoff feature and the Mac App Store build. I'll add a few simple tests for the APIs to verify the methods actually exist. |
I'm going to turn |
@zcbenz Ok. Is it possible to somehow build a production ready app using the GitHub master branch of electron? |
@holgersindbaek @zcbenz I am with you here. I would like to build a production-ready app which includes this merge for IAP. I need to submit my app ASAP, so being able to just build and use this version would be great. Currently, I use the production version of electron using NPM. In the past, I have added NPM packages which point to git URLs. Wonder if that is possible here... or if we need to build it first? |
@sferoze I've tried to see if I could build a production app using the GitHub version of Electron, but it doesn't seem to be possible. Electron seem to always use the officiel version of Electron to build for production. You can build for development using the GitHub version, but not for production. |
@holgersindbaek thanks a lot for the info. this was really helpful in bringing light to the current status of the issue |
Thank you for the PR, it's been educational. We have another use case which also makes use of StoreKit; according to Apples guidelines, it won't be allowed to have custom prompts that request reviews, but one should make use of the requestReview method. I'm wondering
What are you're thoughts? |
If you want to add more StoreKit features, I think that the module should be renamed to something more general. |
Any news on when this will go into the official version of Electron? |
@sferoze In StoreKit, In-App Purchase doesn't have any subscription method. You can use subscription directly with this implementation. The SKProductSubscriptionPeriod class contains only information about the subscription duration of the product.
|
@holgersindbaek we are shooting for a 2.0 beta this week. If I'm not mistaken, this change should land in that release. |
Remark: I have added a method @yuri-karkh Which version of Electron do you use ? |
I used 2.0.0-beta1 @AdrienFery as it was released only in this new version |
@yuri-karkh You should listen for the
|
👍 If you could also add a short tutorial in |
Hi @AdrienFery, could u please advice: |
hi @AdrienFery sorry to bother u again, but have a question again if u have a minute: |
@yuri-karkh What is your bundleID and your productID ? |
bundleID = "com.gentlereader.dev" and productID = "demoprod" @AdrienFery |
As @yuri-karkh said there is no method like getProducts.. @AdrienFery ... |
23 Crashed:: Dispatch queue: SKProductsRequest reply queue I'm getting this error while I called purchaseProduct() |
Waiting for your faster reply @AdrienFery .Thanks in advance |
With the purchaseProduct() method, you can console.log the response in the callback. It should be true or false if product is valid or not. This is working for me but the issue I am having is that the response says the product is invalid. Even though I have gone into iTunes Connect and added the subscription just like I have done for iOS. I think the issue is that you need to call getProducts() before purchaseProduct() otherwise it will always return as an invalid product. @AdrienFery is this correct. You added the getProducts() method and that needs to be called before purchaseProduct() for purchaseProduct() to work? |
yes @sferoze now working fine.I will ask you doubts during development.Thanks for your reply |
@JeganMSD Some of my users are getting the same error. I can't replicate it, but I'm quite sure it happens when I call "remote.inAppPurchase.getProducts". I know it happened to you on "purchaseProduct", but what did you do to fix it? |
In order to release a commercial application on the Mac Apple Store, it must use in-app purchase (see App Store Guidelines). It is why I have added the in-app purchase feature for MacOS into Electron. I have tested the build and it works well but I didn't implement automatic tests.
Let me know if you see some modifications to do.
See in-app-purchase.md for the module documentation.