@capgo/native-purchases 0.0.38 → 0.0.40

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.
@@ -7,14 +7,13 @@ import com.android.billingclient.api.BillingClient;
7
7
  import com.android.billingclient.api.BillingClientStateListener;
8
8
  import com.android.billingclient.api.BillingFlowParams;
9
9
  import com.android.billingclient.api.BillingResult;
10
+ import com.android.billingclient.api.ConsumeParams;
11
+ import com.android.billingclient.api.ConsumeResponseListener;
10
12
  import com.android.billingclient.api.ProductDetails;
11
13
  import com.android.billingclient.api.ProductDetailsResponseListener;
12
14
  import com.android.billingclient.api.Purchase;
13
15
  import com.android.billingclient.api.PurchasesUpdatedListener;
14
16
  import com.android.billingclient.api.QueryProductDetailsParams;
15
- import com.android.billingclient.api.SkuDetails;
16
- import com.android.billingclient.api.SkuDetailsParams;
17
- import com.android.billingclient.api.SkuDetailsResponseListener;
18
17
  import com.getcapacitor.JSObject;
19
18
  import com.getcapacitor.Plugin;
20
19
  import com.getcapacitor.PluginCall;
@@ -22,15 +21,13 @@ import com.getcapacitor.PluginMethod;
22
21
  import com.getcapacitor.annotation.CapacitorPlugin;
23
22
  import com.google.common.collect.ImmutableList;
24
23
  import java.util.ArrayList;
25
- import java.util.Arrays;
26
24
  import java.util.List;
27
25
  import java.util.concurrent.CountDownLatch;
28
- import org.json.JSONArray;
29
- import org.json.JSONException;
30
- import java.util.concurrent.TimeoutException;
31
26
  import java.util.concurrent.Phaser;
32
- import java.util.concurrent.Semaphore;
33
27
  import java.util.concurrent.TimeUnit;
28
+ import java.util.concurrent.TimeoutException;
29
+ import org.json.JSONArray;
30
+ import org.json.JSONException;
34
31
 
35
32
  @CapacitorPlugin(name = "NativePurchases")
36
33
  public class NativePurchasesPlugin extends Plugin {
@@ -102,7 +99,32 @@ public class NativePurchasesPlugin extends Plugin {
102
99
  private void handlePurchase(Purchase purchase, PluginCall purchaseCall) {
103
100
  if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
104
101
  // Grant entitlement to the user, then acknowledge the purchase
105
- acknowledgePurchase(purchase.getPurchaseToken());
102
+ // if sub then acknowledgePurchase
103
+ // if one time then consumePurchase
104
+ if (purchase.isAcknowledged()) {
105
+ ConsumeParams consumeParams = ConsumeParams
106
+ .newBuilder()
107
+ .setPurchaseToken(purchase.getPurchaseToken())
108
+ .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
+ );
125
+ } else {
126
+ acknowledgePurchase(purchase.getPurchaseToken());
127
+ }
106
128
 
107
129
  JSObject ret = new JSObject();
108
130
  ret.put("transactionId", purchase.getPurchaseToken());
@@ -160,7 +182,10 @@ public class NativePurchasesPlugin extends Plugin {
160
182
  BillingResult billingResult,
161
183
  List<Purchase> purchases
162
184
  ) {
163
- Log.i(NativePurchasesPlugin.TAG, "onPurchasesUpdated" + billingResult);
185
+ Log.i(
186
+ NativePurchasesPlugin.TAG,
187
+ "onPurchasesUpdated" + billingResult
188
+ );
164
189
  if (
165
190
  billingResult.getResponseCode() ==
166
191
  BillingClient.BillingResponseCode.OK &&
@@ -172,7 +197,10 @@ public class NativePurchasesPlugin extends Plugin {
172
197
  handlePurchase(purchases.get(0), purchaseCall);
173
198
  } else {
174
199
  // Handle any other error codes.
175
- Log.i(NativePurchasesPlugin.TAG, "onPurchasesUpdated" + billingResult);
200
+ Log.i(
201
+ NativePurchasesPlugin.TAG,
202
+ "onPurchasesUpdated" + billingResult
203
+ );
176
204
  if (purchaseCall != null) {
177
205
  purchaseCall.reject("Purchase is not purchased");
178
206
  }
@@ -253,7 +281,9 @@ public class NativePurchasesPlugin extends Plugin {
253
281
  ImmutableList<QueryProductDetailsParams.Product> productList = ImmutableList.of(
254
282
  QueryProductDetailsParams.Product
255
283
  .newBuilder()
256
- .setProductId(productType.equals("inapp") ? productIdentifier : planIdentifier)
284
+ .setProductId(
285
+ productType.equals("inapp") ? productIdentifier : planIdentifier
286
+ )
257
287
  .setProductType(
258
288
  productType.equals("inapp")
259
289
  ? BillingClient.ProductType.INAPP
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/native-purchases",
3
- "version": "0.0.38",
3
+ "version": "0.0.40",
4
4
  "description": "In-app Subscriptions Made Easy",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",