Android应用程序的phonegap应用内结算

时间:2014-05-15 13:49:05

标签: android cordova phonegap-plugins billing

我正在开发一个android phonegap应用程序,我想在其中使用应用程序结算。我安装了phonegap billing plugin,它完美无缺。你能用链接帮我把它搞定吗?

例如,这是脚本代码:

<script >
function successHandler (result) {
    var strResult = "";
    if(typeof result === 'object') {
        strResult = JSON.stringify(result);
    } else {
        strResult = result;
    }
    alert("SUCCESS: \r\n"+strResult );
}

function errorHandler (error) {
    alert("ERROR: \r\n"+error );
}

// Click on init button
function init(){
    // Initialize the billing plugin
    inappbilling.init(successHandler, errorHandler, {showLog:true});
}

// Click on purchase button
function buy(){
    // make the purchase
    inappbilling.buy(successHandler, errorHandler, "good_id");
}

// Click on ownedProducts button
function ownedProducts(){
    // Initialize the billing plugin
    inappbilling.getPurchases(successHandler, errorHandler);
}

// Click on Consume purchase button
function consumePurchase(){
    inappbilling.consumePurchase(successHandler, errorHandler, "good_id");
}

// Click on subscribe button
function subscribe(){
    // make the purchase
    inappbilling.subscribe(successHandler, errorHandler,"good_id");
}

// Click on Query Details button
function getDetails(){
    // Query the store for the product details
    inappbilling.getProductDetails(successHandler, errorHandler, "good_id");
}

// Click on Get Available Products button
function getAvailable(){
    // Get the products available for purchase.
    inappbilling.getAvailableProducts(successHandler, errorHandler);
}
</script>

我需要它与例如合作 -

<a href="good.html" id='good' data-ignore="true">Good</a>

首先点击链接后,我会在链接到页面之前付款。 谢谢。抱歉我的英语不好。

1 个答案:

答案 0 :(得分:0)

我不确定我理解你想要什么,你的英语比我的还糟糕。但是,如果您只想在点击和重定向后启动购买,您可以使用onclick事件和window.location.replace:

<a href="good.html" id='good' data-ignore="true" onclick="buy()" >Good</a>

// Click on purchase button
function buy(){
// make the purchase
    inappbilling.buy(successHandler, errorHandler, "good_id");
    return false;
}

然后添加window.location.replace('yourlinkpage');你的successHandler

但也许输入提交应该更合适?