I'm using a plugin https://github.com/j3k0/cordova-plugin-purchase to implement a paid subscription in the app. I checked the work of the subscription on Android 5.1.1. And after I called the store.refresh() triggered the update event. But after that the approved event does not fire.
Here is my code
function subscriptionIsApproved(product) {
product.verify();
console.log("Is approved: " + JSON.stringify(product));
}
function subscriptionIsVerified(product){
product.finish();
console.log("Is verified: " + JSON.stringify(product));
}
function subscriptionIsUnverified(){
createErrorAlert(app,localDictionary[storage.getItem('language')].VERIFICATION_ERROR,null);
setNotSubscribeMode(app,$$);
console.log("Subscription is unverified");
}
function subscriptionIsUpdated(product){
if (!product.owned) {
store.order(product);
setNotSubscribeMode(app, $$);
}else
setSubscribeMode(app,$$);
console.log("Is updated: " + JSON.stringify(product));
}
function onDeviceReady() {
var sbType;//subscription type
if(Framework7.device.ios)
sbType = store.NON_RENEWING_SUBSCRIPTION;
else
sbType = store.PAID_SUBSCRIPTION;
store.register({
id: subscriptionId,
type: sbType
});
console.log("PRODUCT: " + JSON.stringify(store.get(subscriptionId)));
store.error(function(e){
console.log("ERROR " + e.code + ": " + e.message);
});
if(Framework7.device.ios)
store.validator = app_store_verification;
else if(Framework7.device.android)
store.validator = play_market_verification;
store.when(subscriptionId).approved(subscriptionIsApproved);
store.when(subscriptionId).verified(subscriptionIsVerified);
store.when(subscriptionId).unverified(subscriptionIsUnverified);
store.when(subscriptionId).updated(subscriptionIsUpdated);
store.when(subscriptionId).cancelled(function(product){console.log("Is cancelled: " +
JSON.stringify(product));});
}
//init purchase by button click
$$(document).on('click','#continueBtn',function(){
mainView.router.navigate('/confirmPhone/');
store.refresh();
});
It doesn't work. After I press the button and call store.refresh() fires the update event in which I call store.order(product) method that should end with an approved event, but that doesn't work. What's wrong with my code?