react-native-nami-sdk 2.0.4 → 3.0.8

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.
Files changed (59) hide show
  1. package/.github/workflows/app_stg.yaml +203 -0
  2. package/.github/workflows/build.yml +2 -2
  3. package/.pre-commit-config.yaml +25 -0
  4. package/android/build.gradle +24 -13
  5. package/android/gradle/wrapper/gradle-wrapper.properties +5 -1
  6. package/android/src/main/java/com/nami/reactlibrary/Constants.kt +1 -1
  7. package/android/src/main/java/com/nami/reactlibrary/NamiBridgeModule.kt +6 -50
  8. package/android/src/main/java/com/nami/reactlibrary/NamiBridgePackage.java +1 -3
  9. package/android/src/main/java/com/nami/reactlibrary/NamiCampaignManagerBridge.kt +133 -0
  10. package/android/src/main/java/com/nami/reactlibrary/NamiCustomerManagerBridge.kt +89 -20
  11. package/android/src/main/java/com/nami/reactlibrary/NamiEmitter.kt +25 -25
  12. package/android/src/main/java/com/nami/reactlibrary/NamiEntitlementManagerBridgeModule.kt +31 -130
  13. package/android/src/main/java/com/nami/reactlibrary/NamiMLManagerBridgeModule.kt +1 -1
  14. package/android/src/main/java/com/nami/reactlibrary/NamiPaywallManagerBridgeModule.kt +36 -147
  15. package/android/src/main/java/com/nami/reactlibrary/NamiPurchaseManagerBridge.kt +37 -39
  16. package/android/src/main/java/com/nami/reactlibrary/NamiUtil.kt +50 -180
  17. package/build-utils/get_version_code.py +140 -0
  18. package/index.d.ts +20 -0
  19. package/index.js +7 -6
  20. package/ios/Nami.m +18 -72
  21. package/ios/NamiBridgeUtil.h +4 -6
  22. package/ios/NamiBridgeUtil.m +37 -99
  23. package/ios/NamiCampaignManagerBridge.m +26 -0
  24. package/ios/NamiCampaignManagerBridge.swift +107 -0
  25. package/ios/NamiCustomerManager.m +19 -24
  26. package/ios/NamiCustomerManager.swift +122 -0
  27. package/ios/NamiEmitter.m +85 -95
  28. package/ios/NamiEntitlementManagerBridge.m +7 -107
  29. package/ios/NamiEntitlementManagerBridge.swift +74 -0
  30. package/ios/NamiMLManagerBridge.m +2 -2
  31. package/ios/NamiPaywallManagerBridge.m +22 -94
  32. package/ios/NamiPaywallManagerBridge.swift +93 -0
  33. package/ios/NamiPurchaseManagerBridge.m +40 -71
  34. package/ios/NamiPurchaseManagerBridge.swift +174 -0
  35. package/ios/Podfile +2 -2
  36. package/ios/RNNami-Bridging-Header.h +5 -0
  37. package/ios/RNNami.h +0 -1
  38. package/ios/RNNami.m +1 -1
  39. package/ios/RNNami.xcodeproj/project.pbxproj +84 -8
  40. package/ios/RNNami.xcodeproj/xcshareddata/xcschemes/RNNami.xcscheme +67 -0
  41. package/package.json +1 -1
  42. package/react-native-nami-sdk.podspec +3 -3
  43. package/src/Nami.d.ts +112 -0
  44. package/src/Nami.js +10 -0
  45. package/src/NamiCampaignManager.d.ts +54 -0
  46. package/src/NamiCampaignManager.js +43 -0
  47. package/src/NamiCustomerManager.d.ts +39 -0
  48. package/src/NamiCustomerManager.js +43 -0
  49. package/src/NamiEntitlementManager.d.ts +24 -0
  50. package/src/NamiEntitlementManager.js +23 -0
  51. package/src/NamiMLManager.d.ts +5 -0
  52. package/src/NamiMLManager.js +7 -0
  53. package/src/NamiPaywallManager.d.ts +57 -0
  54. package/src/NamiPaywallManager.js +28 -0
  55. package/src/NamiPurchaseManager.d.ts +57 -0
  56. package/src/NamiPurchaseManager.js +37 -0
  57. package/src/types.ts +36 -0
  58. package/android/src/main/java/com/nami/reactlibrary/NamiAnalyticsEmitter.kt +0 -121
  59. package/ios/NamiAnalyticsEmitter.m +0 -146
