react-native-nami-sdk 3.0.9 → 3.0.11

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 (43) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.js +12 -0
  3. package/.github/workflows/CI.yaml +610 -0
  4. package/.github/workflows/app_prod.yaml +316 -0
  5. package/.github/workflows/app_stg.yaml +115 -2
  6. package/.pre-commit-config.yaml +0 -1
  7. package/android/build.gradle +4 -4
  8. package/android/src/main/java/com/nami/reactlibrary/NamiBridgeModule.kt +5 -18
  9. package/android/src/main/java/com/nami/reactlibrary/NamiBridgePackage.java +0 -1
  10. package/android/src/main/java/com/nami/reactlibrary/NamiCampaignManagerBridge.kt +45 -27
  11. package/android/src/main/java/com/nami/reactlibrary/NamiCustomerManagerBridge.kt +26 -20
  12. package/android/src/main/java/com/nami/reactlibrary/NamiEntitlementManagerBridgeModule.kt +15 -12
  13. package/android/src/main/java/com/nami/reactlibrary/NamiMLManagerBridgeModule.kt +8 -0
  14. package/android/src/main/java/com/nami/reactlibrary/NamiPaywallManagerBridgeModule.kt +142 -95
  15. package/android/src/main/java/com/nami/reactlibrary/NamiPurchaseManagerBridge.kt +12 -14
  16. package/android/src/main/java/com/nami/reactlibrary/NamiUtil.kt +3 -47
  17. package/ios/Nami.m +3 -25
  18. package/ios/NamiCampaignManagerBridge.swift +13 -7
  19. package/ios/NamiCustomerManager.swift +26 -7
  20. package/ios/NamiEntitlementManagerBridge.swift +9 -1
  21. package/ios/NamiMLManagerBridge.m +0 -2
  22. package/ios/NamiPaywallManagerBridge.m +2 -59
  23. package/ios/NamiPaywallManagerBridge.swift +67 -58
  24. package/ios/NamiPurchaseManagerBridge.m +2 -98
  25. package/ios/NamiPurchaseManagerBridge.swift +45 -5
  26. package/ios/RNNami-Bridging-Header.h +0 -1
  27. package/ios/RNNami.xcodeproj/project.pbxproj +1 -62
  28. package/ios/RNNami.xcworkspace/contents.xcworkspacedata +0 -3
  29. package/package.json +15 -4
  30. package/react-native-nami-sdk.podspec +4 -2
  31. package/src/Nami.d.ts +0 -1
  32. package/src/NamiCustomerManager.js +2 -2
  33. package/src/NamiMLManager.d.ts +3 -3
  34. package/src/NamiMLManager.js +1 -1
  35. package/src/NamiPaywallManager.d.ts +11 -30
  36. package/src/NamiPaywallManager.js +13 -8
  37. package/src/NamiPurchaseManager.d.ts +7 -3
  38. package/src/types.ts +10 -3
  39. package/android/src/main/java/com/nami/reactlibrary/NamiEmitter.kt +0 -163
  40. package/ios/NamiBridgeUtil.h +0 -32
  41. package/ios/NamiBridgeUtil.m +0 -231
  42. package/ios/NamiEmitter.m +0 -350
  43. package/ios/Podfile +0 -71
@@ -1,17 +1,16 @@
1
1
  package com.nami.reactlibrary
2
2
 
3
+ import android.app.Activity
3
4
  import android.content.Intent
4
5
  import android.util.Log
5
6
  import com.facebook.react.bridge.*
6
7
  import com.facebook.react.modules.core.DeviceEventManagerModule
8
+ import com.namiml.billing.NamiPurchase
9
+ import com.namiml.campaign.LaunchCampaignResult
7
10
  import com.namiml.campaign.NamiCampaign
8
11
  import com.namiml.campaign.NamiCampaignManager
9
12
  import com.namiml.paywall.NamiSKU
10
13
  import com.namiml.paywall.model.NamiPaywallAction
11
- import android.app.Activity
12
- import com.namiml.billing.NamiPurchase
13
- import com.namiml.billing.NamiPurchaseState
14
- import com.namiml.campaign.LaunchCampaignResult
15
14
 
16
15
  class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
