j3k0 / cordova-plugin-purchase

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

[iOS] Owned is always true on auto-renewable subscriptions #1192

Open maoliv opened 3 years ago

maoliv commented 3 years ago

system info

OSX Big Sur 11.3.1
Cordova 9.0.0
Device: iPhone iOS 14.5.1 // iPad iPadOS 14.5.1
Xcode: 12.5
Plugin Version: 10.5.3

Expected behavior

product.owned should be false and product.state should not be "owned" if I'm not currently subscribed to the product.

Observed behavior

I am testing the subscriptions in the app by connecting a device to Xcode and using the subscriptions that I have configured in App Store.

To check if I have a subscription, in the "updated" event I check if the product has the parameter owned to true and the state to "owned".

Despite not having any subscription, they all come with owned to true and with state to "owned".

On Android this does not happen, so I understand that it is an iOS problem.

trixyz commented 3 years ago

We're having the same issue, but only in production (downloaded from app store) except iPhone 12 on which it works. It works fine on all devices when testing with xcode or testflight

j3k0 commented 3 years ago

Can you share the code from your updated event? Also some logs (I understand this is production, but it case you have the behavior on a device you can plug to your mac and see some logs in Console.app)?

Also, are you using a receipt validator? Which, for subscriptions, is responsible to set the owned status correctly, because the expiry date isn't available client side.

tominou commented 3 years ago

Indeed the validity of a subscription needs to be checked server side, then passed to the validator callback, as stated in the src/validator.js doc

/// store.validator = function(product, callback) {
///
///     // Here, you will typically want to contact your own webservice
///     // where you check transaction receipts with either Apple or
///     // Google servers.
///     callback(true, { ... transaction details ... }); // success!
///     callback(true, { transaction: "your custom details" }); // success!
///         // your custom details will be merged into the product's transaction field
///
///     // OR
///     callback(false, {
///         code: store.PURCHASE_EXPIRED, // **Validation error code
///         error: {
///             message: "XYZ"
///         }
///     });
///
///     // OR
///     callback(false, "Impossible to proceed with validation");
///
///     // Here, you will typically want to contact your own webservice
///     // where you check transaction receipts with either Apple or
///     // Google servers.
/// });
stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.