@@ -1,42 +1,111 @@
1
1
  package com.nami.reactlibrary
2
2
 
3
3
  import android.util.Log
4
- import com.facebook.react.bridge.Callback
5
- import com.facebook.react.bridge.ReactApplicationContext
6
- import com.facebook.react.bridge.ReactContextBaseJavaModule
7
- import com.facebook.react.bridge.ReactMethod
4
+ import com.facebook.react.bridge.*
8
5
  import com.facebook.react.modules.core.DeviceEventManagerModule
6
+ import com.namiml.campaign.NamiCampaignManager
9
7
  import com.namiml.customer.CustomerJourneyState
10
8
  import com.namiml.customer.NamiCustomerManager
11
9
 
10
+
12
11
  class NamiCustomerManagerBridgeModule(reactContext: ReactApplicationContext) :
13
12
  ReactContextBaseJavaModule(reactContext) {
14
13
 
15
14
  override fun getName(): String {
16
- return "NamiCustomerManagerBridge"
15
+ return "RNNamiCustomerManager"
17
16
  }
18
17
 
19
- init {
20
- NamiCustomerManager.registerCustomerJourneyChangedListener { customerJourneyState ->
21
- emitCustomerJourneyChanged(customerJourneyState)
22
- }
18
+ private fun journeyStateToReadableMap(journeyState: CustomerJourneyState): ReadableMap {
19
+ val readableMap = Arguments.createMap()
20
+ readableMap.putBoolean("formerSubscriber", journeyState.formerSubscriber)
21
+ readableMap.putBoolean("inGracePeriodl", journeyState.inGracePeriod)
22
+ readableMap.putBoolean("inTrialPeriod", journeyState.inTrialPeriod)
23
+ readableMap.putBoolean("inIntroOfferPeriod", journeyState.inIntroOfferPeriod)
24
+ readableMap.putBoolean("isCancelled", journeyState.isCancelled)
25
+ readableMap.putBoolean("inPause", journeyState.inPause)
26
+ readableMap.putBoolean("inAccountHold", journeyState.inAccountHold)
27
+ return readableMap
28
+ }
29
+ @ReactMethod
30
+ fun setCustomerAttribute(key: String, value: String){
31
+ NamiCustomerManager.setCustomerAttribute(key, value)
32
+ }
33
+
34
+ @ReactMethod
35
+ fun getCustomerAttribute(key: String, promise: Promise){
36
+ val customerAttribute = NamiCustomerManager.getCustomerAttribute(key)
37
+ promise.resolve(customerAttribute)
38
+ }
39
+
40
+ @ReactMethod
41
+ fun clearCustomerAttribute(key: String){
42
+ NamiCustomerManager.clearCustomerAttribute(key)
43
+ }
44
+
45
+ @ReactMethod
46
+ fun clearAllCustomerAttributes(){
47
+ NamiCustomerManager.clearAllCustomerAttributes()
48
+ }
49
+
50
+ @ReactMethod
51
+ fun journeyState(promise: Promise){
52
+ val journeyState = NamiCustomerManager.journeyState()
53
+ if (journeyState != null) {
54
+ val handledJourneyState = journeyStateToReadableMap(journeyState)
55
+ promise.resolve(handledJourneyState)
56
+ } else {
57
+ promise.resolve(null)
58
+ }
59
+ }
60
+
61
+ @ReactMethod
62
+ fun isLoggedIn(promise: Promise){
63
+ val isLoggedIn = NamiCustomerManager.isLoggedIn()
64
+ promise.resolve(isLoggedIn)
65
+ }
66
+
67
+ @ReactMethod
68
+ fun loggedInId(promise: Promise){
69
+ val id = NamiCustomerManager.loggedInId()
70
+ promise.resolve(id)
71
+ }
72
+
73
+ @ReactMethod
74
+ fun deviceId(promise: Promise){
75
+ val id = NamiCustomerManager.deviceId()
76
+ promise.resolve(id)
23
77
  }
24
78
 
25
- private fun emitCustomerJourneyChanged(customerJourneyState: CustomerJourneyState) {
26
- Log.i(LOG_TAG, "Emitting CustomerJourneyState changed")
27
- try {
79
+ @ReactMethod
80
+ fun login(customerId: String){
81
+ NamiCustomerManager.login(customerId)
82
+ }
83
+
84
+ @ReactMethod
85
+ fun logout() {
86
+ NamiCustomerManager.logout()
87
+ }
88
+
89
+ @ReactMethod
90
+ fun registerJourneyStateHandler() {
91
+ NamiCustomerManager.registerJourneyStateHandler { journeyState ->
92
+ val handledJourneyState = journeyStateToReadableMap(journeyState)
28
93
  reactApplicationContext
29
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
30
- .emit("CustomerJourneyStateChanged", customerJourneyState.toDict())
31
- } catch (e: Exception) {
32
- Log.e(LOG_TAG, "Caught Exception: " + e.message)
94
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
95
+ .emit("JourneyStateChanged", handledJourneyState)
33
96
  }
34
97
  }
35
98
 
36
99
  @ReactMethod
37
- fun currentCustomerJourneyState(resultsCallback: Callback) {
38
- reactApplicationContext.runOnUiQueueThread {
39
- resultsCallback.invoke(NamiCustomerManager.currentCustomerJourneyState().toDict())
100
+ fun registerAccountStateHandler() {
101
+ NamiCustomerManager.registerAccountStateHandler { action, success, error ->
102
+ val body = Arguments.createMap()
103
+ body.putString("action", action.toString())
104
+ body.putBoolean("success", success)
105
+ body.putString("error", error.toString())
106
+ reactApplicationContext
107
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
108
+ .emit("AccountStateChanged", body)
40
109
  }
41
110
  }
42
- }
111
+ }
@@ -33,31 +33,31 @@ class NamiEmitter(reactContext: ReactApplicationContext) :
33
33
  }
34
34
 
35
35
  override fun initialize() {
36
- NamiPaywallManager.registerSignInListener { _, _, developerPaywallID ->
37
- Log.i(LOG_TAG, "Sign in clicked with developerPaywallID $developerPaywallID")
38
-
39
- emitSignInActivated(developerPaywallID)
40
- }
36
+ // NamiPaywallManager.registerSignInListener { _, _, developerPaywallID ->
37
+ // Log.i(LOG_TAG, "Sign in clicked with developerPaywallID $developerPaywallID")
38
+ //
39
+ // emitSignInActivated(developerPaywallID)
40
+ // }
41
41
 
42
42
  Log.i(LOG_TAG, "In Emitter Initialize()")
43
43
 
44
- NamiPaywallManager.registerPaywallRaiseListener { _, paywallData, products, developerPaywallId ->
45
- Log.i(
46
- LOG_TAG,
47
- "Products from registerPaywallRaiseListener callback are $products"
48
- )
49
-
50
- val sendProducts: List<NamiSKU> = products ?: ArrayList<NamiSKU>()
51
- emitPaywallRaise(paywallData, sendProducts, developerPaywallId)
52
- }
53
-
54
- NamiPurchaseManager.registerPurchasesChangedListener { list, namiPurchaseState, s ->
55
- emitPurchaseMade(list, namiPurchaseState, s)
56
- }
57
-
58
- NamiCustomerManager.registerCustomerJourneyChangedListener {
59
- emitCustomerJourneyChanged(it)
60
- }
44
+ // NamiPaywallManager.registerPaywallRaiseListener { _, paywallData, products, developerPaywallId ->
45
+ // Log.i(
46
+ // LOG_TAG,
47
+ // "Products from registerPaywallRaiseListener callback are $products"
48
+ // )
49
+ //
50
+ // val sendProducts: List<NamiSKU> = products ?: ArrayList<NamiSKU>()
51
+ // emitPaywallRaise(paywallData, sendProducts, developerPaywallId)
52
+ // }
53
+
54
+ // NamiPurchaseManager.registerPurchasesChangedListener { list, namiPurchaseState, s ->
55
+ // emitPurchaseMade(list, namiPurchaseState, s)
56
+ // }
57
+ //
58
+ // NamiCustomerManager.registerCustomerJourneyChangedListener {
59
+ // emitCustomerJourneyChanged(it)
60
+ // }
61
61
  }
62
62
 
63
63
  private fun emitCustomerJourneyChanged(customerJourneyState: CustomerJourneyState) {
@@ -126,8 +126,8 @@ class NamiEmitter(reactContext: ReactApplicationContext) :
126
126
  }
127
127
 
128
128
  // Populate paywall metadata map
129
- val paywallMap: WritableMap = namiPaywall.toNamiPaywallDict()
130
- map.putMap("paywallMetadata", paywallMap)
129
+ // val paywallMap: WritableMap = namiPaywall.toNamiPaywallDict()
130
+ // map.putMap("paywallMetadata", paywallMap)
131
131
 
132
132
  // Populate SKU details
133
133
  val skusArray: WritableArray = Arguments.createArray()
@@ -160,4 +160,4 @@ class NamiEmitter(reactContext: ReactApplicationContext) :
160
160
  Log.e(LOG_TAG, "Caught Exception: " + e.message)
161
161
  }
162
162
  }
163
- }
163
+ }
@@ -1,167 +1,68 @@
1
1
  package com.nami.reactlibrary
