首次实施应用内结算。我能够完成第一笔交易,但第二次购买相同的商品时我得到“错误回复:7:项目已经拥有” onIabPurchaseFinished 方法,如何制作重新购买,能够?任何帮助将不胜感激。
Onclick购买我正在调用以下方法: initilizeInAppPurchasePakages();
public void initilizeInAppPurchasePakages()
{
String base64EncodedPublicKey=getString(R.string.inAppBillingKey);
mHelper = new IabHelper(getActivity(), base64EncodedPublicKey);
mPurchaseFinishedListener
= new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase)
{
if (result.isFailure()) {
Log.d(TAG, "Error purchasing: " + result);
// Toast.makeText(getActivity(),"fail to purchase"+result, Toast.LENGTH_SHORT).show();
return;
}
else if (purchase.getSku().equals(purchaseItemId)) {
transactionId=purchase.getOrderId();
PackageFragment.isNeedToUpdate = true;
// consume the gas and update the UI
// Toast.makeText(getActivity(), "purchase successfully", Toast.LENGTH_SHORT).show();
mHelper.consumeAsync(purchase,
mConsumeFinishedListener);
}
else if (purchase.getSku().equals(purchaseItemId)) {
// give user access to premium content and update the UI
// Toast.makeText(getActivity(), "purchase successfully", Toast.LENGTH_SHORT).show();
}
}
};
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// Oh no, there was a problem.
// Toast.makeText(getActivity(), "connection Error", Toast.LENGTH_SHORT).show();
}
else
{
// Toast.makeText(getActivity(), "connected successfully", Toast.LENGTH_SHORT).show();
Log.d(TAG, "Problem setting up In-app Billing: " + result);
mHelper.launchPurchaseFlow(getActivity(), purchaseItemId, 10001,
mPurchaseFinishedListener, "testing");
}
// Hooray, IAB is fully set up!
}
});
mConsumeFinishedListener =
new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase, IabResult result) {
if (result.isSuccess()) {
serverUtilities.savePayment(pakageId,pakagePrice,transactionId);
// Toast.makeText(getActivity(), "consumed", Toast.LENGTH_SHORT).show();
// provision the in-app purchase to the user
// (for example, credit 50 gold coins to player's character)
}
else {
// handle error
}
}
};
}
答案 0 :(得分:0)
好的,
在阅读谷歌应用程序计费文档后,我发现我需要通过测试在应用程序计费中进行测试,所以我做了什么
测试结算:
mHelper.launchPurchaseFlow(getActivity(), purchaseItemIdSKU, 10001,
mPurchaseFinishedListener, "testing");
仅在第一次调用时删除上面使用的测试结算行上方已购买的条目记录: ArrayList skusToBeListed = null;
skusToBeListed = new ArrayList<String> ();
skusToBeListed.add (SKU_PREMIUM);
skusToBeListed.add (SKU_PREMIUM_ELITE);
skusToBeListed.add (SKU_PREMIUM_PLUS);
mHelper.queryInventoryAsync(true,skusToBeListed,mGotInventoryListener);
一旦完成,你可以毫不费力地做很多测试预订。
mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
@Override
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
if (result.isFailure()) {
//complain("Failed to query inventory: " + result);
return;
}
Purchase currentPurchase = inventory.getPurchase(purchaseItemIdSKU);
if(currentPurchase != null)
{
//Boolean mIsPremium = (currentPurchase != null && verifyDeveloperPayload(currentPurchase));
mHelper.consumeAsync(currentPurchase,mConsumeFinishedListener);
}
}
} ;
注意:强> 在测试结算的情况下,交易ID将不会返回,因此请确保如何处理,我确实通过硬编码以下格式测试了我的应用内结算:&#34; GPA.1234-5678-9012-34567& #34; 强>
简而言之,我的代码很好,如果我在生产模式下使用它,但在测试模式的情况下它给了我错误,我解释并给出解决方案我是如何解决它。