@capgo/native-purchases 8.7.0 → 8.8.1
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.
package/android/build.gradle
CHANGED
|
@@ -49,8 +49,8 @@ repositories {
|
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
dependencies {
|
|
52
|
-
implementation "com.google.guava:guava:33.
|
|
53
|
-
def billing_version = "
|
|
52
|
+
implementation "com.google.guava:guava:33.7.1-android"
|
|
53
|
+
def billing_version = "9.1.0"
|
|
54
54
|
implementation "com.android.billingclient:billing:$billing_version"
|
|
55
55
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
56
56
|
implementation project(':capacitor-android')
|
|
@@ -39,12 +39,13 @@ import java.util.concurrent.Executors;
|
|
|
39
39
|
import java.util.concurrent.TimeUnit;
|
|
40
40
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
41
41
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
42
|
+
import java.util.concurrent.atomic.AtomicReference;
|
|
42
43
|
import org.json.JSONArray;
|
|
43
44
|
|
|
44
45
|
@CapacitorPlugin(name = "NativePurchases")
|
|
45
46
|
public class NativePurchasesPlugin extends Plugin {
|
|
46
47
|
|
|
47
|
-
private final String pluginVersion = "8.
|
|
48
|
+
private final String pluginVersion = "8.8.1";
|
|
48
49
|
public static final String TAG = "NativePurchases";
|
|
49
50
|
private static final int BILLING_CONNECTION_MAX_ATTEMPTS = 2;
|
|
50
51
|
private static final long BILLING_SETUP_TIMEOUT_SECONDS = 5;
|
|
@@ -196,6 +197,53 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
196
197
|
}
|
|
197
198
|
}
|
|
198
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Maps a {@link BillingClient.BillingResponseCode} to a readable name so
|
|
202
|
+
* consumers can tell why a purchase was refused - most importantly
|
|
203
|
+
* USER_CANCELED (not an error) and ITEM_ALREADY_OWNED (the user already
|
|
204
|
+
* paid and the app should restore instead of showing a failure).
|
|
205
|
+
*/
|
|
206
|
+
private static String billingResponseCodeName(int code) {
|
|
207
|
+
switch (code) {
|
|
208
|
+
case BillingClient.BillingResponseCode.USER_CANCELED:
|
|
209
|
+
return "USER_CANCELED";
|
|
210
|
+
case BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED:
|
|
211
|
+
return "ITEM_ALREADY_OWNED";
|
|
212
|
+
case BillingClient.BillingResponseCode.ITEM_NOT_OWNED:
|
|
213
|
+
return "ITEM_NOT_OWNED";
|
|
214
|
+
case BillingClient.BillingResponseCode.ITEM_UNAVAILABLE:
|
|
215
|
+
return "ITEM_UNAVAILABLE";
|
|
216
|
+
case BillingClient.BillingResponseCode.BILLING_UNAVAILABLE:
|
|
217
|
+
return "BILLING_UNAVAILABLE";
|
|
218
|
+
case BillingClient.BillingResponseCode.SERVICE_DISCONNECTED:
|
|
219
|
+
return "SERVICE_DISCONNECTED";
|
|
220
|
+
case BillingClient.BillingResponseCode.SERVICE_UNAVAILABLE:
|
|
221
|
+
return "SERVICE_UNAVAILABLE";
|
|
222
|
+
case BillingClient.BillingResponseCode.DEVELOPER_ERROR:
|
|
223
|
+
return "DEVELOPER_ERROR";
|
|
224
|
+
case BillingClient.BillingResponseCode.FEATURE_NOT_SUPPORTED:
|
|
225
|
+
return "FEATURE_NOT_SUPPORTED";
|
|
226
|
+
case BillingClient.BillingResponseCode.NETWORK_ERROR:
|
|
227
|
+
return "NETWORK_ERROR";
|
|
228
|
+
case BillingClient.BillingResponseCode.ERROR:
|
|
229
|
+
return "ERROR";
|
|
230
|
+
default:
|
|
231
|
+
return "UNKNOWN_" + code;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
private static String describeQueryFailure(String productType, BillingResult billingResult) {
|
|
236
|
+
return (
|
|
237
|
+
productType +
|
|
238
|
+
": " +
|
|
239
|
+
billingResponseCodeName(billingResult.getResponseCode()) +
|
|
240
|
+
" (" +
|
|
241
|
+
billingResult.getResponseCode() +
|
|
242
|
+
") " +
|
|
243
|
+
billingResult.getDebugMessage()
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
199
247
|
private void rejectBillingSetupCall(PluginCall purchaseCall, AtomicBoolean callRejected, String code, String message) {
|
|
200
248
|
if (purchaseCall != null && callRejected.compareAndSet(false, true)) {
|
|
201
249
|
purchaseCall.reject(code, message);
|
|
@@ -310,7 +358,7 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
310
358
|
Log.d(TAG, "Purchase state is OTHER: " + purchase.getPurchaseState());
|
|
311
359
|
// Handle any other error codes.
|
|
312
360
|
if (purchaseCall != null) {
|
|
313
|
-
purchaseCall.reject("Purchase is not purchased");
|
|
361
|
+
purchaseCall.reject("Purchase is not purchased", "PURCHASE_STATE_" + purchase.getPurchaseState());
|
|
314
362
|
} else {
|
|
315
363
|
Log.d(TAG, "purchaseCall is null for failed purchase");
|
|
316
364
|
}
|
|
@@ -429,7 +477,10 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
429
477
|
Log.d(TAG, "Purchase update failed or purchases is null");
|
|
430
478
|
Log.i(NativePurchasesPlugin.TAG, "onPurchasesUpdated" + billingResult);
|
|
431
479
|
if (purchaseCall != null) {
|
|
432
|
-
purchaseCall.reject(
|
|
480
|
+
purchaseCall.reject(
|
|
481
|
+
"Purchase is not purchased",
|
|
482
|
+
billingResponseCodeName(billingResult.getResponseCode())
|
|
483
|
+
);
|
|
433
484
|
}
|
|
434
485
|
}
|
|
435
486
|
closeBillingClient();
|
|
@@ -1103,15 +1154,25 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
1103
1154
|
JSONArray allPurchases = new JSONArray();
|
|
1104
1155
|
AtomicInteger pendingQueries = new AtomicInteger((queryInApp ? 1 : 0) + (querySubs ? 1 : 0));
|
|
1105
1156
|
AtomicBoolean finished = new AtomicBoolean(false);
|
|
1157
|
+
// A query that fails must not be reported as "no purchases": callers use an
|
|
1158
|
+
// empty list to revoke entitlements, so a transient Play error would strip
|
|
1159
|
+
// a paying user. Remember the first failure and reject instead.
|
|
1160
|
+
AtomicReference<String> queryFailure = new AtomicReference<>(null);
|
|
1106
1161
|
|
|
1107
1162
|
Runnable maybeFinish = () -> {
|
|
1108
1163
|
int remaining = pendingQueries.decrementAndGet();
|
|
1109
1164
|
Log.d(TAG, "Pending purchase queries remaining: " + remaining);
|
|
1110
1165
|
if (remaining <= 0 && finished.compareAndSet(false, true)) {
|
|
1166
|
+
closeBillingClient();
|
|
1167
|
+
String failure = queryFailure.get();
|
|
1168
|
+
if (failure != null) {
|
|
1169
|
+
Log.w(TAG, "Rejecting getPurchases: " + failure);
|
|
1170
|
+
call.reject("Failed to query purchases: " + failure, "QUERY_PURCHASES_FAILED");
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1111
1173
|
JSObject result = new JSObject();
|
|
1112
1174
|
result.put("purchases", allPurchases);
|
|
1113
1175
|
Log.d(TAG, "Returning " + allPurchases.length() + " purchases");
|
|
1114
|
-
closeBillingClient();
|
|
1115
1176
|
call.resolve(result);
|
|
1116
1177
|
}
|
|
1117
1178
|
};
|
|
@@ -1160,9 +1221,11 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
1160
1221
|
}
|
|
1161
1222
|
} else {
|
|
1162
1223
|
Log.d(TAG, "In-app purchase query failed: " + billingResult.getDebugMessage());
|
|
1224
|
+
queryFailure.compareAndSet(null, describeQueryFailure("inapp", billingResult));
|
|
1163
1225
|
}
|
|
1164
1226
|
} catch (Exception ex) {
|
|
1165
1227
|
Log.d(TAG, "Error processing in-app purchase query: " + ex.getMessage());
|
|
1228
|
+
queryFailure.compareAndSet(null, describeQueryFailure("inapp", billingResult) + " / " + ex.getMessage());
|
|
1166
1229
|
} finally {
|
|
1167
1230
|
maybeFinish.run();
|
|
1168
1231
|
}
|
|
@@ -1213,9 +1276,11 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
1213
1276
|
}
|
|
1214
1277
|
} else {
|
|
1215
1278
|
Log.d(TAG, "Subscription purchase query failed: " + billingResult.getDebugMessage());
|
|
1279
|
+
queryFailure.compareAndSet(null, describeQueryFailure("subs", billingResult));
|
|
1216
1280
|
}
|
|
1217
1281
|
} catch (Exception ex) {
|
|
1218
1282
|
Log.d(TAG, "Error processing subscription purchase query: " + ex.getMessage());
|
|
1283
|
+
queryFailure.compareAndSet(null, describeQueryFailure("subs", billingResult) + " / " + ex.getMessage());
|
|
1219
1284
|
} finally {
|
|
1220
1285
|
maybeFinish.run();
|
|
1221
1286
|
}
|
|
@@ -23,7 +23,7 @@ public class NativePurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
23
23
|
CAPPluginMethod(name: "getStorefront", returnType: CAPPluginReturnPromise)
|
|
24
24
|
]
|
|
25
25
|
|
|
26
|
-
private let pluginVersion: String = "8.
|
|
26
|
+
private let pluginVersion: String = "8.8.1"
|
|
27
27
|
private var transactionUpdatesTask: Task<Void, Never>?
|
|
28
28
|
|
|
29
29
|
@objc func getPluginVersion(_ call: CAPPluginCall) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/native-purchases",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.8.1",
|
|
4
4
|
"description": "In-app Subscriptions Made Easy",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
43
43
|
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
44
44
|
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
45
|
-
"eslint": "eslint .
|
|
45
|
+
"eslint": "eslint .",
|
|
46
46
|
"prettier": "prettier-pretty-check \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
47
47
|
"swiftlint": "node-swiftlint",
|
|
48
48
|
"docgen": "docgen --api NativePurchasesPlugin --output-readme README.md --output-json dist/docs.json",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"watch": "tsc --watch",
|
|
51
51
|
"prepublishOnly": "bun run build",
|
|
52
52
|
"check:wiring": "node scripts/check-capacitor-plugin-wiring.mjs",
|
|
53
|
+
"check:cap9-deprecated": "node scripts/check-cap9-deprecated.mjs",
|
|
53
54
|
"example:install": "cd example-app && bun install --frozen-lockfile",
|
|
54
55
|
"example:build": "bun run build && cd example-app && bun install --frozen-lockfile && bun run build",
|
|
55
56
|
"changelog:ai": "node scripts/generate-ai-changelog.mjs"
|
|
@@ -60,12 +61,13 @@
|
|
|
60
61
|
"@capacitor/core": "^8.0.0",
|
|
61
62
|
"@capacitor/docgen": "^0.3.1",
|
|
62
63
|
"@capacitor/ios": "^8.0.0",
|
|
63
|
-
"@ionic/eslint-config": "^0.
|
|
64
|
+
"@ionic/eslint-config": "^0.5.0",
|
|
64
65
|
"@ionic/prettier-config": "^4.0.0",
|
|
65
66
|
"@ionic/swiftlint-config": "^2.0.0",
|
|
66
67
|
"@types/node": "^24.10.1",
|
|
67
|
-
"eslint": "^8.
|
|
68
|
-
"eslint
|
|
68
|
+
"@typescript-eslint/eslint-plugin": "^8.70.0",
|
|
69
|
+
"@typescript-eslint/parser": "^8.70.0",
|
|
70
|
+
"eslint": "^10.0.0",
|
|
69
71
|
"husky": "^9.1.7",
|
|
70
72
|
"prettier": "^3.6.2",
|
|
71
73
|
"prettier-plugin-java": "^2.7.7",
|
|
@@ -80,9 +82,6 @@
|
|
|
80
82
|
},
|
|
81
83
|
"prettier": "@ionic/prettier-config",
|
|
82
84
|
"swiftlint": "@ionic/swiftlint-config",
|
|
83
|
-
"eslintConfig": {
|
|
84
|
-
"extends": "@ionic/eslint-config/recommended"
|
|
85
|
-
},
|
|
86
85
|
"capacitor": {
|
|
87
86
|
"ios": {
|
|
88
87
|
"src": "ios"
|