@capgo/native-purchases 8.8.2 → 8.9.0

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.
@@ -3,7 +3,6 @@ package ee.forgr.nativepurchases;
3
3
  import android.content.pm.PackageInfo;
4
4
  import android.content.pm.PackageManager;
5
5
  import android.os.Build;
6
- import android.util.Log;
7
6
  import androidx.annotation.NonNull;
8
7
  import com.android.billingclient.api.AccountIdentifiers;
9
8
  import com.android.billingclient.api.AcknowledgePurchaseParams;
@@ -29,7 +28,6 @@ import com.getcapacitor.Plugin;
29
28
  import com.getcapacitor.PluginCall;
30
29
  import com.getcapacitor.PluginMethod;
31
30
  import com.getcapacitor.annotation.CapacitorPlugin;
32
- import com.google.common.collect.ImmutableList;
33
31
  import java.util.ArrayList;
34
32
  import java.util.Collections;
35
33
  import java.util.List;
@@ -45,7 +43,7 @@ import org.json.JSONArray;
45
43
  @CapacitorPlugin(name = "NativePurchases")
46
44
  public class NativePurchasesPlugin extends Plugin {
47
45
 
48
- private final String pluginVersion = "8.8.2";
46
+ private final String pluginVersion = "8.9.0";
49
47
  public static final String TAG = "NativePurchases";
50
48
  private static final int BILLING_CONNECTION_MAX_ATTEMPTS = 2;
51
49
  private static final long BILLING_SETUP_TIMEOUT_SECONDS = 5;
@@ -57,32 +55,146 @@ public class NativePurchasesPlugin extends Plugin {
57
55
  return thread;
58
56
  });
59
57
  private BillingClient billingClient;
58
+ private volatile boolean autoFinishTransactions = true;
59
+
60
+ @PluginMethod
61
+ public void configure(PluginCall call) {
62
+ Boolean value = call.getBoolean("autoFinishTransactions");
63
+ if (value != null) {
64
+ autoFinishTransactions = value;
65
+ NativePurchasesLog.d(TAG, "autoFinishTransactions set to " + value);
66
+ }
67
+ call.resolve();
68
+ }
69
+
70
+ @PluginMethod
71
+ public void finishTransaction(PluginCall call) {
72
+ call.reject(
73
+ "finishTransaction is for StoreKit 2 on iOS. On Android, call acknowledgePurchase({ purchaseToken }) to acknowledge Google Play purchases."
74
+ );
75
+ }
76
+
77
+ @PluginMethod
78
+ public void getUnfinishedTransactions(PluginCall call) {
79
+ NativePurchasesLog.d(TAG, "getUnfinishedTransactions() called");
80
+ withBillingClient(call, () -> {
81
+ JSONArray unacknowledged = new JSONArray();
82
+ AtomicInteger pendingQueries = new AtomicInteger(2);
83
+ AtomicBoolean finished = new AtomicBoolean(false);
84
+ AtomicReference<String> queryFailure = new AtomicReference<>(null);
85
+
86
+ Runnable maybeFinish = () -> {
87
+ if (pendingQueries.decrementAndGet() <= 0 && finished.compareAndSet(false, true)) {
88
+ closeBillingClient();
89
+ String failure = queryFailure.get();
90
+ if (failure != null) {
91
+ NativePurchasesLog.w(TAG, "Rejecting getUnfinishedTransactions: " + failure);
92
+ call.reject("Failed to query purchases: " + failure, "QUERY_PURCHASES_FAILED");
93
+ return;
94
+ }
95
+ JSObject result = new JSObject();
96
+ result.put("transactions", unacknowledged);
97
+ call.resolve(result);
98
+ }
99
+ };
100
+
101
+ QueryPurchasesParams inAppParams = QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.INAPP).build();
102
+ billingClient.queryPurchasesAsync(inAppParams, (billingResult, purchases) -> {
103
+ try {
104
+ if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && purchases != null) {
105
+ appendUnacknowledgedPurchases(billingResult, purchases, "inapp", unacknowledged);
106
+ } else {
107
+ queryFailure.compareAndSet(null, describeQueryFailure("inapp", billingResult));
108
+ }
109
+ } catch (Exception ex) {
110
+ queryFailure.compareAndSet(null, describeQueryFailure("inapp", billingResult) + " / " + ex.getMessage());
111
+ } finally {
112
+ maybeFinish.run();
113
+ }
114
+ });
115
+
116
+ QueryPurchasesParams subsParams = QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.SUBS).build();
117
+ billingClient.queryPurchasesAsync(subsParams, (billingResult, purchases) -> {
118
+ try {
119
+ if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && purchases != null) {
120
+ appendUnacknowledgedPurchases(billingResult, purchases, "subs", unacknowledged);
121
+ } else {
122
+ queryFailure.compareAndSet(null, describeQueryFailure("subs", billingResult));
123
+ }
124
+ } catch (Exception ex) {
125
+ queryFailure.compareAndSet(null, describeQueryFailure("subs", billingResult) + " / " + ex.getMessage());
126
+ } finally {
127
+ maybeFinish.run();
128
+ }
129
+ });
130
+ });
131
+ }
132
+
133
+ private void appendUnacknowledgedPurchases(
134
+ BillingResult billingResult,
135
+ List<Purchase> purchases,
136
+ String productType,
137
+ JSONArray target
138
+ ) {
139
+ if (billingResult.getResponseCode() != BillingClient.BillingResponseCode.OK || purchases == null) {
140
+ return;
141
+ }
142
+ for (Purchase purchase : purchases) {
143
+ if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED && !purchase.isAcknowledged()) {
144
+ target.put(buildPurchaseTransactionObject(purchase, productType));
145
+ }
146
+ }
147
+ }
148
+
149
+ private static String formatUtcIso8601(long timeMillis) {
150
+ java.text.SimpleDateFormat purchaseDateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", java.util.Locale.US);
151
+ purchaseDateFormat.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));
152
+ return purchaseDateFormat.format(new java.util.Date(timeMillis));
153
+ }
154
+
155
+ private JSObject buildPurchaseTransactionObject(Purchase purchase, String productType) {
156
+ AccountIdentifiers accountIdentifiers = purchase.getAccountIdentifiers();
157
+ String purchaseAccountId = accountIdentifiers != null ? accountIdentifiers.getObfuscatedAccountId() : null;
158
+ JSObject purchaseData = new JSObject();
159
+ purchaseData.put("transactionId", purchase.getPurchaseToken());
160
+ purchaseData.put("productIdentifier", purchase.getProducts().isEmpty() ? null : purchase.getProducts().get(0));
161
+ purchaseData.put("purchaseDate", formatUtcIso8601(purchase.getPurchaseTime()));
162
+ purchaseData.put("quantity", purchase.getQuantity());
163
+ purchaseData.put("productType", productType);
164
+ purchaseData.put("orderId", purchase.getOrderId());
165
+ purchaseData.put("purchaseToken", purchase.getPurchaseToken());
166
+ purchaseData.put("isAcknowledged", purchase.isAcknowledged());
167
+ purchaseData.put("purchaseState", String.valueOf(purchase.getPurchaseState()));
168
+ purchaseData.put("appAccountToken", purchaseAccountId);
169
+ purchaseData.put("willCancel", null);
170
+ return purchaseData;
171
+ }
60
172
 
61
173
  @PluginMethod