17
16
  ReactContextBaseJavaModule(reactContext), ActivityEventListener {
@@ -31,24 +30,35 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
31
30
 
32
31
  @ReactMethod
33
32
  fun launch(label: String?, resultCallback: Callback, actionCallback: Callback) {
34
- reactApplicationContext.runOnUiQueueThread {
35
- if (label != null) {
36
- NamiCampaignManager.launch(currentActivity!!, label,
33
+ var theActivity: Activity? = null
34
+ if (reactApplicationContext.hasCurrentActivity()) {
35
+ theActivity = reactApplicationContext.getCurrentActivity()
36
+ }
37
+
38
+ if (theActivity != null) {
39
+ reactApplicationContext.runOnUiQueueThread {
40
+ if (label != null) {
41
+ NamiCampaignManager.launch(
42
+ theActivity,
43
+ label,
37
44
  paywallActionCallback = { campaignId, campaignLabel, paywallId, action, sku, purchaseError, purchases ->
38
45
  handlePaywallCallback(campaignId, campaignLabel, paywallId, action, sku, purchaseError, purchases, actionCallback)
39
- }
40
- ) { result -> handleResult(result, resultCallback) }
41
- } else {
42
- NamiCampaignManager.launch(currentActivity!!,
43
- paywallActionCallback = { campaignId, campaignLabel, paywallId, action, sku,purchaseError, purchases ->
46
+ },
47
+ ) { result -> handleResult(result, resultCallback) }
48
+ } else {
49
+ NamiCampaignManager.launch(
50
+ theActivity,
51
+ paywallActionCallback = { campaignId, campaignLabel, paywallId, action, sku, purchaseError, purchases ->
44
52
  handlePaywallCallback(campaignId, campaignLabel, paywallId, action, sku, purchaseError, purchases, actionCallback)
45
- }
46
- ) { result -> handleResult(result, resultCallback) }
53
+ },
54
+ ) { result -> handleResult(result, resultCallback) }
55
+ }
47
56
  }
48
57
  }
58
+
49
59
  }
50
60
 
51
- private fun handlePaywallCallback(campaignId: String, campaignLabel: String?, paywallId: String, action: NamiPaywallAction, sku: NamiSKU?, purchaseError: String?, purchases: List<NamiPurchase>?, actionCallback: Callback){
61
+ private fun handlePaywallCallback(campaignId: String, campaignLabel: String?, paywallId: String, action: NamiPaywallAction, sku: NamiSKU?, purchaseError: String?, purchases: List<NamiPurchase>?, actionCallback: Callback) {
52
62
  val actionString = action.toString()
53
63
  val skuString = sku?.skuId.orEmpty()
54
64
  val purchasesArray: WritableArray = WritableNativeArray()
@@ -66,8 +76,8 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
66
76
  resultMap.putString("purchaseError", purchaseError)
67
77
  resultMap.putArray("purchases", purchasesArray)
68
78
  reactApplicationContext
69
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
70
- .emit("ResultCampaign", resultMap)
79
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
80
+ .emit("ResultCampaign", resultMap)
71
81
  }
72
82
 
73
83
  private fun handleResult(result: LaunchCampaignResult, resultCallback: Callback) {
@@ -83,10 +93,10 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
83
93
  }
84
94
 
85
95
  override fun onActivityResult(
86
- activity: Activity?,
87
- requestCode: Int,
88
- resultCode: Int,
89
- intent: Intent?
96
+ activity: Activity?,
97
+ requestCode: Int,
98
+ resultCode: Int,
99
+ intent: Intent?,
90
100
  ) {
91
101
  Log.d(LOG_TAG, "Nami Activity result listener activated, code is $requestCode")
92
102
  }
@@ -96,7 +106,7 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
96
106
  }
97
107
 
98
108
  @ReactMethod
99
- fun allCampaigns(promise: Promise){
109
+ fun allCampaigns(promise: Promise) {
100
110
  val campaigns = NamiCampaignManager.allCampaigns()
101
111
  val array = WritableNativeArray()
102
112
  campaigns.forEach { campaign ->
@@ -106,7 +116,7 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
106
116
  }
107
117
 
108
118
  @ReactMethod
109
- fun isCampaignAvailable(label: String?, promise: Promise){
119
+ fun isCampaignAvailable(label: String?, promise: Promise) {
110
120
  val isCampaignAvailable: Boolean
111
121
  if (label != null) {
112
122
  isCampaignAvailable = NamiCampaignManager.isCampaignAvailable(label)
@@ -117,8 +127,8 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
117
127
  }
118
128
 
119
129
  @ReactMethod
120
- fun refresh(){
121
- NamiCampaignManager.refresh() { }
130
+ fun refresh() {
131
+ NamiCampaignManager.refresh() { }
122
132
  }
123
133
 
124
134
  @ReactMethod
@@ -129,8 +139,16 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
129
139
  array.pushMap(campaignToReadableMap(campaign))
130
140
  }
131
141
  reactApplicationContext
132
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
133
- .emit("AvailableCampaignsChanged", array)
142
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
143
+ .emit("AvailableCampaignsChanged", array)
134
144
  }
135
145
  }
146
+
147
+ @ReactMethod
148
+ fun addListener(eventName: String?) {
149
+ }
150
+
151
+ @ReactMethod
152
+ fun removeListeners(count: Int?) {
153
+ }
136
154
  }
@@ -1,13 +1,10 @@
1
1
  package com.nami.reactlibrary
2
2
 
3
- import android.util.Log
4
3
  import com.facebook.react.bridge.*
5
4
  import com.facebook.react.modules.core.DeviceEventManagerModule
6
- import com.namiml.campaign.NamiCampaignManager
7
5
  import com.namiml.customer.CustomerJourneyState
8
6
  import com.namiml.customer.NamiCustomerManager
9
7
 
10
-
11
8
  class NamiCustomerManagerBridgeModule(reactContext: ReactApplicationContext) :
12
9
  ReactContextBaseJavaModule(reactContext) {
13
10
 
@@ -26,68 +23,69 @@ class NamiCustomerManagerBridgeModule(reactContext: ReactApplicationContext) :
26
23
  readableMap.putBoolean("inAccountHold", journeyState.inAccountHold)
27
24
  return readableMap
28
25
  }
26
+
29
27
  @ReactMethod
30
- fun setCustomerAttribute(key: String, value: String){
28
+ fun setCustomerAttribute(key: String, value: String) {
31
29
  NamiCustomerManager.setCustomerAttribute(key, value)
32
30
  }
33
31
 
34
32
  @ReactMethod
35
- fun getCustomerAttribute(key: String, promise: Promise){
33
+ fun getCustomerAttribute(key: String, promise: Promise) {
36
34
  val customerAttribute = NamiCustomerManager.getCustomerAttribute(key)
37
35
  promise.resolve(customerAttribute)
38
36
  }
39
37
 
40
38
  @ReactMethod
41
- fun clearCustomerAttribute(key: String){
39
+ fun clearCustomerAttribute(key: String) {
42
40
  NamiCustomerManager.clearCustomerAttribute(key)
43
41
  }
44
42
 
45
43
  @ReactMethod
46
- fun clearAllCustomerAttributes(){
44
+ fun clearAllCustomerAttributes() {
47
45
  NamiCustomerManager.clearAllCustomerAttributes()
48
46
  }
49
47
 
50
48
  @ReactMethod
51
- fun clearCustomerDataPlatformId(){
49
+ fun clearCustomerDataPlatformId() {
52
50
  NamiCustomerManager.clearCustomerDataPlatformId()
53
51
  }
54
52
 
55
53
  @ReactMethod
56
- fun setCustomerDataPlatformId(cdpId: String){
54
+ fun setCustomerDataPlatformId(cdpId: String) {
57
55
  NamiCustomerManager.setCustomerDataPlatformId(cdpId)
58
56
  }
59
57
 
60
58
  @ReactMethod
61
- fun journeyState(promise: Promise){
62
- val journeyState = NamiCustomerManager.journeyState()
59
+ fun journeyState(promise: Promise) {
60
+ val journeyState = NamiCustomerManager.journeyState()
63
61
  if (journeyState == null) {
64
62
  promise.resolve(null)
65
63
  } else {
66
64
  val handledJourneyState = journeyStateToReadableMap(journeyState)
67
65
  promise.resolve(handledJourneyState)
68
66
  }
69
- }
67
+ }
70
68
 
71
69
  @ReactMethod
72
- fun isLoggedIn(promise: Promise){
70
+ fun isLoggedIn(promise: Promise) {
73
71
  val isLoggedIn = NamiCustomerManager.isLoggedIn()
74
72
  promise.resolve(isLoggedIn)
75
73
  }
76
74
 
77
75
  @ReactMethod
78
- fun loggedInId(promise: Promise){
76
+ fun loggedInId(promise: Promise) {
79
77
  val id = NamiCustomerManager.loggedInId()
80
78
  promise.resolve(id)
81
79
  }
82
80
 
83
81
  @ReactMethod
84
- fun deviceId(promise: Promise){
82
+ fun deviceId(promise: Promise) {
85
83
  val id = NamiCustomerManager.deviceId()
86
84
  promise.resolve(id)
87
85
  }
88
86
 
89
87
  @ReactMethod
90
- fun login(customerId: String){
88
+ fun login(customerId: String) {
91
89
  NamiCustomerManager.login(customerId)
92
90
  }
93
91
 
@@ -101,8 +99,8 @@ class NamiCustomerManagerBridgeModule(reactContext: ReactApplicationContext) :
101
99
  NamiCustomerManager.registerJourneyStateHandler { journeyState ->
102
100
  val handledJourneyState = journeyStateToReadableMap(journeyState)
103
101
  reactApplicationContext
104
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
105
- .emit("JourneyStateChanged", handledJourneyState)
102
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
103
+ .emit("JourneyStateChanged", handledJourneyState)
106
104
  }
107
105
  }
108
106
 
@@ -114,8 +112,16 @@ class NamiCustomerManagerBridgeModule(reactContext: ReactApplicationContext) :
114
112
  body.putBoolean("success", success)
115
113
  body.putString("error", error.toString())
116
114
  reactApplicationContext
117
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
118
- .emit("AccountStateChanged", body)
115
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
116
+ .emit("AccountStateChanged", body)
119
117
  }
120
118
  }
119
+
120
+ @ReactMethod
121
+ fun addListener(eventName: String?) {
122
+ }
123
+
124
+ @ReactMethod
125
+ fun removeListeners(count: Int?) {
126
+ }
121
127
  }
@@ -1,14 +1,9 @@
1
1
  package com.nami.reactlibrary
2
2
 
3
- import android.util.Log
4
3
  import com.facebook.react.bridge.*
5
4
  import com.facebook.react.modules.core.DeviceEventManagerModule
6
- import com.namiml.entitlement.NamiEntitlement
7
5
  import com.namiml.entitlement.NamiEntitlementManager
8
- //import com.namiml.entitlement.NamiEntitlementSetter
9
- import com.namiml.entitlement.NamiPlatformType
10
- import java.util.ArrayList
11
- import java.util.Date
6
+ // import com.namiml.entitlement.NamiEntitlementSetter
12
7
  import com.facebook.react.bridge.Callback
13
8
 
14
9
  class NamiEntitlementManagerBridgeModule(reactContext: ReactApplicationContext) :
@@ -19,25 +14,25 @@ class NamiEntitlementManagerBridgeModule(reactContext: ReactApplicationContext)
19
14
  }
20
15
 
21
16
  @ReactMethod
22
- fun isEntitlementActive(referenceId: String, promise: Promise){
17
+ fun isEntitlementActive(referenceId: String, promise: Promise) {
23
18
  val isEntitlementActive = NamiEntitlementManager.isEntitlementActive(referenceId)
24
19
  promise.resolve(isEntitlementActive)
25
20
  }
26
21
 
27
22
  @ReactMethod
28
- fun active(promise: Promise){
23
+ fun active(promise: Promise) {
29
24
  val nativeEntitlements = NamiEntitlementManager.active()
30
25
  val resultArray: WritableArray = WritableNativeArray()
31
26
  for (entitlement in nativeEntitlements) {
32
27
  entitlement.toEntitlementDict()?.let { entitlementDict ->
33
28
  resultArray.pushMap(entitlementDict)
34
- }
29
+ }
35
30
  }
36
31
  promise.resolve(resultArray)
37
32
  }
38
33
 
39
34
  @ReactMethod
40
- fun refresh(callback: Callback){
35
+ fun refresh(callback: Callback) {
41
36
  NamiEntitlementManager.refresh { activeNativeEntitlements ->
42
37
  val resultArray: WritableArray = WritableNativeArray()
43
38
  if (activeNativeEntitlements != null) {
@@ -61,8 +56,16 @@ class NamiEntitlementManagerBridgeModule(reactContext: ReactApplicationContext)
61
56
  }
62
57
  }
63
58
  reactApplicationContext
64
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
65
- .emit("EntitlementsChanged", resultArray)
59
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
60
+ .emit("EntitlementsChanged", resultArray)
66
61
  }
67
62
  }
63
+
64
+ @ReactMethod
65
+ fun addListener(eventName: String?) {
66
+ }
67
+
68
+ @ReactMethod
69
+ fun removeListeners(count: Int?) {
70
+ }
68
71
  }
@@ -47,4 +47,12 @@ class NamiMLManagerBridgeModule(reactContext: ReactApplicationContext) :
47
47
  NamiMLManager.coreAction(label)
48
48
  }
49
49
  }
50
+
51
+ @ReactMethod
52
+ fun addListener(eventName: String?) {
53
+ }
54
+
55
+ @ReactMethod
56
+ fun removeListeners(count: Int?) {
57
+ }
50
58
  }
@@ -3,18 +3,19 @@ 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.android.billingclient.api.Purchase
7
6
  import com.facebook.react.bridge.*
8
7
  import com.facebook.react.modules.core.DeviceEventManagerModule
9
- import com.namiml.paywall.*
8
+ import com.namiml.paywall.NamiPaywallManager
9
+ import com.namiml.paywall.NamiPurchaseSource
10
+ import com.namiml.paywall.NamiSKU
11
+ import com.namiml.paywall.NamiSKUType
10
12
  import com.namiml.paywall.model.NamiPurchaseSuccess
11
- import java.text.SimpleDateFormat
12
- import java.util.Date
13
+ import java.util.*
13
14
 
14
15
  class NamiPaywallManagerBridgeModule(reactContext: ReactApplicationContext) :
15
16
  ReactContextBaseJavaModule(reactContext), ActivityEventListener {
16
17
 
17
- private var blockRaisePaywall: Boolean = false
18
+ var latestPaywallActivity: Activity? = null
18
19
 
19
20
  override fun getName(): String {
20
21
  return "RNNamiPaywallManager"
@@ -22,23 +23,66 @@ class NamiPaywallManagerBridgeModule(reactContext: ReactApplicationContext) :
22
23
 
23
24
  @ReactMethod
24
25
  fun buySkuComplete(dict: ReadableMap, storeType: String) {
25
- var product = dict.getMap("product")
26
- var name = product?.getString("name")
27
- var featured = product?.getBoolean("featured")
28
- var productId = product?.getString("id")
29
- var skuId = product?.getString("skuId")
30
- var typeInt = product?.getInt("type")
31
- var purchaseSourceString = dict.getString("purchaseSource")
32
- var purchaseDateInt = dict.getInt("purchaseDate")
33
- var expiresDateInt = dict.getInt("expiresDate")
34
- val type = when (typeInt) {
35
- 0 -> {
26
+ var product: ReadableMap? = null
27
+ var productId: String? = null
28
+ var skuId: String? = null
29
+ var typeString: String? = null
30
+ var purchaseSourceString: String? = null
31
+ var expiresDateInt: Int? = null
32
+ var purchaseDateInt: Int? = null
33
+
34
+ var expiresDate: Date? = null
35
+ var purchaseDate: Date? = null
36
+
37
+ var skuType: NamiSKUType?
38
+
39
+ var purchaseToken: String? = null
40
+ var orderId: String? = null
41
+
42
+ var receiptId: String? = null
43
+ var localizedPrice: String? = null
44
+ var userId: String? = null
45
+ var marketplace: String? = null
46
+
47
+ if (dict.hasKey("product")) {
48
+ product = dict.getMap("product")
49
+ }
50
+
51
+ if (product != null) {
52
+ if (product.hasKey("id")) {
53
+ productId = product.getString("id")
54
+ }
55
+
56
+ if (product.hasKey("skuId")) {
57
+ skuId = product.getString("skuId")
58
+ }
59
+
60
+ if (product.hasKey("type")) {
61
+ typeString = product.getString("type")
62
+ }
63
+ }
64
+
65
+ if (dict.hasKey("purchaseSource")) {
66
+ purchaseSourceString = dict.getString("purchaseSource")
67
+ }
68
+
69
+ if (dict.hasKey("expiresDate")) {
70
+ expiresDateInt = dict.getInt("expiresDate")
71
+ expiresDate = Date(expiresDateInt * 1000L)
72
+ }
73
+ if (dict.hasKey("purchaseDate")) {
74
+ purchaseDateInt = dict.getInt("purchaseDate")
75
+ purchaseDate = Date(purchaseDateInt * 1000L)
76
+ }
77
+
78
+ skuType = when (typeString) {
79
+ "UNKNOWN" -> {
36
80
  NamiSKUType.UNKNOWN
37
81
  }
38
- 1 -> {
82
+ "SUBSCRIPTION" -> {
39
83
  NamiSKUType.SUBSCRIPTION
40
84
  }
41
- 2 -> {
85
+ "ONE_TIME_PURCHASE" -> {
42
86
  NamiSKUType.ONE_TIME_PURCHASE
43
87
  }
44
88
  else -> {
@@ -61,125 +105,128 @@ class NamiPaywallManagerBridgeModule(reactContext: ReactApplicationContext) :
61
105
  }
62
106
  }
63
107
 
64
- if (name != null && skuId != null && featured != null) {
108
+ if (productId != null && skuId != null && skuType != null) {
65
109
  val namiSku = NamiSKU(
66
- skuId = skuId,
67
- skuDetails = null,
68
- amazonProduct = null,
69
- id = productId,
70
- type = type,
71
- name = name,
72
- featured = featured,
73
- rawDisplayText = null,
74
- rawSubDisplayText = null,
75
- entitlements = emptyList(),
76
- variables = null
110
+ skuId = skuId,
111
+ skuDetails = null,
112
+ amazonProduct = null,
113
+ id = productId,
114
+ type = skuType,
115
+ name = "",
116
+ featured = false,
117
+ rawDisplayText = null,
118
+ rawSubDisplayText = null,
119
+ entitlements = emptyList(),
120
+ variables = null,
77
121
  )
78
- val purchaseDate = Date(purchaseDateInt * 1000L)
79
- var expiresDate = Date(expiresDateInt * 1000L )
80
- var purchaseSuccess: NamiPurchaseSuccess? = null;
122
+ var purchaseSuccess: NamiPurchaseSuccess? = null
123
+
81
124
  if (storeType == "GooglePlay") {
82
- var purchaseToken = dict.getString("purchaseToken")
83
- var orderId = dict.getString("orderId")
84
- if (purchaseToken != null && orderId != null) {
125
+ if (dict.hasKey("purchaseToken")) {
126
+ purchaseToken = dict.getString("purchaseToken")
127
+ }
128
+ if (dict.hasKey("orderId")) {
129
+ orderId = dict.getString("orderId")
130
+ }
131
+ Log.d(LOG_TAG, "$namiSku $purchaseToken $orderId $purchaseDateInt $purchaseDate")
132
+
133
+ if (namiSku != null && purchaseToken != null && orderId != null && purchaseDate != null) {
85
134
  purchaseSuccess = NamiPurchaseSuccess.GooglePlay(
86
- product = namiSku,
87
- expiresDate = expiresDate,
88
- purchaseDate = purchaseDate,
89
- purchaseSource = purchaseSource,
90
- description = null,
91
- orderId = orderId,
92
- purchaseToken = purchaseToken,
135
+ product = namiSku,
136
+ expiresDate = expiresDate,
137
+ purchaseDate = purchaseDate,
138
+ purchaseSource = purchaseSource,
139
+ description = null,
140
+ orderId = orderId,
141
+ purchaseToken = purchaseToken,
93
142
  )
94
143
  }
95
144
  } else if (storeType == "Amazon") {
96
- var receiptId = dict.getString("receiptId")
97
- var localizedPrice = dict.getString("localizedPrice")
98
- var userId = dict.getString("userId")
99
- var marketplace = dict.getString("marketplace")
100
- if (receiptId != null && localizedPrice != null && userId != null && marketplace != null) {
145
+ if (dict.hasKey("receiptId")) {
146
+ receiptId = dict.getString("receiptId")
147
+ }
148
+ if (dict.hasKey("localizedPrice")) {
149
+ localizedPrice = dict.getString("localizedPrice")
150
+ }
151
+ if (dict.hasKey("userId")) {
152
+ userId = dict.getString("userId")
153
+ }
154
+ if (dict.hasKey("marketplace")) {
155
+ marketplace = dict.getString("marketplace")
156
+ }
157
+ if (namiSku != null && receiptId != null && localizedPrice != null && userId != null && marketplace != null && purchaseDate != null) {
101
158
  purchaseSuccess = NamiPurchaseSuccess.Amazon(
102
- product = namiSku,
103
- expiresDate = expiresDate,
104
- purchaseDate = purchaseDate,
105
- purchaseSource = purchaseSource,
106
- description = null,
107
- receiptId = receiptId,
108
- localizedPrice = localizedPrice,
109
- userId = userId,
110
- marketplace = marketplace,
159
+ product = namiSku,
160
+ expiresDate = expiresDate,
161
+ purchaseDate = purchaseDate,
162
+ purchaseSource = purchaseSource,
163
+ description = null,
164
+ receiptId = receiptId,
165
+ localizedPrice = localizedPrice,
166
+ userId = userId,
167
+ marketplace = marketplace,
111
168
  )
112
169
  }
113
170
  }
114
171
 
115
172
  if (purchaseSuccess != null) {
116
173
  NamiPaywallManager.buySkuComplete(currentActivity!!, purchaseSuccess)
174
+ } else {
175
+ Log.d(LOG_TAG, "Unable to create a valid NamiPurchaseSuccess object, so buySkuComplete will not succeed. Paywall conversion will not be reported for this purchase.")
117
176
  }
118
177
  }
119
178
  }
120
179
 
121
-
122
180
  @ReactMethod
123
- fun registerCloseHandler(blockDismiss: Boolean) {
181
+ fun registerCloseHandler() {
124
182
  NamiPaywallManager.registerCloseHandler { activity ->
125
- val resultMap = Arguments.createMap()
126
- resultMap.putBoolean("blockingPaywallClosed", true)
127
- reactApplicationContext
128
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
129
- .emit("BlockingPaywallClosed", resultMap)
130
- if (!blockDismiss) {
131
- activity.finish()
183
+ latestPaywallActivity = activity
184
+ val map = Arguments.createMap().apply {
185
+ putBoolean("paywallCloseRequested", true)
132
186
  }
187
+ reactApplicationContext
188
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
189
+ .emit("PaywallCloseRequested", map)
190
+ }
191
+ }
192
+
193
+ @ReactMethod
194
+ fun dismiss(animated: Boolean) {
195
+ if (latestPaywallActivity != null) {
196
+ val paywallActivity = latestPaywallActivity as Activity
197
+ NamiPaywallManager.dismiss(paywallActivity)
133
198
  }
134
199
  }
135
200
 
136
201
  @ReactMethod
137
202
  fun registerBuySkuHandler() {
138
203
  NamiPaywallManager.registerBuySkuHandler { activity, sku ->
204
+ latestPaywallActivity = activity
139
205
  val dictionary = sku.toSkuDict()
140
206
  reactApplicationContext
141
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
142
- .emit("RegisterBuySKU", dictionary)
207
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
208
+ .emit("RegisterBuySKU", dictionary)
143
209
  }
144
210
  }
145
211
 
212
+ @ReactMethod
213
+ fun addListener(eventName: String?) {
214
+ }
215
+
216
+ @ReactMethod
217
+ fun removeListeners(count: Int?) {
218
+ }
146
219
 
147
220
  override fun onActivityResult(
148
221
  activity: Activity?,
149
222
  requestCode: Int,
150
223
  resultCode: Int,
151
- data: Intent?
224
+ data: Intent?,
152
225
  ) {
153
226
  Log.d(LOG_TAG, "Nami Activity result listener activated, code is $requestCode")
154
- if (NamiPaywallManager.didUserCloseBlockingNamiPaywall(requestCode, resultCode)) {
155
- Log.i(
156
- LOG_TAG, "User closed blocking paywall, sending event. " +
157
- "Activity was." + activity.toString()
158
- )
159
- emitBockedPaywallClosed()
160
- }
161
- }
162
-
163
- private fun emitBockedPaywallClosed() {
164
- val map = Arguments.createMap().apply {
165
- putBoolean("blockingPaywallClosed", true)
166
- }
167
- try {
168
- reactApplicationContext
169
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
170
- .emit("BlockingPaywallClosed", map)
171
- } catch (e: Exception) {
172
- Log.e(LOG_TAG, "Caught Exception: " + e.message)
173
- }
174
227
  }
175
228
 
176
229
  override fun onNewIntent(intent: Intent?) {
177
230
  // do nothing
178
231
  }
179
-
180
- // @ReactMethod
181
- // fun blockRaisePaywall(blockRaise: Boolean) {
182
- // blockRaisePaywall = blockRaise
183
- // }
184
-
185
232
  }