2
2
 
3
3
  import android.util.Log
4
- import com.facebook.react.bridge.Callback
5
- import com.facebook.react.bridge.ReactApplicationContext
6
- import com.facebook.react.bridge.ReactContextBaseJavaModule
7
- import com.facebook.react.bridge.ReactMethod
8
- import com.facebook.react.bridge.ReadableArray
9
- import com.facebook.react.bridge.ReadableMap
10
- import com.facebook.react.bridge.WritableArray
11
- import com.facebook.react.bridge.WritableMap
12
- import com.facebook.react.bridge.WritableNativeArray
13
- import com.facebook.react.bridge.WritableNativeMap
4
+ import com.facebook.react.bridge.*
14
5
  import com.facebook.react.modules.core.DeviceEventManagerModule
15
6
  import com.namiml.entitlement.NamiEntitlement
16
7
  import com.namiml.entitlement.NamiEntitlementManager
17
- import com.namiml.entitlement.NamiEntitlementSetter
8
+ //import com.namiml.entitlement.NamiEntitlementSetter
18
9
  import com.namiml.entitlement.NamiPlatformType
19
10
  import java.util.ArrayList
20
11
  import java.util.Date
12
+ import com.facebook.react.bridge.Callback
21
13
 
22
14
  class NamiEntitlementManagerBridgeModule(reactContext: ReactApplicationContext) :