62
174
  public void isBillingSupported(PluginCall call) {
63
- Log.d(TAG, "isBillingSupported() called");
175
+ NativePurchasesLog.d(TAG, "isBillingSupported() called");
64
176
  billingExecutor.execute(() -> {
65
177
  try {
66
178
  // Pass null so initBillingClient doesn't reject the call - we'll handle the result ourselves
67
179
  this.initBillingClient(null);
68
180
  JSObject ret = new JSObject();
69
181
  ret.put("isBillingSupported", true);
70
- Log.d(TAG, "isBillingSupported() returning true - billing client initialized successfully");
182
+ NativePurchasesLog.d(TAG, "isBillingSupported() returning true - billing client initialized successfully");
71
183
  closeBillingClient();
72
184
  call.resolve(ret);
73
185
  } catch (RuntimeException e) {
74
- Log.e(TAG, "isBillingSupported() - billing client initialization failed: " + e.getMessage());
186
+ NativePurchasesLog.e(TAG, "isBillingSupported() - billing client initialization failed: " + e.getMessage());
75
187
  closeBillingClient();
76
188
  JSObject ret = new JSObject();
77
189
  ret.put("isBillingSupported", false);
78
- Log.d(TAG, "isBillingSupported() returning false - billing not available");
190
+ NativePurchasesLog.d(TAG, "isBillingSupported() returning false - billing not available");
79
191
  call.resolve(ret);
80
192
  } catch (Exception e) {
81
- Log.e(TAG, "isBillingSupported() - unexpected error: " + e.getMessage());
193
+ NativePurchasesLog.e(TAG, "isBillingSupported() - unexpected error: " + e.getMessage());
82
194
  closeBillingClient();
83
195
  JSObject ret = new JSObject();
84
196
  ret.put("isBillingSupported", false);
85
- Log.d(TAG, "isBillingSupported() returning false - unexpected error");
197
+ NativePurchasesLog.d(TAG, "isBillingSupported() returning false - unexpected error");
86
198
  call.resolve(ret);
87
199
  }
88
200
  });
@@ -90,7 +202,7 @@ public class NativePurchasesPlugin extends Plugin {
90
202
 
91
203
  @PluginMethod
92
204
  public void getStorefront(PluginCall call) {
93
- Log.d(TAG, "getStorefront() called");
205
+ NativePurchasesLog.d(TAG, "getStorefront() called");
94
206
  billingExecutor.execute(() -> {
95
207
  try {
96
208
  // Pass null so initBillingClient doesn't reject the call - getStorefront
@@ -105,11 +217,11 @@ public class NativePurchasesPlugin extends Plugin {
105
217
  JSObject ret = new JSObject();
106
218
  if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && billingConfig != null) {
107
219
  String countryCode = billingConfig.getCountryCode();
108
- Log.d(TAG, "getBillingConfig success, countryCode: " + countryCode);
220
+ NativePurchasesLog.d(TAG, "getBillingConfig success, countryCode: " + countryCode);
109
221
  // JSObject.put(name, null) removes the key, so coalesce to "".
110
222
  ret.put("countryCode", countryCode != null ? countryCode : "");
111
223
  } else {
112
- Log.e(
224
+ NativePurchasesLog.e(
113
225
  TAG,
114
226
  "getBillingConfig unavailable: " +
115
227
  billingResult.getResponseCode() +
@@ -124,11 +236,11 @@ public class NativePurchasesPlugin extends Plugin {
124
236
  }
125
237
  );
126
238
  } catch (RuntimeException e) {
127
- Log.e(TAG, "getStorefront() - billing client init failed: " + e.getMessage());
239
+ NativePurchasesLog.e(TAG, "getStorefront() - billing client init failed: " + e.getMessage());
128
240
  closeBillingClient();
129
241
  call.resolve(emptyStorefront());
130
242
  } catch (Exception e) {
131
- Log.e(TAG, "getBillingConfigAsync threw: " + e.getMessage());
243
+ NativePurchasesLog.e(TAG, "getBillingConfigAsync threw: " + e.getMessage());
132
244
  closeBillingClient();
133
245
  call.resolve(emptyStorefront());
134
246
  }
@@ -143,10 +255,12 @@ public class NativePurchasesPlugin extends Plugin {
143
255
 
144
256
  @Override
145
257
  public void load() {
258
+ autoFinishTransactions = getConfig().getBoolean("autoFinishTransactions", true);
146
259
  super.load();
147
- Log.d(TAG, "Plugin load() called");
148
- Log.i(NativePurchasesPlugin.TAG, "load");
149
- Log.d(TAG, "Plugin load() completed");
260
+ NativePurchasesLog.configure(getConfig().getBoolean("debugLogging", false));
261
+ NativePurchasesLog.d(TAG, "Plugin load() called, autoFinishTransactions=" + autoFinishTransactions);
262
+ NativePurchasesLog.i(NativePurchasesPlugin.TAG, "load");
263
+ NativePurchasesLog.d(TAG, "Plugin load() completed");
150
264
  }
151
265
 
152
266
  @FunctionalInterface
@@ -160,10 +274,10 @@ public class NativePurchasesPlugin extends Plugin {
160
274
  initBillingClient(call);
161
275
  task.run();
162
276
  } catch (RuntimeException e) {
163
- Log.e(TAG, "Failed to initialize billing client: " + e.getMessage());
277
+ NativePurchasesLog.e(TAG, "Failed to initialize billing client: " + e.getMessage());
164
278
  closeBillingClient();
165
279
  } catch (Exception e) {
166
- Log.e(TAG, "Billing task failed: " + e.getMessage());
280
+ NativePurchasesLog.e(TAG, "Billing task failed: " + e.getMessage());
167
281
  closeBillingClient();
168
282
  if (call != null) {
169
283
  call.reject(e.getMessage());
@@ -186,14 +300,14 @@ public class NativePurchasesPlugin extends Plugin {
186
300
  }
187
301
 
188
302
  private void closeBillingClientLocked() {
189
- Log.d(TAG, "closeBillingClient() called");
303
+ NativePurchasesLog.d(TAG, "closeBillingClient() called");
190
304
  if (billingClient != null) {
191
- Log.d(TAG, "Ending billing client connection");
305
+ NativePurchasesLog.d(TAG, "Ending billing client connection");
192
306
  billingClient.endConnection();
193
307
  billingClient = null;
194
- Log.d(TAG, "Billing client closed and set to null");
308
+ NativePurchasesLog.d(TAG, "Billing client closed and set to null");
195
309
  } else {
196
- Log.d(TAG, "Billing client was already null");
310
+ NativePurchasesLog.d(TAG, "Billing client was already null");
197
311
  }
198
312
  }
199
313
 
@@ -266,55 +380,55 @@ public class NativePurchasesPlugin extends Plugin {
266
380
  }
267
381
 
268
382
  private void handlePurchase(Purchase purchase, PluginCall purchaseCall) {
269
- Log.d(TAG, "handlePurchase() called");
270
- Log.d(TAG, "Purchase details: " + purchase.toString());
271
- Log.i(NativePurchasesPlugin.TAG, "handlePurchase" + purchase);
272
- Log.i(NativePurchasesPlugin.TAG, "getPurchaseState" + purchase.getPurchaseState());
273
- Log.d(TAG, "Purchase state: " + purchase.getPurchaseState());
274
- Log.d(TAG, "Purchase token: " + purchase.getPurchaseToken());
275
- Log.d(TAG, "Is acknowledged: " + purchase.isAcknowledged());
383
+ NativePurchasesLog.d(TAG, "handlePurchase() called");
384
+ NativePurchasesLog.d(TAG, NativePurchasesLog.purchaseDebugSummary(purchase));
385
+ NativePurchasesLog.d(TAG, "Purchase state: " + purchase.getPurchaseState());
386
+ NativePurchasesLog.d(TAG, "Is acknowledged: " + purchase.isAcknowledged());
276
387
 
277
388
  if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
278
- Log.d(TAG, "Purchase state is PURCHASED");
389
+ NativePurchasesLog.d(TAG, "Purchase state is PURCHASED");
279
390
  boolean isConsumable = purchaseCall != null && purchaseCall.getBoolean("isConsumable", false);
280
391
  boolean autoAcknowledge = purchaseCall != null ? purchaseCall.getBoolean("autoAcknowledgePurchases", true) : true;
281
- Log.d(TAG, "Auto-acknowledge enabled: " + autoAcknowledge);
392
+ boolean shouldAutoAcknowledge = autoFinishTransactions && autoAcknowledge;
393
+ NativePurchasesLog.d(TAG, "Auto-acknowledge enabled: " + shouldAutoAcknowledge);
282
394
 
283
395
  PurchaseAction action = PurchaseActionDecider.decide(isConsumable, purchase);
284
396
 
285
397
  AccountIdentifiers accountIdentifiers = purchase.getAccountIdentifiers();
286
398
  String purchaseAccountId = accountIdentifiers != null ? accountIdentifiers.getObfuscatedAccountId() : null;
287
- Log.d(TAG, "Purchase account identifier present: " + (purchaseAccountId != null ? "[REDACTED]" : "none"));
399
+ NativePurchasesLog.d(TAG, "Purchase account identifier present: " + (purchaseAccountId != null ? "[REDACTED]" : "none"));
288
400
 
289
401
  switch (action) {
290
402
  case CONSUME:
291
- Log.d(TAG, "Purchase flagged as consumable, consuming...");
403
+ if (!shouldAutoAcknowledge) {
404
+ NativePurchasesLog.d(TAG, "Consumable purchase deferred until manual consumePurchase()");
405
+ break;
406
+ }
407
+ NativePurchasesLog.d(TAG, "Purchase flagged as consumable, consuming...");
292
408
  ConsumeParams consumeParams = ConsumeParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();
293
409
  billingClient.consumeAsync(consumeParams, this::onConsumeResponse);
294
410
  break;
295
411
  case ACKNOWLEDGE:
296
- if (autoAcknowledge) {
297
- Log.d(TAG, "Purchase not acknowledged, auto-acknowledging...");
412
+ if (shouldAutoAcknowledge) {
413
+ NativePurchasesLog.d(TAG, "Purchase not acknowledged, auto-acknowledging...");
298
414
  acknowledgePurchase(purchase.getPurchaseToken());
299
415
  } else {
300
- Log.d(TAG, "Purchase not acknowledged, but auto-acknowledge is disabled. Developer must manually acknowledge.");
416
+ NativePurchasesLog.d(
417
+ TAG,
418
+ "Purchase not acknowledged, but auto-acknowledge is disabled. Developer must manually acknowledge."
419
+ );
301
420
  }
302
421
  break;
303
422
  case NONE:
304
423
  default:
305
- Log.d(TAG, "No additional purchase handling required");
424
+ NativePurchasesLog.d(TAG, "No additional purchase handling required");
306
425
  break;
307
426
  }
308
427
 
309
428
  JSObject ret = new JSObject();
310
429
  ret.put("transactionId", purchase.getPurchaseToken());
311
430
  ret.put("productIdentifier", purchase.getProducts().get(0));
312
- ret.put(
313
- "purchaseDate",
314
- new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", java.util.Locale.US).format(
315
- new java.util.Date(purchase.getPurchaseTime())
316
- )
317
- );
431
+ ret.put("purchaseDate", formatUtcIso8601(purchase.getPurchaseTime()));
318
432
  ret.put("quantity", purchase.getQuantity());
319
433
  ret.put("productType", purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED ? "inapp" : "subs");
320
434
  ret.put("orderId", purchase.getOrderId());
@@ -337,14 +451,14 @@ public class NativePurchasesPlugin extends Plugin {
337
451
  // This would require additional Google Play API calls to get subscription details
338
452
  }
339
453
 
340
- Log.d(TAG, "Resolving purchase call with transactionId: " + purchase.getPurchaseToken());
454
+ NativePurchasesLog.d(TAG, "Resolving purchase call for product: " + purchase.getProducts().get(0));
341
455
  if (purchaseCall != null) {
342
456
  purchaseCall.resolve(ret);
343
457
  } else {
344
- Log.d(TAG, "purchaseCall is null, cannot resolve");
458
+ NativePurchasesLog.d(TAG, "purchaseCall is null, cannot resolve");
345
459
  }
346
460
  } else if (purchase.getPurchaseState() == Purchase.PurchaseState.PENDING) {
347
- Log.d(TAG, "Purchase state is PENDING");
461
+ NativePurchasesLog.d(TAG, "Purchase state is PENDING");
348
462
  // Here you can confirm to the user that they've started the pending
349
463
  // purchase, and to complete it, they should follow instructions that are
350
464
  // given to them. You can also choose to remind the user to complete the
@@ -352,21 +466,21 @@ public class NativePurchasesPlugin extends Plugin {
352
466
  if (purchaseCall != null) {
353
467
  purchaseCall.reject("Purchase is pending");
354
468
  } else {
355
- Log.d(TAG, "purchaseCall is null for pending purchase");
469
+ NativePurchasesLog.d(TAG, "purchaseCall is null for pending purchase");
356
470
  }
357
471
  } else {
358
- Log.d(TAG, "Purchase state is OTHER: " + purchase.getPurchaseState());
472
+ NativePurchasesLog.d(TAG, "Purchase state is OTHER: " + purchase.getPurchaseState());
359
473
  // Handle any other error codes.
360
474
  if (purchaseCall != null) {
361
475
  purchaseCall.reject("Purchase is not purchased", "PURCHASE_STATE_" + purchase.getPurchaseState());
362
476
  } else {
363
- Log.d(TAG, "purchaseCall is null for failed purchase");
477
+ NativePurchasesLog.d(TAG, "purchaseCall is null for failed purchase");
364
478
  }
365
479
  }
366
480
  }
367
481
 
368
482
  private void acknowledgePurchase(String purchaseToken) {
369
- Log.d(TAG, "acknowledgePurchase() called with token: " + purchaseToken);
483
+ NativePurchasesLog.d(TAG, "acknowledgePurchase() called");
370
484
  AcknowledgePurchaseParams acknowledgePurchaseParams = AcknowledgePurchaseParams.newBuilder()
371
485
  .setPurchaseToken(purchaseToken)
372
486
  .build();
@@ -376,17 +490,20 @@ public class NativePurchasesPlugin extends Plugin {
376
490
  @Override
377
491
  public void onAcknowledgePurchaseResponse(@NonNull BillingResult billingResult) {
378
492
  // Handle the result of the acknowledge purchase
379
- Log.d(TAG, "onAcknowledgePurchaseResponse() called");
380
- Log.d(TAG, "Acknowledge result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage());
381
- Log.i(NativePurchasesPlugin.TAG, "onAcknowledgePurchaseResponse" + billingResult);
493
+ NativePurchasesLog.d(TAG, "onAcknowledgePurchaseResponse() called");
494
+ NativePurchasesLog.d(
495
+ TAG,
496
+ "Acknowledge result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage()
497
+ );
498
+ NativePurchasesLog.i(NativePurchasesPlugin.TAG, "onAcknowledgePurchaseResponse" + billingResult);
382
499
  }
383
500
  }
384
501
  );
385
502
  }
386
503
 
387
504
  private void initBillingClient(PluginCall purchaseCall) {
388
- Log.d(TAG, "initBillingClient() called");
389
- Log.d(TAG, "purchaseCall is null: " + (purchaseCall == null));
505
+ NativePurchasesLog.d(TAG, "initBillingClient() called");
506
+ NativePurchasesLog.d(TAG, "purchaseCall is null: " + (purchaseCall == null));
390
507
 
391
508
  synchronized (billingClientLock) {
392
509
  closeBillingClientLocked();
@@ -398,7 +515,7 @@ public class NativePurchasesPlugin extends Plugin {
398
515
  for (int attempt = 1; attempt <= BILLING_CONNECTION_MAX_ATTEMPTS; attempt++) {
399
516
  if (attempt > 1) {
400
517
  long backoffMs = BILLING_CONNECTION_BACKOFF_MS[Math.min(attempt - 1, BILLING_CONNECTION_BACKOFF_MS.length - 1)];
401
- Log.d(
518
+ NativePurchasesLog.d(
402
519
  TAG,
403
520
  "Retrying billing client connection (attempt " +
404
521
  attempt +
@@ -426,7 +543,7 @@ public class NativePurchasesPlugin extends Plugin {
426
543
  } catch (RuntimeException e) {
427
544
  lastFailure = e;
428
545
  boolean willRetry = attempt < BILLING_CONNECTION_MAX_ATTEMPTS && isRetriableBillingSetupFailure(e);
429
- Log.w(
546
+ NativePurchasesLog.w(
430
547
  TAG,
431
548
  "Billing client connection attempt " + attempt + " failed: " + e.getMessage() + (willRetry ? " (will retry)" : "")
432
549
  );
@@ -458,7 +575,7 @@ public class NativePurchasesPlugin extends Plugin {
458
575
  final BillingResult[] setupError = new BillingResult[1];
459
576
  final AtomicBoolean setupSettled = new AtomicBoolean(false);
460
577
 
461
- Log.d(TAG, "Creating new BillingClient (attempt " + attempt + "/" + BILLING_CONNECTION_MAX_ATTEMPTS + ")");
578
+ NativePurchasesLog.d(TAG, "Creating new BillingClient (attempt " + attempt + "/" + BILLING_CONNECTION_MAX_ATTEMPTS + ")");
462
579
  final BillingClient client;
463
580
  synchronized (billingClientLock) {
464
581
  client = BillingClient.newBuilder(getContext())
@@ -466,16 +583,19 @@ public class NativePurchasesPlugin extends Plugin {
466
583
  new PurchasesUpdatedListener() {
467
584
  @Override
468
585
  public void onPurchasesUpdated(@NonNull BillingResult billingResult, List<Purchase> purchases) {
469
- Log.d(TAG, "onPurchasesUpdated() called");
470
- Log.d(TAG, "Billing result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage());
471
- Log.d(TAG, "Purchases count: " + (purchases != null ? purchases.size() : 0));
472
- Log.i(NativePurchasesPlugin.TAG, "onPurchasesUpdated" + billingResult);
586
+ NativePurchasesLog.d(TAG, "onPurchasesUpdated() called");
587
+ NativePurchasesLog.d(
588
+ TAG,
589
+ "Billing result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage()
590
+ );
591
+ NativePurchasesLog.d(TAG, "Purchases count: " + (purchases != null ? purchases.size() : 0));
592
+ NativePurchasesLog.i(NativePurchasesPlugin.TAG, "onPurchasesUpdated" + billingResult);
473
593
  if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && purchases != null) {
474
- Log.d(TAG, "Purchase update successful, processing first purchase");
594
+ NativePurchasesLog.d(TAG, "Purchase update successful, processing first purchase");
475
595
  handlePurchase(purchases.get(0), purchaseCall);
476
596
  } else {
477
- Log.d(TAG, "Purchase update failed or purchases is null");
478
- Log.i(NativePurchasesPlugin.TAG, "onPurchasesUpdated" + billingResult);
597
+ NativePurchasesLog.d(TAG, "Purchase update failed or purchases is null");
598
+ NativePurchasesLog.i(NativePurchasesPlugin.TAG, "onPurchasesUpdated" + billingResult);
479
599
  if (purchaseCall != null) {
480
600
  purchaseCall.reject(
481
601
  "Purchase is not purchased",
@@ -492,22 +612,22 @@ public class NativePurchasesPlugin extends Plugin {
492
612
  billingClient = client;
493
613
  }
494
614
 
495
- Log.d(TAG, "Starting billing client connection");
615
+ NativePurchasesLog.d(TAG, "Starting billing client connection");
496
616
  client.startConnection(
497
617
  new BillingClientStateListener() {
498
618
  @Override
499
619
  public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
500
620
  if (!setupSettled.compareAndSet(false, true)) {
501
- Log.d(TAG, "Ignoring stale onBillingSetupFinished callback");
621
+ NativePurchasesLog.d(TAG, "Ignoring stale onBillingSetupFinished callback");
502
622
  return;
503
623
  }
504
- Log.d(TAG, "onBillingSetupFinished() called");
505
- Log.d(TAG, "Setup result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage());
624
+ NativePurchasesLog.d(TAG, "onBillingSetupFinished() called");
625
+ NativePurchasesLog.d(TAG, "Setup result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage());
506
626
  if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
507
- Log.d(TAG, "Billing setup successful, client is ready");
627
+ NativePurchasesLog.d(TAG, "Billing setup successful, client is ready");
508
628
  } else {
509
- Log.e(TAG, "Billing setup failed with code: " + billingResult.getResponseCode());
510
- Log.e(TAG, "Error message: " + billingResult.getDebugMessage());
629
+ NativePurchasesLog.e(TAG, "Billing setup failed with code: " + billingResult.getResponseCode());
630
+ NativePurchasesLog.e(TAG, "Error message: " + billingResult.getDebugMessage());
511
631
  setupError[0] = billingResult;
512
632
  }
513
633
  setupLatch.countDown();
@@ -515,9 +635,9 @@ public class NativePurchasesPlugin extends Plugin {
515
635
 
516
636
  @Override
517
637
  public void onBillingServiceDisconnected() {
518
- Log.d(TAG, "onBillingServiceDisconnected() called");
638
+ NativePurchasesLog.d(TAG, "onBillingServiceDisconnected() called");
519
639
  if (!setupSettled.compareAndSet(false, true)) {
520
- Log.d(TAG, "Billing service disconnected after setup settled");
640
+ NativePurchasesLog.d(TAG, "Billing service disconnected after setup settled");
521
641
  return;
522
642
  }
523
643
  synchronized (billingClientLock) {
@@ -535,22 +655,22 @@ public class NativePurchasesPlugin extends Plugin {
535
655
  );
536
656
 
537
657
  try {
538
- Log.d(TAG, "Waiting for billing client setup to finish");
658
+ NativePurchasesLog.d(TAG, "Waiting for billing client setup to finish");
539
659
  boolean setupCompleted = setupLatch.await(BILLING_SETUP_TIMEOUT_SECONDS, TimeUnit.SECONDS);
540
660
 
541
661
  if (!setupCompleted) {
542
662
  setupSettled.compareAndSet(false, true);
543
- Log.e(TAG, "Billing client setup timed out after " + BILLING_SETUP_TIMEOUT_SECONDS + " seconds");
663
+ NativePurchasesLog.e(TAG, "Billing client setup timed out after " + BILLING_SETUP_TIMEOUT_SECONDS + " seconds");
544
664
  synchronized (billingClientLock) {
545
665
  closeBillingClientLocked();
546
666
  }
547
667
  throw new RuntimeException("Billing setup timed out");
548
668
  }
549
669
 
550
- Log.d(TAG, "Billing client setup wait completed");
670
+ NativePurchasesLog.d(TAG, "Billing client setup wait completed");
551
671
 
552
672
  if (setupError[0] != null) {
553
- Log.e(TAG, "Billing setup failed, throwing exception");
673
+ NativePurchasesLog.e(TAG, "Billing setup failed, throwing exception");
554
674
  synchronized (billingClientLock) {
555
675
  closeBillingClientLocked();
556
676
  }
@@ -564,11 +684,11 @@ public class NativePurchasesPlugin extends Plugin {
564
684
  }
565
685
  }
566
686
 
567
- Log.d(TAG, "Billing client setup completed successfully");
687
+ NativePurchasesLog.d(TAG, "Billing client setup completed successfully");
568
688
  } catch (InterruptedException e) {
569
689
  Thread.currentThread().interrupt();
570
690
  setupSettled.compareAndSet(false, true);
571
- Log.e(TAG, "InterruptedException while waiting for billing setup: " + e.getMessage());
691
+ NativePurchasesLog.e(TAG, "InterruptedException while waiting for billing setup: " + e.getMessage());
572
692
  rejectBillingSetupCall(purchaseCall, setupCallRejected, "BILLING_INTERRUPTED", "Billing setup was interrupted");
573
693
  synchronized (billingClientLock) {
574
694
  closeBillingClientLocked();
@@ -579,21 +699,21 @@ public class NativePurchasesPlugin extends Plugin {
579
699
 
580
700
  @PluginMethod
581
701
  public void getPluginVersion(final PluginCall call) {
582
- Log.d(TAG, "getPluginVersion() called");
702
+ NativePurchasesLog.d(TAG, "getPluginVersion() called");
583
703
  try {
584
704
  final JSObject ret = new JSObject();
585
705
  ret.put("version", this.pluginVersion);
586
- Log.d(TAG, "Returning plugin version: " + this.pluginVersion);
706
+ NativePurchasesLog.d(TAG, "Returning plugin version: " + this.pluginVersion);
587
707
  call.resolve(ret);
588
708
  } catch (final Exception e) {
589
- Log.d(TAG, "Error getting plugin version: " + e.getMessage());
709
+ NativePurchasesLog.d(TAG, "Error getting plugin version: " + e.getMessage());
590
710
  call.reject("Could not get plugin version", e);
591
711
  }
592
712
  }
593
713
 
594
714
  @PluginMethod
595
715
  public void purchaseProduct(PluginCall call) {
596
- Log.d(TAG, "purchaseProduct() called");
716
+ NativePurchasesLog.d(TAG, "purchaseProduct() called");
597
717
  String productIdentifier = call.getString("productIdentifier");
598
718
  String planIdentifier = call.getString("planIdentifier");
599
719
  String offerToken = call.getString("offerToken");
@@ -604,44 +724,44 @@ public class NativePurchasesPlugin extends Plugin {
604
724
  boolean isConsumable = call.getBoolean("isConsumable", false);
605
725
  boolean autoAcknowledgePurchases = call.getBoolean("autoAcknowledgePurchases", true);
606
726
 
607
- Log.d(TAG, "Product identifier: " + productIdentifier);
608
- Log.d(TAG, "Plan identifier: " + planIdentifier);
609
- Log.d(TAG, "Offer token provided: " + (offerToken != null && !offerToken.isEmpty()));
610
- Log.d(TAG, "Product type: " + productType);
611
- Log.d(TAG, "Quantity: " + quantity);
612
- Log.d(TAG, "Account identifier provided: " + (accountIdentifier != null ? "[REDACTED]" : "none"));
613
- Log.d(TAG, "Is consumable: " + isConsumable);
614
- Log.d(TAG, "Auto-acknowledge purchases: " + autoAcknowledgePurchases);
727
+ NativePurchasesLog.d(TAG, "Product identifier: " + productIdentifier);
728
+ NativePurchasesLog.d(TAG, "Plan identifier: " + planIdentifier);
729
+ NativePurchasesLog.d(TAG, "Offer token provided: " + (offerToken != null && !offerToken.isEmpty()));
730
+ NativePurchasesLog.d(TAG, "Product type: " + productType);
731
+ NativePurchasesLog.d(TAG, "Quantity: " + quantity);
732
+ NativePurchasesLog.d(TAG, "Account identifier provided: " + (accountIdentifier != null ? "[REDACTED]" : "none"));
733
+ NativePurchasesLog.d(TAG, "Is consumable: " + isConsumable);
734
+ NativePurchasesLog.d(TAG, "Auto-acknowledge purchases: " + autoAcknowledgePurchases);
615
735
 
616
736
  // cannot use quantity, because it's done in native modal
617
- Log.d("CapacitorPurchases", "purchaseProduct: " + productIdentifier);
737
+ NativePurchasesLog.d("CapacitorPurchases", "purchaseProduct: " + productIdentifier);
618
738
  if (productIdentifier == null || productIdentifier.isEmpty()) {
619
739
  // Handle error: productIdentifier is empty
620
- Log.d(TAG, "Error: productIdentifier is empty");
740
+ NativePurchasesLog.d(TAG, "Error: productIdentifier is empty");
621
741
  call.reject("productIdentifier is empty");
622
742
  return;
623
743
  }
624
744
  if (productType == null || productType.isEmpty()) {
625
745
  // Handle error: productType is empty
626
- Log.d(TAG, "Error: productType is empty");
746
+ NativePurchasesLog.d(TAG, "Error: productType is empty");
627
747
  call.reject("productType is empty");
628
748
  return;
629
749
  }
630
750
  if (productType.equals("subs") && (planIdentifier == null || planIdentifier.isEmpty())) {
631
751
  // Handle error: no planIdentifier with productType subs
632
- Log.d(TAG, "Error: planIdentifier cannot be empty if productType is subs");
752
+ NativePurchasesLog.d(TAG, "Error: planIdentifier cannot be empty if productType is subs");
633
753
  call.reject("planIdentifier cannot be empty if productType is subs");
634
754
  return;
635
755
  }
636
756
  assert quantity != null;
637
757
  if (quantity.intValue() < 1) {
638
758
  // Handle error: quantity is less than 1
639
- Log.d(TAG, "Error: quantity is less than 1");
759
+ NativePurchasesLog.d(TAG, "Error: quantity is less than 1");
640
760
  call.reject("quantity is less than 1");
641
761
  return;
642
762
  }
643
763
  if (isConsumable && productType.equals("subs")) {
644
- Log.d(TAG, "isConsumable is not supported for subscriptions, ignoring flag");
764
+ NativePurchasesLog.d(TAG, "isConsumable is not supported for subscriptions, ignoring flag");
645
765
  isConsumable = false;
646
766
  }
647
767
 
@@ -650,18 +770,18 @@ public class NativePurchasesPlugin extends Plugin {
650
770
 
651
771
  // For subscriptions, always use the productIdentifier (subscription ID) to query
652
772
  // The planIdentifier is used later when setting the offer token
653
- Log.d(TAG, "Using product ID for query: " + productIdentifier);
773
+ NativePurchasesLog.d(TAG, "Using product ID for query: " + productIdentifier);
654
774
 
655
- ImmutableList<QueryProductDetailsParams.Product> productList = ImmutableList.of(
775
+ List<QueryProductDetailsParams.Product> productList = Collections.singletonList(
656
776
  QueryProductDetailsParams.Product.newBuilder()
657
777
  .setProductId(productIdentifier)
658
778
  .setProductType(productType.equals("inapp") ? BillingClient.ProductType.INAPP : BillingClient.ProductType.SUBS)
659
779
  .build()
660
780
  );
661
781
  QueryProductDetailsParams params = QueryProductDetailsParams.newBuilder().setProductList(productList).build();
662
- Log.d(TAG, "Initializing billing client for purchase");
782
+ NativePurchasesLog.d(TAG, "Initializing billing client for purchase");
663
783
  withBillingClient(call, () -> {
664
- Log.d(TAG, "Querying product details for purchase");
784
+ NativePurchasesLog.d(TAG, "Querying product details for purchase");
665
785
  billingClient.queryProductDetailsAsync(
666
786
  params,
667
787
  new ProductDetailsResponseListener() {
@@ -671,12 +791,15 @@ public class NativePurchasesPlugin extends Plugin {
671
791
  @NonNull QueryProductDetailsResult queryProductDetailsResult
672
792
  ) {
673
793
  List<ProductDetails> productDetailsList = queryProductDetailsResult.getProductDetailsList();
674
- Log.d(TAG, "onProductDetailsResponse() called for purchase");
675
- Log.d(TAG, "Query result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage());
676
- Log.d(TAG, "Product details count: " + productDetailsList.size());
794
+ NativePurchasesLog.d(TAG, "onProductDetailsResponse() called for purchase");
795
+ NativePurchasesLog.d(
796
+ TAG,
797
+ "Query result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage()
798
+ );
799
+ NativePurchasesLog.d(TAG, "Product details count: " + productDetailsList.size());
677
800
 
678
801
  if (productDetailsList.isEmpty()) {
679
- Log.d(TAG, "No products found");
802
+ NativePurchasesLog.d(TAG, "No products found");
680
803
  closeBillingClient();
681
804
  call.reject("Product not found");
682
805
  return;
@@ -684,31 +807,37 @@ public class NativePurchasesPlugin extends Plugin {
684
807
  // Process the result
685
808
  List<BillingFlowParams.ProductDetailsParams> productDetailsParamsList = new ArrayList<>();
686
809
  for (ProductDetails productDetailsItem : productDetailsList) {
687
- Log.d(TAG, "Processing product: " + productDetailsItem.getProductId());
810
+ NativePurchasesLog.d(TAG, "Processing product: " + productDetailsItem.getProductId());
688
811
  BillingFlowParams.ProductDetailsParams.Builder productDetailsParams =
689
812
  BillingFlowParams.ProductDetailsParams.newBuilder().setProductDetails(productDetailsItem);
690
813
  if (productType.equals("subs")) {
691
- Log.d(TAG, "Processing subscription product");
814
+ NativePurchasesLog.d(TAG, "Processing subscription product");
692
815
  // list the SubscriptionOfferDetails and find the one who match the planIdentifier if not found get the first one
693
816
  ProductDetails.SubscriptionOfferDetails selectedOfferDetails = null;
694
817
  assert productDetailsItem.getSubscriptionOfferDetails() != null;
695
- Log.d(TAG, "Available offer details count: " + productDetailsItem.getSubscriptionOfferDetails().size());
818
+ NativePurchasesLog.d(
819
+ TAG,
820
+ "Available offer details count: " + productDetailsItem.getSubscriptionOfferDetails().size()
821
+ );
696
822
  for (ProductDetails.SubscriptionOfferDetails offerDetails : productDetailsItem.getSubscriptionOfferDetails()) {
697
- Log.d(TAG, "Checking offer: " + offerDetails.getBasePlanId());
823
+ NativePurchasesLog.d(TAG, "Checking offer: " + offerDetails.getBasePlanId());
698
824
  if (offerDetails.getBasePlanId().equals(planIdentifier)) {
699
825
  selectedOfferDetails = offerDetails;
700
- Log.d(TAG, "Found matching plan: " + planIdentifier);
826
+ NativePurchasesLog.d(TAG, "Found matching plan: " + planIdentifier);
701
827
  break;
702
828
  }
703
829
  }
704
830
  if (selectedOfferDetails == null) {
705
831
  selectedOfferDetails = productDetailsItem.getSubscriptionOfferDetails().get(0);
706
- Log.d(TAG, "Using first available offer: " + selectedOfferDetails.getBasePlanId());
832
+ NativePurchasesLog.d(TAG, "Using first available offer: " + selectedOfferDetails.getBasePlanId());
707
833
  }
708
834
  productDetailsParams.setOfferToken(selectedOfferDetails.getOfferToken());
709
- Log.d(TAG, "Set offer token: " + selectedOfferDetails.getOfferToken());
835
+ NativePurchasesLog.d(
836
+ TAG,
837
+ "Set offer token: " + NativePurchasesLog.redactSensitive(selectedOfferDetails.getOfferToken())
838
+ );
710
839
  } else if (productType.equals("inapp")) {
711
- Log.d(TAG, "Processing in-app product");
840
+ NativePurchasesLog.d(TAG, "Processing in-app product");
712
841
  List<ProductDetails.OneTimePurchaseOfferDetails> oneTimeOffers =
713
842
  ProductPayloadMapper.resolveOneTimePurchaseOffers(productDetailsItem);
714
843
  if (offerToken != null && !offerToken.isEmpty()) {
@@ -720,16 +849,23 @@ public class NativePurchasesPlugin extends Plugin {
720
849
  }
721
850
  }
722
851
  if (selectedOffer == null) {
723
- Log.d(TAG, "Offer token not found for product: " + productIdentifier);
852
+ NativePurchasesLog.d(TAG, "Offer token not found for product: " + productIdentifier);
724
853
  closeBillingClient();
725
854
  call.reject("Offer token not found for product: " + productIdentifier);
726
855
  return;
727
856
  }
728
857
  productDetailsParams.setOfferToken(selectedOffer.getOfferToken());
729
- Log.d(TAG, "Set one-time offer token: " + selectedOffer.getOfferToken());
858
+ NativePurchasesLog.d(
859
+ TAG,
860
+ "Set one-time offer token: " + NativePurchasesLog.redactSensitive(selectedOffer.getOfferToken())
861
+ );
730
862
  } else if (productDetailsItem.getOneTimePurchaseOfferDetails() == null && !oneTimeOffers.isEmpty()) {
731
863
  productDetailsParams.setOfferToken(oneTimeOffers.get(0).getOfferToken());
732
- Log.d(TAG, "Set default one-time offer token: " + oneTimeOffers.get(0).getOfferToken());
864
+ NativePurchasesLog.d(
865
+ TAG,
866
+ "Set default one-time offer token: " +
867
+ NativePurchasesLog.redactSensitive(oneTimeOffers.get(0).getOfferToken())
868
+ );
733
869
  }
734
870
  }
735
871
  productDetailsParamsList.add(productDetailsParams.build());
@@ -742,13 +878,13 @@ public class NativePurchasesPlugin extends Plugin {
742
878
  }
743
879
  BillingFlowParams billingFlowParams = billingFlowBuilder.build();
744
880
  // Launch the billing flow
745
- Log.d(TAG, "Launching billing flow");
881
+ NativePurchasesLog.d(TAG, "Launching billing flow");
746
882
  BillingResult billingResult2 = billingClient.launchBillingFlow(getActivity(), billingFlowParams);
747
- Log.d(
883
+ NativePurchasesLog.d(
748
884
  TAG,
749
885
  "Billing flow launch result: " + billingResult2.getResponseCode() + " - " + billingResult2.getDebugMessage()
750
886
  );
751
- Log.i(NativePurchasesPlugin.TAG, "onProductDetailsResponse2" + billingResult2);
887
+ NativePurchasesLog.i(NativePurchasesPlugin.TAG, "onProductDetailsResponse2" + billingResult2);
752
888
  }
753
889
  }
754
890
  );
@@ -756,80 +892,82 @@ public class NativePurchasesPlugin extends Plugin {
756
892
  }
757
893
 
758
894
  private void processUnfinishedPurchases() {
759
- Log.d(TAG, "processUnfinishedPurchases() called");
895
+ NativePurchasesLog.d(TAG, "processUnfinishedPurchases() called");
760
896
  QueryPurchasesParams queryInAppPurchasesParams = QueryPurchasesParams.newBuilder()
761
897
  .setProductType(BillingClient.ProductType.INAPP)
762
898
  .build();
763
- Log.d(TAG, "Querying unfinished in-app purchases");
899
+ NativePurchasesLog.d(TAG, "Querying unfinished in-app purchases");
764
900
  billingClient.queryPurchasesAsync(queryInAppPurchasesParams, this::handlePurchases);
765
901
 
766
902
  QueryPurchasesParams querySubscriptionsParams = QueryPurchasesParams.newBuilder()
767
903
  .setProductType(BillingClient.ProductType.SUBS)
768
904
  .build();
769
- Log.d(TAG, "Querying unfinished subscription purchases");
905
+ NativePurchasesLog.d(TAG, "Querying unfinished subscription purchases");
770
906
  billingClient.queryPurchasesAsync(querySubscriptionsParams, this::handlePurchases);
771
907
  }
772
908
 
773
909
  private void handlePurchases(BillingResult billingResult, List<Purchase> purchases) {
774
- Log.d(TAG, "handlePurchases() called");
775
- Log.d(TAG, "Query purchases result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage());
776
- Log.d(TAG, "Purchases count: " + (purchases != null ? purchases.size() : 0));
910
+ NativePurchasesLog.d(TAG, "handlePurchases() called");
911
+ NativePurchasesLog.d(TAG, "Query purchases result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage());
912
+ NativePurchasesLog.d(TAG, "Purchases count: " + (purchases != null ? purchases.size() : 0));
777
913
 
778
914
  if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
779
915
  assert purchases != null;
916
+ if (!autoFinishTransactions) {
917
+ NativePurchasesLog.d(TAG, "autoFinishTransactions disabled, skipping recovery acknowledgment");
918
+ return;
919
+ }
780
920
  for (Purchase purchase : purchases) {
781
- Log.d(TAG, "Processing purchase: " + purchase.getOrderId());
782
- Log.d(TAG, "Purchase state: " + purchase.getPurchaseState());
921
+ NativePurchasesLog.d(TAG, "Processing purchase for products: " + purchase.getProducts());
922
+ NativePurchasesLog.d(TAG, "Purchase state: " + purchase.getPurchaseState());
783
923
  if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
784
924
  PurchaseAction action = PurchaseActionDecider.decide(false, purchase);
785
925
  if (action == PurchaseAction.ACKNOWLEDGE) {
786
- Log.d(TAG, "Purchase not acknowledged, acknowledging");
926
+ NativePurchasesLog.d(TAG, "Purchase not acknowledged, acknowledging");
787
927
  acknowledgePurchase(purchase.getPurchaseToken());
788
928
  } else {
789
- Log.d(TAG, "Purchase already acknowledged, skipping consume");
929
+ NativePurchasesLog.d(TAG, "Purchase already acknowledged, skipping consume");
790
930
  }
791
931
  }
792
932
  }
793
933
  } else {
794
- Log.d(TAG, "Query purchases failed");
934
+ NativePurchasesLog.d(TAG, "Query purchases failed");
795
935
  }
796
936
  }
797
937
 
798
938
  private void onConsumeResponse(BillingResult billingResult, String purchaseToken) {
799
- Log.d(TAG, "onConsumeResponse() called");
800
- Log.d(TAG, "Consume result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage());
801
- Log.d(TAG, "Purchase token: " + purchaseToken);
802
-
939
+ NativePurchasesLog.d(TAG, "onConsumeResponse() called");
940
+ NativePurchasesLog.d(TAG, "Consume result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage());
803
941
  if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
804
942
  // Handle the success of the consume operation.
805
943
  // For example, you can update the UI to reflect that the item has been consumed.
806
- Log.d(TAG, "Consume operation successful");
807
- Log.i(NativePurchasesPlugin.TAG, "onConsumeResponse OK " + billingResult + purchaseToken);
944
+ NativePurchasesLog.d(TAG, "Consume operation successful");
945
+ NativePurchasesLog.i(NativePurchasesPlugin.TAG, "onConsumeResponse OK " + billingResult.getResponseCode());
808
946
  } else {
809
947
  // Handle error responses.
810
- Log.d(TAG, "Consume operation failed");
811
- Log.i(NativePurchasesPlugin.TAG, "onConsumeResponse OTHER " + billingResult + purchaseToken);
948
+ NativePurchasesLog.d(TAG, "Consume operation failed");
949
+ NativePurchasesLog.i(NativePurchasesPlugin.TAG, "onConsumeResponse OTHER " + billingResult.getResponseCode());
812
950
  }
813
951
  }
814
952
 
815
953
  @PluginMethod
816
954
  public void restorePurchases(PluginCall call) {
817
- Log.d(TAG, "restorePurchases() called");
818
- Log.d(NativePurchasesPlugin.TAG, "restorePurchases");
955
+ NativePurchasesLog.d(TAG, "restorePurchases() called");
956
+ NativePurchasesLog.d(NativePurchasesPlugin.TAG, "restorePurchases");
819
957
  withBillingClient(call, () -> {
820
958
  this.processUnfinishedPurchases();
821
959
  call.resolve();
822
- Log.d(TAG, "restorePurchases() completed");
960
+ NativePurchasesLog.d(TAG, "restorePurchases() completed");
823
961
  });
824
962
  }
825
963
 
826
964
  private void querySingleProductDetails(String productIdentifier, String productType, PluginCall call) {
827
- Log.d(TAG, "querySingleProductDetails() called");
828
- Log.d(TAG, "Product identifier: " + productIdentifier);
829
- Log.d(TAG, "Product type: " + productType);
965
+ NativePurchasesLog.d(TAG, "querySingleProductDetails() called");
966
+ NativePurchasesLog.d(TAG, "Product identifier: " + productIdentifier);
967
+ NativePurchasesLog.d(TAG, "Product type: " + productType);
830
968
 
831
969
  String productTypeForQuery = productType.equals("inapp") ? BillingClient.ProductType.INAPP : BillingClient.ProductType.SUBS;
832
- Log.d(TAG, "Creating query product: ID='" + productIdentifier + "', Type='" + productTypeForQuery + "'");
970
+ NativePurchasesLog.d(TAG, "Creating query product: ID='" + productIdentifier + "', Type='" + productTypeForQuery + "'");
833
971
 
834
972
  List<QueryProductDetailsParams.Product> productList = new ArrayList<>();
835
973
  productList.add(
@@ -837,9 +975,9 @@ public class NativePurchasesPlugin extends Plugin {
837
975
  );
838
976
 
839
977
  QueryProductDetailsParams params = QueryProductDetailsParams.newBuilder().setProductList(productList).build();
840
- Log.d(TAG, "Initializing billing client for single product query");
978
+ NativePurchasesLog.d(TAG, "Initializing billing client for single product query");
841
979
  withBillingClient(call, () -> {
842
- Log.d(TAG, "Querying product details");
980
+ NativePurchasesLog.d(TAG, "Querying product details");
843
981
  billingClient.queryProductDetailsAsync(
844
982
  params,
845
983
  new ProductDetailsResponseListener() {
@@ -849,36 +987,42 @@ public class NativePurchasesPlugin extends Plugin {
849
987
  @NonNull QueryProductDetailsResult queryProductDetailsResult
850
988
  ) {
851
989
  List<ProductDetails> productDetailsList = queryProductDetailsResult.getProductDetailsList();
852
- Log.d(TAG, "onProductDetailsResponse() called for single product query");
853
- Log.d(TAG, "Query result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage());
854
- Log.d(TAG, "Product details count: " + productDetailsList.size());
990
+ NativePurchasesLog.d(TAG, "onProductDetailsResponse() called for single product query");
991
+ NativePurchasesLog.d(
992
+ TAG,
993
+ "Query result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage()
994
+ );
995
+ NativePurchasesLog.d(TAG, "Product details count: " + productDetailsList.size());
855
996
 
856
997
  if (productDetailsList.isEmpty()) {
857
- Log.d(TAG, "No product found in query");
858
- Log.d(TAG, "This usually means:");
859
- Log.d(TAG, "1. Product doesn't exist in Google Play Console");
860
- Log.d(TAG, "2. Product is not published/active");
861
- Log.d(TAG, "3. App is not properly configured for the product type");
862
- Log.d(TAG, "4. Wrong product ID or type");
998
+ NativePurchasesLog.d(TAG, "No product found in query");
999
+ NativePurchasesLog.d(TAG, "This usually means:");
1000
+ NativePurchasesLog.d(TAG, "1. Product doesn't exist in Google Play Console");
1001
+ NativePurchasesLog.d(TAG, "2. Product is not published/active");
1002
+ NativePurchasesLog.d(TAG, "3. App is not properly configured for the product type");
1003
+ NativePurchasesLog.d(TAG, "4. Wrong product ID or type");
863
1004
  closeBillingClient();
864
1005
  call.reject("Product not found");
865
1006
  return;
866
1007
  }
867
1008
 
868
1009
  ProductDetails productDetails = productDetailsList.get(0);
869
- Log.d(TAG, "Processing product details: " + productDetails.getProductId());
1010
+ NativePurchasesLog.d(TAG, "Processing product details: " + productDetails.getProductId());
870
1011
  JSObject product = new JSObject();
871
1012
  product.put("title", productDetails.getName());
872
1013
  product.put("description", productDetails.getDescription());
873
- Log.d(TAG, "Product title: " + productDetails.getName());
874
- Log.d(TAG, "Product description: " + productDetails.getDescription());
1014
+ NativePurchasesLog.d(TAG, "Product title: " + productDetails.getName());
1015
+ NativePurchasesLog.d(TAG, "Product description: " + productDetails.getDescription());
875
1016
 
876
1017
  if (productType.equals("inapp")) {
877
- Log.d(TAG, "Processing as in-app product");
1018
+ NativePurchasesLog.d(TAG, "Processing as in-app product");
878
1019
  List<ProductDetails.OneTimePurchaseOfferDetails> oneTimeOffers =
879
1020
  ProductPayloadMapper.resolveOneTimePurchaseOffers(productDetails);
880
1021
  if (oneTimeOffers.isEmpty()) {
881
- Log.w(TAG, "No one-time purchase offer details found for product: " + productDetails.getProductId());
1022
+ NativePurchasesLog.w(
1023
+ TAG,
1024
+ "No one-time purchase offer details found for product: " + productDetails.getProductId()
1025
+ );
882
1026
  closeBillingClient();
883
1027
  call.reject("No one-time purchase offer details found for product: " + productDetails.getProductId());
884
1028
  return;
@@ -887,15 +1031,18 @@ public class NativePurchasesPlugin extends Plugin {
887
1031
  ProductDetails.OneTimePurchaseOfferDetails selectedOffer = oneTimeOffers.get(0);
888
1032
  product.put("identifier", productDetails.getProductId());
889
1033
  ProductPayloadMapper.applyOneTimePurchaseOfferPricing(product, selectedOffer);
890
- Log.d(TAG, "Price: " + product.optDouble("price", 0.0));
891
- Log.d(TAG, "Formatted price: " + product.getString("priceString"));
892
- Log.d(TAG, "Currency: " + product.getString("currencyCode"));
893
- Log.d(TAG, "One-time offers available: " + oneTimeOffers.size());
1034
+ NativePurchasesLog.d(TAG, "Price: " + product.optDouble("price", 0.0));
1035
+ NativePurchasesLog.d(TAG, "Formatted price: " + product.getString("priceString"));
1036
+ NativePurchasesLog.d(TAG, "Currency: " + product.getString("currencyCode"));
1037
+ NativePurchasesLog.d(TAG, "One-time offers available: " + oneTimeOffers.size());
894
1038
  } else {
895
- Log.d(TAG, "Processing as subscription product");
1039
+ NativePurchasesLog.d(TAG, "Processing as subscription product");
896
1040
  List<ProductDetails.SubscriptionOfferDetails> offerDetailsList = productDetails.getSubscriptionOfferDetails();
897
1041
  if (offerDetailsList == null || offerDetailsList.isEmpty()) {
898
- Log.w(TAG, "No subscription offer details found for product: " + productDetails.getProductId());
1042
+ NativePurchasesLog.w(
1043
+ TAG,
1044
+ "No subscription offer details found for product: " + productDetails.getProductId()
1045
+ );
899
1046
  closeBillingClient();
900
1047
  call.reject("No subscription offers found for product: " + productDetails.getProductId());
901
1048
  return;
@@ -913,7 +1060,10 @@ public class NativePurchasesPlugin extends Plugin {
913
1060
  }
914
1061
 
915
1062
  if (selectedOfferDetails == null) {
916
- Log.w(TAG, "No offers with pricing phases found for product: " + productDetails.getProductId());
1063
+ NativePurchasesLog.w(
1064
+ TAG,
1065
+ "No offers with pricing phases found for product: " + productDetails.getProductId()
1066
+ );
917
1067
  closeBillingClient();
918
1068
  call.reject("No pricing phases found for product: " + productDetails.getProductId());
919
1069
  return;
@@ -925,18 +1075,21 @@ public class NativePurchasesPlugin extends Plugin {
925
1075
  product.put("offerId", selectedOfferDetails.getOfferId());
926
1076
  ProductPayloadMapper.applySubscriptionPricing(product, selectedOfferDetails, offerDetailsList);
927
1077
  double price = product.optDouble("price", 0.0);
928
- Log.d(TAG, "Plan identifier: " + productDetails.getProductId());
929
- Log.d(TAG, "Base plan ID: " + selectedOfferDetails.getBasePlanId());
930
- Log.d(TAG, "Offer token: " + selectedOfferDetails.getOfferToken());
931
- Log.d(TAG, "Price: " + price);
932
- Log.d(TAG, "Formatted price: " + product.getString("priceString"));
933
- Log.d(TAG, "Currency: " + product.getString("currencyCode"));
1078
+ NativePurchasesLog.d(TAG, "Plan identifier: " + productDetails.getProductId());
1079
+ NativePurchasesLog.d(TAG, "Base plan ID: " + selectedOfferDetails.getBasePlanId());
1080
+ NativePurchasesLog.d(
1081
+ TAG,
1082
+ "Offer token: " + NativePurchasesLog.redactSensitive(selectedOfferDetails.getOfferToken())
1083
+ );
1084
+ NativePurchasesLog.d(TAG, "Price: " + price);
1085
+ NativePurchasesLog.d(TAG, "Formatted price: " + product.getString("priceString"));
1086
+ NativePurchasesLog.d(TAG, "Currency: " + product.getString("currencyCode"));
934
1087
  }
935
1088
  product.put("isFamilyShareable", false);
936
1089
 
937
1090
  JSObject ret = new JSObject();
938
1091
  ret.put("product", product);
939
- Log.d(TAG, "Returning single product");
1092
+ NativePurchasesLog.d(TAG, "Returning single product");
940
1093
  closeBillingClient();
941
1094
  call.resolve(ret);
942
1095
  }
@@ -946,26 +1099,26 @@ public class NativePurchasesPlugin extends Plugin {
946
1099
  }
947
1100
 
948
1101
  private void queryProductDetails(List<String> productIdentifiers, String productType, PluginCall call) {
949
- Log.d(TAG, "queryProductDetails() called");
950
- Log.d(TAG, "Product identifiers count: " + productIdentifiers.size());
951
- Log.d(TAG, "Product type: " + productType);
1102
+ NativePurchasesLog.d(TAG, "queryProductDetails() called");
1103
+ NativePurchasesLog.d(TAG, "Product identifiers count: " + productIdentifiers.size());
1104
+ NativePurchasesLog.d(TAG, "Product type: " + productType);
952
1105
  for (String id : productIdentifiers) {
953
- Log.d(TAG, "Product ID: " + id);
1106
+ NativePurchasesLog.d(TAG, "Product ID: " + id);
954
1107
  }
955
1108
 
956
1109
  List<QueryProductDetailsParams.Product> productList = new ArrayList<>();
957
1110
  for (String productIdentifier : productIdentifiers) {
958
1111
  String productTypeForQuery = productType.equals("inapp") ? BillingClient.ProductType.INAPP : BillingClient.ProductType.SUBS;
959
- Log.d(TAG, "Creating query product: ID='" + productIdentifier + "', Type='" + productTypeForQuery + "'");
1112
+ NativePurchasesLog.d(TAG, "Creating query product: ID='" + productIdentifier + "', Type='" + productTypeForQuery + "'");
960
1113
  productList.add(
961
1114
  QueryProductDetailsParams.Product.newBuilder().setProductId(productIdentifier).setProductType(productTypeForQuery).build()
962
1115
  );
963
1116
  }
964
- Log.d(TAG, "Total products in query list: " + productList.size());
1117
+ NativePurchasesLog.d(TAG, "Total products in query list: " + productList.size());
965
1118
  QueryProductDetailsParams params = QueryProductDetailsParams.newBuilder().setProductList(productList).build();
966
- Log.d(TAG, "Initializing billing client for product query");
1119
+ NativePurchasesLog.d(TAG, "Initializing billing client for product query");
967
1120
  withBillingClient(call, () -> {
968
- Log.d(TAG, "Querying product details");
1121
+ NativePurchasesLog.d(TAG, "Querying product details");
969
1122
  billingClient.queryProductDetailsAsync(
970
1123
  params,
971
1124
  new ProductDetailsResponseListener() {
@@ -975,33 +1128,39 @@ public class NativePurchasesPlugin extends Plugin {
975
1128
  @NonNull QueryProductDetailsResult queryProductDetailsResult
976
1129
  ) {
977
1130
  List<ProductDetails> productDetailsList = queryProductDetailsResult.getProductDetailsList();
978
- Log.d(TAG, "onProductDetailsResponse() called for query");
979
- Log.d(TAG, "Query result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage());
980
- Log.d(TAG, "Product details count: " + productDetailsList.size());
1131
+ NativePurchasesLog.d(TAG, "onProductDetailsResponse() called for query");
1132
+ NativePurchasesLog.d(
1133
+ TAG,
1134
+ "Query result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage()
1135
+ );
1136
+ NativePurchasesLog.d(TAG, "Product details count: " + productDetailsList.size());
981
1137
 
982
1138
  if (productDetailsList.isEmpty()) {
983
- Log.d(TAG, "No products found in query");
984
- Log.d(TAG, "This usually means:");
985
- Log.d(TAG, "1. Product doesn't exist in Google Play Console");
986
- Log.d(TAG, "2. Product is not published/active");
987
- Log.d(TAG, "3. App is not properly configured for the product type");
988
- Log.d(TAG, "4. Wrong product ID or type");
1139
+ NativePurchasesLog.d(TAG, "No products found in query");
1140
+ NativePurchasesLog.d(TAG, "This usually means:");
1141
+ NativePurchasesLog.d(TAG, "1. Product doesn't exist in Google Play Console");
1142
+ NativePurchasesLog.d(TAG, "2. Product is not published/active");
1143
+ NativePurchasesLog.d(TAG, "3. App is not properly configured for the product type");
1144
+ NativePurchasesLog.d(TAG, "4. Wrong product ID or type");
989
1145
  closeBillingClient();
990
1146
  call.reject("Product not found");
991
1147
  return;
992
1148
  }
993
1149
  JSONArray products = new JSONArray();
994
1150
  for (ProductDetails productDetails : productDetailsList) {
995
- Log.d(TAG, "Processing product details: " + productDetails.getProductId());
996
- Log.d(TAG, "Product title: " + productDetails.getName());
997
- Log.d(TAG, "Product description: " + productDetails.getDescription());
1151
+ NativePurchasesLog.d(TAG, "Processing product details: " + productDetails.getProductId());
1152
+ NativePurchasesLog.d(TAG, "Product title: " + productDetails.getName());
1153
+ NativePurchasesLog.d(TAG, "Product description: " + productDetails.getDescription());
998
1154
 
999
1155
  if (productType.equals("inapp")) {
1000
- Log.d(TAG, "Processing as in-app product");
1156
+ NativePurchasesLog.d(TAG, "Processing as in-app product");
1001
1157
  List<ProductDetails.OneTimePurchaseOfferDetails> oneTimeOffers =
1002
1158
  ProductPayloadMapper.resolveOneTimePurchaseOffers(productDetails);
1003
1159
  if (oneTimeOffers.isEmpty()) {
1004
- Log.w(TAG, "No one-time purchase offer details found for product: " + productDetails.getProductId());
1160
+ NativePurchasesLog.w(
1161
+ TAG,
1162
+ "No one-time purchase offer details found for product: " + productDetails.getProductId()
1163
+ );
1005
1164
  continue;
1006
1165
  }
1007
1166
 
@@ -1014,24 +1173,33 @@ public class NativePurchasesPlugin extends Plugin {
1014
1173
  product.put("isFamilyShareable", false);
1015
1174
  ProductPayloadMapper.applyOneTimePurchaseOfferPricing(product, offerDetails);
1016
1175
 
1017
- Log.d(TAG, "Price: " + product.optDouble("price", 0.0));
1018
- Log.d(TAG, "Formatted price: " + product.getString("priceString"));
1019
- Log.d(TAG, "Currency: " + product.getString("currencyCode"));
1020
- Log.d(TAG, "Offer token: " + product.getString("offerToken"));
1176
+ NativePurchasesLog.d(TAG, "Price: " + product.optDouble("price", 0.0));
1177
+ NativePurchasesLog.d(TAG, "Formatted price: " + product.getString("priceString"));
1178
+ NativePurchasesLog.d(TAG, "Currency: " + product.getString("currencyCode"));
1179
+ NativePurchasesLog.d(
1180
+ TAG,
1181
+ "Offer token: " + NativePurchasesLog.redactSensitive(product.getString("offerToken"))
1182
+ );
1021
1183
 
1022
1184
  products.put(product);
1023
1185
  addedOffers++;
1024
1186
  }
1025
1187
 
1026
1188
  if (addedOffers == 0) {
1027
- Log.w(TAG, "No one-time purchase offers mapped for product: " + productDetails.getProductId());
1189
+ NativePurchasesLog.w(
1190
+ TAG,
1191
+ "No one-time purchase offers mapped for product: " + productDetails.getProductId()
1192
+ );
1028
1193
  }
1029
1194
  } else {
1030
- Log.d(TAG, "Processing as subscription product");
1195
+ NativePurchasesLog.d(TAG, "Processing as subscription product");
1031
1196
  List<ProductDetails.SubscriptionOfferDetails> offerDetailsList =
1032
1197
  productDetails.getSubscriptionOfferDetails();
1033
1198
  if (offerDetailsList == null || offerDetailsList.isEmpty()) {
1034
- Log.w(TAG, "No subscription offer details found for product: " + productDetails.getProductId());
1199
+ NativePurchasesLog.w(
1200
+ TAG,
1201
+ "No subscription offer details found for product: " + productDetails.getProductId()
1202
+ );
1035
1203
  continue;
1036
1204
  }
1037
1205
 
@@ -1041,7 +1209,7 @@ public class NativePurchasesPlugin extends Plugin {
1041
1209
  offerDetails.getPricingPhases() == null ||
1042
1210
  offerDetails.getPricingPhases().getPricingPhaseList().isEmpty()
1043
1211
  ) {
1044
- Log.w(TAG, "No pricing phases found for offer: " + offerDetails.getBasePlanId());
1212
+ NativePurchasesLog.w(TAG, "No pricing phases found for offer: " + offerDetails.getBasePlanId());
1045
1213
  continue;
1046
1214
  }
1047
1215
 
@@ -1057,18 +1225,18 @@ public class NativePurchasesPlugin extends Plugin {
1057
1225
  ProductPayloadMapper.applySubscriptionPricing(product, offerDetails, offerDetailsList);
1058
1226
  double price = product.optDouble("price", 0.0);
1059
1227
 
1060
- Log.d(TAG, "Plan identifier: " + productDetails.getProductId());
1061
- Log.d(TAG, "Base plan ID: " + offerDetails.getBasePlanId());
1062
- Log.d(TAG, "Price: " + price);
1063
- Log.d(TAG, "Formatted price: " + product.getString("priceString"));
1064
- Log.d(TAG, "Currency: " + product.getString("currencyCode"));
1228
+ NativePurchasesLog.d(TAG, "Plan identifier: " + productDetails.getProductId());
1229
+ NativePurchasesLog.d(TAG, "Base plan ID: " + offerDetails.getBasePlanId());
1230
+ NativePurchasesLog.d(TAG, "Price: " + price);
1231
+ NativePurchasesLog.d(TAG, "Formatted price: " + product.getString("priceString"));
1232
+ NativePurchasesLog.d(TAG, "Currency: " + product.getString("currencyCode"));
1065
1233
 
1066
1234
  products.put(product);
1067
1235
  addedOffers++;
1068
1236
  }
1069
1237
 
1070
1238
  if (addedOffers == 0) {
1071
- Log.w(
1239
+ NativePurchasesLog.w(
1072
1240
  TAG,
1073
1241
  "All subscription offers missing pricing phases for product: " + productDetails.getProductId()
1074
1242
  );
@@ -1077,7 +1245,7 @@ public class NativePurchasesPlugin extends Plugin {
1077
1245
  }
1078
1246
  JSObject ret = new JSObject();
1079
1247
  ret.put("products", products);
1080
- Log.d(TAG, "Returning " + products.length() + " products");
1248
+ NativePurchasesLog.d(TAG, "Returning " + products.length() + " products");
1081
1249
  closeBillingClient();
1082
1250
  call.resolve(ret);
1083
1251
  }
@@ -1088,15 +1256,18 @@ public class NativePurchasesPlugin extends Plugin {
1088
1256
 
1089
1257
  @PluginMethod
1090
1258
  public void getProducts(PluginCall call) {
1091
- Log.d(TAG, "getProducts() called");
1259
+ NativePurchasesLog.d(TAG, "getProducts() called");
1092
1260
  JSONArray productIdentifiersArray = call.getArray("productIdentifiers");
1093
1261
  String productType = call.getString("productType", "inapp");
1094
- Log.d(TAG, "Product type: " + productType);
1095
- Log.d(TAG, "Raw productIdentifiersArray: " + productIdentifiersArray);
1096
- Log.d(TAG, "productIdentifiersArray length: " + (productIdentifiersArray != null ? productIdentifiersArray.length() : "null"));
1262
+ NativePurchasesLog.d(TAG, "Product type: " + productType);
1263
+ NativePurchasesLog.d(TAG, "Raw productIdentifiersArray: " + productIdentifiersArray);
1264
+ NativePurchasesLog.d(
1265
+ TAG,
1266
+ "productIdentifiersArray length: " + (productIdentifiersArray != null ? productIdentifiersArray.length() : "null")
1267
+ );
1097
1268
 
1098
1269
  if (productIdentifiersArray == null || productIdentifiersArray.length() == 0) {
1099
- Log.d(TAG, "Error: productIdentifiers array missing or empty");
1270
+ NativePurchasesLog.d(TAG, "Error: productIdentifiers array missing or empty");
1100
1271
  call.reject("productIdentifiers array missing");
1101
1272
  return;
1102
1273
  }
@@ -1104,25 +1275,25 @@ public class NativePurchasesPlugin extends Plugin {
1104
1275
  List<String> productIdentifiers = new ArrayList<>();
1105
1276
  for (int i = 0; i < productIdentifiersArray.length(); i++) {
1106
1277
  String productId = productIdentifiersArray.optString(i, "");
1107
- Log.d(TAG, "Array index " + i + ": '" + productId + "'");
1278
+ NativePurchasesLog.d(TAG, "Array index " + i + ": '" + productId + "'");
1108
1279
  productIdentifiers.add(productId);
1109
- Log.d(TAG, "Added product identifier: " + productId);
1280
+ NativePurchasesLog.d(TAG, "Added product identifier: " + productId);
1110
1281
  }
1111
- Log.d(TAG, "Final productIdentifiers list: " + productIdentifiers.toString());
1282
+ NativePurchasesLog.d(TAG, "Final productIdentifiers list: " + productIdentifiers.toString());
1112
1283
  queryProductDetails(productIdentifiers, productType, call);
1113
1284
  }
1114
1285
 
1115
1286
  @PluginMethod
1116
1287
  public void getProduct(PluginCall call) {
1117
- Log.d(TAG, "getProduct() called");
1288
+ NativePurchasesLog.d(TAG, "getProduct() called");
1118
1289
  String productIdentifier = call.getString("productIdentifier");
1119
1290
  String productType = call.getString("productType", "inapp");
1120
- Log.d(TAG, "Product identifier: " + productIdentifier);
1121
- Log.d(TAG, "Product type: " + productType);
1291
+ NativePurchasesLog.d(TAG, "Product identifier: " + productIdentifier);
1292
+ NativePurchasesLog.d(TAG, "Product type: " + productType);
1122
1293
 
1123
1294
  assert productIdentifier != null;
1124
1295
  if (productIdentifier.isEmpty()) {
1125
- Log.d(TAG, "Error: productIdentifier is empty");
1296
+ NativePurchasesLog.d(TAG, "Error: productIdentifier is empty");
1126
1297
  call.reject("productIdentifier is empty");
1127
1298
  return;
1128
1299
  }
@@ -1131,19 +1302,19 @@ public class NativePurchasesPlugin extends Plugin {
1131
1302
 
1132
1303
  @PluginMethod
1133
1304
  public void getPurchases(PluginCall call) {
1134
- Log.d(TAG, "getPurchases() called");
1305
+ NativePurchasesLog.d(TAG, "getPurchases() called");
1135
1306
  String productType = call.getString("productType");
1136
- Log.d(TAG, "Product type filter: " + productType);
1307
+ NativePurchasesLog.d(TAG, "Product type filter: " + productType);
1137
1308
  String appAccountToken = call.getString("appAccountToken");
1138
1309
  final String accountFilter = appAccountToken != null && !appAccountToken.isEmpty() ? appAccountToken : null;
1139
1310
  final boolean hasAccountFilter = accountFilter != null && !accountFilter.isEmpty();
1140
- Log.d(TAG, "Account filter provided: " + (hasAccountFilter ? "[REDACTED]" : "none"));
1311
+ NativePurchasesLog.d(TAG, "Account filter provided: " + (hasAccountFilter ? "[REDACTED]" : "none"));
1141
1312
 
1142
1313
  final boolean queryInApp = productType == null || productType.equals("inapp");
1143
1314
  final boolean querySubs = productType == null || productType.equals("subs");
1144
1315
 
1145
1316
  if (!queryInApp && !querySubs) {
1146
- Log.d(TAG, "Unknown product type filter provided, returning empty result");
1317
+ NativePurchasesLog.d(TAG, "Unknown product type filter provided, returning empty result");
1147
1318
  JSObject result = new JSObject();
1148
1319
  result.put("purchases", new JSONArray());
1149
1320
  call.resolve(result);
@@ -1161,38 +1332,38 @@ public class NativePurchasesPlugin extends Plugin {
1161
1332
 
1162
1333
  Runnable maybeFinish = () -> {
1163
1334
  int remaining = pendingQueries.decrementAndGet();
1164
- Log.d(TAG, "Pending purchase queries remaining: " + remaining);
1335
+ NativePurchasesLog.d(TAG, "Pending purchase queries remaining: " + remaining);
1165
1336
  if (remaining <= 0 && finished.compareAndSet(false, true)) {
1166
1337
  closeBillingClient();
1167
1338
  String failure = queryFailure.get();
1168
1339
  if (failure != null) {
1169
- Log.w(TAG, "Rejecting getPurchases: " + failure);
1340
+ NativePurchasesLog.w(TAG, "Rejecting getPurchases: " + failure);
1170
1341
  call.reject("Failed to query purchases: " + failure, "QUERY_PURCHASES_FAILED");
1171
1342
  return;
1172
1343
  }
1173
1344
  JSObject result = new JSObject();
1174
1345
  result.put("purchases", allPurchases);
1175
- Log.d(TAG, "Returning " + allPurchases.length() + " purchases");
1346
+ NativePurchasesLog.d(TAG, "Returning " + allPurchases.length() + " purchases");
1176
1347
  call.resolve(result);
1177
1348
  }
1178
1349
  };
1179
1350
 
1180
1351
  if (queryInApp) {
1181
- Log.d(TAG, "Querying in-app purchases");
1352
+ NativePurchasesLog.d(TAG, "Querying in-app purchases");
1182
1353
  QueryPurchasesParams queryInAppParams = QueryPurchasesParams.newBuilder()
1183
1354
  .setProductType(BillingClient.ProductType.INAPP)
1184
1355
  .build();
1185
1356
 
1186
1357
  billingClient.queryPurchasesAsync(queryInAppParams, (billingResult, purchases) -> {
1187
1358
  try {
1188
- Log.d(TAG, "In-app purchases query result: " + billingResult.getResponseCode());
1359
+ NativePurchasesLog.d(TAG, "In-app purchases query result: " + billingResult.getResponseCode());
1189
1360
  if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && purchases != null) {
1190
1361
  for (Purchase purchase : purchases) {
1191
- Log.d(TAG, "Processing in-app purchase: " + purchase.getOrderId());
1362
+ NativePurchasesLog.d(TAG, "Processing in-app purchase for products: " + purchase.getProducts());
1192
1363
  AccountIdentifiers accountIdentifiers = purchase.getAccountIdentifiers();
1193
1364
  String purchaseAccountId = accountIdentifiers != null ? accountIdentifiers.getObfuscatedAccountId() : null;
1194
1365
  if (hasAccountFilter && (purchaseAccountId == null || !purchaseAccountId.equals(accountFilter))) {
1195
- Log.d(TAG, "Skipping in-app purchase due to account filter mismatch");
1366
+ NativePurchasesLog.d(TAG, "Skipping in-app purchase due to account filter mismatch");
1196
1367
  continue;
1197
1368
  }
1198
1369
  JSObject purchaseData = new JSObject();
@@ -1201,12 +1372,7 @@ public class NativePurchasesPlugin extends Plugin {
1201
1372
  "productIdentifier",
1202
1373
  purchase.getProducts().isEmpty() ? null : purchase.getProducts().get(0)
1203
1374
  );
1204
- purchaseData.put(
1205
- "purchaseDate",
1206
- new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", java.util.Locale.US).format(
1207
- new java.util.Date(purchase.getPurchaseTime())
1208
- )
1209
- );
1375
+ purchaseData.put("purchaseDate", formatUtcIso8601(purchase.getPurchaseTime()));
1210
1376
  purchaseData.put("quantity", purchase.getQuantity());
1211
1377
  purchaseData.put("productType", "inapp");
1212
1378
  purchaseData.put("orderId", purchase.getOrderId());
@@ -1220,11 +1386,11 @@ public class NativePurchasesPlugin extends Plugin {
1220
1386
  }
1221
1387
  }
1222
1388
  } else {
1223
- Log.d(TAG, "In-app purchase query failed: " + billingResult.getDebugMessage());
1389
+ NativePurchasesLog.d(TAG, "In-app purchase query failed: " + billingResult.getDebugMessage());
1224
1390
  queryFailure.compareAndSet(null, describeQueryFailure("inapp", billingResult));
1225
1391
  }
1226
1392
  } catch (Exception ex) {
1227
- Log.d(TAG, "Error processing in-app purchase query: " + ex.getMessage());
1393
+ NativePurchasesLog.d(TAG, "Error processing in-app purchase query: " + ex.getMessage());
1228
1394
  queryFailure.compareAndSet(null, describeQueryFailure("inapp", billingResult) + " / " + ex.getMessage());
1229
1395
  } finally {
1230
1396
  maybeFinish.run();
@@ -1233,21 +1399,21 @@ public class NativePurchasesPlugin extends Plugin {
1233
1399
  }
1234
1400
 
1235
1401
  if (querySubs) {
1236
- Log.d(TAG, "Querying only subscription purchases");
1402
+ NativePurchasesLog.d(TAG, "Querying only subscription purchases");
1237
1403
  QueryPurchasesParams querySubsParams = QueryPurchasesParams.newBuilder()
1238
1404
  .setProductType(BillingClient.ProductType.SUBS)
1239
1405
  .build();
1240
1406
 
1241
1407
  billingClient.queryPurchasesAsync(querySubsParams, (billingResult, purchases) -> {
1242
1408
  try {
1243
- Log.d(TAG, "Subscription purchases query result: " + billingResult.getResponseCode());
1409
+ NativePurchasesLog.d(TAG, "Subscription purchases query result: " + billingResult.getResponseCode());
1244
1410
  if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && purchases != null) {
1245
1411
  for (Purchase purchase : purchases) {
1246
- Log.d(TAG, "Processing subscription purchase: " + purchase.getOrderId());
1412
+ NativePurchasesLog.d(TAG, "Processing subscription purchase for products: " + purchase.getProducts());
1247
1413
  AccountIdentifiers accountIdentifiers = purchase.getAccountIdentifiers();
1248
1414
  String purchaseAccountId = accountIdentifiers != null ? accountIdentifiers.getObfuscatedAccountId() : null;
1249
1415
  if (hasAccountFilter && (purchaseAccountId == null || !purchaseAccountId.equals(accountFilter))) {
1250
- Log.d(TAG, "Skipping subscription purchase due to account filter mismatch");
1416
+ NativePurchasesLog.d(TAG, "Skipping subscription purchase due to account filter mismatch");
1251
1417
  continue;
1252
1418
  }
1253
1419
  JSObject purchaseData = new JSObject();
@@ -1256,12 +1422,7 @@ public class NativePurchasesPlugin extends Plugin {
1256
1422
  "productIdentifier",
1257
1423
  purchase.getProducts().isEmpty() ? null : purchase.getProducts().get(0)
1258
1424
  );
1259
- purchaseData.put(
1260
- "purchaseDate",
1261
- new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", java.util.Locale.US).format(
1262
- new java.util.Date(purchase.getPurchaseTime())
1263
- )
1264
- );
1425
+ purchaseData.put("purchaseDate", formatUtcIso8601(purchase.getPurchaseTime()));
1265
1426
  purchaseData.put("quantity", purchase.getQuantity());
1266
1427
  purchaseData.put("productType", "subs");
1267
1428
  purchaseData.put("orderId", purchase.getOrderId());
@@ -1275,11 +1436,11 @@ public class NativePurchasesPlugin extends Plugin {
1275
1436
  }
1276
1437
  }
1277
1438
  } else {
1278
- Log.d(TAG, "Subscription purchase query failed: " + billingResult.getDebugMessage());
1439
+ NativePurchasesLog.d(TAG, "Subscription purchase query failed: " + billingResult.getDebugMessage());
1279
1440
  queryFailure.compareAndSet(null, describeQueryFailure("subs", billingResult));
1280
1441
  }
1281
1442
  } catch (Exception ex) {
1282
- Log.d(TAG, "Error processing subscription purchase query: " + ex.getMessage());
1443
+ NativePurchasesLog.d(TAG, "Error processing subscription purchase query: " + ex.getMessage());
1283
1444
  queryFailure.compareAndSet(null, describeQueryFailure("subs", billingResult) + " / " + ex.getMessage());
1284
1445
  } finally {
1285
1446
  maybeFinish.run();
@@ -1291,7 +1452,7 @@ public class NativePurchasesPlugin extends Plugin {
1291
1452
 
1292
1453
  @PluginMethod
1293
1454
  public void manageSubscriptions(PluginCall call) {
1294
- Log.d(TAG, "manageSubscriptions() called");
1455
+ NativePurchasesLog.d(TAG, "manageSubscriptions() called");
1295
1456
  try {
1296
1457
  // Open the Google Play subscription management page
1297
1458
  // This intent opens the subscription center for the app
@@ -1302,32 +1463,32 @@ public class NativePurchasesPlugin extends Plugin {
1302
1463
  intent.addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
1303
1464
  getContext().startActivity(intent);
1304
1465
 
1305
- Log.d(TAG, "manageSubscriptions() opened successfully");
1466
+ NativePurchasesLog.d(TAG, "manageSubscriptions() opened successfully");
1306
1467
  call.resolve();
1307
1468
  } catch (Exception e) {
1308
- Log.d(TAG, "manageSubscriptions() error: " + e.getMessage());
1469
+ NativePurchasesLog.d(TAG, "manageSubscriptions() error: " + e.getMessage());
1309
1470
  call.reject("Failed to open subscription management page", e);
1310
1471
  }
1311
1472
  }
1312
1473
 
1313
1474
  @PluginMethod
1314
1475
  public void presentOfferCodeRedeemSheet(PluginCall call) {
1315
- Log.d(TAG, "presentOfferCodeRedeemSheet() called");
1476
+ NativePurchasesLog.d(TAG, "presentOfferCodeRedeemSheet() called");
1316
1477
  call.reject("presentOfferCodeRedeemSheet is only available on iOS");
1317
1478
  }
1318
1479
 
1319
1480
  @PluginMethod
1320
1481
  public void acknowledgePurchase(PluginCall call) {
1321
- Log.d(TAG, "acknowledgePurchase() called");
1482
+ NativePurchasesLog.d(TAG, "acknowledgePurchase() called");
1322
1483
  String purchaseToken = call.getString("purchaseToken");
1323
1484
 
1324
1485
  if (purchaseToken == null || purchaseToken.isEmpty()) {
1325
- Log.d(TAG, "Error: purchaseToken is empty");
1486
+ NativePurchasesLog.d(TAG, "Error: purchaseToken is empty");
1326
1487
  call.reject("purchaseToken is required");
1327
1488
  return;
1328
1489
  }
1329
1490
 
1330
- Log.d(TAG, "Manually acknowledging purchase with token: " + purchaseToken);
1491
+ NativePurchasesLog.d(TAG, "Manually acknowledging purchase");
1331
1492
  withBillingClient(call, () -> {
1332
1493
  AcknowledgePurchaseParams acknowledgePurchaseParams = AcknowledgePurchaseParams.newBuilder()
1333
1494
  .setPurchaseToken(purchaseToken)
@@ -1338,15 +1499,18 @@ public class NativePurchasesPlugin extends Plugin {
1338
1499
  new AcknowledgePurchaseResponseListener() {
1339
1500
  @Override
1340
1501
  public void onAcknowledgePurchaseResponse(@NonNull BillingResult billingResult) {
1341
- Log.d(TAG, "onAcknowledgePurchaseResponse() called");
1342
- Log.d(TAG, "Acknowledge result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage());
1502
+ NativePurchasesLog.d(TAG, "onAcknowledgePurchaseResponse() called");
1503
+ NativePurchasesLog.d(
1504
+ TAG,
1505
+ "Acknowledge result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage()
1506
+ );
1343
1507
 
1344
1508
  if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
1345
- Log.d(TAG, "Purchase acknowledged successfully");
1509
+ NativePurchasesLog.d(TAG, "Purchase acknowledged successfully");
1346
1510
  closeBillingClient();
1347
1511
  call.resolve();
1348
1512
  } else {
1349
- Log.d(TAG, "Purchase acknowledgment failed");
1513
+ NativePurchasesLog.d(TAG, "Purchase acknowledgment failed");
1350
1514
  closeBillingClient();
1351
1515
  call.reject("Failed to acknowledge purchase: " + billingResult.getDebugMessage());
1352
1516
  }
@@ -1358,29 +1522,29 @@ public class NativePurchasesPlugin extends Plugin {
1358
1522
 
1359
1523
  @PluginMethod
1360
1524
  public void consumePurchase(PluginCall call) {
1361
- Log.d(TAG, "consumePurchase() called");
1525
+ NativePurchasesLog.d(TAG, "consumePurchase() called");
1362
1526
  String purchaseToken = call.getString("purchaseToken");
1363
1527
 
1364
1528
  if (purchaseToken == null || purchaseToken.isEmpty()) {
1365
- Log.d(TAG, "Error: purchaseToken is empty");
1529
+ NativePurchasesLog.d(TAG, "Error: purchaseToken is empty");
1366
1530
  call.reject("purchaseToken is required");
1367
1531
  return;
1368
1532
  }
1369
1533
 
1370
- Log.d(TAG, "Consuming purchase with token: " + purchaseToken);
1534
+ NativePurchasesLog.d(TAG, "Consuming purchase");
1371
1535
  withBillingClient(call, () -> {
1372
1536
  ConsumeParams consumeParams = ConsumeParams.newBuilder().setPurchaseToken(purchaseToken).build();
1373
1537
 
1374
1538
  billingClient.consumeAsync(consumeParams, (billingResult, consumedToken) -> {
1375
- Log.d(TAG, "onConsumeResponse() called");
1376
- Log.d(TAG, "Consume result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage());
1539
+ NativePurchasesLog.d(TAG, "onConsumeResponse() called");
1540
+ NativePurchasesLog.d(TAG, "Consume result: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage());
1377
1541
 
1378
1542
  if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
1379
- Log.d(TAG, "Purchase consumed successfully");
1543
+ NativePurchasesLog.d(TAG, "Purchase consumed successfully");
1380
1544
  closeBillingClient();
1381
1545
  call.resolve();
1382
1546
  } else {
1383
- Log.d(TAG, "Purchase consumption failed");
1547
+ NativePurchasesLog.d(TAG, "Purchase consumption failed");
1384
1548
  closeBillingClient();
1385
1549
  call.reject("Failed to consume purchase: " + billingResult.getDebugMessage());
1386
1550
  }
@@ -1390,7 +1554,7 @@ public class NativePurchasesPlugin extends Plugin {
1390
1554
 
1391
1555
  @PluginMethod
1392
1556
  public void getAppTransaction(PluginCall call) {
1393
- Log.d(TAG, "getAppTransaction() called");
1557
+ NativePurchasesLog.d(TAG, "getAppTransaction() called");
1394
1558
  try {
1395
1559
  PackageManager pm = getContext().getPackageManager();
1396
1560
  String packageName = getContext().getPackageName();
@@ -1417,9 +1581,7 @@ public class NativePurchasesPlugin extends Plugin {
1417
1581
 
1418
1582
  // First install time on this device (milliseconds since epoch)
1419
1583
  long firstInstallTime = packageInfo.firstInstallTime;
1420
- String originalPurchaseDate = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", java.util.Locale.US).format(
1421
- new java.util.Date(firstInstallTime)
1422
- );
1584
+ String originalPurchaseDate = formatUtcIso8601(firstInstallTime);
1423
1585
  appTransaction.put("originalPurchaseDate", originalPurchaseDate);
1424
1586
 
1425
1587
  // Package name (bundle ID equivalent)
@@ -1431,27 +1593,27 @@ public class NativePurchasesPlugin extends Plugin {
1431
1593
  // Android doesn't have JWS representation
1432
1594
  // jwsRepresentation is not set (will be undefined in JS)
1433
1595
 
1434
- Log.d(TAG, "App transaction - version: " + versionName + ", firstInstall: " + originalPurchaseDate);
1596
+ NativePurchasesLog.d(TAG, "App transaction - version: " + versionName + ", firstInstall: " + originalPurchaseDate);
1435
1597
 
1436
1598
  JSObject result = new JSObject();
1437
1599
  result.put("appTransaction", appTransaction);
1438
1600
  call.resolve(result);
1439
1601
  } catch (PackageManager.NameNotFoundException e) {
1440
- Log.d(TAG, "getAppTransaction() error: " + e.getMessage());
1602
+ NativePurchasesLog.d(TAG, "getAppTransaction() error: " + e.getMessage());
1441
1603
  call.reject("Failed to get package info: " + e.getMessage());
1442
1604
  } catch (Exception e) {
1443
- Log.d(TAG, "getAppTransaction() error: " + e.getMessage());
1605
+ NativePurchasesLog.d(TAG, "getAppTransaction() error: " + e.getMessage());
1444
1606
  call.reject("Failed to get app transaction: " + e.getMessage());
1445
1607
  }
1446
1608
  }
1447
1609
 
1448
1610
  @PluginMethod
1449
1611
  public void isEntitledToOldBusinessModel(PluginCall call) {
1450
- Log.d(TAG, "isEntitledToOldBusinessModel() called");
1612
+ NativePurchasesLog.d(TAG, "isEntitledToOldBusinessModel() called");
1451
1613
  String targetVersion = call.getString("targetVersion");
1452
1614
 
1453
1615
  if (targetVersion == null || targetVersion.isEmpty()) {
1454
- Log.d(TAG, "Error: targetVersion is empty");
1616
+ NativePurchasesLog.d(TAG, "Error: targetVersion is empty");
1455
1617
  call.reject("targetVersion is required on Android");
1456
1618
  return;
1457
1619
  }
@@ -1475,7 +1637,7 @@ public class NativePurchasesPlugin extends Plugin {
1475
1637
  // Compare versions
1476
1638
  boolean isOlder = compareVersions(originalVersion, targetVersion) < 0;
1477
1639
 
1478
- Log.d(
1640
+ NativePurchasesLog.d(
1479
1641
  TAG,
1480
1642
  "isEntitledToOldBusinessModel - original: " + originalVersion + ", target: " + targetVersion + ", isOlder: " + isOlder
1481
1643
  );
@@ -1485,10 +1647,10 @@ public class NativePurchasesPlugin extends Plugin {
1485
1647
  result.put("originalAppVersion", originalVersion);
1486
1648
  call.resolve(result);
1487
1649
  } catch (PackageManager.NameNotFoundException e) {
1488
- Log.d(TAG, "isEntitledToOldBusinessModel() error: " + e.getMessage());
1650
+ NativePurchasesLog.d(TAG, "isEntitledToOldBusinessModel() error: " + e.getMessage());
1489
1651
  call.reject("Failed to get package info: " + e.getMessage());
1490
1652
  } catch (Exception e) {
1491
- Log.d(TAG, "isEntitledToOldBusinessModel() error: " + e.getMessage());
1653
+ NativePurchasesLog.d(TAG, "isEntitledToOldBusinessModel() error: " + e.getMessage());
1492
1654
  call.reject("Failed to check business model entitlement: " + e.getMessage());
1493
1655
  }
1494
1656
  }