-
Notifications
You must be signed in to change notification settings - Fork 66
added: Initial part of the GooglePlay consumable support #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
87b3bfb
7a270d6
bcc54e1
297d8ec
8926706
3b8d8e1
a002cf3
f314c49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |||||
| import java.util.List; | ||||||
| import java.util.ArrayList; | ||||||
| import java.util.Objects; | ||||||
|
|
||||||
| import java.util.HashSet; | ||||||
| import android.app.Activity; | ||||||
| import androidx.annotation.NonNull; | ||||||
| import android.util.Log; | ||||||
|
|
@@ -35,6 +35,9 @@ public class PlayStore extends Store { | |||||
| /* A map from sku to ProductDetails object. */ | ||||||
| private HashMap<String, ProductDetails> productDetailsMap = new HashMap<>(); | ||||||
|
|
||||||
| /* A set of SKUs that are consumable. */ | ||||||
| private HashSet<String> consumableSKUs = new HashSet<>(); | ||||||
neyunse marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
neyunse marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| public PlayStore(Activity activity) { | ||||||
| this.activity = activity; | ||||||
|
|
||||||
|
|
@@ -212,4 +215,57 @@ public boolean requestReview() { | |||||
|
|
||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public boolean consumePurchase(String sku) { | ||||||
| try { | ||||||
| Log.i("iap", "consumePurchase " + sku); | ||||||
| finished = false; | ||||||
|
|
||||||
| billingClient.queryPurchasesAsync( | ||||||
| QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.INAPP).build(), | ||||||
| new PurchasesResponseListener() { | ||||||
| @Override | ||||||
| public void onQueryPurchasesResponse(@NonNull BillingResult billingResult, @NonNull List<Purchase> purchases) { | ||||||
| if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) { | ||||||
| for (Purchase p : purchases) { | ||||||
| if (p.getProducts().contains(sku) && p.getPurchaseState() == Purchase.PurchaseState.PURCHASED) { | ||||||
| ConsumeParams consumeParams = ConsumeParams.newBuilder() | ||||||
| .setPurchaseToken(p.getPurchaseToken()) | ||||||
| .build(); | ||||||
|
|
||||||
neyunse marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| billingClient.consumeAsync(consumeParams, new ConsumeResponseListener() { | ||||||
| @Override | ||||||
| public void onConsumeResponse(@NonNull BillingResult billingResult, @NonNull String purchaseToken) { | ||||||
| if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) { | ||||||
| Log.i("iap", "Successfully consumed " + sku); | ||||||
| purchased.remove(sku); | ||||||
| } else { | ||||||
| Log.e("iap", "Failed to consume " + sku); | ||||||
|
||||||
| Log.e("iap", "Failed to consume " + sku); | |
| Log.e("iap", "Failed to consume " + sku + ": " + billingResult.getDebugMessage()); |
Uh oh!
There was an error while loading. Please reload this page.