Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit da87b2e

Browse files
authored
Merge pull request #87 from superwall/develop
2.1.1
2 parents 9332d88 + b697adf commit da87b2e

6 files changed

Lines changed: 1018 additions & 858 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
The changelog for `Superwall`. Also see the [releases](https://github.com/superwall/react-native-superwall/releases) on GitHub.
44

5+
6+
## 2.1.1
7+
8+
### Enhancements
9+
10+
- Upgrades Android SDK to 2.1.0 [View Android SDK release notes](https://github.com/superwall/Superwall-Android/releases/tag/2.1.0).
11+
512
## 2.1.0
613

714
### Fixes

android/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ buildscript {
1111
classpath "com.android.tools.build:gradle:7.2.1"
1212
// noinspection DifferentKotlinGradleVersion
1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14+
classpath "org.jetbrains.kotlin:kotlin-serialization:1.6.0"
15+
1416
}
1517
}
1618

@@ -20,6 +22,7 @@ def isNewArchitectureEnabled() {
2022

2123
apply plugin: "com.android.library"
2224
apply plugin: "kotlin-android"
25+
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'
2326

2427
if (isNewArchitectureEnabled()) {
2528
apply plugin: "com.facebook.react"
@@ -91,6 +94,7 @@ dependencies {
9194
implementation "com.facebook.react:react-native:+"
9295
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
9396

94-
implementation "com.superwall.sdk:superwall-android:2.0.6"
97+
implementation "com.superwall.sdk:superwall-android:2.1.0"
9598
implementation 'com.android.billingclient:billing:6.1.0'
99+
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.2'
96100
}

android/src/main/java/com/superwallreactnative/bridges/SuperwallDelegateBridge.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.superwall.sdk.paywall.presentation.PaywallInfo
1010
import com.superwallreactnative.models.SuperwallEvent
1111
import com.superwallreactnative.models.convertMapToReadableMap
1212
import com.superwallreactnative.models.toJson
13+
import com.superwall.sdk.models.internal.RedemptionResult
1314
import java.net.URI
1415
import android.net.Uri
1516

@@ -129,4 +130,25 @@ class SuperwallDelegateBridge(
129130
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
130131
.emit("handleLog", data)
131132
}
133+
134+
override fun willRedeemLink(){
135+
try {
136+
reactContext
137+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
138+
.emit("willRedeemLink", null)
139+
} catch (e: Exception) {
140+
e.printStackTrace()
141+
}
142+
}
143+
144+
override fun didRedeemLink(result: RedemptionResult){
145+
val resultJson = result.toJson()
146+
try {
147+
reactContext
148+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
149+
.emit("didRedeemLink", resultJson)
150+
} catch (e: Exception) {
151+
e.printStackTrace()
152+
}
153+
}
132154
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package com.superwallreactnative.models
2+
3+
import com.facebook.react.bridge.Arguments
4+
import com.facebook.react.bridge.ReadableMap
5+
import com.superwall.sdk.models.internal.RedemptionResult
6+
import com.superwall.sdk.models.internal.RedemptionInfo
7+
import com.superwall.sdk.models.internal.PurchaserInfo
8+
import com.superwall.sdk.models.internal.StoreIdentifiers
9+
import com.superwall.sdk.models.internal.ErrorInfo
10+
import com.superwall.sdk.models.internal.ExpiredInfo
11+
import com.superwall.sdk.models.internal.RedemptionOwnership
12+
import com.superwall.sdk.models.entitlements.Entitlement
13+
14+
fun RedemptionResult.toJson(): ReadableMap {
15+
val map = Arguments.createMap()
16+
map.putString("code", this.code)
17+
18+
when (this) {
19+
is RedemptionResult.Success -> {
20+
map.putString("status", "SUCCESS")
21+
map.putMap("redemptionInfo", this.redemptionInfo.toJson())
22+
}
23+
is RedemptionResult.Error -> {
24+
map.putString("status", "ERROR")
25+
map.putMap("error", this.error.toJson())
26+
}
27+
is RedemptionResult.Expired -> {
28+
map.putString("status", "CODE_EXPIRED")
29+
map.putMap("expired", this.expired.toJson())
30+
}
31+
is RedemptionResult.InvalidCode -> {
32+
map.putString("status", "INVALID_CODE")
33+
}
34+
is RedemptionResult.ExpiredSubscription -> {
35+
map.putString("status", "EXPIRED_SUBSCRIPTION")
36+
map.putMap("redemptionInfo", this.redemptionInfo.toJson())
37+
}
38+
}
39+
40+
return map
41+
}
42+
43+
private fun RedemptionInfo.toJson(): ReadableMap {
44+
val map = Arguments.createMap()
45+
map.putMap("ownership", this.ownership.toJson())
46+
map.putMap("purchaserInfo", this.purchaserInfo.toJson())
47+
this.paywallInfo?.let { map.putMap("paywallInfo", it.toJson()) }
48+
49+
val entitlementsArray = Arguments.createArray()
50+
this.entitlements.forEach { entitlement ->
51+
val entitlementMap = Arguments.createMap()
52+
entitlementMap.putString("id", entitlement.id)
53+
entitlementsArray.pushMap(entitlementMap)
54+
}
55+
map.putArray("entitlements", entitlementsArray)
56+
57+
return map
58+
}
59+
60+
private fun PurchaserInfo.toJson(): ReadableMap {
61+
val map = Arguments.createMap()
62+
map.putString("appUserId", this.appUserId)
63+
this.email?.let { map.putString("email", it) }
64+
map.putMap("storeIdentifiers", this.storeIdentifiers.toJson())
65+
return map
66+
}
67+
68+
private fun StoreIdentifiers.toJson(): ReadableMap {
69+
val map = Arguments.createMap()
70+
when (this) {
71+
is StoreIdentifiers.Stripe -> {
72+
map.putString("store", "STRIPE")
73+
map.putString("stripeCustomerId", this.stripeCustomerId)
74+
val subscriptionIdsArray = Arguments.createArray()
75+
this.subscriptionIds.forEach { id ->
76+
subscriptionIdsArray.pushString(id)
77+
}
78+
map.putArray("stripeSubscriptionIds", subscriptionIdsArray)
79+
}
80+
is StoreIdentifiers.Unknown -> {
81+
map.putString("store", "UNKNOWN")
82+
}
83+
}
84+
return map
85+
}
86+
87+
private fun ErrorInfo.toJson(): ReadableMap {
88+
val map = Arguments.createMap()
89+
map.putString("message", this.message)
90+
return map
91+
}
92+
93+
private fun ExpiredInfo.toJson(): ReadableMap {
94+
val map = Arguments.createMap()
95+
map.putBoolean("resent", this.resent)
96+
this.obfuscatedEmail?.let { map.putString("obfuscatedEmail", it) }
97+
return map
98+
}
99+
100+
private fun RedemptionOwnership.toJson(): ReadableMap {
101+
val map = Arguments.createMap()
102+
when (this) {
103+
is RedemptionOwnership.Device -> {
104+
map.putString("type", "DEVICE")
105+
map.putString("deviceId", this.deviceId)
106+
}
107+
is RedemptionOwnership.AppUser -> {
108+
map.putString("type", "APP_USER")
109+
map.putString("appUserId", this.appUserId)
110+
}
111+
}
112+
return map
113+
}
114+
115+
private fun RedemptionResult.PaywallInfo.toJson(): ReadableMap {
116+
val map = Arguments.createMap()
117+
map.putString("identifier", this.identifier)
118+
map.putString("placementName", this.placementName)
119+
120+
val placementParamsMap = Arguments.createMap()
121+
this.placementParams.forEach { (key, value) ->
122+
placementParamsMap.putString(key, value.toString())
123+
}
124+
map.putMap("placementParams", placementParamsMap)
125+
126+
map.putString("variantId", this.variantId)
127+
map.putString("experimentId", this.experimentId)
128+
return map
129+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@superwall/react-native-superwall",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "The React Native package for Superwall",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

0 commit comments

Comments
 (0)