我在PlayStore上的生产环境中有一个应用程序,InAppBilling可以正常运行,但是我有一个我认为没有道理的错误。
我的应用程序中只有一个产品,它可以用来激活Premium。保费将在数据库中以“ 1-0”字段激活。
有时候,人们可以在不支付我费用的情况下激活保险费,我也不知道为什么。通常情况下可以完美运行,但是我不知道问题出在哪里。
我的代码是下一个:
public void startBuyProcess(final android.app.AlertDialog dialogo, final Activity activity) {
billingHelper = new IabHelper(activity, CLAVE);
billingHelper.enableDebugLogging(true, "TAG");
billingHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
@Override
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
Utiles.addToErrorPremium(User_Singleton.getInstance().getIdUsuario(), result.getMessage(), activity);
} else {
try {
if (!billingHelper.queryInventory(true, null, null).hasPurchase(SKU)) {
addPremiumElement(dialogo, activity);
} else {
/// BOUGHT ///
Utiles.showDialog(activity, activity.getString(R.string.informacion), activity.getString(R.string.premiumYaComprado), activity.getString(R.string.known));
}
} catch (IabException e) {
e.printStackTrace();
Utiles.addToErrorPremium(User_Singleton.getInstance().getIdUsuario(), e.getMessage(), activity);
}
}
}
});
}
public void addPremiumElement(final android.app.AlertDialog dialogo, final Activity activity) {
List<String> additionalSkuList = new ArrayList<>();
additionalSkuList.add(SKU);
try {
billingHelper.queryInventoryAsync(true, additionalSkuList, null, new IabHelper.QueryInventoryFinishedListener() {
@Override
public void onQueryInventoryFinished(IabResult result, Inventory inv) throws IabHelper.IabAsyncInProgressException {
if (result.isFailure()) {
Utiles.addToErrorPremium(User_Singleton.getInstance().getIdUsuario(), result.getMessage(), activity);
} else {
realizarCompra(dialogo, activity);
}
}
});
} catch (IabHelper.IabAsyncInProgressException e) {
Utiles.addToErrorPremium(User_Singleton.getInstance().getIdUsuario(), e.getMessage(), activity);
e.printStackTrace();
}
}
public void realizarCompra(final android.app.AlertDialog dialogo, final Activity activity) {
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
= new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) throws IabHelper.IabAsyncInProgressException {
if (result.isFailure() && result.getResponse() != USER_CANCELED) {
Utiles.addToErrorPremium(User_Singleton.getInstance().getIdUsuario(), result.getMessage(), activity);
} else if (purchase != null && purchase.getSku() != null && purchase.getSku().trim().length() > 0 && purchase.getSku().equals(SKU)) {
/// UPDATE ///
needUpdatePremium(activity, purchase);
dialogo.dismiss();
}
}
};
try {
billingHelper.launchPurchaseFlow(activity, SKU, CODIGO_IN_APP_BILLING,
mPurchaseFinishedListener, "premiumCompra");
} catch (IabHelper.IabAsyncInProgressException e) {
e.printStackTrace();
Utiles.addToErrorPremium(User_Singleton.getInstance().getIdUsuario(), e.getMessage(), activity);
}
}
public void needUpdatePremium(final Activity activity, Purchase purchase) {
if (User_Singleton.getInstance().getIdUsuario() != null &&
User_Singleton.getInstance().getIdUsuario().trim().length() > 0 &&
User_Singleton.getInstance().getPremium() == PREMIUM_DESACTIVADO) {
/// CONSUMIMOS EL PRODUCTO ///
try {
billingHelper.consumeAsync(purchase, new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase, IabResult result) {
if (result.isSuccess()) {
/// ACTIVAR PREMIUM ///
Utiles.updatePremium(User_Singleton.getInstance().getIdUsuario(), activity);
User_Singleton.getInstance().setPremium(PREMIUM_ACTIVADO); // update
showOrDisappearAd(); // Disabled los Ads
} else {
Utiles.addToErrorPremium(User_Singleton.getInstance().getIdUsuario(), result.getMessage(), activity);
}
}
});
} catch (IabHelper.IabAsyncInProgressException e) {
Utiles.addToErrorPremium(User_Singleton.getInstance().getIdUsuario(), e.getMessage(), activity);
e.printStackTrace();
}
} else {
Utiles.addToErrorPremium(User_Singleton.getInstance().getIdUsuario(), ERROR_PREMIUM_YA_COMPRADO, activity);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
try {
if (requestCode == CODIGO_IN_APP_BILLING) {
if (!billingHelper.handleActivityResult(requestCode, resultCode, data)) {
Utiles.addToErrorPremium(User_Singleton.getInstance().getIdUsuario(), data.getDataString(), MainActivity.this);
super.onActivityResult(requestCode, resultCode, data);
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
} catch (IabHelper.IabAsyncInProgressException e) {
e.printStackTrace();
Utiles.addToErrorPremium(User_Singleton.getInstance().getIdUsuario(), e.getMessage(), MainActivity.this);
}
我不知道为什么会这样,但是我认为这是一个巨大的错误。 你能帮我吗?
感谢您的优势。