Cant purchase anything in testing purchase mode. Here is the code. When i clicked YES in my DialogFragment nothing change. But if i try to purchase in release APK all ok. What the problem guys?
public void StupidLogic(){
ITEM_SKU = "android.test.purchased";
mHelper.launchPurchaseFlow(getActivity(), ITEM_SKU, 10001, mPurchaseFinishedListener, "mytoken");
}
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
= new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result,
Purchase purchase)
{
if (result.isFailure()) {
// Handle error
return;
}
else if (purchase.getSku().equals(ITEM_SKU)) {
consumeItem();
}
}
};
public void consumeItem() {
mHelper.queryInventoryAsync(mReceivedInventoryListener);
}
IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener
= new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (result.isFailure()) {
Log.d("Billing"," Such Failure! WOW!");
} else {
mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU),
mConsumeFinishedListener);
}
}
};
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
new IabHelper.OnConsumeFinishedListener() {
public void onConsumeFinished(Purchase purchase,
IabResult result) {
if (result.isSuccess()) {
//Приходящий ответ!!!!!--------------------------------------------------------------------------------------------
//String URL = "http://cybergenesis.ru/egor/add_service?ontime=" + ontimeString + "&offtime=" + offtimeString + "&user_id=" + info_id + "&service=" + Integer.toString(position + 1) + "&balance=" + String.valueOf(balance);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://cybergenesis.ru/egor/")
.addConverterFactory(GsonConverterFactory.create())
.build();
APIService service = retrofit.create(APIService.class);
Call<Post> call = service.addService(ontimeString, offtimeString, info_id, positionStr, Balance);
call.enqueue(new Callback<Post>() {
@Override
public void onResponse(Call<Post> call, retrofit2.Response<Post> response) {
}
@Override
public void onFailure(Call<Post> call, Throwable t) {
}
});
} else {
// handle error
}
}
};
@Override
public void onDestroy() {
super.onDestroy();
if (mHelper != null) mHelper.dispose();
mHelper = null;
}
}
All ok if i purchase not in Dialog.
If IAB works in the signed release version of the apk but not in debugging, this might be your problem:
You should modify your Security.java file to have debugging mode activated. This allows the method to work in unsigned apks. This is for debugging only, remember to revert it before publishing.
public static boolean verifyPurchase(String base64PublicKey,
String signedData, String signature) {
if (TextUtils.isEmpty(signedData) ||
TextUtils.isEmpty(base64PublicKey) ||
TextUtils.isEmpty(signature)) {
Log.e(TAG, "Purchase verification failed: missing data.");
if (BuildConfig.DEBUG) {
return true;
}
return false;
}
PublicKey key = Security.generatePublicKey(base64PublicKey);
return Security.verify(key, signedData, signature);
}
InApp purchases only and only works in production application, so you will have to get signed apk and upload it to alpha testing on play console.
These steps can help you more:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.