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

receiptsVerified is called even when device is offline #1476

Closed dominic-simplan closed 7 months ago

dominic-simplan commented 7 months ago

Observed behavior

I disconnect my device from the internet and start the app. The receiptsVerified() callback gets called:

[CdvPurchase] DEBUG: Calling callback: type=ready() name=
instrument.ts:124 AppStore is ready
instrument.ts:124 [CdvPurchase] DEBUG: Calling callback: type=receiptsReady() name=
instrument.ts:124 [CdvPurchase.ReceiptsMonitor] DEBUG: receiptsReady...
instrument.ts:124 [CdvPurchase.Validator] DEBUG: Validation requests=3 responses=1
2instrument.ts:124 [CdvPurchase.Validator.Ajax] DEBUG: ajax -> send request to https://validator.iaptic.com/v3/validate?appName=def&apiKey=abc
instrument.ts:124 [CdvPurchase.Validator.Ajax] WARNING: ajax -> request to https://validator.iaptic.com/v3/validate?appName=abc&apiKey=abc failed with status 0 ()
(anonymous) @ instrument.ts:124
instrument.ts:124 [CdvPurchase.Validator] DEBUG: validator failed, response: "Error 0: "
instrument.ts:124 [CdvPurchase.Validator] DEBUG: body => undefined
instrument.ts:124 [CdvPurchase.Validator] DEBUG: Validation requests=3 responses=2
validator.iaptic.com/v3/validate?appName=def&apiKey=abc:1     Failed to load resource: net::ERR_INTERNET_DISCONNECTED
instrument.ts:124 [CdvPurchase.Validator.Ajax] WARNING: ajax -> request to https://validator.iaptic.com/v3/validate?appName=def&apiKey=abc failed with status 0 ()
(anonymous) @ instrument.ts:124
instrument.ts:124 [CdvPurchase.Validator] DEBUG: validator failed, response: "Error 0: "
instrument.ts:124 [CdvPurchase.Validator] DEBUG: body => undefined
instrument.ts:124 [CdvPurchase.Validator] DEBUG: Validation requests=3 responses=3
validator.iaptic.com/v3/validate?appName=def&apiKey=abc:1     Failed to load resource: net::ERR_INTERNET_DISCONNECTED
instrument.ts:124 [CdvPurchase] DEBUG: Calling callback: type=unverified() name=check
instrument.ts:124 [CdvPurchase.ReceiptsMonitor] DEBUG: check(3/3)
instrument.ts:124 [CdvPurchase.ReceiptsMonitor] INFO: receiptsVerified()
instrument.ts:124 [CdvPurchase] DEBUG: Calling callback: type=unverified() name=check
instrument.ts:124 [CdvPurchase.ReceiptsMonitor] DEBUG: check(3/3)
instrument.ts:124 [CdvPurchase] DEBUG: Calling callback: type=receiptsVerified() name=

Expected behavior

My expectation would be that the receiptsVerified callback is not executed if the receipts couldn't be verified.

System Info

Output of cordova info: Cordova Packages:

cli: 12.0.0
    common: 5.0.0
    create: 5.0.0
    lib: 12.0.1
        common: 5.0.0
        fetch: 4.0.0
        serve: 4.0.1

Project Installed Platforms:

ios: 6.3.0

Project Installed Plugins:

cordova-plugin-androidx-adapter: 1.1.3
cordova-plugin-camera: 6.0.0
cordova-plugin-device: 2.1.0
cordova-plugin-file: 7.0.0
cordova-plugin-inappbrowser: 5.0.0
cordova-plugin-msal: 4.0.0
cordova-plugin-network-information: 3.0.0
cordova-plugin-printer: 0.8.0
cordova-plugin-purchase: 13.6.0
cordova-plugin-splashscreen: 6.0.2
cordova-plugin-wkkeyboardfix: 1.1.0
cordova-plugin-x-socialsharing: 6.0.4
cordova-sqlite-storage: 6.1.0
es6-promise-plugin: 4.2.2

Environment:

OS: Microsoft Windows 11 Pro 10.0.22621 (22621) (Windows 10.0.22621) x64   
Node: v18.15.0
npm: 8.1.0
j3k0 commented 7 months ago

This is probably a naming issue: receiptsVerified means all validation calls have been resolved (either with unverified or verified), it lets your app know that there's no more receipt validation calls in progress. Obviously here all validation calls have failed (with calls to unverified).

What are you trying to achieve with it?

dominic-simplan commented 7 months ago

I think in v11 of this plugin we used the store.isReady method to dermine if a user is online / has internet access and then either showed the in-app-purchase options or a message that the user is not online. If I remember correctly the store.isReady method would only return true if the device is online. Now in v13 it seems to be independent of the online state of the device.

Anyway, probably the better way to do it is to check the online state of the device independent of the store.isReady state.

I think we can close this issue. Thanks for yor reply and for clarifying how receiptsVerified is supposted to work!