23
15
  ReactContextBaseJavaModule(reactContext) {
24
16
 
25
- init {
26
- NamiEntitlementManager.registerEntitlementChangeListener {
27
- emitEntitlementsChanged(it)
28
- }
17
+ override fun getName(): String {
18
+ return "RNNamiEntitlementManager"
29
19
  }
30
20
 
31
- private fun emitEntitlementsChanged(activeEntitlements: List<NamiEntitlement>) {
32
- val map: WritableMap = WritableNativeMap()
21
+ @ReactMethod
22
+ fun isEntitlementActive(referenceId: String, promise: Promise){
23
+ val isEntitlementActive = NamiEntitlementManager.isEntitlementActive(referenceId)
24
+ promise.resolve(isEntitlementActive)
25
+ }
33
26
 
27
+ @ReactMethod
28
+ fun active(promise: Promise){
29
+ val nativeEntitlements = NamiEntitlementManager.active()
34
30
  val resultArray: WritableArray = WritableNativeArray()
35
- for (entitlement in activeEntitlements) {
31
+ for (entitlement in nativeEntitlements) {
36
32
  entitlement.toEntitlementDict()?.let { entitlementDict ->
37
33
  resultArray.pushMap(entitlementDict)
38
- }
39
- }
40
-
41
- map.putArray("activeEntitlements", resultArray)
42
- try {
43
- reactApplicationContext
44
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
45
- .emit("EntitlementsChanged", map)
46
- } catch (e: Exception) {
47
- Log.e(LOG_TAG, "Caught Exception: " + e.message)
34
+ }
48
35
  }
49
- }
50
-
51
- override fun getName(): String {
52
- return "NamiEntitlementManagerBridge"
36
+ promise.resolve(resultArray)
53
37
  }
54
38
 
55
39
  @ReactMethod
56
- fun isEntitlementActive(entitlementRefID: String, resultsCallback: Callback) {
57
- reactApplicationContext.runOnUiQueueThread {
58
- val isActive = NamiEntitlementManager.isEntitlementActive(entitlementRefID)
59
-
60
- Log.i(
61
- LOG_TAG,
62
- "Checking for $entitlementRefID entitlement active, result was $isActive"
63
- )
64
- resultsCallback.invoke(isActive)
65
- }
66
- }
67
-
68
- @ReactMethod
69
- fun activeEntitlements(resultsCallback: Callback) {
70
-
71
- reactApplicationContext.runOnUiQueueThread {
72
- val nativeEntitlements = NamiEntitlementManager.activeEntitlements()
73
-
40
+ fun refresh(callback: Callback){
41
+ NamiEntitlementManager.refresh { activeNativeEntitlements ->
74
42
  val resultArray: WritableArray = WritableNativeArray()
75
- for (entitlement in nativeEntitlements) {
76
- entitlement.toEntitlementDict()?.let { entitlementDict ->
77
- resultArray.pushMap(entitlementDict)
43
+ if (activeNativeEntitlements != null) {
44
+ for (entitlement in activeNativeEntitlements) {
45
+ entitlement.toEntitlementDict()?.let { entitlementDict ->
46
+ resultArray.pushMap(entitlementDict)
47
+ }
78
48
  }
79
49
  }
80
- resultsCallback.invoke(resultArray)
50
+ callback.invoke(resultArray)
81
51
  }
82
52
  }
83
53
 
84
54
  @ReactMethod
85
- fun getEntitlements(resultsCallback: Callback) {
86
-
87
- reactApplicationContext.runOnUiQueueThread {
88
- val nativeEntitlements = NamiEntitlementManager.getEntitlements()
89
-
90
- Log.i(LOG_TAG, "getEntitlements result is $nativeEntitlements")
91
-
55
+ fun registerActiveEntitlementsHandler() {
56
+ NamiEntitlementManager.registerActiveEntitlementsHandler { activeNativeEntitlements ->
92
57
  val resultArray: WritableArray = WritableNativeArray()
93
- for (entitlement in nativeEntitlements) {
58
+ for (entitlement in activeNativeEntitlements) {
94
59
  entitlement.toEntitlementDict()?.let { entitlementDict ->
95
60
  resultArray.pushMap(entitlementDict)
96
61
  }
97
62
  }
98
- resultsCallback.invoke(resultArray)
99
- }
100
- }
101
-
102
- @ReactMethod
103
- fun setEntitlements(entitlements: ReadableArray) {
104
- val entitlementsToSet = ArrayList<NamiEntitlementSetter>()
105
-
106
- val size = entitlements.size()
107
- var index = 0
108
- while (index < size) {
109
- val setterMap: ReadableMap? = entitlements.getMap(index)
110
- setterMap?.let {
111
- val entitlementSetter = entitlementSetterFromSetterMap(setterMap)
112
- entitlementSetter?.let {
113
- entitlementsToSet.add(entitlementSetter)
114
- }
115
- }
116
- index += 1
117
- }
118
-
119
- reactApplicationContext.runOnUiQueueThread {
120
- NamiEntitlementManager.setEntitlements(entitlementsToSet)
121
- }
122
- }
123
-
124
- @ReactMethod
125
- fun clearAllEntitlements() {
126
- reactApplicationContext.runOnUiQueueThread {
127
- NamiEntitlementManager.clearAllEntitlements()
128
- }
129
- }
130
-
131
- private fun entitlementSetterFromSetterMap(entitlementSetterMap: ReadableMap): NamiEntitlementSetter? {
132
- if (entitlementSetterMap.hasKey("referenceID")) {
133
- val referenceID = entitlementSetterMap.getString("referenceID").orEmpty()
134
- if (referenceID.isNotEmpty()) {
135
- val expires: Date? = null
136
-
137
- var purchasedSKUid: String? = null
138
- if (entitlementSetterMap.hasKey("purchasedSKUID")) {
139
- purchasedSKUid = entitlementSetterMap.getString("purchasedSKUid")
140
- }
141
-
142
- var platform: NamiPlatformType = NamiPlatformType.OTHER
143
- if (entitlementSetterMap.hasKey("platform")) {
144
- platform = when (entitlementSetterMap.getString("platform")) {
145
- "other" -> NamiPlatformType.OTHER
146
-
147
- "android" -> NamiPlatformType.ANDROID
148
-
149
- "apple" -> NamiPlatformType.APPLE
150
-
151
- "roku" -> NamiPlatformType.ROKU
152
-
153
- "web" -> NamiPlatformType.WEB
154
-
155
- else -> NamiPlatformType.OTHER
156
- }
157
- }
158
-
159
- //referenceId: kotlin.String, purchasedSKUid: kotlin.String?, expires: java.util.Date?, platform: com.namiml.entitlement.NamiPlatformType
160
- return NamiEntitlementSetter(referenceID, platform, purchasedSKUid, expires)
161
- }
63
+ reactApplicationContext
64
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
65
+ .emit("EntitlementsChanged", resultArray)
162
66
  }
163
- Log.e(LOG_TAG, "Attempted to set entitlement with no referenceID $entitlementSetterMap")
164
-
165
- return null
166
67
  }
167
- }
68
+ }
@@ -47,4 +47,4 @@ class NamiMLManagerBridgeModule(reactContext: ReactApplicationContext) :
47
47
  NamiMLManager.coreAction(label)
48
48
  }
49
49
  }
50
- }
50
+ }
@@ -3,13 +3,8 @@ package com.nami.reactlibrary
3
3
  import android.app.Activity
4
4
  import android.content.Intent
5
5
  import android.util.Log
6
- import com.facebook.react.bridge.ActivityEventListener
7
- import com.facebook.react.bridge.Arguments
8
- import com.facebook.react.bridge.Callback
9
- import com.facebook.react.bridge.ReactApplicationContext
10
- import com.facebook.react.bridge.ReactContextBaseJavaModule
11
- import com.facebook.react.bridge.ReactMethod
12
- import com.facebook.react.bridge.WritableNativeMap
6
+ import com.android.billingclient.api.Purchase
7
+ import com.facebook.react.bridge.*
13
8
  import com.facebook.react.modules.core.DeviceEventManagerModule
14
9
  import com.namiml.paywall.NamiPaywallManager
15
10
  import com.namiml.paywall.PreparePaywallResult
@@ -19,18 +14,41 @@ class NamiPaywallManagerBridgeModule(reactContext: ReactApplicationContext) :
19
14
 
20
15
  private var blockRaisePaywall: Boolean = false
21
16
 
22
- init {
23
- NamiPaywallManager.registerApplicationAutoRaisePaywallBlocker {
24
- Log.i(LOG_TAG, "Nami flag for blocking paywall raise is $blockRaisePaywall")
25
- blockRaisePaywall
17
+ override fun getName(): String {
18
+ return "RNNamiPaywallManager"
19
+ }
20
+
21
+ @ReactMethod
22
+ fun buySkuComplete(purchase: WritableMap, skuRefId: String) {
23
+ // NamiPaywallManager.buySkuComplete(currentActivity!!, purchase, skuRefId)
24
+ }
25
+
26
+
27
+ @ReactMethod
28
+ fun registerCloseHandler(blockDismiss: Boolean) {
29
+ NamiPaywallManager.registerCloseHandler { activity ->
30
+ val resultMap = Arguments.createMap()
31
+ resultMap.putBoolean("blockingPaywallClosed", true)
32
+ reactApplicationContext
33
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
34
+ .emit("BlockingPaywallClosed", resultMap)
35
+ if (!blockDismiss) {
36
+ activity.finish()
37
+ }
26
38
  }
27
- reactContext.addActivityEventListener(this)
28
39
  }
29
40
 
30
- override fun getName(): String {
31
- return "NamiPaywallManagerBridge"
41
+ @ReactMethod
42
+ fun registerBuySkuHandler() {
43
+ NamiPaywallManager.registerBuySkuHandler { activity, sku ->
44
+ val dictionary = sku.toSkuDict()
45
+ reactApplicationContext
46
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
47
+ .emit("RegisterBuySKU", dictionary)
48
+ }
32
49
  }
33
50
 
51
+
34
52
  override fun onActivityResult(
35
53
  activity: Activity?,
36
54
  requestCode: Int,
@@ -64,138 +82,9 @@ class NamiPaywallManagerBridgeModule(reactContext: ReactApplicationContext) :
64
82
  // do nothing
65
83
  }
66
84
 
67
- @ReactMethod
68
- fun raisePaywall() {
69
- reactApplicationContext.runOnUiQueueThread {
70
- raisePaywall(currentActivity, null)
71
- }
72
- }
73
-
74
- @ReactMethod
75
- fun raisePaywallByDeveloperPaywallId(developerPaywallID: String) {
76
- reactApplicationContext.runOnUiQueueThread {
77
- raisePaywall(currentActivity, developerPaywallID)
78
- }
79
- }
80
-
81
- private fun raisePaywall(activity: Activity?, developerPaywallID: String?) {
82
- if (NamiPaywallManager.canRaisePaywall()) {
83
- Log.d(LOG_TAG, "About to raise Paywall ")
84
- if (activity != null) {
85
- Log.i(LOG_TAG, "Nami Activity to raise paywall is $activity")
86
- if (developerPaywallID == null) {
87
- Log.i(LOG_TAG, "Raising Paywall: ")
88
- NamiPaywallManager.raisePaywall(activity)
89
- } else {
90
- Log.i(LOG_TAG, "Raising Paywall by Id: $developerPaywallID")
91
- NamiPaywallManager.raisePaywall(developerPaywallID, activity)
92
- }
93
- } else {
94
- Log.w(LOG_TAG, "Activity from react getCurrentActivity was null.")
95
- }
96
- } else {
97
- Log.w(LOG_TAG, "Paywall not raised, SDK says paywall cannot be raised at this time.")
98
- }
99
- }
100
-
101
- @ReactMethod
102
- fun canRaisePaywall(successCallback: Callback) {
103
- reactApplicationContext.runOnUiQueueThread {
104
- val canRaiseResult = NamiPaywallManager.canRaisePaywall()
105
- successCallback.invoke(canRaiseResult)
106
- }
107
- }
108
-
109
- @ReactMethod
110
- fun blockRaisePaywall(blockRaise: Boolean) {
111
- blockRaisePaywall = blockRaise
112
- }
113
-
114
- @ReactMethod
115
- fun fetchCustomMetadataForDeveloperID(paywallDeveloperID: String, successCallback: Callback) {
116
- val sendDict = WritableNativeMap()
117
- //TODO: Android SDK needs fetchCustomMetadataForDeveloperID
118
- successCallback(sendDict)
119
- }
120
-
121
- @ReactMethod
122
- fun paywallImpression(developerPaywallID: String) {
123
- // TODO: Android SDK paywall impression call.
124
- }
125
-
126
- @ReactMethod
127
- fun preparePaywallForDisplay(backgroundImageRequired: Boolean, imageFetchTimeout: Double) {
128
- val imageFetchTimeoutConvertedToLong: Long = imageFetchTimeout.toLong()
129
- reactApplicationContext.runOnUiQueueThread {
130
-
131
- NamiPaywallManager.preparePaywallForDisplay(
132
- backgroundImageRequired,
133
- imageFetchTimeoutConvertedToLong
134
- ) { result ->
135
- when (result) {
136
- is PreparePaywallResult.Success -> {
137
- emitPreparePaywallFinished(true, null, null)
138
- }
139
- is PreparePaywallResult.Failure -> {
140
- emitPreparePaywallFinished(false, null, result.error)
141
- }
142
- }
143
- }
144
- }
145
- }
146
-
147
- @ReactMethod
148
- fun preparePaywallForDisplayByDeveloperPaywallId(
149
- developerPaywallID: String,
150
- backgroundImageRequired: Boolean,
151
- imageFetchTimeout: Double
152
- ) {
153
- val imageFetchTimeoutConvertedToLong: Long = imageFetchTimeout.toLong()
154
- reactApplicationContext.runOnUiQueueThread {
155
- NamiPaywallManager.preparePaywallForDisplay(
156
- developerPaywallID,
157
- backgroundImageRequired,
158
- imageFetchTimeoutConvertedToLong
159
- ) { result ->
160
- when (result) {
161
- is PreparePaywallResult.Success -> {
162
- emitPreparePaywallFinished(true, developerPaywallID, null)
163
- }
164
- is PreparePaywallResult.Failure -> {
165
- emitPreparePaywallFinished(false, developerPaywallID, result.error)
166
- }
167
- }
168
- }
169
- }
170
- }
171
-
172
- private fun emitPreparePaywallFinished(
173
- success: Boolean,
174
- developerPaywallID: String?,
175
- error: com.namiml.paywall.PreparePaywallError?
176
- ) {
177
- val prepareContentMap = Arguments.createMap()
178
- prepareContentMap.putBoolean("success", success)
179
-
180
- if (developerPaywallID != null) {
181
- prepareContentMap.putString("developerPaywallID", developerPaywallID)
182
- }
183
-
184
- if (error != null) {
185
- prepareContentMap.putInt("errorCode", error.ordinal)
186
- prepareContentMap.putString("errorMessage", error.toString())
187
- }
85
+ // @ReactMethod
86
+ // fun blockRaisePaywall(blockRaise: Boolean) {
87
+ // blockRaisePaywall = blockRaise
88
+ // }
188
89
 
189
- Log.i(
190
- LOG_TAG,
191
- "Emitting preparePaywallForDisplay finished with result " + success + "error: " + error.toString()
192
- )
193
- try {
194
- reactApplicationContext
195
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
196
- .emit("PreparePaywallFinished", prepareContentMap)
197
- } catch (e: Exception) {
198
- Log.e(LOG_TAG, "Caught Exception: " + e.message)
199
- }
200
- }
201
90
  }