Comments (1)
If you don't need the "ProductDetails", you can easily solve it. Google caches the purchases and you can use it. In the "BillingService.kt" change the following code (comments with XXX):
private fun processPurchases(purchasesList: List<Purchase>?, isRestore: Boolean = false) {
if (!purchasesList.isNullOrEmpty()) {
log("processPurchases: " + purchasesList.size + " purchase(s)")
purchases@ for (purchase in purchasesList) {
// The purchase is considered successful in both PURCHASED and PENDING states.
val purchaseSuccess = purchase.purchaseState == Purchase.PurchaseState.PURCHASED
|| purchase.purchaseState == Purchase.PurchaseState.PENDING
// XXX comment a part of this line
if (purchaseSuccess /* && purchase.products[0].isProductReady() */) {
if (!isSignatureValid(purchase)) {
log("processPurchases. Signature is not valid for: $purchase")
continue@purchases
}
// Grant entitlement to the user.
val productDetails = productDetails[purchase.products[0]]
when (productDetails?.productType) {
BillingClient.ProductType.INAPP -> {
// Consume the purchase
when {
consumableKeys.contains(purchase.products[0]) -> {
mBillingClient.consumeAsync(
ConsumeParams.newBuilder()
.setPurchaseToken(purchase.purchaseToken).build()
) { billingResult, _ ->
when (billingResult.responseCode) {
BillingClient.BillingResponseCode.OK -> {
productOwned(getPurchaseInfo(purchase), false)
}
else -> {
Log.d(
TAG,
"Handling consumables : Error during consumption attempt -> ${billingResult.debugMessage}"
)
}
}
}
}
else -> {
productOwned(getPurchaseInfo(purchase), isRestore)
}
}
}
BillingClient.ProductType.SUBS -> {
subscriptionOwned(getPurchaseInfo(purchase), isRestore)
}
}
// XXX add the next 3 lines of code
if (productDetails == null) {
productOwned(getPurchaseInfo(purchase), isRestore)
}
// If the state is PURCHASED, acknowledge the purchase if it hasn't been acknowledged yet.
if (!purchase.isAcknowledged && purchase.purchaseState == Purchase.PurchaseState.PURCHASED) {
val acknowledgePurchaseParams = AcknowledgePurchaseParams.newBuilder()
.setPurchaseToken(purchase.purchaseToken).build()
mBillingClient.acknowledgePurchase(acknowledgePurchaseParams, this)
}
} else {
Log.e(
TAG, "processPurchases failed. purchase: $purchase " +
"purchaseState: ${purchase.purchaseState} isSkuReady: ${purchase.products[0].isProductReady()}"
)
}
}
} else {
log("processPurchases: with no purchases")
}
}
from google-iap.
Related Issues (20)
- Class file has wrong version 61.0, should be 55.0 HOT 5
- Subscription Period HOT 1
- offerToken is required (NullPointerException) for subscription
- Promotion codes aren't working
- Cannot import a lot of methods HOT 2
- Remove Entitlement from Google play console
- Pending purchase status should not result in entitlement HOT 1
- How to get price of any product?
- Pending purchases still to be managed
- Payment Bypassed while using lucky patcher
- Refunded purchase still appearing in purchase list HOT 2
- How to subscribe to specific base plan?
- Failed to resolve: com.github.akshaaatt:Google-IAP:1.5.0 HOT 2
- Add a method to check if service is initialized and usable
- How to check Subscription cancelled or expired
- onPurchaseFailed working
- The product cannot be consumed.
- iapConnector.addPurchaseListener
- Can you add some constants of Google Play Billing API to your wrapped Google-IAP API? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-iap.