购买Cordova插件。批准的事件不会触发

时间:2019-12-16 20:03:33

标签: android cordova subscription

我正在使用插件https://github.com/j3k0/cordova-plugin-purchase在应用中实施付费订阅。我检查了Android 5.1.1上的订阅工作。在我调用store.refresh()之后触发了更新事件。但是之后,批准的事件不会触发。

这是我的代码

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();
});

它不起作用。在我按下按钮并调用store.refresh()后,会触发更新事件,在该事件中,我调用store.order(product)方法,该方法应以批准的事件结尾,但是不起作用。我的代码有什么问题?

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。我添加了cordova-plugin-purchase插件,这是必需的cc.fovea.cordova.purchase。现在批准的作品。但我仍然收到一个错误:您的订单正在处理中。该产品将在几分钟内上市