@app-swiss-knife/react-native-sdk 0.5.0 → 0.5.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/CHANGELOG.md +88 -0
- package/README.md +57 -12
- package/android/src/main/java/com/swissknife/purchases/SwissKnifeJson.kt +17 -4
- package/android/vendor/GENERATED.md +1 -0
- package/android/vendor/java/com/appswissknife/SwissKnife.kt +4 -0
- package/android/vendor/java/com/appswissknife/context/DeviceContext.kt +1 -1
- package/android/vendor/java/com/appswissknife/net/IngestClient.kt +1 -1
- package/android/vendor/java/com/appswissknife/offerings/OfferingsRepository.kt +47 -2
- package/android/vendor/java/com/appswissknife/purchases/BillingClientGateway.kt +185 -33
- package/android/vendor/java/com/appswissknife/purchases/ProductKindHint.kt +8 -0
- package/android/vendor/java/com/appswissknife/purchases/PurchasesGateway.kt +10 -0
- package/app.plugin.js +61 -5
- package/ios/SwissKnifeJSON.swift +24 -2
- package/ios/vendor/GENERATED.md +1 -0
- package/ios/vendor/SwissKnifeiOS/Context/DeviceContext.swift +1 -1
- package/ios/vendor/SwissKnifeiOS/Services/OfferingsService.swift +37 -5
- package/ios/vendor/SwissKnifeiOS/Types.swift +31 -1
- package/ios-notification-service/SwissKnifeNotificationService.podspec +37 -0
- package/ios-notification-service/vendor/GENERATED.md +11 -0
- package/ios-notification-service/vendor/SwissKnifeNotificationService/SwissKnifeNotificationServiceExtension.swift +177 -0
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,94 @@ vendored into this npm tarball at pack time, so a version here covers all three.
|
|
|
12
12
|
|
|
13
13
|
## [Unreleased]
|
|
14
14
|
|
|
15
|
+
## [0.5.1] - 2026-11-24
|
|
16
|
+
|
|
17
|
+
Google Play consumables can be bought again, both platforms report each
|
|
18
|
+
product's real type, the iOS Notification Service Extension pod ships in this
|
|
19
|
+
package, and one Expo config can build for Google Play and for RuStore. The
|
|
20
|
+
fixes are in native code, so they reach users only through a new store build.
|
|
21
|
+
|
|
22
|
+
### Upgrading from 0.5.0
|
|
23
|
+
|
|
24
|
+
1. **Bump the dependency, commit the lockfile, rebuild the native app.**
|
|
25
|
+
`npm install @app-swiss-knife/react-native-sdk@0.5.1`, commit
|
|
26
|
+
`package.json` and the lockfile, then `npx expo prebuild --clean` (or let
|
|
27
|
+
EAS Build run prebuild), or `cd ios && pod install` and a Gradle sync on
|
|
28
|
+
bare React Native. Ship it as a new store build: an over-the-air JS update
|
|
29
|
+
does not carry it.
|
|
30
|
+
2. **iOS product labels are now real.** Before, every iOS product reached JS
|
|
31
|
+
as `productCategory: "SUBSCRIPTION"` and
|
|
32
|
+
`productType: "AUTO_RENEWABLE_SUBSCRIPTION"`. A lifetime unlock or a
|
|
33
|
+
consumable is now `NON_SUBSCRIPTION` with its own `productType`. If your
|
|
34
|
+
paywall filters on `productCategory === "SUBSCRIPTION"` and should keep
|
|
35
|
+
one-time products, filter on `productType` instead, or show every package.
|
|
36
|
+
3. **Android (Play): consumables can be sold for repeat purchase.** Type the
|
|
37
|
+
product as a consumable in the dashboard. A consumable a user bought with
|
|
38
|
+
0.5.0 stays owned until `restorePurchases()` runs, or until the app reads
|
|
39
|
+
offerings that name it a consumable (see **Fixed**).
|
|
40
|
+
|
|
41
|
+
### Added
|
|
42
|
+
|
|
43
|
+
- The iOS Notification Service Extension pod is part of this package. In the
|
|
44
|
+
extension target of your Podfile:
|
|
45
|
+
`pod 'SwissKnifeNotificationService', :path => '../node_modules/@app-swiss-knife/react-native-sdk/ios-notification-service'`.
|
|
46
|
+
It compiles only the extension class (Foundation and UserNotifications), and
|
|
47
|
+
the app pod compiles the same files as in 0.5.0. This replaces the 0.5.0
|
|
48
|
+
note that the extension class was not part of the npm package. See README
|
|
49
|
+
"Rich notifications".
|
|
50
|
+
- Expo config plugin: `SWISS_KNIFE_ANDROID_STORE=play|rustore`, read at
|
|
51
|
+
prebuild, so one app config can produce a Google Play build and a RuStore
|
|
52
|
+
build (set it in each EAS build profile's `env`). Unset keeps the old
|
|
53
|
+
behaviour: RuStore when `android.rustore` is configured. `rustore` without a
|
|
54
|
+
complete `android.rustore`, or any other value, fails the prebuild with an
|
|
55
|
+
error naming the fields; the check runs when the config is read, so it fails
|
|
56
|
+
an iOS prebuild too.
|
|
57
|
+
- Native iOS: `StoreProduct.productType` (`StoreProductType`, with
|
|
58
|
+
`isSubscription`).
|
|
59
|
+
- Native Android: `ProductKindHint.productKind`, the server's product type for
|
|
60
|
+
a product, and `PurchasesGateway.onServerProductTypes(types)` (default
|
|
61
|
+
no-op), which receives the server's type for each of the store's products
|
|
62
|
+
that the offerings name.
|
|
63
|
+
|
|
64
|
+
### Changed
|
|
65
|
+
|
|
66
|
+
- iOS: `productType` and `productCategory` report the product's StoreKit type:
|
|
67
|
+
`AUTO_RENEWABLE_SUBSCRIPTION`, `NON_RENEWABLE_SUBSCRIPTION`, `CONSUMABLE` or
|
|
68
|
+
`NON_CONSUMABLE`, and `UNKNOWN` for a dashboard-only one-time product that
|
|
69
|
+
StoreKit did not return. `productCategory` is `SUBSCRIPTION` only for an
|
|
70
|
+
auto-renewable product; non-subscriptions have no `subscriptionPeriod`.
|
|
71
|
+
- Android: a one-time product is `CONSUMABLE` or `NON_CONSUMABLE` when the
|
|
72
|
+
server's catalogue names its type, `UNKNOWN` otherwise (it was always
|
|
73
|
+
`UNKNOWN`).
|
|
74
|
+
- The server's offerings name each product's type (`product_type`), except a
|
|
75
|
+
product with no duration whose type is still the dashboard's default
|
|
76
|
+
subscription type: that one is left out, so the SDKs keep treating it as a
|
|
77
|
+
one-time product.
|
|
78
|
+
|
|
79
|
+
### Fixed
|
|
80
|
+
|
|
81
|
+
- Android (Play): consumables can be bought again. A one-time purchase is
|
|
82
|
+
consumed once the server's validation answer says its product is a
|
|
83
|
+
consumable (the server has recorded the purchase by then); every other
|
|
84
|
+
product is still only acknowledged. A failed consume is retried and never
|
|
85
|
+
fails the purchase. A consumable that 0.5.0 acknowledged and left owned is
|
|
86
|
+
consumed by `restorePurchases()`, and by the purchase check that runs after
|
|
87
|
+
`getOfferings()` reads offerings naming it a consumable; the same check runs
|
|
88
|
+
when Play answers `ITEM_ALREADY_OWNED`, so the next attempt can buy.
|
|
89
|
+
- Expo config plugin: `android.rustore` no longer turns every Android build
|
|
90
|
+
into a RuStore build when `SWISS_KNIFE_ANDROID_STORE=play` is set.
|
|
91
|
+
- The dashboard's native Android install snippet showed version 0.4.0; it now
|
|
92
|
+
follows the SDK version.
|
|
93
|
+
|
|
94
|
+
### Known limitations
|
|
95
|
+
|
|
96
|
+
- Android: Play has no non-renewing subscriptions, so a product the server
|
|
97
|
+
types `non_renewing` is reported as `AUTO_RENEWABLE_SUBSCRIPTION`; iOS
|
|
98
|
+
reports `NON_RENEWABLE_SUBSCRIPTION`.
|
|
99
|
+
- Android (Play): a consumable bought before sign-in with 0.5.0 and validated
|
|
100
|
+
again under the signed-in user is refused by the server as another user's
|
|
101
|
+
purchase, so it stays owned, as in 0.5.0.
|
|
102
|
+
|
|
15
103
|
## [0.5.0] - 2026-11-24
|
|
16
104
|
|
|
17
105
|
Push notifications, Android offerings and one-time products, Google Play
|
package/README.md
CHANGED
|
@@ -31,11 +31,12 @@ has to exist on any registry for a consumer app to build.
|
|
|
31
31
|
`scripts/vendor-native.mjs` runs on `build` and `prepack` and copies the
|
|
32
32
|
native sources into this package:
|
|
33
33
|
|
|
34
|
-
| From
|
|
35
|
-
|
|
|
36
|
-
| `packages/swiss-knife-ios/Sources/SwissKnifeiOS`
|
|
37
|
-
| `packages/swiss-knife-android/src/main/java`
|
|
38
|
-
| `packages/swiss-knife-android/src/main/res`
|
|
34
|
+
| From | To | Compiled by |
|
|
35
|
+
| ---------------------------------------------------------------- | --------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
|
|
36
|
+
| `packages/swiss-knife-ios/Sources/SwissKnifeiOS` | `ios/vendor/SwissKnifeiOS` | `SwissKnifePurchases.podspec` (`source_files = ios/**`) |
|
|
37
|
+
| `packages/swiss-knife-android/src/main/java` | `android/vendor/java` | `android/build.gradle` (`sourceSets.main.java.srcDirs`) |
|
|
38
|
+
| `packages/swiss-knife-android/src/main/res` | `android/vendor/res` | `android/build.gradle` (`sourceSets.main.res.srcDirs`) |
|
|
39
|
+
| `packages/swiss-knife-ios/Sources/SwissKnifeNotificationService` | `ios-notification-service/vendor/SwissKnifeNotificationService` | `ios-notification-service/SwissKnifeNotificationService.podspec` (extension target only) |
|
|
39
40
|
|
|
40
41
|
The vendored trees are **git-ignored build artifacts** (same status as `lib/`)
|
|
41
42
|
but ARE included in the tarball. The single source of truth stays in
|
|
@@ -411,11 +412,23 @@ The plugin does **not** generate the extension target (it needs an Xcode
|
|
|
411
412
|
project rewrite). Manual steps:
|
|
412
413
|
|
|
413
414
|
1. Xcode → File → New → Target → _Notification Service Extension_.
|
|
414
|
-
2. Add the `SwissKnifeNotificationService`
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
415
|
+
2. Add the `SwissKnifeNotificationService` pod, which ships in this package, to
|
|
416
|
+
**that target only**: in `ios/Podfile`, at the top level, then `pod install`.
|
|
417
|
+
|
|
418
|
+
```ruby
|
|
419
|
+
target 'YourNotificationService' do
|
|
420
|
+
pod 'SwissKnifeNotificationService', :path => '../node_modules/@app-swiss-knife/react-native-sdk/ios-notification-service'
|
|
421
|
+
end
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
The path is relative to `ios/`; in a monorepo that hoists `node_modules`,
|
|
425
|
+
point it at the folder where the package is actually installed.
|
|
426
|
+
|
|
427
|
+
It is deliberately separate from the SDK's pod and imports only Foundation +
|
|
428
|
+
UserNotifications, so the extension stays under its memory cap. (A native
|
|
429
|
+
app without React Native adds the `SwissKnifeNotificationService` product of
|
|
430
|
+
the Swift package in `packages/swiss-knife-ios` instead.)
|
|
431
|
+
|
|
419
432
|
3. Replace the generated class:
|
|
420
433
|
|
|
421
434
|
```swift
|
|
@@ -466,8 +479,40 @@ The npm package includes the native RuStore adapter. Enable it in Expo:
|
|
|
466
479
|
```
|
|
467
480
|
|
|
468
481
|
Prebuild configures the payment return deeplink and selects `swissKnifeStore=rustore`.
|
|
469
|
-
Without this option, builds use Play and do not load RuStore dependencies.
|
|
470
|
-
|
|
482
|
+
Without this option, builds use Play and do not load RuStore dependencies.
|
|
483
|
+
|
|
484
|
+
To ship one app config to both stores, choose the store per build with the
|
|
485
|
+
`SWISS_KNIFE_ANDROID_STORE` environment variable, which the config plugin reads
|
|
486
|
+
at prebuild:
|
|
487
|
+
|
|
488
|
+
| `SWISS_KNIFE_ANDROID_STORE` | Build |
|
|
489
|
+
| --------------------------- | ------------------------------------------------------------------------------------------------------------------- |
|
|
490
|
+
| unset or empty | RuStore when `android.rustore` is configured, Google Play otherwise (the behaviour above) |
|
|
491
|
+
| `play` | Google Play: `swissKnifeStore=play`, no RuStore strings or manifest entries, even with `android.rustore` configured |
|
|
492
|
+
| `rustore` | RuStore; prebuild fails, naming the missing fields, unless `android.rustore` has `consoleAppId` and `scheme` |
|
|
493
|
+
|
|
494
|
+
Any other value fails the prebuild, an iOS one included, since the plugin checks
|
|
495
|
+
the variable whenever it reads the app config. With EAS Build, set it in each
|
|
496
|
+
build profile's `env`; EAS runs prebuild with it when `android/` is not
|
|
497
|
+
committed (a bare project sets `swissKnifeStore` itself, see below):
|
|
498
|
+
|
|
499
|
+
```json
|
|
500
|
+
{
|
|
501
|
+
"build": {
|
|
502
|
+
"production-play": {
|
|
503
|
+
"env": { "SWISS_KNIFE_ANDROID_STORE": "play" }
|
|
504
|
+
},
|
|
505
|
+
"production-rustore": {
|
|
506
|
+
"env": { "SWISS_KNIFE_ANDROID_STORE": "rustore" }
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
Locally, `SWISS_KNIFE_ANDROID_STORE=play npx expo prebuild -p android --clean`;
|
|
513
|
+
`--clean` matters when switching stores, since prebuild without it keeps the
|
|
514
|
+
RuStore entries an earlier RuStore prebuild wrote into `android/`. Bare React
|
|
515
|
+
Native apps can set the `swissKnifeStore` Gradle property and provide RuStore's manifest metadata
|
|
471
516
|
(`console_app_id_value`, `sdk_pay_scheme_value`) plus the launcher Activity's
|
|
472
517
|
singleTask payment return intent filter. Backend credentials use `rustore_api_key`;
|
|
473
518
|
products and entitlements must be configured for platform `rustore`.
|
|
@@ -115,11 +115,12 @@ object SwissKnifeJson {
|
|
|
115
115
|
map.putDouble("price", product.price.amountMicros / 1_000_000.0)
|
|
116
116
|
map.putString("currencyCode", product.price.currencyCode)
|
|
117
117
|
// A product the SDK knows is one-time (Play INAPP, or a dashboard product
|
|
118
|
-
// with no duration) is not labelled a subscription.
|
|
119
|
-
//
|
|
120
|
-
val
|
|
118
|
+
// with no duration) is not labelled a subscription. Any other product keeps
|
|
119
|
+
// the subscription label.
|
|
120
|
+
val hint = product as? ProductKindHint
|
|
121
|
+
val oneTime = hint?.isOneTime == true
|
|
121
122
|
map.putString("productCategory", if (oneTime) "NON_SUBSCRIPTION" else "SUBSCRIPTION")
|
|
122
|
-
map.putString("productType",
|
|
123
|
+
map.putString("productType", productTypeLabel(oneTime, hint?.productKind))
|
|
123
124
|
map.putNullableString(
|
|
124
125
|
"subscriptionPeriod",
|
|
125
126
|
product.subscriptionPeriod?.let { periodToISOString(it) },
|
|
@@ -373,4 +374,16 @@ object SwissKnifeJson {
|
|
|
373
374
|
private fun WritableMap.putNullableMap(key: String, value: WritableMap?) {
|
|
374
375
|
if (value == null) putNull(key) else putMap(key, value)
|
|
375
376
|
}
|
|
377
|
+
/**
|
|
378
|
+
* The `productType` label, as iOS reports it for the same product: a one-time
|
|
379
|
+
* product is CONSUMABLE or NON_CONSUMABLE when the server's catalogue names
|
|
380
|
+
* its type, UNKNOWN otherwise. Play has no non-renewing subscription, so
|
|
381
|
+
* every subscription is AUTO_RENEWABLE_SUBSCRIPTION.
|
|
382
|
+
*/
|
|
383
|
+
internal fun productTypeLabel(oneTime: Boolean, kind: String?): String = when {
|
|
384
|
+
!oneTime -> "AUTO_RENEWABLE_SUBSCRIPTION"
|
|
385
|
+
kind == "consumable" -> "CONSUMABLE"
|
|
386
|
+
kind == "non_consumable" -> "NON_CONSUMABLE"
|
|
387
|
+
else -> "UNKNOWN"
|
|
388
|
+
}
|
|
376
389
|
}
|
|
@@ -4,6 +4,7 @@ Copied verbatim by packages/react-native-sdk/scripts/vendor-native.mjs from the
|
|
|
4
4
|
standalone native SDK sources in the monorepo. Edit those instead:
|
|
5
5
|
|
|
6
6
|
packages/swiss-knife-ios/Sources/SwissKnifeiOS/**
|
|
7
|
+
packages/swiss-knife-ios/Sources/SwissKnifeNotificationService/**
|
|
7
8
|
packages/swiss-knife-android/src/main/{java,res}/**
|
|
8
9
|
|
|
9
10
|
This directory is gitignored and regenerated on every `build` / `prepack`.
|
|
@@ -290,6 +290,7 @@ object SwissKnife {
|
|
|
290
290
|
// one wired by an earlier configure in this process must not shadow it.
|
|
291
291
|
// A blank proxyURL means the SDK's default host, as on iOS.
|
|
292
292
|
val priceProvider = gateway.priceEnrichmentProvider()
|
|
293
|
+
val storeGateway = gateway
|
|
293
294
|
offeringsRepository = priceProvider?.let {
|
|
294
295
|
com.appswissknife.offerings.OfferingsRepository(
|
|
295
296
|
httpClient = com.appswissknife.net.BackendHttpClientAdapter(),
|
|
@@ -297,6 +298,9 @@ object SwissKnife {
|
|
|
297
298
|
apiKey = apiKey,
|
|
298
299
|
platformTags = it.platformTags(),
|
|
299
300
|
priceProvider = it,
|
|
301
|
+
// The backend's product types reach the gateway that sells them (the
|
|
302
|
+
// Play gateway finds consumables an older SDK left unconsumed).
|
|
303
|
+
onServerProductTypes = storeGateway::onServerProductTypes,
|
|
300
304
|
)
|
|
301
305
|
}
|
|
302
306
|
// Same store-agnostic gate as the offerings wiring: real store gateways
|
|
@@ -42,7 +42,7 @@ internal object DeviceContextProvider {
|
|
|
42
42
|
* eventually inject this via `BuildConfig`, but for now keep it in
|
|
43
43
|
* source so we don't have to thread build settings through every test.
|
|
44
44
|
*/
|
|
45
|
-
const val SDK_VERSION: String = "0.5.
|
|
45
|
+
const val SDK_VERSION: String = "0.5.1"
|
|
46
46
|
|
|
47
47
|
private val cacheLock = Any()
|
|
48
48
|
|
|
@@ -59,6 +59,10 @@ class OfferingsRepository(
|
|
|
59
59
|
// Live price enrichment for the active store; null = backend prices only.
|
|
60
60
|
private val priceProvider: PriceEnrichmentProvider?,
|
|
61
61
|
private val clock: () -> Long = System::currentTimeMillis,
|
|
62
|
+
// Told the backend's product type of each of this store's products it reads
|
|
63
|
+
// (only those the backend names a type for). SwissKnife hands it to the
|
|
64
|
+
// gateway (PurchasesGateway.onServerProductTypes).
|
|
65
|
+
private val onServerProductTypes: (Map<String, String>) -> Unit = {},
|
|
62
66
|
) {
|
|
63
67
|
|
|
64
68
|
private data class CacheEntry(val offerings: Offerings, val fetchedAt: Long, val ttlMillis: Long) {
|
|
@@ -169,6 +173,7 @@ class OfferingsRepository(
|
|
|
169
173
|
)
|
|
170
174
|
}
|
|
171
175
|
val storeProducts = parsed.flatMap { o -> o.packages.map { it.product } }
|
|
176
|
+
reportProductTypes(storeProducts)
|
|
172
177
|
val priced = priceByStore(storeProducts)
|
|
173
178
|
val all = LinkedHashMap<String, Offering>()
|
|
174
179
|
for (o in parsed) {
|
|
@@ -180,7 +185,7 @@ class OfferingsRepository(
|
|
|
180
185
|
SimplePackage(
|
|
181
186
|
identifier = p.identifier ?: p.product.productId,
|
|
182
187
|
packageType = p.packageType?.let(::packageTypeOf) ?: p.product.durationDays.toPackageType(),
|
|
183
|
-
product = priced[p.product.productId] ?: StoreProductFromBackend(p.product),
|
|
188
|
+
product = withServerKind(priced[p.product.productId] ?: StoreProductFromBackend(p.product), p.product),
|
|
184
189
|
offeringIdentifier = o.identifier,
|
|
185
190
|
)
|
|
186
191
|
},
|
|
@@ -199,11 +204,12 @@ class OfferingsRepository(
|
|
|
199
204
|
}
|
|
200
205
|
// Filter to the active store's products (Play: play/android; RuStore: rustore).
|
|
201
206
|
val storeProducts = backendProducts.filter { it.isForThisStore() }
|
|
207
|
+
reportProductTypes(storeProducts)
|
|
202
208
|
// Enrich with live store prices; ids the store can't resolve fall back to
|
|
203
209
|
// the backend-priced product.
|
|
204
210
|
val enriched = priceByStore(storeProducts)
|
|
205
211
|
val packages = storeProducts.map { bp ->
|
|
206
|
-
val storeProduct = enriched[bp.productId] ?: StoreProductFromBackend(bp)
|
|
212
|
+
val storeProduct = withServerKind(enriched[bp.productId] ?: StoreProductFromBackend(bp), bp)
|
|
207
213
|
SimplePackage(
|
|
208
214
|
identifier = bp.productId,
|
|
209
215
|
packageType = bp.durationDays.toPackageType(),
|
|
@@ -249,6 +255,24 @@ class OfferingsRepository(
|
|
|
249
255
|
|
|
250
256
|
private fun BackendProduct.isForThisStore(): Boolean = platform.lowercase() in storeTags
|
|
251
257
|
|
|
258
|
+
/**
|
|
259
|
+
* Tell [onServerProductTypes] the types the backend named; a failure there
|
|
260
|
+
* never fails the read. A LinkageError is caught too: a PurchasesGateway
|
|
261
|
+
* compiled separately against an SDK that predates
|
|
262
|
+
* `PurchasesGateway.onServerProductTypes` has no such method.
|
|
263
|
+
*/
|
|
264
|
+
private fun reportProductTypes(products: List<BackendProduct>) {
|
|
265
|
+
val types = products.mapNotNull { p -> p.productType?.let { p.productId to it } }.toMap()
|
|
266
|
+
if (types.isEmpty()) return
|
|
267
|
+
try {
|
|
268
|
+
onServerProductTypes(types)
|
|
269
|
+
} catch (e: RuntimeException) {
|
|
270
|
+
Log.w(TAG, "product type listener failed", e)
|
|
271
|
+
} catch (e: LinkageError) {
|
|
272
|
+
Log.w(TAG, "product type listener failed", e)
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
252
276
|
/**
|
|
253
277
|
* Live store prices for [products], keyed by product id. A store failure
|
|
254
278
|
* leaves every product on its dashboard price rather than failing the read.
|
|
@@ -391,6 +415,7 @@ private class StoreProductFromBackend(private val bp: BackendProduct) : StorePro
|
|
|
391
415
|
amountMicros = (bp.backendPrice * 1_000_000).toLong(),
|
|
392
416
|
)
|
|
393
417
|
override val isOneTime: Boolean = bp.isOneTime
|
|
418
|
+
override val productKind: String? = bp.productType
|
|
394
419
|
/** From the dashboard duration, as iOS's backend-priced product; null for a one-time product. */
|
|
395
420
|
override val subscriptionPeriod: SubscriptionPeriod? =
|
|
396
421
|
if (bp.isOneTime) null else subscriptionPeriodFromDays(bp.durationDays)
|
|
@@ -398,6 +423,26 @@ private class StoreProductFromBackend(private val bp: BackendProduct) : StorePro
|
|
|
398
423
|
override val discounts: List<StoreProductDiscount> = emptyList()
|
|
399
424
|
}
|
|
400
425
|
|
|
426
|
+
/**
|
|
427
|
+
* [product] with the server's product type attached ([ProductKindHint.productKind]),
|
|
428
|
+
* so the React Native bridge can label a store-priced one-time product
|
|
429
|
+
* CONSUMABLE or NON_CONSUMABLE. Unchanged when the server names no type. The
|
|
430
|
+
* store's own one-time/subscription answer ([ProductKindHint.isOneTime]) wins
|
|
431
|
+
* over the server's type.
|
|
432
|
+
*/
|
|
433
|
+
private fun withServerKind(product: StoreProduct, bp: BackendProduct): StoreProduct {
|
|
434
|
+
val kind = bp.productType ?: return product
|
|
435
|
+
val hint = product as? ProductKindHint
|
|
436
|
+
if (hint?.productKind == kind) return product
|
|
437
|
+
return KindedStoreProduct(product, kind, hint?.isOneTime ?: bp.isOneTime)
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
private class KindedStoreProduct(
|
|
441
|
+
inner: StoreProduct,
|
|
442
|
+
override val productKind: String,
|
|
443
|
+
override val isOneTime: Boolean,
|
|
444
|
+
) : StoreProduct by inner, ProductKindHint
|
|
445
|
+
|
|
401
446
|
/** iOS `OfferingsService.subscriptionPeriodFromDays`, for the same dashboard durations. */
|
|
402
447
|
private fun subscriptionPeriodFromDays(days: Int): SubscriptionPeriod? = when (days) {
|
|
403
448
|
0 -> null
|