j3k0 / cordova-plugin-purchase

In-App Purchase for Cordova on iOS, Android and Windows
https://purchase.cordova.fovea.cc
1.29k stars 529 forks source link

Store.order() returns undefined if a receipt or transaction has been updated while the purchase dialog is opened, thus never calling cancel or error #1548

Open DavidTalevski opened 1 month ago

DavidTalevski commented 1 month ago

Observed behavior

When the purchase dialog is opened, and some of the receipts get updated they trigger the order promise to resolve and return undefined, thus making it impossible to listen for cancel or error events during the current ordering of a product. The easiest way to reproduce this is to order a product, when the purchase dialog appears minimize the app, upon returning to the app some of the receipts might have gotten updated and then they trigger the order to resolve. The order is resolved and the purchase dialog is left open and then it is impossible for us to listen to cancel or error events for the currently opened dialog. In the previous versions this could've been remedied with the store.when().cancelled event but now that everything is tied to store.order() this makes it impossible to handle.

These are the logs when the app is resumed and the purchase dialog is still opened:

[CdvPurchase] DEBUG: Calling callback: type=approved() name=transactionStateMonitors_callOnChange reason=adapterListener_receiptsUpdated_approved
[CdvPurchase] DEBUG: Calling callback: type=approved() name=#fb6c4b9c7fe59d61a15b3c3e14723044 reason=adapterListener_receiptsUpdated_approved

After the order falsely finishes, in logcat when the close dialog is closed this is the output:

onPurchasesUpdated() -> Cancelled: USER_CANCELED: User pressed back or canceled a dialog
callError({code:6777006, msg:"USER_CANCELED")

This error is no longer listened to because the order has finished and the js code never gets notified that this dialog has closed.

Expected behavior

When ordering a product and some of the receipt get updated, this should not affect the current order that is taking place. The promise should not resolve with "undefined" if a different receipt has been updated, it should only resolve when the order is completed or it has failed.