我在用户可以为我捐款的应用程序中使用了https://github.com/Mahadev-code/Android-inApp-Billing示例代码(否则它非常好,易于使用)(技术上以 1 美元购买一件物品)。
但是我有一个问题,好像我尝试购买一样,我收到“无法购买此商品”的消息。该应用程序已发布到 Google Play,我创建了一个要购买的项目,但它不起作用。(我有另一个 2020 年的应用程序,它使用的是旧的 BillingClient,它正在工作,消耗品以相同的方式在 Play 上注册。)
有人可以帮我解决这个问题吗?
提前致谢。
相关的代码部分是:
public BillingConnector billingConnector;
billingConnector = new BillingConnector(this, "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjZXQIdwZV4lxYJeXUNafqECbbpL9rxJCPJYLxmzNj/d69NBz/gYAnmMrFsB70iefjTd7rffnWe4MyTF3RAHbUY8Z43J0Jx7Y6vj5kQXyvNTYTuDI5f4gj1AgRuAqk64robKCOjXdtTdvf2tbxDzNT9CF3SDepJfhqMazEnGK0Tb6mksyPIvxsXxHZNVGp8FCeHSXYSwtQLA/yLLV3ZXzcTmEjf8kLqfrsznOt9pjfLED7jpeNKIzA1z3gOnGrFnfuvAA+o/sNCDq1ERc/5KPSfshGI/D406v/Z/ZTXRUWY/yNYlNQYlenTMFZz1Oa0LTCKqujIb4jrnu3m8FxoQbAwIDAQAB")
.setConsumableIds(consumableIds)
.setNonConsumableIds(nonConsumableIds)
.setSubscriptionIds(subscriptionIds)
.autoAcknowledge()
.autoConsume()
.enableLogging()
.connect();
billingConnector.setBillingEventListener(new BillingEventListener() {
@Override
public void onProductsFetched(@NonNull List<SkuInfo> skuDetails) {
/*Provides a list with fetched products*/
}
@Override
public void onPurchasedProductsFetched(@NonNull List<PurchaseInfo> purchases) {
/*Provides a list with fetched purchased products*/
}
@Override
public void onProductsPurchased(@NonNull List<PurchaseInfo> purchases) {
/*Callback after a product is purchased*/
}
@Override
public void onPurchaseAcknowledged(@NonNull PurchaseInfo purchase) {
/*Callback after a purchase is acknowledged*/
/*
* Grant user entitlement for NON-CONSUMABLE products and SUBSCRIPTIONS here
*
* Even though onProductsPurchased is triggered when a purchase is successfully made
* there might be a problem along the way with the payment and the purchase won't be acknowledged
*
* Google will refund users purchases that aren't acknowledged in 3 days
*
* To ensure that all valid purchases are acknowledged the library will automatically
* check and acknowledge all unacknowledged products at the startup
* */
}
@Override
public void onPurchaseConsumed(@NonNull PurchaseInfo purchase) {
/*Callback after a purchase is consumed*/
/*
* CONSUMABLE products entitlement can be granted either here or in onProductsPurchased
* */
}
@Override
public void onBillingError(@NonNull BillingConnector billingConnector, @NonNull BillingResponse response) {
/*Callback after an error occurs*/
switch (response.getErrorType()) {
case CLIENT_NOT_READY:
//TODO - client is not ready yet
break;
case CLIENT_DISCONNECTED:
//TODO - client has disconnected
break;
case SKU_NOT_EXIST:
//TODO - sku does not exist
break;
case CONSUME_ERROR:
//TODO - error during consumption
break;
case ACKNOWLEDGE_ERROR:
//TODO - error during acknowledgment
break;
case ACKNOWLEDGE_WARNING:
/*
* This will be triggered when a purchase can not be acknowledged because the state is PENDING
* A purchase can be acknowledged only when the state is PURCHASED
*
* PENDING transactions usually occur when users choose cash as their form of payment
*
* Here users can be informed that it may take a while until the purchase complete
* and to come back later to receive their purchase
* */
//TODO - warning during acknowledgment
break;
case FETCH_PURCHASED_PRODUCTS_ERROR:
//TODO - error occurred while querying purchased products
break;
case BILLING_ERROR:
//TODO - error occurred during initialization / querying sku details
break;
case USER_CANCELED:
//TODO - user pressed back or canceled a dialog
break;
case SERVICE_UNAVAILABLE:
//TODO - network connection is down
break;
case BILLING_UNAVAILABLE:
//TODO - billing API version is not supported for the type requested
break;
case ITEM_UNAVAILABLE:
//TODO - requested product is not available for purchase
break;
case DEVELOPER_ERROR:
//TODO - invalid arguments provided to the API
break;
case ERROR:
//TODO - fatal error during the API action
break;
case ITEM_ALREADY_OWNED:
//TODO - failure to purchase since item is already owned
break;
case ITEM_NOT_OWNED:
//TODO - failure to consume since item is not owned
break;
}
}
});
donate_button = (Button) popupView.findViewById(R.id.donatebutton);
donate_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View popupView) {
/*a donate gombra*/
billingConnector.purchase(MainActivity.this, "1d");
// billingConnector.purchase(MainActivity.this, "$1 donation");
//return true;
}
});