react-native-nami-sdk 3.0.8 → 3.0.10
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.
- package/.eslintignore +2 -0
- package/.eslintrc.js +12 -0
- package/.github/workflows/CI.yaml +610 -0
- package/.github/workflows/app_prod.yaml +316 -0
- package/.github/workflows/app_stg.yaml +114 -1
- package/.pre-commit-config.yaml +0 -1
- package/android/build.gradle +2 -2
- package/android/src/main/java/com/nami/reactlibrary/NamiBridgeModule.kt +4 -17
- package/android/src/main/java/com/nami/reactlibrary/NamiBridgePackage.java +0 -1
- package/android/src/main/java/com/nami/reactlibrary/NamiCampaignManagerBridge.kt +51 -30
- package/android/src/main/java/com/nami/reactlibrary/NamiCustomerManagerBridge.kt +40 -24
- package/android/src/main/java/com/nami/reactlibrary/NamiEntitlementManagerBridgeModule.kt +15 -12
- package/android/src/main/java/com/nami/reactlibrary/NamiMLManagerBridgeModule.kt +8 -0
- package/android/src/main/java/com/nami/reactlibrary/NamiPaywallManagerBridgeModule.kt +185 -43
- package/android/src/main/java/com/nami/reactlibrary/NamiPurchaseManagerBridge.kt +12 -14
- package/android/src/main/java/com/nami/reactlibrary/NamiUtil.kt +3 -47
- package/ios/Nami.m +3 -25
- package/ios/NamiCampaignManagerBridge.swift +17 -6
- package/ios/NamiCustomerManager.m +4 -0
- package/ios/NamiCustomerManager.swift +34 -5
- package/ios/NamiEntitlementManagerBridge.swift +9 -1
- package/ios/NamiMLManagerBridge.m +0 -2
- package/ios/NamiPaywallManagerBridge.m +2 -59
- package/ios/NamiPaywallManagerBridge.swift +67 -58
- package/ios/NamiPurchaseManagerBridge.m +2 -98
- package/ios/NamiPurchaseManagerBridge.swift +45 -5
- package/ios/RNNami-Bridging-Header.h +0 -1
- package/ios/RNNami.xcodeproj/project.pbxproj +2 -67
- package/ios/RNNami.xcworkspace/contents.xcworkspacedata +0 -3
- package/package.json +14 -4
- package/react-native-nami-sdk.podspec +4 -2
- package/src/Nami.d.ts +0 -1
- package/src/NamiCampaignManager.d.ts +4 -1
- package/src/NamiCampaignManager.js +12 -1
- package/src/NamiCustomerManager.d.ts +2 -0
- package/src/NamiCustomerManager.js +2 -2
- package/src/NamiMLManager.d.ts +3 -3
- package/src/NamiMLManager.js +1 -1
- package/src/NamiPaywallManager.d.ts +27 -21
- package/src/NamiPaywallManager.js +21 -7
- package/src/NamiPurchaseManager.d.ts +7 -3
- package/src/types.ts +10 -3
- package/android/src/main/java/com/nami/reactlibrary/NamiEmitter.kt +0 -163
- package/ios/NamiBridgeUtil.h +0 -32
- package/ios/NamiBridgeUtil.m +0 -231
- package/ios/NamiEmitter.m +0 -350
- 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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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,
|
|
44
|
+
paywallActionCallback = { campaignId, campaignLabel, paywallId, action, sku, purchaseError, purchases ->
|
|
45
|
+
handlePaywallCallback(campaignId, campaignLabel, paywallId, action, sku, purchaseError, purchases, actionCallback)
|
|
46
|
+
},
|
|
47
|
+
) { result -> handleResult(result, resultCallback) }
|
|
48
|
+
} else {
|
|
49
|
+
NamiCampaignManager.launch(
|
|
50
|
+
theActivity,
|
|
51
|
+
paywallActionCallback = { campaignId, campaignLabel, paywallId, action, sku, purchaseError, purchases ->
|
|
52
|
+
handlePaywallCallback(campaignId, campaignLabel, paywallId, action, sku, purchaseError, purchases, actionCallback)
|
|
53
|
+
},
|
|
54
|
+
) { result -> handleResult(result, resultCallback) }
|
|
55
|
+
}
|
|
47
56
|
}
|
|
48
57
|
}
|
|
58
|
+
|
|
49
59
|
}
|
|
50
60
|
|
|
51
|
-
private fun handlePaywallCallback(action: NamiPaywallAction, sku: NamiSKU?, purchaseError: String?, purchases: List<NamiPurchase>?,
|
|
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()
|
|
@@ -58,13 +68,16 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
58
68
|
}
|
|
59
69
|
}
|
|
60
70
|
val resultMap = Arguments.createMap()
|
|
71
|
+
resultMap.putString("campaignId", campaignId)
|
|
72
|
+
resultMap.putString("campaignLabel", campaignLabel)
|
|
73
|
+
resultMap.putString("paywallId", paywallId)
|
|
61
74
|
resultMap.putString("action", actionString)
|
|
62
75
|
resultMap.putString("skuId", skuString)
|
|
63
76
|
resultMap.putString("purchaseError", purchaseError)
|
|
64
77
|
resultMap.putArray("purchases", purchasesArray)
|
|
65
78
|
reactApplicationContext
|
|
66
|
-
|
|
67
|
-
|
|
79
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
80
|
+
.emit("ResultCampaign", resultMap)
|
|
68
81
|
}
|
|
69
82
|
|
|
70
83
|
private fun handleResult(result: LaunchCampaignResult, resultCallback: Callback) {
|
|
@@ -80,10 +93,10 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
80
93
|
}
|
|
81
94
|
|
|
82
95
|
override fun onActivityResult(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
96
|
+
activity: Activity?,
|
|
97
|
+
requestCode: Int,
|
|
98
|
+
resultCode: Int,
|
|
99
|
+
intent: Intent?,
|
|
87
100
|
) {
|
|
88
101
|
Log.d(LOG_TAG, "Nami Activity result listener activated, code is $requestCode")
|
|
89
102
|
}
|
|
@@ -93,7 +106,7 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
93
106
|
}
|
|
94
107
|
|
|
95
108
|
@ReactMethod
|
|
96
|
-
fun allCampaigns(promise: Promise){
|
|
109
|
+
fun allCampaigns(promise: Promise) {
|
|
97
110
|
val campaigns = NamiCampaignManager.allCampaigns()
|
|
98
111
|
val array = WritableNativeArray()
|
|
99
112
|
campaigns.forEach { campaign ->
|
|
@@ -103,7 +116,7 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
103
116
|
}
|
|
104
117
|
|
|
105
118
|
@ReactMethod
|
|
106
|
-
fun isCampaignAvailable(label: String?, promise: Promise){
|
|
119
|
+
fun isCampaignAvailable(label: String?, promise: Promise) {
|
|
107
120
|
val isCampaignAvailable: Boolean
|
|
108
121
|
if (label != null) {
|
|
109
122
|
isCampaignAvailable = NamiCampaignManager.isCampaignAvailable(label)
|
|
@@ -114,8 +127,8 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
114
127
|
}
|
|
115
128
|
|
|
116
129
|
@ReactMethod
|
|
117
|
-
fun refresh(){
|
|
118
|
-
NamiCampaignManager.refresh() {
|
|
130
|
+
fun refresh() {
|
|
131
|
+
NamiCampaignManager.refresh() { }
|
|
119
132
|
}
|
|
120
133
|
|
|
121
134
|
@ReactMethod
|
|
@@ -126,8 +139,16 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
126
139
|
array.pushMap(campaignToReadableMap(campaign))
|
|
127
140
|
}
|
|
128
141
|
reactApplicationContext
|
|
129
|
-
|
|
130
|
-
|
|
142
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
143
|
+
.emit("AvailableCampaignsChanged", array)
|
|
131
144
|
}
|
|
132
145
|
}
|
|
146
|
+
|
|
147
|
+
@ReactMethod
|
|
148
|
+
fun addListener(eventName: String?) {
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@ReactMethod
|
|
152
|
+
fun removeListeners(count: Int?) {
|
|
153
|
+
}
|
|
133
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,58 +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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
val handledJourneyState = journeyStateToReadableMap(journeyState)
|
|
55
|
-
promise.resolve(handledJourneyState)
|
|
56
|
-
} else {
|
|
57
|
-
promise.resolve(null)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
49
|
+
fun clearCustomerDataPlatformId() {
|
|
50
|
+
NamiCustomerManager.clearCustomerDataPlatformId()
|
|
51
|
+
}
|
|
60
52
|
|
|
61
53
|
@ReactMethod
|
|
62
|
-
fun
|
|
54
|
+
fun setCustomerDataPlatformId(cdpId: String) {
|
|
55
|
+
NamiCustomerManager.setCustomerDataPlatformId(cdpId)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@ReactMethod
|
|
59
|
+
fun journeyState(promise: Promise) {
|
|
60
|
+
val journeyState = NamiCustomerManager.journeyState()
|
|
61
|
+
if (journeyState == null) {
|
|
62
|
+
promise.resolve(null)
|
|
63
|
+
} else {
|
|
64
|
+
val handledJourneyState = journeyStateToReadableMap(journeyState)
|
|
65
|
+
promise.resolve(handledJourneyState)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@ReactMethod
|
|
70
|
+
fun isLoggedIn(promise: Promise) {
|
|
63
71
|
val isLoggedIn = NamiCustomerManager.isLoggedIn()
|
|
64
72
|
promise.resolve(isLoggedIn)
|
|
65
73
|
}
|
|
66
74
|
|
|
67
75
|
@ReactMethod
|
|
68
|
-
fun loggedInId(promise: Promise){
|
|
76
|
+
fun loggedInId(promise: Promise) {
|
|
69
77
|
val id = NamiCustomerManager.loggedInId()
|
|
70
78
|
promise.resolve(id)
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
@ReactMethod
|
|
74
|
-
fun deviceId(promise: Promise){
|
|
82
|
+
fun deviceId(promise: Promise) {
|
|
75
83
|
val id = NamiCustomerManager.deviceId()
|
|
76
84
|
promise.resolve(id)
|
|
77
85
|
}
|
|
78
86
|
|
|
79
87
|
@ReactMethod
|
|
80
|
-
fun login(customerId: String){
|
|
88
|
+
fun login(customerId: String) {
|
|
81
89
|
NamiCustomerManager.login(customerId)
|
|
82
90
|
}
|
|
83
91
|
|
|
@@ -91,8 +99,8 @@ class NamiCustomerManagerBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
91
99
|
NamiCustomerManager.registerJourneyStateHandler { journeyState ->
|
|
92
100
|
val handledJourneyState = journeyStateToReadableMap(journeyState)
|
|
93
101
|
reactApplicationContext
|
|
94
|
-
|
|
95
|
-
|
|
102
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
103
|
+
.emit("JourneyStateChanged", handledJourneyState)
|
|
96
104
|
}
|
|
97
105
|
}
|
|
98
106
|
|
|
@@ -104,8 +112,16 @@ class NamiCustomerManagerBridgeModule(reactContext: ReactApplicationContext) :
|
|
|
104
112
|
body.putBoolean("success", success)
|
|
105
113
|
body.putString("error", error.toString())
|
|
106
114
|
reactApplicationContext
|
|
107
|
-
|
|
108
|
-
|
|
115
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
116
|
+
.emit("AccountStateChanged", body)
|
|
109
117
|
}
|
|
110
118
|
}
|
|
119
|
+
|
|
120
|
+
@ReactMethod
|
|
121
|
+
fun addListener(eventName: String?) {
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@ReactMethod
|
|
125
|
+
fun removeListeners(count: Int?) {
|
|
126
|
+
}
|
|
111
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
|
-
|
|
65
|
-
|
|
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
|
}
|
|
@@ -3,88 +3,230 @@ 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
8
|
import com.namiml.paywall.NamiPaywallManager
|
|
10
|
-
import com.namiml.paywall.
|
|
9
|
+
import com.namiml.paywall.NamiPurchaseSource
|
|
10
|
+
import com.namiml.paywall.NamiSKU
|
|
11
|
+
import com.namiml.paywall.NamiSKUType
|
|
12
|
+
import com.namiml.paywall.model.NamiPurchaseSuccess
|
|
13
|
+
import java.util.*
|
|
11
14
|
|
|
12
15
|
class NamiPaywallManagerBridgeModule(reactContext: ReactApplicationContext) :
|
|
13
16
|
ReactContextBaseJavaModule(reactContext), ActivityEventListener {
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
var latestPaywallActivity: Activity? = null
|
|
16
19
|
|
|
17
20
|
override fun getName(): String {
|
|
18
21
|
return "RNNamiPaywallManager"
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
@ReactMethod
|
|
22
|
-
fun buySkuComplete(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
fun buySkuComplete(dict: ReadableMap, storeType: String) {
|
|
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" -> {
|
|
80
|
+
NamiSKUType.UNKNOWN
|
|
81
|
+
}
|
|
82
|
+
"SUBSCRIPTION" -> {
|
|
83
|
+
NamiSKUType.SUBSCRIPTION
|
|
84
|
+
}
|
|
85
|
+
"ONE_TIME_PURCHASE" -> {
|
|
86
|
+
NamiSKUType.ONE_TIME_PURCHASE
|
|
87
|
+
}
|
|
88
|
+
else -> {
|
|
89
|
+
NamiSKUType.UNKNOWN
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
val purchaseSource = when (purchaseSourceString) {
|
|
94
|
+
"CAMPAIGN" -> {
|
|
95
|
+
NamiPurchaseSource.CAMPAIGN
|
|
96
|
+
}
|
|
97
|
+
"MARKETPLACE" -> {
|
|
98
|
+
NamiPurchaseSource.MARKETPLACE
|
|
99
|
+
}
|
|
100
|
+
"UNKNOWN" -> {
|
|
101
|
+
NamiPurchaseSource.UNKNOWN
|
|
102
|
+
}
|
|
103
|
+
else -> {
|
|
104
|
+
NamiPurchaseSource.UNKNOWN
|
|
105
|
+
}
|
|
106
|
+
}
|
|
25
107
|
|
|
108
|
+
if (productId != null && skuId != null && skuType != null) {
|
|
109
|
+
val namiSku = NamiSKU(
|
|
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,
|
|
121
|
+
)
|
|
122
|
+
var purchaseSuccess: NamiPurchaseSuccess? = null
|
|
123
|
+
|
|
124
|
+
if (storeType == "GooglePlay") {
|
|
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) {
|
|
134
|
+
purchaseSuccess = NamiPurchaseSuccess.GooglePlay(
|
|
135
|
+
product = namiSku,
|
|
136
|
+
expiresDate = expiresDate,
|
|
137
|
+
purchaseDate = purchaseDate,
|
|
138
|
+
purchaseSource = purchaseSource,
|
|
139
|
+
description = null,
|
|
140
|
+
orderId = orderId,
|
|
141
|
+
purchaseToken = purchaseToken,
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
} else if (storeType == "Amazon") {
|
|
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) {
|
|
158
|
+
purchaseSuccess = NamiPurchaseSuccess.Amazon(
|
|
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,
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (purchaseSuccess != null) {
|
|
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.")
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
26
179
|
|
|
27
180
|
@ReactMethod
|
|
28
|
-
fun registerCloseHandler(
|
|
181
|
+
fun registerCloseHandler() {
|
|
29
182
|
NamiPaywallManager.registerCloseHandler { activity ->
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
34
|
-
.emit("BlockingPaywallClosed", resultMap)
|
|
35
|
-
if (!blockDismiss) {
|
|
36
|
-
activity.finish()
|
|
183
|
+
latestPaywallActivity = activity
|
|
184
|
+
val map = Arguments.createMap().apply {
|
|
185
|
+
putBoolean("paywallCloseRequested", true)
|
|
37
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)
|
|
38
198
|
}
|
|
39
199
|
}
|
|
40
200
|
|
|
41
201
|
@ReactMethod
|
|
42
202
|
fun registerBuySkuHandler() {
|
|
43
203
|
NamiPaywallManager.registerBuySkuHandler { activity, sku ->
|
|
204
|
+
latestPaywallActivity = activity
|
|
44
205
|
val dictionary = sku.toSkuDict()
|
|
45
206
|
reactApplicationContext
|
|
46
|
-
|
|
47
|
-
|
|
207
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
208
|
+
.emit("RegisterBuySKU", dictionary)
|
|
48
209
|
}
|
|
49
210
|
}
|
|
50
211
|
|
|
212
|
+
@ReactMethod
|
|
213
|
+
fun addListener(eventName: String?) {
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
@ReactMethod
|
|
217
|
+
fun removeListeners(count: Int?) {
|
|
218
|
+
}
|
|
51
219
|
|
|
52
220
|
override fun onActivityResult(
|
|
53
221
|
activity: Activity?,
|
|
54
222
|
requestCode: Int,
|
|
55
223
|
resultCode: Int,
|
|
56
|
-
data: Intent
|
|
224
|
+
data: Intent?,
|
|
57
225
|
) {
|
|
58
226
|
Log.d(LOG_TAG, "Nami Activity result listener activated, code is $requestCode")
|
|
59
|
-
if (NamiPaywallManager.didUserCloseBlockingNamiPaywall(requestCode, resultCode)) {
|
|
60
|
-
Log.i(
|
|
61
|
-
LOG_TAG, "User closed blocking paywall, sending event. " +
|
|
62
|
-
"Activity was." + activity.toString()
|
|
63
|
-
)
|
|
64
|
-
emitBockedPaywallClosed()
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
private fun emitBockedPaywallClosed() {
|
|
69
|
-
val map = Arguments.createMap().apply {
|
|
70
|
-
putBoolean("blockingPaywallClosed", true)
|
|
71
|
-
}
|
|
72
|
-
try {
|
|
73
|
-
reactApplicationContext
|
|
74
|
-
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
75
|
-
.emit("BlockingPaywallClosed", map)
|
|
76
|
-
} catch (e: Exception) {
|
|
77
|
-
Log.e(LOG_TAG, "Caught Exception: " + e.message)
|
|
78
|
-
}
|
|
79
227
|
}
|
|
80
228
|
|
|
81
229
|
override fun onNewIntent(intent: Intent?) {
|
|
82
230
|
// do nothing
|
|
83
231
|
}
|
|
84
|
-
|
|
85
|
-
// @ReactMethod
|
|
86
|
-
// fun blockRaisePaywall(blockRaise: Boolean) {
|
|
87
|
-
// blockRaisePaywall = blockRaise
|
|
88
|
-
// }
|
|
89
|
-
|
|
90
232
|
}
|