@revenuecat/purchases-capacitor 7.5.3 → 7.5.5

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 CHANGED
@@ -60,6 +60,8 @@ This plugin is based on [CapGo's Capacitor plugin](https://www.npmjs.com/package
60
60
  * [`addCustomerInfoUpdateListener(...)`](#addcustomerinfoupdatelistener)
61
61
  * [`removeCustomerInfoUpdateListener(...)`](#removecustomerinfoupdatelistener)
62
62
  * [`getOfferings()`](#getofferings)
63
+ * [`getCurrentOfferingForPlacement(...)`](#getcurrentofferingforplacement)
64
+ * [`syncAttributesAndOfferingsIfNeeded()`](#syncattributesandofferingsifneeded)
63
65
  * [`getProducts(...)`](#getproducts)
64
66
  * [`purchaseStoreProduct(...)`](#purchasestoreproduct)
65
67
  * [`purchaseDiscountedProduct(...)`](#purchasediscountedproduct)
@@ -225,6 +227,39 @@ Gets the map of entitlements -> offerings -> products
225
227
  --------------------
226
228
 
227
229
 
230
+ ### getCurrentOfferingForPlacement(...)
231
+
232
+ ```typescript
233
+ getCurrentOfferingForPlacement(options: { placementIdentifier: string; }) => Promise<PurchasesOffering | null>
234
+ ```
235
+
236
+ Retrieves a current offering for a placement identifier, use this to access offerings defined by targeting
237
+ placements configured in the RevenueCat dashboard.
238
+
239
+ | Param | Type |
240
+ | ------------- | --------------------------------------------- |
241
+ | **`options`** | <code>{ placementIdentifier: string; }</code> |
242
+
243
+ **Returns:** <code>Promise&lt;<a href="#purchasesoffering">PurchasesOffering</a> | null&gt;</code>
244
+
245
+ --------------------
246
+
247
+
248
+ ### syncAttributesAndOfferingsIfNeeded()
249
+
250
+ ```typescript
251
+ syncAttributesAndOfferingsIfNeeded() => Promise<PurchasesOfferings>
252
+ ```
253
+
254
+ Syncs subscriber attributes and then fetches the configured offerings for this user. This method is intended to
255
+ be called when using Targeting Rules with Custom Attributes. Any subscriber attributes should be set before
256
+ calling this method to ensure the returned offerings are applied with the latest subscriber attributes.
257
+
258
+ **Returns:** <code>Promise&lt;<a href="#purchasesofferings">PurchasesOfferings</a>&gt;</code>
259
+
260
+ --------------------
261
+
262
+
228
263
  ### getProducts(...)
229
264
 
230
265
  ```typescript
@@ -1134,32 +1169,34 @@ For more info see https://docs.revenuecat.com/docs/entitlements
1134
1169
  Contains information about the product available for the user to purchase.
1135
1170
  For more info see https://docs.revenuecat.com/docs/entitlements
1136
1171
 
1137
- | Prop | Type | Description |
1138
- | ------------------------ | ----------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
1139
- | **`identifier`** | <code>string</code> | Unique identifier for this package. Can be one a predefined package type or a custom one. |
1140
- | **`packageType`** | <code><a href="#package_type">PACKAGE_TYPE</a></code> | Package type for the product. Will be one of [PACKAGE_TYPE]. |
1141
- | **`product`** | <code><a href="#purchasesstoreproduct">PurchasesStoreProduct</a></code> | Product assigned to this package. |
1142
- | **`offeringIdentifier`** | <code>string</code> | Offering this package belongs to. |
1172
+ | Prop | Type | Description |
1173
+ | ------------------------------ | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
1174
+ | **`identifier`** | <code>string</code> | Unique identifier for this package. Can be one a predefined package type or a custom one. |
1175
+ | **`packageType`** | <code><a href="#package_type">PACKAGE_TYPE</a></code> | Package type for the product. Will be one of [PACKAGE_TYPE]. |
1176
+ | **`product`** | <code><a href="#purchasesstoreproduct">PurchasesStoreProduct</a></code> | Product assigned to this package. |
1177
+ | **`offeringIdentifier`** | <code>string</code> | Offering this package belongs to. |
1178
+ | **`presentedOfferingContext`** | <code><a href="#presentedofferingcontext">PresentedOfferingContext</a></code> | Offering context this package belongs to. Null if not using offerings or if fetched directly from store via getProducts. |
1143
1179
 
1144
1180
 
1145
1181
  #### PurchasesStoreProduct
1146
1182
 
1147
- | Prop | Type | Description |
1148
- | --------------------------------- | --------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1149
- | **`identifier`** | <code>string</code> | Product Id. |
1150
- | **`description`** | <code>string</code> | Description of the product. |
1151
- | **`title`** | <code>string</code> | Title of the product. |
1152
- | **`price`** | <code>number</code> | <a href="#price">Price</a> of the product in the local currency. Contains the price value of defaultOption for Google Play. |
1153
- | **`priceString`** | <code>string</code> | Formatted price of the item, including its currency sign. Contains the formatted price value of defaultOption for Google Play. |
1154
- | **`currencyCode`** | <code>string</code> | Currency code for price and original price. Contains the currency code value of defaultOption for Google Play. |
1155
- | **`introPrice`** | <code><a href="#purchasesintroprice">PurchasesIntroPrice</a> \| null</code> | Introductory price. |
1156
- | **`discounts`** | <code>PurchasesStoreProductDiscount[] \| null</code> | Collection of discount offers for a product. Null for Android. |
1157
- | **`productCategory`** | <code><a href="#product_category">PRODUCT_CATEGORY</a> \| null</code> | Product category. |
1158
- | **`productType`** | <code><a href="#product_type">PRODUCT_TYPE</a></code> | The specific type of subscription or one time purchase this product represents. Important: In iOS, if using StoreKit 1, we cannot determine the type. |
1159
- | **`subscriptionPeriod`** | <code>string \| null</code> | Subscription period, specified in ISO 8601 format. For example, P1W equates to one week, P1M equates to one month, P3M equates to three months, P6M equates to six months, and P1Y equates to one year. Note: Not available for Amazon. |
1160
- | **`defaultOption`** | <code><a href="#subscriptionoption">SubscriptionOption</a> \| null</code> | Default subscription option for a product. Google Play only. |
1161
- | **`subscriptionOptions`** | <code>SubscriptionOption[] \| null</code> | Collection of subscription options for a product. Google Play only. |
1162
- | **`presentedOfferingIdentifier`** | <code>string \| null</code> | Offering identifier the store product was presented from. Null if not using offerings or if fetched directly from store via getProducts. |
1183
+ | Prop | Type | Description |
1184
+ | --------------------------------- | ------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1185
+ | **`identifier`** | <code>string</code> | Product Id. |
1186
+ | **`description`** | <code>string</code> | Description of the product. |
1187
+ | **`title`** | <code>string</code> | Title of the product. |
1188
+ | **`price`** | <code>number</code> | <a href="#price">Price</a> of the product in the local currency. Contains the price value of defaultOption for Google Play. |
1189
+ | **`priceString`** | <code>string</code> | Formatted price of the item, including its currency sign. Contains the formatted price value of defaultOption for Google Play. |
1190
+ | **`currencyCode`** | <code>string</code> | Currency code for price and original price. Contains the currency code value of defaultOption for Google Play. |
1191
+ | **`introPrice`** | <code><a href="#purchasesintroprice">PurchasesIntroPrice</a> \| null</code> | Introductory price. |
1192
+ | **`discounts`** | <code>PurchasesStoreProductDiscount[] \| null</code> | Collection of discount offers for a product. Null for Android. |
1193
+ | **`productCategory`** | <code><a href="#product_category">PRODUCT_CATEGORY</a> \| null</code> | Product category. |
1194
+ | **`productType`** | <code><a href="#product_type">PRODUCT_TYPE</a></code> | The specific type of subscription or one time purchase this product represents. Important: In iOS, if using StoreKit 1, we cannot determine the type. |
1195
+ | **`subscriptionPeriod`** | <code>string \| null</code> | Subscription period, specified in ISO 8601 format. For example, P1W equates to one week, P1M equates to one month, P3M equates to three months, P6M equates to six months, and P1Y equates to one year. Note: Not available for Amazon. |
1196
+ | **`defaultOption`** | <code><a href="#subscriptionoption">SubscriptionOption</a> \| null</code> | Default subscription option for a product. Google Play only. |
1197
+ | **`subscriptionOptions`** | <code>SubscriptionOption[] \| null</code> | Collection of subscription options for a product. Google Play only. |
1198
+ | **`presentedOfferingIdentifier`** | <code>string \| null</code> | Offering identifier the store product was presented from. Null if not using offerings or if fetched directly from store via getProducts. |
1199
+ | **`presentedOfferingContext`** | <code><a href="#presentedofferingcontext">PresentedOfferingContext</a> \| null</code> | Offering context this package belongs to. Null if not using offerings or if fetched directly from store via getProducts. |
1163
1200
 
1164
1201
 
1165
1202
  #### PurchasesIntroPrice
@@ -1192,20 +1229,21 @@ For more info see https://docs.revenuecat.com/docs/entitlements
1192
1229
  Contains all details associated with a SubscriptionOption
1193
1230
  Used only for Google
1194
1231
 
1195
- | Prop | Type | Description |
1196
- | --------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
1197
- | **`id`** | <code>string</code> | Identifier of the subscription option If this <a href="#subscriptionoption">SubscriptionOption</a> represents a base plan, this will be the basePlanId. If it represents an offer, it will be {basePlanId}:{offerId} |
1198
- | **`storeProductId`** | <code>string</code> | Identifier of the StoreProduct associated with this SubscriptionOption This will be {subId}:{basePlanId} |
1199
- | **`productId`** | <code>string</code> | Identifer of the subscription associated with this SubscriptionOption This will be {subId} |
1200
- | **`pricingPhases`** | <code>PricingPhase[]</code> | Pricing phases defining a user's payment plan for the product over time. |
1201
- | **`tags`** | <code>string[]</code> | Tags defined on the base plan or offer. Empty for Amazon. |
1202
- | **`isBasePlan`** | <code>boolean</code> | True if this <a href="#subscriptionoption">SubscriptionOption</a> represents a subscription base plan (rather than an offer). |
1203
- | **`billingPeriod`** | <code><a href="#period">Period</a> \| null</code> | The subscription period of fullPricePhase (after free and intro trials). |
1204
- | **`isPrepaid`** | <code>boolean</code> | True if the subscription is pre-paid. |
1205
- | **`fullPricePhase`** | <code><a href="#pricingphase">PricingPhase</a> \| null</code> | The full price <a href="#pricingphase">PricingPhase</a> of the subscription. Looks for the last price phase of the <a href="#subscriptionoption">SubscriptionOption</a>. |
1206
- | **`freePhase`** | <code><a href="#pricingphase">PricingPhase</a> \| null</code> | The free trial <a href="#pricingphase">PricingPhase</a> of the subscription. Looks for the first pricing phase of the <a href="#subscriptionoption">SubscriptionOption</a> where amountMicros is 0. There can be a freeTrialPhase and an introductoryPhase in the same <a href="#subscriptionoption">SubscriptionOption</a>. |
1207
- | **`introPhase`** | <code><a href="#pricingphase">PricingPhase</a> \| null</code> | The intro trial <a href="#pricingphase">PricingPhase</a> of the subscription. Looks for the first pricing phase of the <a href="#subscriptionoption">SubscriptionOption</a> where amountMicros is greater than 0. There can be a freeTrialPhase and an introductoryPhase in the same <a href="#subscriptionoption">SubscriptionOption</a>. |
1208
- | **`presentedOfferingIdentifier`** | <code>string \| null</code> | Offering identifier the subscription option was presented from |
1232
+ | Prop | Type | Description |
1233
+ | --------------------------------- | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
1234
+ | **`id`** | <code>string</code> | Identifier of the subscription option If this <a href="#subscriptionoption">SubscriptionOption</a> represents a base plan, this will be the basePlanId. If it represents an offer, it will be {basePlanId}:{offerId} |
1235
+ | **`storeProductId`** | <code>string</code> | Identifier of the StoreProduct associated with this SubscriptionOption This will be {subId}:{basePlanId} |
1236
+ | **`productId`** | <code>string</code> | Identifer of the subscription associated with this SubscriptionOption This will be {subId} |
1237
+ | **`pricingPhases`** | <code>PricingPhase[]</code> | Pricing phases defining a user's payment plan for the product over time. |
1238
+ | **`tags`** | <code>string[]</code> | Tags defined on the base plan or offer. Empty for Amazon. |
1239
+ | **`isBasePlan`** | <code>boolean</code> | True if this <a href="#subscriptionoption">SubscriptionOption</a> represents a subscription base plan (rather than an offer). |
1240
+ | **`billingPeriod`** | <code><a href="#period">Period</a> \| null</code> | The subscription period of fullPricePhase (after free and intro trials). |
1241
+ | **`isPrepaid`** | <code>boolean</code> | True if the subscription is pre-paid. |
1242
+ | **`fullPricePhase`** | <code><a href="#pricingphase">PricingPhase</a> \| null</code> | The full price <a href="#pricingphase">PricingPhase</a> of the subscription. Looks for the last price phase of the <a href="#subscriptionoption">SubscriptionOption</a>. |
1243
+ | **`freePhase`** | <code><a href="#pricingphase">PricingPhase</a> \| null</code> | The free trial <a href="#pricingphase">PricingPhase</a> of the subscription. Looks for the first pricing phase of the <a href="#subscriptionoption">SubscriptionOption</a> where amountMicros is 0. There can be a freeTrialPhase and an introductoryPhase in the same <a href="#subscriptionoption">SubscriptionOption</a>. |
1244
+ | **`introPhase`** | <code><a href="#pricingphase">PricingPhase</a> \| null</code> | The intro trial <a href="#pricingphase">PricingPhase</a> of the subscription. Looks for the first pricing phase of the <a href="#subscriptionoption">SubscriptionOption</a> where amountMicros is greater than 0. There can be a freeTrialPhase and an introductoryPhase in the same <a href="#subscriptionoption">SubscriptionOption</a>. |
1245
+ | **`presentedOfferingIdentifier`** | <code>string \| null</code> | Offering identifier the subscription option was presented from |
1246
+ | **`presentedOfferingContext`** | <code><a href="#presentedofferingcontext">PresentedOfferingContext</a> \| null</code> | Offering context this package belongs to. Null if not using offerings or if fetched directly from store via getProducts. |
1209
1247
 
1210
1248
 
1211
1249
  #### PricingPhase
@@ -1243,6 +1281,27 @@ Contains all the details associated with a <a href="#price">Price</a>
1243
1281
  | **`currencyCode`** | <code>string</code> | Returns ISO 4217 currency code for price and original price. For example, if price is specified in British pounds sterling, price_currency_code is "GBP". If currency code cannot be determined, currency symbol is returned. |
1244
1282
 
1245
1283
 
1284
+ #### PresentedOfferingContext
1285
+
1286
+ Contains data about the context in which an offering was presented.
1287
+
1288
+ | Prop | Type | Description |
1289
+ | ------------------------- | ------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- |
1290
+ | **`offeringIdentifier`** | <code>string</code> | The identifier of the offering used to obtain this object. |
1291
+ | **`placementIdentifier`** | <code>string \| null</code> | The identifier of the placement used to obtain this object. |
1292
+ | **`targetingContext`** | <code><a href="#presentedofferingtargetingcontext">PresentedOfferingTargetingContext</a> \| null</code> | The revision of the targeting used to obtain this object. |
1293
+
1294
+
1295
+ #### PresentedOfferingTargetingContext
1296
+
1297
+ Contains data about the context in which an offering was presented.
1298
+
1299
+ | Prop | Type | Description |
1300
+ | -------------- | ------------------- | ---------------------------------------------------------- |
1301
+ | **`revision`** | <code>number</code> | The revision of the targeting used to obtain this object. |
1302
+ | **`ruleId`** | <code>string</code> | The rule id from the targeting used to obtain this object. |
1303
+
1304
+
1246
1305
  #### GetProductOptions
1247
1306
 
1248
1307
  | Prop | Type | Description |
@@ -13,6 +13,6 @@ Pod::Spec.new do |s|
13
13
  s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
14
  s.ios.deployment_target = '13.0'
15
15
  s.dependency 'Capacitor'
16
- s.dependency 'PurchasesHybridCommon', '9.8.0'
16
+ s.dependency 'PurchasesHybridCommon', '10.2.0'
17
17
  s.swift_version = '5.1'
18
18
  end
@@ -53,7 +53,7 @@ dependencies {
53
53
  implementation fileTree(dir: 'libs', include: ['*.jar'])
54
54
  implementation project(':capacitor-android')
55
55
  implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
56
- implementation 'com.revenuecat.purchases:purchases-hybrid-common:9.8.0'
56
+ implementation 'com.revenuecat.purchases:purchases-hybrid-common:10.2.0'
57
57
  testImplementation "junit:junit:$junitVersion"
58
58
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
59
59
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
@@ -13,6 +13,7 @@ import com.revenuecat.purchases.Purchases
13
13
  import com.revenuecat.purchases.Store
14
14
  import com.revenuecat.purchases.common.PlatformInfo
15
15
  import com.revenuecat.purchases.hybridcommon.ErrorContainer
16
+ import com.revenuecat.purchases.hybridcommon.OnNullableResult
16
17
  import com.revenuecat.purchases.hybridcommon.OnResult
17
18
  import com.revenuecat.purchases.hybridcommon.OnResultAny
18
19
  import com.revenuecat.purchases.hybridcommon.OnResultList
@@ -24,10 +25,12 @@ import com.revenuecat.purchases.hybridcommon.purchaseProduct
24
25
  import com.revenuecat.purchases.hybridcommon.showInAppMessagesIfNeeded
25
26
  import com.revenuecat.purchases.interfaces.UpdatedCustomerInfoListener
26
27
  import com.revenuecat.purchases.models.InAppMessageType
28
+ import org.json.JSONObject
27
29
  import com.revenuecat.purchases.hybridcommon.canMakePayments as canMakePaymentsCommon
28
30
  import com.revenuecat.purchases.hybridcommon.checkTrialOrIntroductoryPriceEligibility as checkTrialOrIntroductoryPriceEligibilityCommon
29
31
  import com.revenuecat.purchases.hybridcommon.collectDeviceIdentifiers as collectDeviceIdentifiersCommon
30
32
  import com.revenuecat.purchases.hybridcommon.getAppUserID as getAppUserIDCommon
33
+ import com.revenuecat.purchases.hybridcommon.getCurrentOfferingForPlacement as getCurrentOfferingForPlacementCommon
31
34
  import com.revenuecat.purchases.hybridcommon.getCustomerInfo as getCustomerInfoCommon
32
35
  import com.revenuecat.purchases.hybridcommon.getOfferings as getOfferingsCommon
33
36
  import com.revenuecat.purchases.hybridcommon.invalidateCustomerInfoCache as invalidateCustomerInfoCacheCommon
@@ -61,6 +64,7 @@ import com.revenuecat.purchases.hybridcommon.setOnesignalID as setOnesignalIDCom
61
64
  import com.revenuecat.purchases.hybridcommon.setPhoneNumber as setPhoneNumberCommon
62
65
  import com.revenuecat.purchases.hybridcommon.setProxyURLString as setProxyURLStringCommon
63
66
  import com.revenuecat.purchases.hybridcommon.setPushToken as setPushTokenCommon
67
+ import com.revenuecat.purchases.hybridcommon.syncAttributesAndOfferingsIfNeeded as syncAttributesAndOfferingsIfNeededCommon
64
68
  import com.revenuecat.purchases.hybridcommon.syncPurchases as syncPurchasesCommon
65
69
 
66
70
  @Suppress("unused")
@@ -72,7 +76,7 @@ class PurchasesPlugin : Plugin() {
72
76
 
73
77
  companion object {
74
78
  private const val PLATFORM_NAME = "capacitor"
75
- private const val PLUGIN_VERSION = "7.5.3"
79
+ private const val PLUGIN_VERSION = "7.5.5"
76
80
 
77
81
  private const val CUSTOMER_INFO_KEY = "customerInfo"
78
82
  }
@@ -151,6 +155,19 @@ class PurchasesPlugin : Plugin() {
151
155
  getOfferingsCommon(getOnResult(call))
152
156
  }
153
157
 
158
+ @PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
159
+ fun getCurrentOfferingForPlacement(call: PluginCall) {
160
+ if (rejectIfNotConfigured(call)) return
161
+ val placementIdentifier = call.getStringOrReject("placementIdentifier") ?: return
162
+ getCurrentOfferingForPlacementCommon(placementIdentifier, getOnNullableResult(call))
163
+ }
164
+
165
+ @PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
166
+ fun syncAttributesAndOfferingsIfNeeded(call: PluginCall) {
167
+ if (rejectIfNotConfigured(call)) return
168
+ syncAttributesAndOfferingsIfNeededCommon(getOnResult(call))
169
+ }
170
+
154
171
  @PluginMethod(returnType = PluginMethod.RETURN_PROMISE)
155
172
  fun getProducts(call: PluginCall) {
156
173
  if (rejectIfNotConfigured(call)) return
@@ -175,7 +192,7 @@ class PurchasesPlugin : Plugin() {
175
192
  val storeProduct = call.getObjectOrReject("product") ?: return
176
193
  val productIdentifier = storeProduct.getStringOrReject(call, "identifier") ?: return
177
194
  val type = storeProduct.getStringOrReject(call, "productCategory") ?: return
178
- val presentedOfferingIdentifier = storeProduct.getString("presentedOfferingIdentifier")
195
+ val presentedOfferingContext = storeProduct.optJSONObject("presentedOfferingContext")
179
196
  val optionalPurchaseParams = PurchaseOptionalInfoParams.fromCall(call)
180
197
  purchaseProduct(
181
198
  activity,
@@ -185,7 +202,7 @@ class PurchasesPlugin : Plugin() {
185
202
  optionalPurchaseParams.oldProductIdentifier,
186
203
  optionalPurchaseParams.prorationMode,
187
204
  optionalPurchaseParams.isPersonalizedPrice,
188
- presentedOfferingIdentifier,
205
+ presentedOfferingContext?.convertToAnyMap(),
189
206
  getOnResult(call),
190
207
  )
191
208
  }
@@ -205,13 +222,13 @@ class PurchasesPlugin : Plugin() {
205
222
  if (rejectIfNotConfigured(call)) return
206
223
  val packageToPurchase = call.getObjectOrReject("aPackage") ?: return
207
224
  val packageIdentifier = packageToPurchase.getStringOrReject(call, "identifier") ?: return
208
- val offeringIdentifier = packageToPurchase.getStringOrReject(call, "offeringIdentifier") ?: return
225
+ val presentedOfferingContext = packageToPurchase.getObjectOrReject(call, "presentedOfferingContext") ?: return
209
226
  val optionalPurchaseParams = PurchaseOptionalInfoParams.fromCall(call)
210
227
 
211
228
  purchasePackageCommon(
212
229
  activity,
213
230
  packageIdentifier,
214
- offeringIdentifier,
231
+ presentedOfferingContext.convertToAnyMap(),
215
232
  optionalPurchaseParams.oldProductIdentifier,
216
233
  optionalPurchaseParams.prorationMode,
217
234
  optionalPurchaseParams.isPersonalizedPrice,
@@ -225,7 +242,7 @@ class PurchasesPlugin : Plugin() {
225
242
  val subscriptionOption = call.getObjectOrReject("subscriptionOption") ?: return
226
243
  val productId = subscriptionOption.getStringOrReject(call, "productId") ?: return
227
244
  val subscriptionOptionId = subscriptionOption.getStringOrReject(call, "id") ?: return
228
- val presentedOfferingIdentifier = subscriptionOption.getString("presentedOfferingIdentifier")
245
+ val presentedOfferingContext = subscriptionOption.optJSONObject("presentedOfferingContext")
229
246
  val optionalPurchaseParams = PurchaseOptionalInfoParams.fromCall(call)
230
247
 
231
248
  purchaseSubscriptionOptionCommon(
@@ -235,7 +252,7 @@ class PurchasesPlugin : Plugin() {
235
252
  optionalPurchaseParams.oldProductIdentifier,
236
253
  optionalPurchaseParams.prorationMode,
237
254
  optionalPurchaseParams.isPersonalizedPrice,
238
- presentedOfferingIdentifier,
255
+ presentedOfferingContext?.convertToAnyMap(),
239
256
  getOnResult(call),
240
257
  )
241
258
  }
@@ -596,6 +613,23 @@ class PurchasesPlugin : Plugin() {
596
613
  }
597
614
  }
598
615
 
616
+ private fun getOnNullableResult(call: PluginCall, wrapperKey: String? = null): OnNullableResult {
617
+ return object : OnNullableResult {
618
+ override fun onReceived(map: Map<String, *>?) {
619
+ val mapToConvert = wrapperKey?.let { mapOf(wrapperKey to map) } ?: map
620
+ if (mapToConvert != null) {
621
+ call.resolve(convertMapToJSObject(mapToConvert))
622
+ } else {
623
+ call.resolve(null)
624
+ }
625
+ }
626
+
627
+ override fun onError(errorContainer: ErrorContainer) {
628
+ rejectWithErrorContainer(call, errorContainer)
629
+ }
630
+ }
631
+ }
632
+
599
633
  @Suppress("UNCHECKED_CAST")
600
634
  private fun convertMapToJSObject(readableMap: Map<String, Any?>): JSObject {
601
635
  val jsObject = JSObject()
@@ -677,6 +711,15 @@ class PurchasesPlugin : Plugin() {
677
711
  return value
678
712
  }
679
713
 
714
+ private fun JSObject.getObjectOrReject(call: PluginCall, key: String): JSONObject? {
715
+ val value = optJSONObject(key)
716
+ if (value == null) {
717
+ call.reject("Missing $key parameter in $this")
718
+ return null
719
+ }
720
+ return value
721
+ }
722
+
680
723
  private fun PluginCall.getArrayOrReject(key: String): JSArray? {
681
724
  val value = getArray(key)
682
725
  if (value == null) {
@@ -722,3 +765,19 @@ class PurchasesPlugin : Plugin() {
722
765
  }
723
766
  }
724
767
  }
768
+
769
+ private fun JSONObject.convertToAnyMap(): Map<String, Any?> =
770
+ this.keys().asSequence<String>().associate { key ->
771
+ when (val value = this[key]) {
772
+ is JSONObject -> {
773
+ key to value.convertToAnyMap()
774
+ }
775
+ else -> {
776
+ if (this.isNull(key)) {
777
+ key to null
778
+ } else {
779
+ key to value
780
+ }
781
+ }
782
+ }
783
+ }
package/dist/docs.json CHANGED
@@ -167,6 +167,46 @@
167
167
  ],
168
168
  "slug": "getofferings"
169
169
  },
170
+ {
171
+ "name": "getCurrentOfferingForPlacement",
172
+ "signature": "(options: { placementIdentifier: string; }) => Promise<PurchasesOffering | null>",
173
+ "parameters": [
174
+ {
175
+ "name": "options",
176
+ "docs": "",
177
+ "type": "{ placementIdentifier: string; }"
178
+ }
179
+ ],
180
+ "returns": "Promise<PurchasesOffering | null>",
181
+ "tags": [
182
+ {
183
+ "name": "returns",
184
+ "text": "Promise of optional offering. The promise will be rejected if configure\nhas not been called yet."
185
+ }
186
+ ],
187
+ "docs": "Retrieves a current offering for a placement identifier, use this to access offerings defined by targeting\nplacements configured in the RevenueCat dashboard.",
188
+ "complexTypes": [
189
+ "PurchasesOffering"
190
+ ],
191
+ "slug": "getcurrentofferingforplacement"
192
+ },
193
+ {
194
+ "name": "syncAttributesAndOfferingsIfNeeded",
195
+ "signature": "() => Promise<PurchasesOfferings>",
196
+ "parameters": [],
197
+ "returns": "Promise<PurchasesOfferings>",
198
+ "tags": [
199
+ {
200
+ "name": "returns",
201
+ "text": "Promise of entitlements structure. The promise will be rejected if configure\nhas not been called yet."
202
+ }
203
+ ],
204
+ "docs": "Syncs subscriber attributes and then fetches the configured offerings for this user. This method is intended to\nbe called when using Targeting Rules with Custom Attributes. Any subscriber attributes should be set before\ncalling this method to ensure the returned offerings are applied with the latest subscriber attributes.",
205
+ "complexTypes": [
206
+ "PurchasesOfferings"
207
+ ],
208
+ "slug": "syncattributesandofferingsifneeded"
209
+ },
170
210
  {
171
211
  "name": "getProducts",
172
212
  "signature": "(options: GetProductOptions) => Promise<{ products: PurchasesStoreProduct[]; }>",
@@ -1865,10 +1905,24 @@
1865
1905
  },
1866
1906
  {
1867
1907
  "name": "offeringIdentifier",
1868
- "tags": [],
1908
+ "tags": [
1909
+ {
1910
+ "text": ", use presentedOfferingContext",
1911
+ "name": "deprecated"
1912
+ }
1913
+ ],
1869
1914
  "docs": "Offering this package belongs to.",
1870
1915
  "complexTypes": [],
1871
1916
  "type": "string"
1917
+ },
1918
+ {
1919
+ "name": "presentedOfferingContext",
1920
+ "tags": [],
1921
+ "docs": "Offering context this package belongs to.\nNull if not using offerings or if fetched directly from store via getProducts.",
1922
+ "complexTypes": [
1923
+ "PresentedOfferingContext"
1924
+ ],
1925
+ "type": "PresentedOfferingContext"
1872
1926
  }
1873
1927
  ]
1874
1928
  },
@@ -1984,10 +2038,24 @@
1984
2038
  },
1985
2039
  {
1986
2040
  "name": "presentedOfferingIdentifier",
1987
- "tags": [],
2041
+ "tags": [
2042
+ {
2043
+ "text": ", use presentedOfferingContext",
2044
+ "name": "deprecated"
2045
+ }
2046
+ ],
1988
2047
  "docs": "Offering identifier the store product was presented from.\nNull if not using offerings or if fetched directly from store via getProducts.",
1989
2048
  "complexTypes": [],
1990
2049
  "type": "string | null"
2050
+ },
2051
+ {
2052
+ "name": "presentedOfferingContext",
2053
+ "tags": [],
2054
+ "docs": "Offering context this package belongs to.\nNull if not using offerings or if fetched directly from store via getProducts.",
2055
+ "complexTypes": [
2056
+ "PresentedOfferingContext"
2057
+ ],
2058
+ "type": "PresentedOfferingContext | null"
1991
2059
  }
1992
2060
  ]
1993
2061
  },
@@ -2196,10 +2264,24 @@
2196
2264
  },
2197
2265
  {
2198
2266
  "name": "presentedOfferingIdentifier",
2199
- "tags": [],
2267
+ "tags": [
2268
+ {
2269
+ "text": ", use presentedOfferingContext",
2270
+ "name": "deprecated"
2271
+ }
2272
+ ],
2200
2273
  "docs": "Offering identifier the subscription option was presented from",
2201
2274
  "complexTypes": [],
2202
2275
  "type": "string | null"
2276
+ },
2277
+ {
2278
+ "name": "presentedOfferingContext",
2279
+ "tags": [],
2280
+ "docs": "Offering context this package belongs to.\nNull if not using offerings or if fetched directly from store via getProducts.",
2281
+ "complexTypes": [
2282
+ "PresentedOfferingContext"
2283
+ ],
2284
+ "type": "PresentedOfferingContext | null"
2203
2285
  }
2204
2286
  ]
2205
2287
  },
@@ -2317,6 +2399,61 @@
2317
2399
  }
2318
2400
  ]
2319
2401
  },
2402
+ {
2403
+ "name": "PresentedOfferingContext",
2404
+ "slug": "presentedofferingcontext",
2405
+ "docs": "Contains data about the context in which an offering was presented.",
2406
+ "tags": [],
2407
+ "methods": [],
2408
+ "properties": [
2409
+ {
2410
+ "name": "offeringIdentifier",
2411
+ "tags": [],
2412
+ "docs": "The identifier of the offering used to obtain this object.",
2413
+ "complexTypes": [],
2414
+ "type": "string"
2415
+ },
2416
+ {
2417
+ "name": "placementIdentifier",
2418
+ "tags": [],
2419
+ "docs": "The identifier of the placement used to obtain this object.",
2420
+ "complexTypes": [],
2421
+ "type": "string | null"
2422
+ },
2423
+ {
2424
+ "name": "targetingContext",
2425
+ "tags": [],
2426
+ "docs": "The revision of the targeting used to obtain this object.",
2427
+ "complexTypes": [
2428
+ "PresentedOfferingTargetingContext"
2429
+ ],
2430
+ "type": "PresentedOfferingTargetingContext | null"
2431
+ }
2432
+ ]
2433
+ },
2434
+ {
2435
+ "name": "PresentedOfferingTargetingContext",
2436
+ "slug": "presentedofferingtargetingcontext",
2437
+ "docs": "Contains data about the context in which an offering was presented.",
2438
+ "tags": [],
2439
+ "methods": [],
2440
+ "properties": [
2441
+ {
2442
+ "name": "revision",
2443
+ "tags": [],
2444
+ "docs": "The revision of the targeting used to obtain this object.",
2445
+ "complexTypes": [],
2446
+ "type": "number"
2447
+ },
2448
+ {
2449
+ "name": "ruleId",
2450
+ "tags": [],
2451
+ "docs": "The rule id from the targeting used to obtain this object.",
2452
+ "complexTypes": [],
2453
+ "type": "string"
2454
+ }
2455
+ ]
2456
+ },
2320
2457
  {
2321
2458
  "name": "GetProductOptions",
2322
2459
  "slug": "getproductoptions",
@@ -1,4 +1,4 @@
1
- import type { CustomerInfo, CustomerInfoUpdateListener, GoogleProductChangeInfo, IntroEligibility, LogHandler, LogInResult, MakePurchaseResult, PurchasesConfiguration, PurchasesEntitlementInfo, PurchasesOfferings, PurchasesPackage, PurchasesPromotionalOffer, PurchasesStoreProduct, PurchasesStoreProductDiscount, SubscriptionOption, BILLING_FEATURE, LOG_LEVEL, PRODUCT_CATEGORY, REFUND_REQUEST_STATUS, IN_APP_MESSAGE_TYPE } from '@revenuecat/purchases-typescript-internal-esm';
1
+ import type { CustomerInfo, CustomerInfoUpdateListener, GoogleProductChangeInfo, IntroEligibility, LogHandler, LogInResult, MakePurchaseResult, PurchasesConfiguration, PurchasesEntitlementInfo, PurchasesOfferings, PurchasesPackage, PurchasesPromotionalOffer, PurchasesStoreProduct, PurchasesStoreProductDiscount, SubscriptionOption, BILLING_FEATURE, LOG_LEVEL, PRODUCT_CATEGORY, REFUND_REQUEST_STATUS, IN_APP_MESSAGE_TYPE, PurchasesOffering } from '@revenuecat/purchases-typescript-internal-esm';
2
2
  export * from '@revenuecat/purchases-typescript-internal-esm';
3
3
  export declare type PurchasesCallbackId = string;
4
4
  export interface GetProductOptions {
@@ -165,6 +165,23 @@ export interface PurchasesPlugin {
165
165
  * has not been called yet.
166
166
  */
167
167
  getOfferings(): Promise<PurchasesOfferings>;
168
+ /**
169
+ * Retrieves a current offering for a placement identifier, use this to access offerings defined by targeting
170
+ * placements configured in the RevenueCat dashboard.
171
+ * @returns {Promise<PurchasesOffering | null>} Promise of optional offering. The promise will be rejected if configure
172
+ * has not been called yet.
173
+ */
174
+ getCurrentOfferingForPlacement(options: {
175
+ placementIdentifier: string;
176
+ }): Promise<PurchasesOffering | null>;
177
+ /**
178
+ * Syncs subscriber attributes and then fetches the configured offerings for this user. This method is intended to
179
+ * be called when using Targeting Rules with Custom Attributes. Any subscriber attributes should be set before
180
+ * calling this method to ensure the returned offerings are applied with the latest subscriber attributes.
181
+ * @returns {Promise<PurchasesOfferings>} Promise of entitlements structure. The promise will be rejected if configure
182
+ * has not been called yet.
183
+ */
184
+ syncAttributesAndOfferingsIfNeeded(): Promise<PurchasesOfferings>;
168
185
  /**
169
186
  * Fetch the product info
170
187
  * @returns {Promise<PurchasesStoreProduct[]>} A promise containing an array of products. The promise will be rejected