@revenuecat/purchases-capacitor-ui 11.1.2 → 11.2.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.
@@ -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 = '15.0'
15
15
  s.dependency 'Capacitor'
16
- s.dependency 'PurchasesHybridCommonUI', '17.0.0'
16
+ s.dependency 'PurchasesHybridCommonUI', '17.6.0'
17
17
  s.swift_version = '5.1'
18
18
  end
@@ -8,7 +8,7 @@ buildscript {
8
8
  mavenCentral()
9
9
  }
10
10
  dependencies {
11
- classpath 'com.android.tools.build:gradle:8.12.0'
11
+ classpath 'com.android.tools.build:gradle:8.13.0'
12
12
  classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.20'
13
13
  }
14
14
  }
@@ -51,6 +51,6 @@ repositories {
51
51
  dependencies {
52
52
  implementation project(':capacitor-android')
53
53
  implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
54
- implementation 'com.revenuecat.purchases:purchases-hybrid-common-ui:17.0.0'
54
+ implementation 'com.revenuecat.purchases:purchases-hybrid-common-ui:17.6.0'
55
55
  implementation "org.jetbrains.kotlin:kotlin-stdlib:1.8.20"
56
56
  }
@@ -9,11 +9,13 @@ import com.getcapacitor.Plugin
9
9
  import com.getcapacitor.PluginCall
10
10
  import com.getcapacitor.PluginMethod
11
11
  import com.getcapacitor.annotation.CapacitorPlugin
12
+ import com.revenuecat.purchases.PresentedOfferingContext
12
13
  import com.revenuecat.purchases.hybridcommon.ui.PaywallResultListener
13
14
  import com.revenuecat.purchases.hybridcommon.ui.PaywallSource
14
15
  import com.revenuecat.purchases.hybridcommon.ui.PresentPaywallOptions
15
16
  import com.revenuecat.purchases.hybridcommon.ui.presentPaywallFromFragment
16
17
  import com.revenuecat.purchases.ui.revenuecatui.customercenter.ShowCustomerCenter
18
+ import org.json.JSONObject
17
19
 
18
20
  @CapacitorPlugin(name = "RevenueCatUI")
19
21
  class RevenueCatUIPlugin : Plugin(), PaywallResultListener {
@@ -38,11 +40,15 @@ class RevenueCatUIPlugin : Plugin(), PaywallResultListener {
38
40
  fun presentPaywall(call: PluginCall) {
39
41
  val offering = call.getObject("offering")
40
42
  val offeringIdentifier = offering?.getString("identifier")
43
+ val presentedOfferingContext = offering?.optJSONArray("availablePackages")
44
+ ?.optJSONObject(0)
45
+ ?.optJSONObject("presentedOfferingContext")
41
46
  val displayCloseButton = call.getBoolean("displayCloseButton") ?: false
42
47
 
43
48
  presentPaywallInternal(
44
49
  call = call,
45
50
  offeringIdentifier = offeringIdentifier,
51
+ presentedOfferingContext = presentedOfferingContext,
46
52
  displayCloseButton = displayCloseButton,
47
53
  requiredEntitlementIdentifier = null
48
54
  )
@@ -61,11 +67,15 @@ class RevenueCatUIPlugin : Plugin(), PaywallResultListener {
61
67
 
62
68
  val offering = call.getObject("offering")
63
69
  val offeringIdentifier = offering?.getString("identifier")
70
+ val presentedOfferingContext = offering?.optJSONArray("availablePackages")
71
+ ?.optJSONObject(0)
72
+ ?.optJSONObject("presentedOfferingContext")
64
73
  val displayCloseButton = call.getBoolean("displayCloseButton") ?: false
65
74
 
66
75
  presentPaywallInternal(
67
76
  call = call,
68
77
  offeringIdentifier = offeringIdentifier,
78
+ presentedOfferingContext = presentedOfferingContext,
69
79
  displayCloseButton = displayCloseButton,
70
80
  requiredEntitlementIdentifier = requiredEntitlementIdentifier
71
81
  )
@@ -77,6 +87,7 @@ class RevenueCatUIPlugin : Plugin(), PaywallResultListener {
77
87
  private fun presentPaywallInternal(
78
88
  call: PluginCall,
79
89
  offeringIdentifier: String?,
90
+ presentedOfferingContext: JSONObject?,
80
91
  displayCloseButton: Boolean,
81
92
  requiredEntitlementIdentifier: String?
82
93
  ) {
@@ -100,8 +111,34 @@ class RevenueCatUIPlugin : Plugin(), PaywallResultListener {
100
111
  return
101
112
  }
102
113
 
103
- val paywallSource = offeringIdentifier?.let { PaywallSource.OfferingIdentifier(it) }
104
- ?: PaywallSource.DefaultOffering
114
+ val presentedOfferingContext = presentedOfferingContext?.let { jsContext ->
115
+ val offeringId = jsContext.optString("offeringIdentifier").takeUnless { it.isNullOrEmpty() }
116
+ if (offeringId == null) { return@let null }
117
+ val placementIdentifier = jsContext.optString("placementIdentifier").takeUnless { it.isNullOrEmpty() }
118
+ val targetingContext = jsContext.optJSONObject("targetingContext")?.let { targetingContext ->
119
+ val revision = targetingContext.optInt("revision", -1).takeUnless { it == -1 }
120
+ val ruleId = targetingContext.optString("ruleId").takeUnless { it.isNullOrEmpty() }
121
+ if (revision == null || ruleId == null) { return@let null }
122
+ PresentedOfferingContext.TargetingContext(
123
+ revision = revision,
124
+ ruleId = ruleId,
125
+ )
126
+ }
127
+ PresentedOfferingContext(
128
+ offeringIdentifier = offeringId,
129
+ placementIdentifier = placementIdentifier,
130
+ targetingContext = targetingContext,
131
+ )
132
+ }
133
+
134
+ val paywallSource = if (offeringIdentifier != null && presentedOfferingContext != null) {
135
+ PaywallSource.OfferingIdentifierWithPresentedOfferingContext(
136
+ offeringIdentifier = offeringIdentifier,
137
+ presentedOfferingContext = presentedOfferingContext,
138
+ )
139
+ } else {
140
+ PaywallSource.DefaultOffering
141
+ }
105
142
 
106
143
  val options = PresentPaywallOptions(
107
144
  paywallSource = paywallSource,
@@ -44,7 +44,7 @@ public class RevenueCatUIPlugin: CAPPlugin {
44
44
  return
45
45
  }
46
46
 
47
- let offeringIdentifier = call.getObject("offering")?["identifier"]
47
+ let offeringOptions = self.processOfferingOptions(call)
48
48
  let displayCloseButton = call.getBool("displayCloseButton") ?? false
49
49
 
50
50
  var options: [String: Any] = [
@@ -52,8 +52,10 @@ public class RevenueCatUIPlugin: CAPPlugin {
52
52
  "shouldBlockTouchEvents": true
53
53
  ]
54
54
 
55
- if let offeringIdentifier = offeringIdentifier {
56
- options["offeringIdentifier"] = offeringIdentifier
55
+ if let offeringOptions = offeringOptions {
56
+ options.merge(offeringOptions) { original, offeringOption in
57
+ offeringOption
58
+ }
57
59
  }
58
60
 
59
61
  proxy.presentPaywall(
@@ -87,7 +89,7 @@ public class RevenueCatUIPlugin: CAPPlugin {
87
89
  return
88
90
  }
89
91
 
90
- let offeringIdentifier = call.getString("offeringIdentifier")
92
+ let offeringOptions = self.processOfferingOptions(call)
91
93
  let displayCloseButton = call.getBool("displayCloseButton") ?? false
92
94
 
93
95
  var options: [String: Any] = [
@@ -96,8 +98,10 @@ public class RevenueCatUIPlugin: CAPPlugin {
96
98
  "requiredEntitlementIdentifier": requiredEntitlementIdentifier
97
99
  ]
98
100
 
99
- if let offeringIdentifier = offeringIdentifier {
100
- options["offeringIdentifier"] = offeringIdentifier
101
+ if let offeringOptions = offeringOptions {
102
+ options.merge(offeringOptions) { original, offeringOption in
103
+ offeringOption
104
+ }
101
105
  }
102
106
 
103
107
  proxy.presentPaywallIfNeeded(
@@ -137,6 +141,46 @@ public class RevenueCatUIPlugin: CAPPlugin {
137
141
  }
138
142
  }
139
143
 
144
+ private extension RevenueCatUIPlugin {
145
+
146
+ func processOfferingOptions(_ call: CAPPluginCall) -> [String: Any]? {
147
+ let offering = call.getObject("offering")
148
+ let offeringIdentifier = call.getString("offeringIdentifier")
149
+ let availablePackages = offering?["availablePackages"] as? JSArray
150
+ let firstPackage = availablePackages?.first as? JSObject
151
+ let presentedOfferingContext = firstPackage?["presentedOfferingContext"] as? JSObject
152
+ let contextOfferingIdentifier = presentedOfferingContext?["offeringIdentifier"]
153
+ let contextPlacementIdentifier = presentedOfferingContext?["placementIdentifier"]
154
+ let contextTargetingContext = presentedOfferingContext?["targetingContext"] as? JSObject
155
+ let contextTargetingRevision = contextTargetingContext?["revision"]
156
+ let contextTargetingRuleId = contextTargetingContext?["ruleId"]
157
+ let displayCloseButton = call.getBool("displayCloseButton") ?? false
158
+
159
+ var options: [String: Any] = [:]
160
+ if let offeringIdentifier = offeringIdentifier {
161
+ options[PaywallProxy.PaywallOptionsKeys.offeringIdentifier] = offeringIdentifier
162
+ if let presentedOfferingContext = presentedOfferingContext,
163
+ let contextOfferingIdentifier = contextOfferingIdentifier {
164
+ var presentedOfferingContextMap = [
165
+ PaywallProxy.PresentedOfferingContextKeys.offeringIdentifier: contextOfferingIdentifier,
166
+ PaywallProxy.PresentedOfferingContextKeys.placementIdentifier: contextPlacementIdentifier,
167
+ ]
168
+ if let contextTargetingRevision = contextTargetingRevision,
169
+ let contextTargetingRuleId {
170
+ presentedOfferingContextMap[PaywallProxy.PresentedOfferingContextKeys.targetingContext] = [
171
+ PaywallProxy.PresentedOfferingTargetingContextKeys.revision: contextTargetingRevision,
172
+ PaywallProxy.PresentedOfferingTargetingContextKeys.ruleId: contextTargetingRuleId
173
+ ]
174
+ }
175
+ options[PaywallProxy.PaywallOptionsKeys.presentedOfferingContext] = presentedOfferingContextMap
176
+ }
177
+ return options
178
+ } else {
179
+ return nil
180
+ }
181
+ }
182
+ }
183
+
140
184
  // MARK: - Type Aliases to avoid direct type references
141
185
 
142
186
  /// Type alias for PaywallProxy to avoid direct reference to the concrete type
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revenuecat/purchases-capacitor-ui",
3
- "version": "11.1.2",
3
+ "version": "11.2.1",
4
4
  "description": "UI components for RevenueCat Capacitor SDK",
5
5
  "main": "dist/esm/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -61,7 +61,7 @@
61
61
  "dependencies": {
62
62
  "@capacitor/core": "^7.0.0",
63
63
  "@revenuecat/purchases-capacitor": "^10.2.4",
64
- "@revenuecat/purchases-typescript-internal-esm": "17.0.0"
64
+ "@revenuecat/purchases-typescript-internal-esm": "17.6.0"
65
65
  },
66
66
  "peerDependencies": {
67
67
  "@capacitor/core": "^7.0.0"