react-native-nami-sdk 3.0.13 → 3.0.14

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.
@@ -115,7 +115,7 @@ class NamiBridgeModule(reactContext: ReactApplicationContext) :
115
115
  } else {
116
116
  Arguments.createArray()
117
117
  }
118
- val settingsList = mutableListOf("extendedClientInfo:react-native:3.0.13")
118
+ val settingsList = mutableListOf("extendedClientInfo:react-native:3.0.14")
119
119
  namiCommandsReact?.toArrayList()?.filterIsInstance<String>()?.let { commandsFromReact ->
120
120
  settingsList.addAll(commandsFromReact)
121
121
  }
@@ -11,6 +11,7 @@ import com.namiml.campaign.NamiCampaign
11
11
  import com.namiml.campaign.NamiCampaignManager
12
12
  import com.namiml.paywall.NamiSKU
13
13
  import com.namiml.paywall.model.NamiPaywallAction
14
+ import com.namiml.paywall.model.PaywallLaunchContext
14
15
 
15
16
  class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
16
17
  ReactContextBaseJavaModule(reactContext), ActivityEventListener {
@@ -29,12 +30,47 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
29
30
  }
30
31
 
31
32
  @ReactMethod
32
- fun launch(label: String?, resultCallback: Callback, actionCallback: Callback) {
33
+ fun launch(label: String?, context: ReadableMap?, resultCallback: Callback, actionCallback: Callback) {
33
34
  var theActivity: Activity? = null
34
35
  if (reactApplicationContext.hasCurrentActivity()) {
35
36
  theActivity = reactApplicationContext.getCurrentActivity()
36
37
  }
37
38
 
39
+ var paywallLaunchContext: PaywallLaunchContext? = null
40
+ if (context != null) {
41
+
42
+ val productGroups: MutableList<String> = mutableListOf()
43
+ val customAttributes: MutableMap<String, String> = mutableMapOf()
44
+
45
+ if (context.hasKey("productGroups")) {
46
+ val groups = context.getArray("productGroups")
47
+ if (groups != null) {
48
+ for (i in 0 until groups.size()) {
49
+ val groupString = groups.getString(i)
50
+ if (groupString != null) {
51
+ productGroups.add(groupString)
52
+ }
53
+
54
+ }
55
+ }
56
+ Log.d(LOG_TAG, "productGroups $productGroups")
57
+ }
58
+
59
+ if (context.hasKey("customAttributes")) {
60
+ val attr = context.getMap("customAttributes")
61
+ if (attr != null) {
62
+ val keyIterator = attr.keySetIterator()
63
+ while (keyIterator.hasNextKey()) {
64
+ val key = keyIterator.nextKey()
65
+ customAttributes[key] = attr.getString(key) ?: ""
66
+ }
67
+ Log.d(LOG_TAG, "customAttributes $customAttributes")
68
+ }
69
+ }
70
+
71
+ paywallLaunchContext = PaywallLaunchContext(productGroups.toList(), customAttributes)
72
+ }
73
+
38
74
  if (theActivity != null) {
39
75
  reactApplicationContext.runOnUiQueueThread {
40
76
  if (label != null) {
@@ -44,6 +80,7 @@ class NamiCampaignManagerBridgeModule(reactContext: ReactApplicationContext) :
44
80
  paywallActionCallback = { campaignId, campaignLabel, paywallId, action, sku, purchaseError, purchases ->
45
81
  handlePaywallCallback(campaignId, campaignLabel, paywallId, action, sku, purchaseError, purchases, actionCallback)
46
82
  },
83
+ paywallLaunchContext,
47
84
  ) { result -> handleResult(result, resultCallback) }
48
85
  } else {
49
86
  NamiCampaignManager.launch(
package/ios/Nami.m CHANGED
@@ -52,7 +52,7 @@ RCT_EXPORT_METHOD(configure: (NSDictionary *)configDict completion: (RCTResponse
52
52
  }
53
53
 
54
54
  // Start commands with header iformation for Nami to let them know this is a React client.
55
- NSMutableArray *namiCommandStrings = [NSMutableArray arrayWithArray:@[@"extendedClientInfo:react-native:3.0.13"]];
55
+ NSMutableArray *namiCommandStrings = [NSMutableArray arrayWithArray:@[@"extendedClientInfo:react-native:3.0.14"]];
56
56
 
57
57
  // Add additional namiCommands app may have sent in.
58
58
  NSObject *appCommandStrings = configDict[@"namiCommands"];
@@ -9,7 +9,7 @@
9
9
 
10
10
  @interface RCT_EXTERN_MODULE(RNNamiCampaignManager, NSObject)
11
11
 
12
- RCT_EXTERN_METHOD(launch:(nullable NSString *)label completion:(RCTResponseSenderBlock)callback paywallCompletion:(RCTResponseSenderBlock)cpaywallCallback)
12
+ RCT_EXTERN_METHOD(launch:(nullable NSString *)label context:(nullable NSDictionary *)context completion:(RCTResponseSenderBlock)callback paywallCompletion:(RCTResponseSenderBlock)cpaywallCallback)
13
13
 
14
14
  RCT_EXTERN_METHOD(allCampaigns:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
15
15
 
@@ -34,11 +34,28 @@ class RNNamiCampaignManager: RCTEventEmitter {
34
34
  return NSDictionary(dictionary: dictionary.compactMapValues { $0 })
35
35
  }
36
36
 
37
- @objc(launch:completion:paywallCompletion:)
38
- func launch(label: String?, callback: @escaping RCTResponseSenderBlock, paywallCallback _: @escaping RCTResponseSenderBlock) {
39
- NamiCampaignManager.launch(label: label, launchHandler: { success, error in
37
+ @objc(launch:context:completion:paywallCompletion:)
38
+ func launch(label: String?, context: NSDictionary?, callback: @escaping RCTResponseSenderBlock, paywallCallback _: @escaping RCTResponseSenderBlock) {
39
+ var paywallLaunchContext: PaywallLaunchContext?
40
+
41
+ var productGroups: [String]?
42
+ var customAttributes: [String: Any]?
43
+ if let context = context {
44
+ if let contextProductGroups = context["productGroups"] as? [String] {
45
+ productGroups = contextProductGroups
46
+ }
47
+ if let contextCustomAttributes = context["customAttributes"] as? [String: Any] {
48
+ customAttributes = contextCustomAttributes
49
+ }
50
+ }
51
+
52
+ if productGroups != nil || customAttributes != nil {
53
+ paywallLaunchContext = PaywallLaunchContext(productGroups: productGroups, customAttributes: customAttributes)
54
+ }
55
+
56
+ NamiCampaignManager.launch(label: label, context: paywallLaunchContext, launchHandler: { success, error in
40
57
  callback([success, error?._code as Any])
41
- }, paywallActionHandler: { campaignId, campaignLabel, paywallId, action, sku, purchaseError, purchases in
58
+ }, paywallActionHandler: { campaignId, campaignName, campaignType, campaignLabel, campaignUrl, paywallId, paywallName, segmentId, externalSegmentId, paywallLaunchContext, action, sku, purchaseError, purchases, deeplinkUrl in
42
59
  let actionString: String
43
60
  switch action {
44
61
  case .show_paywall:
@@ -65,6 +82,8 @@ class RNNamiCampaignManager: RCTEventEmitter {
65
82
  actionString = "PURCHASE_CANCELLED"
66
83
  case .purchase_unknown:
67
84
  actionString = "PURCHASE_UNKNOWN"
85
+ case .deeplink:
86
+ actionString = "DEEPLINK"
68
87
  @unknown default:
69
88
  actionString = "PURCHASE_UNKNOWN"
70
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nami-sdk",
3
- "version": "3.0.13",
3
+ "version": "3.0.14",
4
4
  "description": "React Native Module for Nami - Easy subscriptions & in-app purchases, with powerful built-in paywalls and A/B testing.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -20,7 +20,7 @@ Pod::Spec.new do |s|
20
20
  s.source_files = "ios/**/*.{h,m,swift}"
21
21
  s.requires_arc = true
22
22
 
23
- s.dependency 'Nami', '3.0.15'
23
+ s.dependency 'Nami', '3.0.16'
24
24
  s.dependency 'React'
25
25
 
26
26
  end
@@ -7,6 +7,7 @@ export const NamiCampaignManager: {
7
7
  isCampaignAvailable: (label?: string) => boolean;
8
8
  launch: (
9
9
  label?: string,
10
+ context?: PaywallLaunchContext,
10
11
  resultCallback?: (success: boolean, error?: LaunchCampaignError) => void,
11
12
  actionCallback?: (
12
13
  action: NamiPaywallAction,
@@ -55,3 +56,8 @@ export enum LaunchCampaignResultAction {
55
56
  export type FailureResultObject = {
56
57
  error: string;
57
58
  };
59
+
60
+ export type PaywallLaunchContext = {
61
+ productGroups?: string[];
62
+ customAttributes: Map<string, string>;
63
+ };
@@ -6,7 +6,7 @@ export const NamiCampaignManager = {
6
6
  launchSubscription: undefined,
7
7
  emitter: new NativeEventEmitter(RNNamiCampaignManager),
8
8
  ...RNNamiCampaignManager,
9
- launch(label, resultCallback, actionCallback) {
9
+ launch(label, context, resultCallback, actionCallback) {
10
10
  this.launchSubscription?.remove();
11
11
  this.launchSubscription = this.emitter.addListener(
12
12
  "ResultCampaign",
@@ -36,6 +36,7 @@ export const NamiCampaignManager = {
36
36
  );
37
37
  RNNamiCampaignManager.launch(
38
38
  label ?? null,
39
+ context ?? null,
39
40
  resultCallback ?? (() => {}),
40
41
  actionCallback ?? (() => {})
41
42
  );
@@ -60,4 +60,5 @@ export enum NamiPaywallAction {
60
60
  PURCHASE_PENDING = "PURCHASE_PENDING",
61
61
  PURCHASE_UNKNOWN = "PURCHASE_UNKNOWN",
62
62
  PURCHASE_DEFERRED = "PURCHASE_DEFERRED",
63
+ DEEPLINK = "DEEPLINK",
63
64
  }