Skip to content
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 "restore purchases completed/failed" notifications to iOS IAP #242

Closed
johngirvin opened this issue Nov 19, 2019 · 1 comment · Fixed by godotengine/godot-ios-plugins#42

Comments

@johngirvin
Copy link

johngirvin commented Nov 19, 2019

Describe the project you are working on:
Game with iOS IAP

Describe the problem or limitation you are having in your project:
There are no notifications sent to GDScript when iOS "restore purchases" completes or fails overall.

At present, notifications are sent to GDScript for each purchase restored. However in the cases where (1) the user does not have any purchases to restore, and (2) restore purchases fails, no notifications are sent and it is impossible for the GDScript code to react correctly. For example, by updating whatever restore purchase UI the game has implented.

A workaround is perhaps to set a maximum time limit on the restore process, but this is unreliable, a poor end-user experience and generally unsatisfactory.

Describe how this feature / enhancement will help you overcome this problem or limitation:
By introducing new notifications it will be possible for GDScript on iOS to react correctly to the cases above.

Describe implementation detail for your proposal (in code), if possible:
Implement the SKPaymentTransactionObserver paymentQueueRestoreCompletedTransactionsFinished and restoreCompletedTransactionsFailedWithError methods in platform/iphone/in_app_store.mm

Sample code:

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
    Dictionary ret;
    ret["type"]   = "restore";
    ret["result"] = "completed";
    InAppStore::get_singleton()->_post_event(ret);
}

- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error {
    Dictionary ret;
    ret["type"]   = "restore";
    ret["result"] = "error";
    ret["error"]  = String::utf8([error.localizedDescription UTF8String]);
    InAppStore::get_singleton()->_post_event(ret);
}

This will send new notifcations to GDScript, similar to the existing iOS IAP notifications, when the restore purchases process completes or fails overall.

FWIW, I am sucessfully using code similar to this in a released iOS game with a custom build of Godot 3.1

If this enhancement will not be used often, can it be worked around with a few lines of script?:
No. This must be implemented at the iOS platform level.

Is there a reason why this should be core and not an add-on in the asset library?:
The SKPaymentTransactionObserver protocol is implemented in the iOS platform code in platform/iphone/in_app_store.mm. The required new methods are part of this implementation and so must be added in the same place.

I understand a redesign of IAP may be in consideration with the aim of unifying the IAP GDScript API across Android and iOS (I was unable to find an existing issue for this, if it exists). The new notifications proposed here should be part of that design.

@aleksfadini
Copy link

aleksfadini commented Feb 9, 2021

I second this. By the same token, on iOS it is impossible to promote subscriptions and obtain gift keys for subscriptions.
App Store Connect sends this message:

"These in-app purchases can’t be promoted on the App Store because your latest approved binary doesn’t include the SKPaymentTransactionObserver method."

More details here:
https://developer.apple.com/app-store/promoting-in-app-purchases/

EDIT: (there is a sort of workaround to obtain keys, but subscriptions cannot be implemented correctly on iOS)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants