Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

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


## 2.1.1

### Enhancements

- Upgrades Android SDK to 2.1.0 [View Android SDK release notes](https://github.com/superwall/Superwall-Android/releases/tag/2.1.0).

## 2.1.0

### Fixes
Expand Down
6 changes: 5 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ buildscript {
classpath "com.android.tools.build:gradle:7.2.1"
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:1.6.0"

}
}

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

apply plugin: "com.android.library"
apply plugin: "kotlin-android"
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'

if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
Expand Down Expand Up @@ -91,6 +94,7 @@ dependencies {
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

implementation "com.superwall.sdk:superwall-android:2.0.6"
implementation "com.superwall.sdk:superwall-android:2.1.0"
implementation 'com.android.billingclient:billing:6.1.0'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.2'
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.superwall.sdk.paywall.presentation.PaywallInfo
import com.superwallreactnative.models.SuperwallEvent
import com.superwallreactnative.models.convertMapToReadableMap
import com.superwallreactnative.models.toJson
import com.superwall.sdk.models.internal.RedemptionResult
import java.net.URI
import android.net.Uri

Expand Down Expand Up @@ -129,4 +130,25 @@ class SuperwallDelegateBridge(
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
.emit("handleLog", data)
}

override fun willRedeemLink(){
try {
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
.emit("willRedeemLink", null)
} catch (e: Exception) {
e.printStackTrace()
}
}

override fun didRedeemLink(result: RedemptionResult){
val resultJson = result.toJson()
try {
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
.emit("didRedeemLink", resultJson)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package com.superwallreactnative.models

import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReadableMap
import com.superwall.sdk.models.internal.RedemptionResult
import com.superwall.sdk.models.internal.RedemptionInfo
import com.superwall.sdk.models.internal.PurchaserInfo
import com.superwall.sdk.models.internal.StoreIdentifiers
import com.superwall.sdk.models.internal.ErrorInfo
import com.superwall.sdk.models.internal.ExpiredInfo
import com.superwall.sdk.models.internal.RedemptionOwnership
import com.superwall.sdk.models.entitlements.Entitlement

fun RedemptionResult.toJson(): ReadableMap {
val map = Arguments.createMap()
map.putString("code", this.code)

when (this) {
is RedemptionResult.Success -> {
map.putString("status", "SUCCESS")
map.putMap("redemptionInfo", this.redemptionInfo.toJson())
}
is RedemptionResult.Error -> {
map.putString("status", "ERROR")
map.putMap("error", this.error.toJson())
}
is RedemptionResult.Expired -> {
map.putString("status", "CODE_EXPIRED")
map.putMap("expired", this.expired.toJson())
}
is RedemptionResult.InvalidCode -> {
map.putString("status", "INVALID_CODE")
}
is RedemptionResult.ExpiredSubscription -> {
map.putString("status", "EXPIRED_SUBSCRIPTION")
map.putMap("redemptionInfo", this.redemptionInfo.toJson())
}
}

return map
}

private fun RedemptionInfo.toJson(): ReadableMap {
val map = Arguments.createMap()
map.putMap("ownership", this.ownership.toJson())
map.putMap("purchaserInfo", this.purchaserInfo.toJson())
this.paywallInfo?.let { map.putMap("paywallInfo", it.toJson()) }

val entitlementsArray = Arguments.createArray()
this.entitlements.forEach { entitlement ->
val entitlementMap = Arguments.createMap()
entitlementMap.putString("id", entitlement.id)
entitlementsArray.pushMap(entitlementMap)
}
map.putArray("entitlements", entitlementsArray)

return map
}

private fun PurchaserInfo.toJson(): ReadableMap {
val map = Arguments.createMap()
map.putString("appUserId", this.appUserId)
this.email?.let { map.putString("email", it) }
map.putMap("storeIdentifiers", this.storeIdentifiers.toJson())
return map
}

private fun StoreIdentifiers.toJson(): ReadableMap {
val map = Arguments.createMap()
when (this) {
is StoreIdentifiers.Stripe -> {
map.putString("store", "STRIPE")
map.putString("stripeCustomerId", this.stripeCustomerId)
val subscriptionIdsArray = Arguments.createArray()
this.subscriptionIds.forEach { id ->
subscriptionIdsArray.pushString(id)
}
map.putArray("stripeSubscriptionIds", subscriptionIdsArray)
}
is StoreIdentifiers.Unknown -> {
map.putString("store", "UNKNOWN")
}
}
return map
}

private fun ErrorInfo.toJson(): ReadableMap {
val map = Arguments.createMap()
map.putString("message", this.message)
return map
}

private fun ExpiredInfo.toJson(): ReadableMap {
val map = Arguments.createMap()
map.putBoolean("resent", this.resent)
this.obfuscatedEmail?.let { map.putString("obfuscatedEmail", it) }
return map
}

private fun RedemptionOwnership.toJson(): ReadableMap {
val map = Arguments.createMap()
when (this) {
is RedemptionOwnership.Device -> {
map.putString("type", "DEVICE")
map.putString("deviceId", this.deviceId)
}
is RedemptionOwnership.AppUser -> {
map.putString("type", "APP_USER")
map.putString("appUserId", this.appUserId)
}
}
return map
}

private fun RedemptionResult.PaywallInfo.toJson(): ReadableMap {
val map = Arguments.createMap()
map.putString("identifier", this.identifier)
map.putString("placementName", this.placementName)

val placementParamsMap = Arguments.createMap()
this.placementParams.forEach { (key, value) ->
placementParamsMap.putString(key, value.toString())
}
map.putMap("placementParams", placementParamsMap)

map.putString("variantId", this.variantId)
map.putString("experimentId", this.experimentId)
return map
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superwall/react-native-superwall",
"version": "2.1.0",
"version": "2.1.1",
"description": "The React Native package for Superwall",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
Loading
Loading