@purchasely/cordova-plugin-purchasely 2.0.1 → 2.2.0

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.
@@ -73,11 +73,12 @@ public class PurchaselyPlugin extends CordovaPlugin {
73
73
  switch (action) {
74
74
  case "startWithAPIKey":
75
75
  startWithAPIKey(
76
- args.getString(0),
76
+ getStringFromJson(args.getString(0)),
77
77
  args.getJSONArray(1),
78
- args.getString(2),
78
+ getStringFromJson(args.getString(2)),
79
79
  args.getInt(3),
80
80
  args.getInt(4),
81
+ getStringFromJson(args.getString(5)),
81
82
  callbackContext);
82
83
  break;
83
84
  case "close":
@@ -93,19 +94,19 @@ public class PurchaselyPlugin extends CordovaPlugin {
93
94
  getAnonymousUserId(callbackContext);
94
95
  break;
95
96
  case "userLogin":
96
- userLogin(args.getString(0), callbackContext);
97
+ userLogin(getStringFromJson(args.getString(0)), callbackContext);
97
98
  break;
98
99
  case "userLogout":
99
100
  userLogout();
100
101
  break;
101
102
  case "setLanguage":
102
- setLanguage(args.getString(0));
103
+ setLanguage(getStringFromJson(args.getString(0)));
103
104
  break;
104
105
  case "setLogLevel":
105
106
  setLogLevel(args.getInt(0));
106
107
  break;
107
108
  case "setAttribute":
108
- setAttribute(args.getInt(0), args.getString(1));
109
+ setAttribute(args.getInt(0), getStringFromJson(args.getString(1)));
109
110
  break;
110
111
  case "setDefaultPresentationResultHandler":
111
112
  setDefaultPresentationResultHandler(callbackContext);
@@ -121,26 +122,34 @@ public class PurchaselyPlugin extends CordovaPlugin {
121
122
  break;
122
123
  case "presentPresentationWithIdentifier":
123
124
  presentPresentationWithIdentifier(
124
- args.getString(0),
125
- args.getString(1),
125
+ getStringFromJson(args.getString(0)),
126
+ getStringFromJson(args.getString(1)),
126
127
  args.getBoolean(2),
127
128
  callbackContext
128
129
  );
129
130
  break;
131
+ case "presentPresentationForPlacement":
132
+ presentPresentationForPlacement(
133
+ getStringFromJson(args.getString(0)),
134
+ getStringFromJson(args.getString(1)),
135
+ args.getBoolean(2),
136
+ callbackContext
137
+ );
138
+ break;
130
139
  case "presentProductWithIdentifier":
131
140
  presentProductWithIdentifier(
132
- args.getString(0),
133
- args.getString(1),
134
- args.getString(2),
141
+ getStringFromJson(args.getString(0)),
142
+ getStringFromJson(args.getString(1)),
143
+ getStringFromJson(args.getString(2)),
135
144
  args.getBoolean(3),
136
145
  callbackContext
137
146
  );
138
147
  break;
139
148
  case "presentPlanWithIdentifier":
140
149
  presentPlanWithIdentifier(
141
- args.getString(0),
142
- args.getString(1),
143
- args.getString(2),
150
+ getStringFromJson(args.getString(0)),
151
+ getStringFromJson(args.getString(1)),
152
+ getStringFromJson(args.getString(2)),
144
153
  args.getBoolean(3),
145
154
  callbackContext
146
155
  );
@@ -158,21 +167,21 @@ public class PurchaselyPlugin extends CordovaPlugin {
158
167
  userSubscriptions(callbackContext);
159
168
  break;
160
169
  case "handle":
161
- handle(args.getString(0), callbackContext);
170
+ handle(getStringFromJson(args.getString(0)), callbackContext);
162
171
  break;
163
172
  case "allProducts":
164
173
  allProducts(callbackContext);
165
174
  break;
166
175
  case "productWithIdentifier":
167
- productWithIdentifier(args.getString(0), callbackContext);
176
+ productWithIdentifier(getStringFromJson(args.getString(0)), callbackContext);
168
177
  break;
169
178
  case "planWithIdentifier":
170
- planWithIdentifier(args.getString(0), callbackContext);
179
+ planWithIdentifier(getStringFromJson(args.getString(0)), callbackContext);
171
180
  break;
172
181
  case "purchaseWithPlanVendorId":
173
182
  purchaseWithPlanVendorId(
174
- args.getString(0),
175
- args.getString(1),
183
+ getStringFromJson(args.getString(0)),
184
+ getStringFromJson(args.getString(1)),
176
185
  callbackContext
177
186
  );
178
187
  break;
@@ -195,6 +204,14 @@ public class PurchaselyPlugin extends CordovaPlugin {
195
204
  return true;
196
205
  }
197
206
 
207
+ private String getStringFromJson(String value) {
208
+ if(value == null || value.equals("null") || value.isEmpty()) {
209
+ return null;
210
+ }
211
+
212
+ return value;
213
+ }
214
+
198
215
  public static void sendPurchaseResult(PLYProductViewResult result, PLYPlan plan) {
199
216
  int productViewResult = 0;
200
217
  if(result == PLYProductViewResult.PURCHASED) {
@@ -224,6 +241,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
224
241
  String userId,
225
242
  int logLevel,
226
243
  int runningMode,
244
+ String cordovaSdkVersion,
227
245
  CallbackContext callbackContext) {
228
246
  ArrayList<String> list = new ArrayList<>();
229
247
  for (int i=0; i< stores.length(); i++) {
@@ -249,6 +267,7 @@ public class PurchaselyPlugin extends CordovaPlugin {
249
267
  .logLevel(LogLevel.values()[logLevel])
250
268
  .build();
251
269
 
270
+ Purchasely.setSdkBridgeVersion(cordovaSdkVersion);
252
271
  Purchasely.setAppTechnology(PLYAppTechnology.CORDOVA);
253
272
 
254
273
  Purchasely.start((isConfigured, error) -> {
@@ -390,6 +409,18 @@ public class PurchaselyPlugin extends CordovaPlugin {
390
409
  cordova.getActivity().startActivity(intent);
391
410
  }
392
411
 
412
+ private void presentPresentationForPlacement(String placementVendorId,
413
+ String contentId,
414
+ boolean isFullScreen,
415
+ CallbackContext callbackContext) {
416
+ presentationCallback = callbackContext;
417
+ Intent intent = PLYProductActivity.newIntent(cordova.getActivity());
418
+ intent.putExtra("placementId", placementVendorId);
419
+ intent.putExtra("contentId", contentId);
420
+ intent.putExtra("isFullScreen", isFullScreen);
421
+ cordova.getActivity().startActivity(intent);
422
+ }
423
+
393
424
  private void presentProductWithIdentifier(String productVendorId,
394
425
  String presentationVendorId,
395
426
  String contentId,
@@ -556,15 +587,23 @@ public class PurchaselyPlugin extends CordovaPlugin {
556
587
  (info, plyPresentationAction, map, plyProcessActionListener) -> {
557
588
  processActionListener = plyProcessActionListener;
558
589
 
590
+ String url = null;
591
+ if(map.getUrl() != null) {
592
+ url = map.getUrl().toString();
593
+ }
594
+
559
595
  HashMap<String, Object> parametersForCordova = new HashMap<>();
560
596
  parametersForCordova.put("title", map.getTitle());
561
- parametersForCordova.put("url", map.getUrl());
597
+ parametersForCordova.put("url", url);
562
598
  parametersForCordova.put("plan", transformPlanToMap(map.getPlan()));
563
599
  parametersForCordova.put("presentation", map.getPresentation());
564
600
 
565
601
  HashMap<String, Object> infoMap = new HashMap<>();
566
602
  if(info.getContentId() != null) infoMap.put("contentId", info.getContentId());
567
603
  if(info.getPresentationId() != null) infoMap.put("presentationId", info.getPresentationId());
604
+ if(info.getPlacementId() != null) infoMap.put("placementId", info.getPlacementId());
605
+ if(info.getAbTestId() != null) infoMap.put("abTestId", info.getAbTestId());
606
+ if(info.getAbTestVariantId() != null) infoMap.put("abTestVariantId", info.getAbTestVariantId());
568
607
 
569
608
  HashMap<String, Object> resultForCordova = new HashMap<>();
570
609
  resultForCordova.put("info", infoMap);
@@ -28,6 +28,7 @@
28
28
  - (void)isReadyToPurchase:(CDVInvokedUrlCommand*)command;
29
29
  - (void)setDefaultPresentationResultHandler:(CDVInvokedUrlCommand*)command;
30
30
  - (void)presentPresentationWithIdentifier:(CDVInvokedUrlCommand*)command;
31
+ - (void)presentPresentationForPlacement:(CDVInvokedUrlCommand*)command;
31
32
  - (void)presentPlanWithIdentifier:(CDVInvokedUrlCommand*)command;
32
33
  - (void)presentProductWithIdentifier:(CDVInvokedUrlCommand*)command;
33
34
  - (void)presentSubscriptions:(CDVInvokedUrlCommand*)command;