【发布时间】:2014-06-03 22:22:17
【问题描述】:
我们使用 Titanium Studio 开发了我们的应用程序,Appcelerator 为 In-App Billing which only support API v2 提供了一个免费模块(我知道我们应该使用 v3,但我们是一个独立团体,所以 100 美元用于支持 API v3 的模块暂时是不允许的)。
我已经阅读了In-App Billing workflow for API v2 上的文档,到目前为止,购买逻辑就像一个魅力。
直到我们得到退款部分。我们在我们的应用中管理了产品和订阅。
根据文档,退款时会触发 IN_APP_NOTIFY 事件,这需要我们进行 getPurchaseInformation 调用。我们怀疑的是在我们调用 getPurchaseInformation 之后会发生什么。是否触发了 PURCHASE_STATE_CHANGED 事件?如果是,那么更新后返回带有订单的签名数据?
例如,假设用户 Uriel 购买了托管产品 A,然后 Uriel 要求退款。这将触发 IN_APP_NOTIFY 事件并进行 getPurchaseInformation 调用。
将触发什么事件,以便我可以更新应用程序以锁定用户以前可用的内容? PURCHASE_STATE_CHANGED 会被触发吗?如果是,那么带有订单信息的签名数据会返回空吗?在我的 PURCHASE_STATE_CHANGED 中,我验证是否有订单,如果没有找到订单,则所有内容都被阻止。
总之,我的猜测是对的还是退款的工作流程不同?
作为参考,这里是我的 PURCHASE_STATE_CHANGED 函数:
function PURCHASE_STATE_CHANGED_EVENT(e)
{
Ti.API.info('PURCHASE STATE CHANGED CALLED');
Ti.API.info('Signature Verification Result:\n' + VerificationString(e.result));
Ti.API.info('Signed Data:\n' + e.signedData);
/*
* We receive an object that might look like this
* {
* "nonce":-2458019374247073515,
* "orders":[
* {
* "notificationId":"notificationId",
* "orderId":"transactionId",
* "packageName":"my.package",
* "productId":"in_app_identifier",
* "purchaseTime":1394062412214,
* "purchaseState":0
* }
* ]
* }
*/
if (e.signedData != null) {
var response = JSON.parse(e.signedData);
/*
* We are not guaranteed to have any orders returned so
* we need to make sure that this one exists before using it.
*
* If there is no notificationId then there is no need to confirmNotifications().
* This happens when restoreTransactions() triggers a PURCHASE_STATE_CHANGED_EVENT.
*/
if(response.orders.length === 0)
{
Ti.API.info('nothing to restore');
setNoTransactionsToRestore();
return;
}
for(var i = 0; i < response.orders.length; i++)
{
if(typeof response.orders[i] !== 'undefined')
{
Ti.API.info('set purchase flag');
setPurchaseFlag(response.orders[i].productId);
}
if (response.orders[i] && response.orders[i].notificationId)
{
Ti.API.info('confirming notification for order ' + JSON.stringify(response.orders[i]));
var synchronousResponse = InAppBilling.confirmNotifications({
notificationIds: [response.orders[i].notificationId]
});
displaySynchronousResponseCodes(synchronousResponse);
}
}
}
else
{
Ti.API.info('signed data was null');
}
}
InAppBilling.addEventListener(InAppBilling.PURCHASE_STATE_CHANGED_EVENT, PURCHASE_STATE_CHANGED_EVENT);
还有我的 IN_APP_NOTIFY 函数:
function NOTIFY_EVENT(e)
{
Ti.API.info('NOTIFY CALLED \n' + 'Notify Id:\n' + e.notifyId);
var synchronousResponse = InAppBilling.getPurchaseInformation({
notificationIds: [e.notifyId]
});
displaySynchronousResponseCodes(synchronousResponse);
}
InAppBilling.addEventListener(InAppBilling.NOTIFY_EVENT, NOTIFY_EVENT);
【问题讨论】:
标签: android in-app-purchase in-app-billing titanium-modules