【发布时间】:2021-04-09 14:46:52
【问题描述】:
BillingResponse.developerError I/flutter (5091):购买处于无效状态。
有时我会收到此错误,但我会遇到计费响应正常 (BillingResponse.ok) 的情况。可能是什么问题?我的代码遵循flutter.dev的官方示例https://pub.dev/packages/in_app_purchase 在这段代码之前一切都很好
var completePurchase = await InAppPurchaseConnection.instance
.completePurchase(purchaseDetails);
返回 BillingResponse.developerError 或者有时魔法返回 BillingResponse.ok
在小部件中我只是调用 buyNonConsumable
instance.buyNonConsumable(prod);
是否有可能是因为它不在生产中或其他与内部测试相关的东西,因为应用程序正在进行内部测试? 总而言之,代码是这样的
_subscription = getPurchaseStream.listen(
(purchaseDetailsList) {
_listenToPurchaseUpdated(purchaseDetailsList);
}, onDone: () {
_subscription.cancel();
}, onError: (error) {
// handle error here.
print('Subscription error: $error');
});
_isAvailable = await _connection.isAvailable();
if(!_isAvailable) {
print('The store is not available, try again later..');
return;
}
_myProductsIds = await _categoryRepository.getCategoriesGoogleProductsIds();
await _getProducts();
await _getPastPurchases();
for (PurchaseDetails purchase in _purchases) {
verifyPurchase(purchase.productID);
if (_isPurchased) { //Check if product is purchased
await deliverProduct(); // Give the products on the user
} else {
_handleInvalidPurchase(purchase);
}
}
purchaseDetailsList.forEach((PurchaseDetails purchaseDetails) async {
if (purchaseDetails.status == PurchaseStatus.pending) {
print('Pending..');
} else {
if (purchaseDetails.status == PurchaseStatus.error) {
print('To purchases status error: ${purchaseDetails.error}');
} else if (purchaseDetails.status == PurchaseStatus.purchased) {
verifyPurchase(purchaseDetails.productID); // change value of _isPurchased
if (_isPurchased) {
_purchases.add(purchaseDetails);
for(String id in _myProductsIds) {
if (purchaseDetails.productID == id) {
await deliverProduct(); // Give the products on the user
}
}
} else {
_handleInvalidPurchase(purchaseDetails);
return;
}
}
if (Platform.isAndroid) {
for(String id in _myProductsIds) {
if (purchaseDetails.productID == id) {
await InAppPurchaseConnection.instance
.consumePurchase(purchaseDetails);
}
}
}
if (purchaseDetails.pendingCompletePurchase) {
var completePurchase = await InAppPurchaseConnection.instance
.completePurchase(purchaseDetails);
}
}
【问题讨论】:
标签: flutter dart in-app-purchase