[英]Android In-App Purchase Failure on Successful Purchase
I am developing an with in-app purchases.我正在开发具有应用内购买功能的应用程序。 I have put the app on play store in closed testing.
我已将该应用程序放在 Play 商店进行封闭测试。 With tester emails and added tester emails in account settings.
使用测试人员电子邮件并在帐户设置中添加测试人员电子邮件。 I have 2 managed products on play store.
我在 Play 商店有 2 个托管产品。 I tested android.test.purchased in debug mode and it's working fine.
我在调试模式下测试了 android.test.purchased,它工作正常。 But on release build installed from play store when I purchase a SKU it completes purchase successfully but I am getting failure response for some reason.
但是,当我购买 SKU 时,从 Play 商店安装的发布版本会成功完成购买,但由于某种原因我收到了失败响应。 I am trying to figure this out.
我想弄清楚这一点。 Also I am consuming the items after purchasing so It becomes available again.
此外,我在购买后正在消费这些物品,因此它再次可用。 Here's my code
这是我的代码
mHelper = new IabHelper(this, Constants.BASE64_ENCODED_PUBLIC_KEY);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
Log.d(TAG, "In-app Billing setup failed due to: " +
result.getMessage());
} else {
//do further steps here.
Log.d(TAG, "In-app Billing is set up OK");
}
}
});
Then on button click然后点击按钮
mHelper.launchPurchaseFlow(PurchaseActivity.this, ITEM_SKU, 10001,
mPurchaseFinishedListener, "mypurchasetoken");
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
if (result.isFailure()) {
Toast.makeText(PurchaseActivity.this, "mPurchaseFinishedListener: " + result.getMessage(), Toast.LENGTH_SHORT).show();
if (result.getResponse() == 7) {
consumeItem();
} else {
dismissProgressDialog();
Log.d(TAG, "onIabPurchaseFinishedWithError: " + result.getMessage());
AlertHelper.errorAlert(PurchaseActivity.this,
getString(R.string.purchase_unsuccessful_text), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
}
} else if (purchase.getSku().equals(ITEM_SKU)) {
Log.d(TAG, "onIabPurchaseFinishedWithSuccess: ");
consumeItem();
}
}
};
public void consumeItem() {
/* if (isTest) {
try {
int response = mHelper.mService.consumePurchase(3, getPackageName(), "inapp:" + getPackageName() + ":android.test.purchased");
if (response == 0) {
//Save purchase status to shared pref.
updateUserAccount(ITEM_SKU);
//Sign up user to our server.
signUpUserToServer("android.test.purchased:9090");
Log.d(TAG, "onConsumeFinishedSuccessfully");
} else {
Log.d(TAG, "onConsumeFinishedWithError: " + response);
}
} catch (RemoteException e) {
e.printStackTrace();
}
} else*/
mHelper.queryInventoryAsync(mReceivedInventoryListener);
}
IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (result.isFailure()) {
dismissProgressDialog();
Log.d(TAG, "onQueryInventoryFinishedWithError: " + result.getMessage());
Toast.makeText(PurchaseActivity.this, "mReceivedInventoryListener: " + result.getMessage(), Toast.LENGTH_SHORT)
.show();
} else {
Log.d(TAG, "onQueryInventoryFinished. asyncConsume fired. ");
mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU),
mConsumeFinishedListener);
}
}
};
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase, IabResult result) {
if (result.isSuccess()) {
if (isAlreadyOwned) {
isAlreadyOwned = false;
processPurchaseClick();
} else {
//Save purchase status to shared pref.
updateUserAccount(ITEM_SKU);
//Sign up user to our server.
signUpUserToServer(purchase.getToken());
Log.d(TAG, "onConsumeFinishedSuccessfully");
}
} else {
Toast.makeText(PurchaseActivity.this, "onConsumeFinishedWithError: " + result.getMessage(), Toast.LENGTH_SHORT)
.show();
Log.d(TAG, "onConsumeFinishedWithError: " + result.getMessage());
}
}
};
On successful purchase from my test account I am getting failure result and R.string.purchase_unsuccessful_text in onPurchasefinishedListener.从我的测试帐户成功购买后,我在 onPurchasefinishedListener 中收到失败结果和 R.string.purchase_unsuccessful_text。 Help plz
请帮忙
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.