Languages

Menu
Sites
Language
How to validate if a user has an active subscription

Edit: This is for a Wearable project. (Samsung Gear S3 & Samsung Galaxy Watch)

Hi, I'm trying to check if the user has an active subsription. I tried the following but it doesn't appear to be working. 

var fetchSubscriptions = function() {
	// Request the available item list
	webapis.inapppurchase.getItemList(1, 15, "ALL", "IAP_COMMERCIAL_MODE", checkPurchases, failedSubscription);
}

var checkPurchases = function(purchases) {
	// Find the highest expiry timestamp of all purchases
	var highestTimestamp = 0;
	
	// Loop through all purchases
	for (var i = 0; i < purchases._items.length; i++) {			
		// Turn expiry date into a timestamp
		var endDateString = purchases._items[i].mSubscriptionEndDate;
		var endDateTimestamp = new Date(endDateString).getTime();
		
		// Check if this timestamp is higher than the previous highest
		if(highestTimestamp > endDateTimestamp) {
			// Replace highest with new highest timestamp
			highestTimestamp = endDateTimestamp;
		}
	}
	
	// If the highest timestamp is higher than today
	var today = new Date().getTime();
	if(highestTimestamp > today) {
		// User is subscribed
	} else {
		// User is NOT subscribed
	}
}

var failedSubscription = function() {
	// Show some error
}

How am I supposed to check subscription validity and does this method gives "not subscribed" in case the user cancelled his/her subscription?

Since the last Tizen update IAP is no longer working on my Watch & Phone (which I'm already in contact for with the Samsung Developers), in the meantime it makes testing IAP features extremely hard. 

Edited by: Gilles Lesire on 18 Oct, 2019