@capgo/native-purchases 8.9.16 → 8.10.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.
- package/README.md +19 -10
- package/android/src/main/java/ee/forgr/nativepurchases/BillingResponseCodes.java +53 -0
- package/android/src/main/java/ee/forgr/nativepurchases/NativePurchasesPlugin.java +527 -72
- package/dist/docs.json +2 -2
- package/dist/esm/definitions.d.ts +22 -7
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/NativePurchasesPlugin/NativePurchasesPlugin.swift +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ We build, improve and fix our plugins with heavy use of AI, so issues usually ge
|
|
|
34
34
|
- **Purchases**: `purchaseProduct()` for consumables, non-consumables and subscriptions, with `acknowledgePurchase()`, plus `consumePurchase()` on Android.
|
|
35
35
|
- **Restore and history**: `restorePurchases()` and `getPurchases()`.
|
|
36
36
|
- **Subscription tools**: `manageSubscriptions()`, `presentOfferCodeRedeemSheet()` and `getStorefront()`.
|
|
37
|
-
- **Server validation**: receipt data and the `transactionUpdated` and `transactionVerificationFailed`
|
|
37
|
+
- **Server validation**: receipt data, purchase tokens, and the `transactionUpdated` event on iOS and Android (`transactionVerificationFailed` is iOS only).
|
|
38
38
|
- **Platforms**: iOS and Android. Web mocks the purchase calls for development, except `consumePurchase()`, which is Android only.
|
|
39
39
|
|
|
40
40
|
## In-app Purchases Made Easy
|
|
@@ -111,6 +111,10 @@ Add this to manifest
|
|
|
111
111
|
<uses-permission android:name="com.android.vending.BILLING" />
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
+
### Android rejection codes
|
|
115
|
+
|
|
116
|
+
Mapped Android billing and operation failures expose a stable `error.code` (see `NativePurchasesAndroidErrorCode` in `definitions.ts`). Branch on `error.code` instead of message text to tell user cancel (`USER_CANCELED`), pending purchase (`PURCHASE_PENDING`), and Play billing failures (`SERVICE_TIMEOUT`, `NETWORK_ERROR`, and the other mapped codes). For missing products, handle both `PRODUCT_NOT_FOUND` (the product-details query succeeded but returned no details) and `ITEM_UNAVAILABLE` (Play reported the SKU as unavailable).
|
|
117
|
+
|
|
114
118
|
### Testing with Google Play Console
|
|
115
119
|
|
|
116
120
|
> 📖 **[Complete Android Testing Guide](./docs/ANDROID_TESTING_GUIDE.md)** - Comprehensive guide covering Internal Testing, License Testing, and Internal App Sharing methods with step-by-step instructions, troubleshooting, and best practices.
|
|
@@ -1815,8 +1819,8 @@ By default the plugin finishes StoreKit 2 transactions and acknowledges Google P
|
|
|
1815
1819
|
|
|
1816
1820
|
| Setting | Scope |
|
|
1817
1821
|
| -------- | ----- |
|
|
1818
|
-
| `autoFinishTransactions` (default `true`) | Plugin-wide: iOS `transactionUpdated
|
|
1819
|
-
| `autoAcknowledgePurchases` on `purchaseProduct()` (default `true`) | Per purchase call. Effective auto finish/ack requires both flags to be true. Does not change the
|
|
1822
|
+
| `autoFinishTransactions` (default `true`) | Plugin-wide: iOS and Android `transactionUpdated`, and `purchaseProduct` when combined with `autoAcknowledgePurchases`. Android `restorePurchases` recovery. |
|
|
1823
|
+
| `autoAcknowledgePurchases` on `purchaseProduct()` (default `true`) | Per purchase call. Effective auto finish/ack requires both flags to be true. Does not change the `transactionUpdated` listener by itself. |
|
|
1820
1824
|
|
|
1821
1825
|
Set `autoFinishTransactions: false` in `capacitor.config` under `plugins.NativePurchases` so iOS applies it before the native update listener starts, or call `NativePurchases.configure({ autoFinishTransactions: false })` at startup.
|
|
1822
1826
|
|
|
@@ -1838,7 +1842,7 @@ After validation when automatic acknowledgment is off (for example `configure({
|
|
|
1838
1842
|
|
|
1839
1843
|
An acknowledge or consume can be lost before Google Play answers, for example when the app is killed mid-finish. Plugin teardown (when Capacitor destroys the plugin with its activity) also closes the current billing client even while a finish is still in flight, and Play drops any work that client had queued. The purchase then stays unacknowledged, and Google Play refunds purchases that are not acknowledged within three days.
|
|
1840
1844
|
|
|
1841
|
-
With `autoFinishTransactions: true` (the default), call `restorePurchases()` at app launch. It acknowledges any `PURCHASED` purchase that is still unacknowledged, so a purchase interrupted by a lost finish is completed on the next start. With `autoFinishTransactions: false`, use `getUnfinishedTransactions()` at launch
|
|
1845
|
+
With `autoFinishTransactions: true` (the default), call `restorePurchases()` at app launch. It acknowledges any `PURCHASED` purchase that is still unacknowledged, so a purchase interrupted by a lost finish is completed on the next start. With `autoFinishTransactions: false`, use `getUnfinishedTransactions()` at launch, or listen for `transactionUpdated`, and finish each purchase after validation.
|
|
1842
1846
|
|
|
1843
1847
|
## Breaking (TypeScript typings)
|
|
1844
1848
|
|
|
@@ -2326,14 +2330,19 @@ can change their store region.
|
|
|
2326
2330
|
addListener(eventName: 'transactionUpdated', listenerFunc: (transaction: Transaction) => void) => Promise<PluginListenerHandle>
|
|
2327
2331
|
```
|
|
2328
2332
|
|
|
2329
|
-
Listen for
|
|
2330
|
-
Fires on app launch if there are unfinished transactions, and for any updates afterward.
|
|
2333
|
+
Listen for purchase transaction updates outside an in-flight `purchaseProduct()` call.
|
|
2331
2334
|
|
|
2332
|
-
|
|
2333
|
-
before emitting the event. When `false`, the event includes `needsFinish: true` and you must call
|
|
2334
|
-
`finishTransaction()` after backend validation.
|
|
2335
|
+
**iOS:** StoreKit <a href="#transaction">Transaction</a>.updates. Fires on app launch for unfinished transactions.
|
|
2335
2336
|
|
|
2336
|
-
|
|
2337
|
+
**Android:** Google Play PurchasesUpdatedListener on a persistent billing connection while this
|
|
2338
|
+
listener is registered, plus queryPurchasesAsync when the first listener is added and when the
|
|
2339
|
+
app returns to the foreground. Pending purchases that complete later are reported here.
|
|
2340
|
+
|
|
2341
|
+
When `autoFinishTransactions` is `true` (default), iOS finishes each verified transaction before
|
|
2342
|
+
emitting; Android attempts to acknowledge each PURCHASED purchase before emitting (pending
|
|
2343
|
+
purchases and failed acknowledgements are still emitted without acknowledgement). When `false`,
|
|
2344
|
+
purchased `transactionUpdated` events include `needsFinish: true` when not yet acknowledged; call
|
|
2345
|
+
`finishTransaction()` or `acknowledgePurchase()` after backend validation.
|
|
2337
2346
|
|
|
2338
2347
|
| Param | Type |
|
|
2339
2348
|
| ------------------ | ----------------------------------------------------------------------------- |
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
package ee.forgr.nativepurchases;
|
|
2
|
+
|
|
3
|
+
import com.android.billingclient.api.BillingClient;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Stable rejection {@code code} strings for Android {@link com.getcapacitor.PluginCall#reject}.
|
|
7
|
+
* Play {@link BillingClient.BillingResponseCode} values are mapped in {@link #name(int)}.
|
|
8
|
+
*/
|
|
9
|
+
public final class BillingResponseCodes {
|
|
10
|
+
|
|
11
|
+
public static final String PURCHASE_PENDING = "PURCHASE_PENDING";
|
|
12
|
+
public static final String PRODUCT_NOT_FOUND = "PRODUCT_NOT_FOUND";
|
|
13
|
+
public static final String BILLING_CLIENT_CLOSED = "BILLING_CLIENT_CLOSED";
|
|
14
|
+
public static final String PURCHASE_NOT_FOUND = "PURCHASE_NOT_FOUND";
|
|
15
|
+
|
|
16
|
+
private BillingResponseCodes() {}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Maps a Play billing response code to a stable plugin error code.
|
|
20
|
+
*/
|
|
21
|
+
public static String name(int code) {
|
|
22
|
+
switch (code) {
|
|
23
|
+
case BillingClient.BillingResponseCode.OK:
|
|
24
|
+
return "OK";
|
|
25
|
+
case BillingClient.BillingResponseCode.USER_CANCELED:
|
|
26
|
+
return "USER_CANCELED";
|
|
27
|
+
case BillingClient.BillingResponseCode.ITEM_ALREADY_OWNED:
|
|
28
|
+
return "ITEM_ALREADY_OWNED";
|
|
29
|
+
case BillingClient.BillingResponseCode.ITEM_NOT_OWNED:
|
|
30
|
+
return "ITEM_NOT_OWNED";
|
|
31
|
+
case BillingClient.BillingResponseCode.ITEM_UNAVAILABLE:
|
|
32
|
+
return "ITEM_UNAVAILABLE";
|
|
33
|
+
case BillingClient.BillingResponseCode.BILLING_UNAVAILABLE:
|
|
34
|
+
return "BILLING_UNAVAILABLE";
|
|
35
|
+
case BillingClient.BillingResponseCode.SERVICE_DISCONNECTED:
|
|
36
|
+
return "SERVICE_DISCONNECTED";
|
|
37
|
+
case BillingClient.BillingResponseCode.SERVICE_UNAVAILABLE:
|
|
38
|
+
return "SERVICE_UNAVAILABLE";
|
|
39
|
+
case BillingClient.BillingResponseCode.SERVICE_TIMEOUT:
|
|
40
|
+
return "SERVICE_TIMEOUT";
|
|
41
|
+
case BillingClient.BillingResponseCode.DEVELOPER_ERROR:
|
|
42
|
+
return "DEVELOPER_ERROR";
|
|
43
|
+
case BillingClient.BillingResponseCode.FEATURE_NOT_SUPPORTED:
|
|
44
|
+
return "FEATURE_NOT_SUPPORTED";
|
|
45
|
+
case BillingClient.BillingResponseCode.NETWORK_ERROR:
|
|
46
|
+
return "NETWORK_ERROR";
|
|
47
|
+
case BillingClient.BillingResponseCode.ERROR:
|
|
48
|
+
return "ERROR";
|
|
49
|
+
default:
|
|
50
|
+
return "UNKNOWN_" + code;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|