@capgo/native-purchases 0.0.40 → 0.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -8,12 +8,12 @@ import com.android.billingclient.api.BillingClientStateListener;
|
|
|
8
8
|
import com.android.billingclient.api.BillingFlowParams;
|
|
9
9
|
import com.android.billingclient.api.BillingResult;
|
|
10
10
|
import com.android.billingclient.api.ConsumeParams;
|
|
11
|
-
import com.android.billingclient.api.ConsumeResponseListener;
|
|
12
11
|
import com.android.billingclient.api.ProductDetails;
|
|
13
12
|
import com.android.billingclient.api.ProductDetailsResponseListener;
|
|
14
13
|
import com.android.billingclient.api.Purchase;
|
|
15
14
|
import com.android.billingclient.api.PurchasesUpdatedListener;
|
|
16
15
|
import com.android.billingclient.api.QueryProductDetailsParams;
|
|
16
|
+
import com.android.billingclient.api.QueryPurchasesParams;
|
|
17
17
|
import com.getcapacitor.JSObject;
|
|
18
18
|
import com.getcapacitor.Plugin;
|
|
19
19
|
import com.getcapacitor.PluginCall;
|
|
@@ -97,6 +97,11 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
private void handlePurchase(Purchase purchase, PluginCall purchaseCall) {
|
|
100
|
+
Log.i(NativePurchasesPlugin.TAG, "handlePurchase" + purchase);
|
|
101
|
+
Log.i(
|
|
102
|
+
NativePurchasesPlugin.TAG,
|
|
103
|
+
"getPurchaseState" + purchase.getPurchaseState()
|
|
104
|
+
);
|
|
100
105
|
if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
|
|
101
106
|
// Grant entitlement to the user, then acknowledge the purchase
|
|
102
107
|
// if sub then acknowledgePurchase
|
|
@@ -106,22 +111,7 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
106
111
|
.newBuilder()
|
|
107
112
|
.setPurchaseToken(purchase.getPurchaseToken())
|
|
108
113
|
.build();
|
|
109
|
-
billingClient.consumeAsync(
|
|
110
|
-
consumeParams,
|
|
111
|
-
new ConsumeResponseListener() {
|
|
112
|
-
@Override
|
|
113
|
-
public void onConsumeResponse(
|
|
114
|
-
BillingResult billingResult,
|
|
115
|
-
String purchaseToken
|
|
116
|
-
) {
|
|
117
|
-
// Handle the result
|
|
118
|
-
Log.i(
|
|
119
|
-
NativePurchasesPlugin.TAG,
|
|
120
|
-
"onConsumeResponse" + billingResult + purchaseToken
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
);
|
|
114
|
+
billingClient.consumeAsync(consumeParams, this::onConsumeResponse);
|
|
125
115
|
} else {
|
|
126
116
|
acknowledgePurchase(purchase.getPurchaseToken());
|
|
127
117
|
}
|
|
@@ -357,10 +347,85 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
357
347
|
}
|
|
358
348
|
}
|
|
359
349
|
|
|
350
|
+
private void processUnfinishedPurchases() {
|
|
351
|
+
QueryPurchasesParams queryInAppPurchasesParams = QueryPurchasesParams
|
|
352
|
+
.newBuilder()
|
|
353
|
+
.setProductType(BillingClient.ProductType.INAPP)
|
|
354
|
+
.build();
|
|
355
|
+
billingClient.queryPurchasesAsync(
|
|
356
|
+
queryInAppPurchasesParams,
|
|
357
|
+
this::handlePurchases
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
QueryPurchasesParams querySubscriptionsParams = QueryPurchasesParams
|
|
361
|
+
.newBuilder()
|
|
362
|
+
.setProductType(BillingClient.ProductType.SUBS)
|
|
363
|
+
.build();
|
|
364
|
+
billingClient.queryPurchasesAsync(
|
|
365
|
+
querySubscriptionsParams,
|
|
366
|
+
this::handlePurchases
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
private void handlePurchases(
|
|
371
|
+
BillingResult billingResult,
|
|
372
|
+
List<Purchase> purchases
|
|
373
|
+
) {
|
|
374
|
+
if (
|
|
375
|
+
billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK
|
|
376
|
+
) {
|
|
377
|
+
for (Purchase purchase : purchases) {
|
|
378
|
+
if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
|
|
379
|
+
if (!purchase.isAcknowledged()) {
|
|
380
|
+
if (purchase.getSkus().contains(BillingClient.ProductType.SUBS)) {
|
|
381
|
+
// Acknowledge subscription purchase
|
|
382
|
+
acknowledgePurchase(purchase.getPurchaseToken());
|
|
383
|
+
} else if (
|
|
384
|
+
purchase.getSkus().contains(BillingClient.ProductType.INAPP)
|
|
385
|
+
) {
|
|
386
|
+
// Consume in-app purchase
|
|
387
|
+
ConsumeParams consumeParams = ConsumeParams
|
|
388
|
+
.newBuilder()
|
|
389
|
+
.setPurchaseToken(purchase.getPurchaseToken())
|
|
390
|
+
.build();
|
|
391
|
+
billingClient.consumeAsync(
|
|
392
|
+
consumeParams,
|
|
393
|
+
this::onConsumeResponse
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
private void onConsumeResponse(
|
|
403
|
+
BillingResult billingResult,
|
|
404
|
+
String purchaseToken
|
|
405
|
+
) {
|
|
406
|
+
if (
|
|
407
|
+
billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK
|
|
408
|
+
) {
|
|
409
|
+
// Handle the success of the consume operation.
|
|
410
|
+
// For example, you can update the UI to reflect that the item has been consumed.
|
|
411
|
+
Log.i(
|
|
412
|
+
NativePurchasesPlugin.TAG,
|
|
413
|
+
"onConsumeResponse OK " + billingResult + purchaseToken
|
|
414
|
+
);
|
|
415
|
+
} else {
|
|
416
|
+
// Handle error responses.
|
|
417
|
+
Log.i(
|
|
418
|
+
NativePurchasesPlugin.TAG,
|
|
419
|
+
"onConsumeResponse OTHER " + billingResult + purchaseToken
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
360
424
|
@PluginMethod
|
|
361
425
|
public void restorePurchases(PluginCall call) {
|
|
362
426
|
Log.d(NativePurchasesPlugin.TAG, "restorePurchases");
|
|
363
427
|
this.initBillingClient(null);
|
|
428
|
+
this.processUnfinishedPurchases();
|
|
364
429
|
call.resolve();
|
|
365
430
|
}
|
|
366
431
|
|